Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/home/landauf/painter/miniproject/effects/color.cpp

Go to the documentation of this file.
00001 #include "color.h"
00002 
00004 // Brigthness                                                                //
00006 brightness::brightness(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00007 {
00008     glutSetWindowTitle("Paint Application | Brightness");
00009 
00010     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00011 
00012     value1 = 20;
00013     limitValue1.set(-255, 255);
00014     imageRgbaCopy(img, temp);
00015    
00016     LBpressed = true;
00017     this->LBAction();
00018     LBpressed = false;
00019 }
00020 
00021 void brightness::action(int location)
00022 {
00023     img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + int(value1));
00024     img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + int(value1));
00025     img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + int(value1));
00026 }
00027 
00028 
00030 // Contrast                                                                  //
00032 contrast::contrast(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00033 {
00034     glutSetWindowTitle("Paint Application | Contrast");
00035 
00036     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00037 
00038     value1 = 20;
00039     limitValue1.set(-255, 255);
00040     imageRgbaCopy(img, temp);
00041    
00042     LBpressed = true;
00043     this->LBAction();
00044     LBpressed = false;
00045 }
00046 
00047 void contrast::action(int location)
00048 {
00049     if (value1 >= 0)
00050     {
00051         img->data[location].r = limitRGBA.intForceLimit(int((temp->data[location].r - 127.5) * 255.0 / (256.0 - value1)) + 128);
00052         img->data[location].g = limitRGBA.intForceLimit(int((temp->data[location].g - 127.5) * 255.0 / (256.0 - value1)) + 128);
00053         img->data[location].b = limitRGBA.intForceLimit(int((temp->data[location].b - 127.5) * 255.0 / (256.0 - value1)) + 128);
00054     }
00055     else
00056     {
00057         img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + int((temp->data[location].r - 128) / 255.0 * value1));
00058         img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + int((temp->data[location].g - 128) / 255.0 * value1));
00059         img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + int((temp->data[location].b - 128) / 255.0 * value1));
00060     }
00061 }
00062 
00064 // Saturation                                                               //
00066 saturation::saturation(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00067 {
00068     glutSetWindowTitle("Paint Application | Saturation");
00069 
00070     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00071 
00072     value1 = 20;
00073     limitValue1.set(-255, 255);
00074     imageRgbaCopy(img, temp);
00075    
00076     LBpressed = true;
00077     this->LBAction();
00078     LBpressed = false;
00079 }
00080 
00081 void saturation::action(int location)
00082 {
00083     int midcolor = int((temp->data[location].r + temp->data[location].g + temp->data[location].b) / 3);
00084     img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + int(value1 / 255.0 * (temp->data[location].r - midcolor)));
00085     img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + int(value1 / 255.0 * (temp->data[location].g - midcolor)));
00086     img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + int(value1 / 255.0 * (temp->data[location].b - midcolor)));
00087 }
00088 
00090 // Hue                                                                       //
00092 hue::hue(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00093 {
00094     glutSetWindowTitle("Paint Application | Hue");
00095 
00096     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00097 
00098     value1 = 20;
00099     limitValue1.set(0, 359);
00100     imageRgbaCopy(img, temp);
00101    
00102     LBpressed = true;
00103     this->LBAction();
00104     LBpressed = false;
00105 }
00106 
00107 void hue::action(int location)
00108 {
00109     Hsva HSVColor = RGBtoHSV(temp->data[location]);
00110         
00111     HSVColor.h += value1;
00112 
00113 //    while (HSVColor.h < 0)
00114 //        HSVColor.h += 359;
00115 //    while (HSVColor.h > 359)
00116 //        HSVColor.h -= 359;
00117 
00118     if (HSVColor.h > 359)
00119         HSVColor.h -= 359;
00120     if (HSVColor.h < 0)
00121         HSVColor.h += 359;
00122         
00123     img->data[location] = HSVtoRGB(HSVColor);
00124 }
00125 
00126 void hue::changeValue(char _key)
00127 {
00128     if (_key == GLUT_KEY_UP)
00129         value1 += 5;
00130     else if (_key == GLUT_KEY_DOWN)
00131         value1 -= 5;
00132         
00133     if (value1 > 359)
00134         value1 = 0;
00135     else if (value1 < 0)
00136         value1 = 359;
00137         
00138     if (!LBpressed)
00139     {
00140         LBpressed = true;
00141         this->LBAction();
00142         LBpressed = false;
00143     }
00144     else
00145         this->LBAction();
00146 }
00147 
00149 // Colorize                                                                  //
00151 colorize::colorize(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00152 {
00153     glutSetWindowTitle("Paint Application | Colorize");
00154 
00155     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00156 
00157     value1 = 20;
00158     limitValue1.set(0, 359);
00159     imageRgbaCopy(img, temp);
00160    
00161     LBpressed = true;
00162     this->LBAction();
00163     LBpressed = false;
00164 }
00165 
00166 void colorize::action(int location)
00167 {
00168     Hsva HSVColor = RGBtoHSV(temp->data[location]);
00169         
00170     HSVColor.h = value1;
00171 
00172     img->data[location] = HSVtoRGB(HSVColor);
00173 }
00174 
00175 void colorize::changeValue(char _key)
00176 {
00177     if (_key == GLUT_KEY_UP)
00178         value1 += 5;
00179     else if (_key == GLUT_KEY_DOWN)
00180         value1 -= 5;
00181         
00182     if (value1 > 359)
00183         value1 = 0;
00184     else if (value1 < 0)
00185         value1 = 359;
00186         
00187     if (!LBpressed)
00188     {
00189         LBpressed = true;
00190         this->LBAction();
00191         LBpressed = false;
00192     }
00193     else
00194         this->LBAction();
00195 }
00196 
00198 // Gray                                                                      //
00200 gray::gray(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00201 {
00202     glutSetWindowTitle("Paint Application | Gray");
00203 
00204     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00205     imageRgbaCopy(img, temp);
00206 
00207     LBpressed = true;
00208     this->LBAction();
00209     LBpressed = false;
00210 }
00211 
00212 void gray::action(int location)
00213 {
00214         int greyvalue;
00215         
00216         greyvalue = limitRGBA.intForceLimit(int((0.27 * temp->data[location].r) + (0.58 * temp->data[location].g) + (0.15 * temp->data[location].b)));
00217 
00218         img->data[location].r = greyvalue;
00219         img->data[location].g = greyvalue;
00220         img->data[location].b = greyvalue;
00221 }
00222 
00224 // Invert                                                                    //
00226 invert::invert(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00227 {
00228     glutSetWindowTitle("Paint Application | Invert");
00229 
00230     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00231     imageRgbaCopy(img, temp);
00232 
00233     LBpressed = true;
00234     this->LBAction();
00235     LBpressed = false;
00236 }
00237 
00238 void invert::action(int location)
00239 {
00240     img->data[location].r = 255 - img->data[location].r;
00241     img->data[location].g = 255 - img->data[location].g;
00242     img->data[location].b = 255 - img->data[location].b;
00243 }
00244 
00246 // Channel                                                                   //
00248 channel::channel(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00249 {
00250     glutSetWindowTitle("Paint Application | Channel");
00251 
00252     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00253 
00254     value1 = 20;
00255     limitValue1.set(-255, 255);
00256     imageRgbaCopy(img, temp);
00257 
00258     numModes = 3;
00259     this->changeMode(1);
00260 }
00261 
00262 void channel::action(int location)
00263 {
00264     img->data[location] = temp->data[location];
00265     
00266     if (mode == 1)
00267         img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + value1);
00268     else if (mode == 2)
00269         img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + value1);
00270     else if (mode == 3)
00271         img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + value1);
00272 }
00273 
00274 void channel::changeMode(char _mode)
00275 {
00276     mode = _mode;
00277     if (mode == 1)
00278         glutSetWindowTitle("Paint Application | Channel | Mode 1: Red");
00279     else if (mode == 2)
00280         glutSetWindowTitle("Paint Application | Channel | Mode 2: Green");
00281     else if (mode == 3)
00282         glutSetWindowTitle("Paint Application | Channel | Mode 3: Blue");
00283         
00284     LBpressed = true;
00285     this->LBAction();
00286     LBpressed = false;
00287 }
00288 
00290 // Posterize                                                                 //
00292 posterize::posterize(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00293 {
00294     glutSetWindowTitle("Paint Application | Posterize");
00295 
00296     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00297 
00298     value1 = 8;
00299     limitValue1.set(1, 255);
00300     imageRgbaCopy(img, temp);
00301    
00302     LBpressed = true;
00303     this->LBAction();
00304     LBpressed = false;
00305 }
00306 
00307 void posterize::action(int location)
00308 {
00309     float newValue1 = 255 / value1;
00310         
00311     img->data[location].r = limitRGBA.intForceLimit(int((temp->data[location].r + (newValue1 / 2)) / newValue1) * newValue1);
00312     img->data[location].g = limitRGBA.intForceLimit(int((temp->data[location].g + (newValue1 / 2)) / newValue1) * newValue1);
00313     img->data[location].b = limitRGBA.intForceLimit(int((temp->data[location].b + (newValue1 / 2)) / newValue1) * newValue1);
00314 }
00315 
00317 // Solarize                                                                  //
00319 solarize::solarize(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00320 {
00321     glutSetWindowTitle("Paint Application | Solarize");
00322 
00323     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00324 
00325     value1 = 150;
00326     limitValue1.set(0, 255);
00327     imageRgbaCopy(img, temp);
00328    
00329     LBpressed = true;
00330     this->LBAction();
00331     LBpressed = false;
00332 }
00333 
00334 void solarize::action(int location)
00335 {
00336     img->data[location] = temp->data[location];
00337     
00338     if (temp->data[location].r >= value1)
00339         img->data[location].r = 255 - temp->data[location].r;
00340     if (temp->data[location].g >= value1)
00341         img->data[location].g = 255 - temp->data[location].g;
00342     if (temp->data[location].b >= value1)
00343         img->data[location].b = 255 - temp->data[location].b;
00344 }

Generated on Mon Jan 30 09:13:02 2006 for Painter Framework by doxygen1.2.18