• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE Support
  • Sitemap
  • Contact Us
 

qimageblitz

inlinehsv.h

Go to the documentation of this file.
00001 #ifndef __PIXIE_INLINEHSV_H
00002 #define __PIXIE_INLINEHSV_H
00003 
00004 /*
00005  Copyright (C) 2005, 2007 Daniel M. Duley <daniel.duley@verizon.net>
00006 
00007 Redistribution and use in source and binary forms, with or without
00008 modification, are permitted provided that the following conditions
00009 are met:
00010 
00011 1. Redistributions of source code must retain the above copyright
00012    notice, this list of conditions and the following disclaimer.
00013 2. Redistributions in binary form must reproduce the above copyright
00014    notice, this list of conditions and the following disclaimer in the
00015    documentation and/or other materials provided with the distribution.
00016 
00017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 
00028 */
00029 
00030 #include <QColor>
00031 
00042 class InlineHSV
00043 {
00044 public:
00045     InlineHSV(){;}
00051     inline void convertRGB2HSV(unsigned int rgb);
00052     inline void convertRGB2HSV(int red, int green, int blue);
00058     inline void convertHSV2RGB(int hue, int saturation, int value);
00062     inline void convertHSV2RGB();
00063 
00064     inline void setHSV(int hue, int saturation, int value)
00065         {h = hue; s = saturation; v = value;}
00066     inline void setHue(int hue){h = hue;}
00067     inline void setSaturation(int saturation){s = saturation;}
00068     inline void setValue(int value){v = value;}
00069     inline int hue(){return(h);}
00070     inline int saturation(){return(s);}
00071     inline int value(){return(v);}
00072 
00073     inline void setRGB(int red, int green, int blue)
00074         {r = red; g = green; b=blue;}
00075     inline void setRed(int red){r = red;}
00076     inline void setGreen(int green){g = green;}
00077     inline void setBlue(int blue){b = blue;}
00078     inline int red(){return(r);}
00079     inline int green(){return(g);}
00080     inline int blue(){return(b);}
00081 private:
00082     int h, s, v;
00083     int r, g, b;
00084     int max, whatmax, min, delta;
00085     unsigned int f, p, q, t;
00086 };
00087 
00088 inline void InlineHSV::convertRGB2HSV(unsigned int pixel)
00089 {
00090     convertRGB2HSV(qRed(pixel), qGreen(pixel), qBlue(pixel));
00091 }
00092 
00093 inline void InlineHSV::convertRGB2HSV(int red, int green, int blue)
00094 {
00095     r = red; g = green; b = blue;
00096     h = 0;
00097     max = r;                               // maximum RGB component
00098     whatmax = 0;                            // r=>0, g=>1, b=>2
00099     if(g > max) { max = g; whatmax = 1; }
00100     if(b > max) { max = b; whatmax = 2; }
00101     min = r;                               // find minimum value
00102     if(g < min) min = g;
00103     if(b < min) min = b;
00104     delta = max-min;
00105     v = max;                                   // calc value
00106     s = max ? (510*delta+max)/(2*max) : 0;
00107     if(s == 0)
00108         h = -1;                                // undefined hue
00109     else{
00110         switch(whatmax){
00111         case 0:                             // red is max component
00112             h = (g >= b) ? (120*(g-b)+delta)/(2*delta) :
00113                 (120*(g-b+delta)+delta)/(2*delta) + 300;
00114             break;
00115         case 1:                             // green is max component
00116             h = (b > r) ? h = 120 + (120*(b-r)+delta)/(2*delta) :
00117                 60 + (120*(b-r+delta)+delta)/(2*delta);
00118             break;
00119         case 2:                             // blue is max component
00120             h = (r > g) ? h = 240 + (120*(r-g)+delta)/(2*delta) :
00121                 h = 180 + (120*(r-g+delta)+delta)/(2*delta);
00122             break;
00123         }
00124     }
00125 }
00126 
00127 inline void InlineHSV::convertHSV2RGB(int hue, int saturation, int value)
00128 {
00129     h = hue; s = saturation; v = value;
00130     convertHSV2RGB();
00131 }
00132 
00133 inline void InlineHSV::convertHSV2RGB()
00134 {
00135     if(h < -1 || s > 255 || v > 255)
00136         return;
00137 
00138     r = g = b = v;
00139     if(s > 0 && h != -1){
00140         if(h >= 360) h %= 360;
00141         f = h%60;
00142         h /= 60;
00143         p = (2*v*(255-s)+255)/510;
00144         if(h&1){
00145             q = (2*v*(15300-s*f)+15300)/30600;
00146             switch( h ) {
00147                 case 1: r=q; g=v, b=p; break;
00148                 case 3: r=p; g=q, b=v; break;
00149                 case 5: r=v; g=p, b=q; break;
00150             }
00151         } else {
00152             t = (2*v*(15300-(s*(60-f)))+15300)/30600;
00153             switch( h ) {
00154                 case 0: r=v; g=t, b=p; break;
00155                 case 2: r=p; g=v, b=t; break;
00156                 case 4: r=t; g=p, b=v; break;
00157             }
00158         }
00159     }
00160 }
00161 
00162 #endif
00163 

qimageblitz

Skip menu "qimageblitz"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDE Support

Skip menu "KDE Support"
  • akonadi
  • Decibel
  • grantlee
  • kdewin
  • phonon
  •     Backend
  • polkit-qt
  • qca
  • qimageblitz
  • soprano
  • strigi
  •     searchclient
  •     streamanalyzer
  •     streams
Generated for KDE Support by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal