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

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

Go to the documentation of this file.
00001 #include "artistic.h"
00002 
00004 // Chrome                                                                    //
00006 chrome::chrome(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00007 {
00008     glutSetWindowTitle("Paint Application | Chrome");
00009 
00010     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00011 
00012     value1 = 4;
00013     limitValue1.set(1, 20);
00014     value2 = 4;
00015     limitValue2.set(0, 100);
00016     
00017     imageRgbaCopy(img, temp);
00018    
00019     numModes = 2;
00020     this->changeMode(2);
00021 }
00022 
00023 void chrome::LBAction()
00024 {
00025     if (LBpressed)
00026     {
00027         int newColor, location;
00028         imageRgbaCopy(temp, temp2);
00029         gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value2, mode);
00030 
00031         for (int y = lowArea.y; y <= highArea.y; y++)
00032         {
00033             for (int x = lowArea.x; x <= highArea.x; x++)
00034             {
00035                 location = x + img->width * y;
00036                 newColor = temp2->data[location].r + temp2->data[location].g + temp2->data[location].b;
00037                 newColor = int(value1 / 2 * newColor);
00038                 while (newColor < 0 || newColor > 255)
00039                 {
00040                     if (newColor > 255)
00041                         newColor = 511 - newColor;
00042                     else if (newColor < 0)
00043                         newColor = abs(newColor);
00044                 }
00045                 img->data[location].r = newColor;
00046                 img->data[location].g = newColor;
00047                 img->data[location].b = newColor;
00048             }
00049         }
00050     }
00051 }
00052 
00053 void chrome::changeMode(char _mode)
00054 {
00055     mode = _mode;
00056     if (mode == 1)
00057         glutSetWindowTitle("Paint Application | Chrome | Mode 1: Simple");
00058     else if (mode == 2)
00059         glutSetWindowTitle("Paint Application | Chrome | Mode 2: Gaussian");
00060         
00061     LBpressed = true;
00062     this->LBAction();
00063     LBpressed = false;
00064 }
00065 
00067 // Relief                                                                    //
00069 relief::relief(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00070 {
00071     glutSetWindowTitle("Paint Application | Relief");
00072 
00073     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00074 
00075     value1 = 10;
00076     limitValue1.set(0, 50);
00077     value2 = 10;
00078     limitValue2.set(1, 50);
00079     
00080     bColorMenu = true;
00081     myColor = (Rgba){0, 0, 0, 255};
00082 
00083     opacity = 1;
00084         
00085     imageRgbaCopy(img, temp);
00086     numModes = 2;
00087     mode = 1;
00088     this->changeMode(1);
00089 }
00090 
00091 void relief::LBAction()
00092 {
00093     if (LBpressed)
00094     {
00095         imageRgbaCopy(temp, temp2);
00096         gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
00097 
00098         float newValue1 = 255 / value2;
00099         int location;
00100         
00101         for (int y = lowArea.y; y <= highArea.y; y++)
00102         {
00103             for (int x = lowArea.x; x <= highArea.x; x++)
00104             {
00105                 location = x + img->width * y;
00106                 img->data[location].r = limitRGBA.intForceLimit(int((temp2->data[location].r + (newValue1 / 2)) / newValue1) * newValue1);
00107                 img->data[location].g = limitRGBA.intForceLimit(int((temp2->data[location].g + (newValue1 / 2)) / newValue1) * newValue1);
00108                 img->data[location].b = limitRGBA.intForceLimit(int((temp2->data[location].b + (newValue1 / 2)) / newValue1) * newValue1);
00109             }
00110         }
00111         Rgba color, nearColor, borderColor;
00112         for (int y = lowArea.y; y <= highArea.y; y++)
00113         {
00114             for (int x = lowArea.x; x <= highArea.x; x++)
00115             {
00116                 location = x + img->width * y;
00117                 color = img->data[location];
00118                 borderColor.r = limitRGBA.intForceLimit(((1 - opacity) * img->data[location].r) + (opacity * myColor.r));
00119                 borderColor.g = limitRGBA.intForceLimit(((1 - opacity) * img->data[location].g) + (opacity * myColor.g));
00120                 borderColor.b = limitRGBA.intForceLimit(((1 - opacity) * img->data[location].b) + (opacity * myColor.b));
00121                 borderColor.a = 255;
00122                 
00123                 if (x >= 1)
00124                 {
00125                     nearColor = img->data[(x-1) + img->width * y];
00126                     if (color.r != nearColor.r || color.g != nearColor.g || color.b != nearColor.b)
00127                         if (nearColor.r != borderColor.r || nearColor.g != borderColor.g || nearColor.b != borderColor.b)
00128                             img->data[location] = borderColor;
00129                 }
00130                 if (y >= 1)
00131                 {
00132                     nearColor = img->data[x + img->width * (y - 1)];
00133                     if (color.r != nearColor.r || color.g != nearColor.g || color.b != nearColor.b)
00134                         if (nearColor.r != borderColor.r || nearColor.g != borderColor.g || nearColor.b != borderColor.b)
00135                             img->data[location] = borderColor;
00136                 }
00137             }
00138         }
00139     }
00140 }
00141 
00142 void relief::changeMode(char _mode)
00143 {
00144     mode = _mode;
00145     if (mode == 1)
00146         glutSetWindowTitle("Paint Application | Relief | Mode 1: Simple");
00147     else if (mode == 2)
00148         glutSetWindowTitle("Paint Application | Relief | Mode 2: Gaussian");
00149         
00150     LBpressed = true;
00151     this->LBAction();
00152     LBpressed = false;
00153 }
00154 
00155 void relief::changeValue(char _key)
00156 {
00157     if (_key == GLUT_KEY_UP)
00158         value1 += 1;
00159     else if (_key == GLUT_KEY_DOWN)
00160         value1 -= 1;
00161     else if (_key == GLUT_KEY_RIGHT)
00162         value2 += 1;
00163     else if (_key == GLUT_KEY_LEFT)
00164         value2 -= 1;
00165     else if (_key == GLUT_KEY_END)
00166     {
00167         if (opacity > 0)
00168             opacity = 0;
00169         else
00170             opacity = 1;
00171     }
00172     else if (_key == GLUT_KEY_PAGE_DOWN)
00173     {
00174         opacity += 0.1;
00175         if (opacity > 1)
00176             opacity = 1;
00177     }
00178             
00179     value1 = limitValue1.intForceLimit(value1);
00180     value2 = limitValue2.intForceLimit(value2);
00181 
00182     if (_key)
00183     {
00184         if (!LBpressed)
00185         {
00186             LBpressed = true;
00187             this->LBAction();
00188             LBpressed = false;
00189         }
00190         else
00191             this->LBAction();
00192     }
00193 }
00194 
00195 void relief::key(unsigned char _key)
00196 {
00197     inAction = inActionState;
00198 
00199     if (_key == ' ')
00200         bMenu = !bMenu;
00201 
00202     if (_key == 127)
00203     {
00204         opacity -= 0.1;
00205         if (opacity < 0)
00206             opacity = 0;
00207             
00208         if (!LBpressed)
00209         {
00210             LBpressed = true;
00211             this->LBAction();
00212             LBpressed = false;
00213         }
00214         else
00215             this->LBAction();
00216     }
00217 }
00218 
00219 void relief::specialKey(int _key)
00220 {
00221     inAction = inActionState;
00222 
00223     if (_key <= numModes)
00224         this->changeMode(_key);
00225         
00226     if (_key == GLUT_KEY_LEFT || _key == GLUT_KEY_RIGHT || _key == GLUT_KEY_UP || _key == GLUT_KEY_DOWN || _key == GLUT_KEY_END || _key == GLUT_KEY_PAGE_DOWN)
00227         this->changeValue(_key);
00228 }
00229 
00231 // Black and White                                                           //
00233 bw::bw(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00234 {
00235     glutSetWindowTitle("Paint Application | Black and White");
00236 
00237     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00238 
00239     value1 = 5;
00240     limitValue1.set(0, 100);
00241     value2 = 200;
00242     limitValue2.set(0, 255);
00243     
00244     imageRgbaCopy(img, temp);
00245     
00246     numModes = 2;
00247     this->changeMode(1);
00248 }
00249 
00250 void bw::LBAction()
00251 {
00252     if (LBpressed)
00253     {
00254         imageRgbaCopy(temp, temp2);
00255         
00256         int location, MAX;
00257         Rgba up, down, left, right;
00258         int finalColor;
00259         
00260         if (mode == 2)
00261         {
00262             for (int y = lowArea.y; y <= highArea.y; y++)
00263             {
00264                 for (int x = lowArea.x; x <= highArea.x; x++)
00265                 {
00266                     location = x + img->width * y;
00267                     if (x >= (lowArea.x + value1))
00268                         left = temp->data[int(x-value1) + img->width * y];
00269                     else
00270                         left = temp->data[lowArea.x + img->width * y];
00271 
00272                     if (x < (highArea.x - value1))
00273                         right = temp->data[int(x+value1) + img->width * y];
00274                     else
00275                         right = temp->data[highArea.x + img->width * y];
00276 
00277                     if (y >= (lowArea.y + value1))
00278                         up = temp->data[x + img->width * int(y-value1)];
00279                     else
00280                         up = temp->data[x + img->width * lowArea.y];
00281 
00282                     if (y < (highArea.y - value1))
00283                         down = temp->data[x + img->width * int(y+value1)];
00284                     else
00285                         down = temp->data[x + img->width * highArea.y];
00286                         
00287                     finalColor = (abs(left.r - right.r) + abs(up.r - down.r)) + (abs(left.g - right.g) + abs(up.g - down.g)) + (abs(left.b - right.b) + abs(up.b - down.b));
00288                     temp2->data[location].r = limitRGBA.intForceLimit(finalColor);
00289                     temp2->data[location].g = limitRGBA.intForceLimit(finalColor);
00290                     temp2->data[location].b = limitRGBA.intForceLimit(finalColor);
00291                 }
00292             }
00293         }
00294         
00295         gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, 1);
00296 
00297         for (int y = lowArea.y; y <= highArea.y; y++)
00298         {
00299             for (int x = lowArea.x; x <= highArea.x; x++)
00300             {
00301                 location = x + img->width * y;
00302                 
00303                 MAX = temp2->data[location].r;
00304                 if (temp2->data[location].g > MAX)
00305                     MAX = temp2->data[location].g;
00306                 if (temp2->data[location].b > MAX)
00307                     MAX = temp2->data[location].b;
00308                     
00309                 if (MAX <= value2)
00310                     img->data[location] = (Rgba){0, 0, 0, 255};
00311                 else
00312                     img->data[location] = (Rgba){255, 255, 255, 255};
00313             }
00314         }
00315     }
00316 }
00317 
00318 void bw::changeMode(char _mode)
00319 {
00320     mode = _mode;
00321     if (mode == 1)
00322         glutSetWindowTitle("Paint Application | Black and White | Mode 1: Brightness");
00323     else if (mode == 2)
00324         glutSetWindowTitle("Paint Application | Black and White | Mode 2: Edge");
00325         
00326     LBpressed = true;
00327     this->LBAction();
00328     LBpressed = false;
00329 }
00330 
00332 // Starlight                                                                 //
00334 starlight::starlight(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00335 {
00336     glutSetWindowTitle("Paint Application | Starlight");
00337 
00338     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00339 
00340     value1 = 15;
00341     limitValue1.set(0, 100);
00342     value2 = 40;
00343     limitValue2.set(0, 255);
00344     
00345     strength = 10;
00346     imageRgbaCopy(img, temp);
00347     
00348     bColorMenu = true;
00349     myColor = (Rgba){255, 0, 128, 255};
00350     
00351     numModes = 6;
00352     this->changeMode(1);
00353 }
00354 
00355 void starlight::LBAction()
00356 {
00357     if (LBpressed)
00358     {
00359         imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
00360         float newStrength = ((float)strength / 10)*((float)strength / 10);
00361         int location, MAX;
00362         for (int y = lowArea.y; y <= highArea.y; y++)
00363         {
00364             for (int x = lowArea.x; x <= highArea.x; x++)
00365             {
00366                 location = x + img->width * y;
00367                 
00368                 MAX = temp->data[location].r;
00369                 if (temp->data[location].g > MAX)
00370                     MAX = temp->data[location].g;
00371                 if (temp->data[location].b > MAX)
00372                     MAX = temp->data[location].b;
00373                     
00374                 if (MAX >= (255-value2))
00375                 {
00376                     if (mode <= 3)
00377                         temp2->data[location] = temp->data[location];
00378                     else
00379                         temp2->data[location] = myColor;
00380                     temp2->data[location].a = 255;
00381                 }
00382                 else
00383                     temp2->data[location] = (Rgba){0,0,0,0};
00384 //                    temp2->data[location].a = 0;
00385             }
00386         }
00387         if ((mode % 3) == 1 || (mode % 3) == 2)
00388         {
00389             horizontal_blur(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode, 1);
00390             vertical_blur(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode, 2);
00391         }
00392         if ((mode % 3) == 1 || (mode % 3) == 0)
00393         {
00394             motion_blur(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, 45, mode, 2);
00395             motion_blur(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, 135, mode, 2);
00396         }
00397 
00398         for (int y = lowArea.y; y <= highArea.y; y++)
00399         {
00400             for (int x = lowArea.x; x <= highArea.x; x++)
00401             {
00402                 location = x + img->width * y;
00403                 img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + ((float)(img->data[location].a)/255) * newStrength * img->data[location].r);
00404                 img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + ((float)(img->data[location].a)/255) * newStrength * img->data[location].g);
00405                 img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + ((float)(img->data[location].a)/255) * newStrength * img->data[location].b);
00406                 img->data[location].a = 255;
00407 //                img->data[location] = temp2->data[location];
00408             }
00409         }
00410         display = img;
00411         this->refreshImage();
00412     }
00413 }
00414 
00415 void starlight::changeMode(char _mode)
00416 {
00417     mode = _mode;
00418     if (mode == 1)
00419         glutSetWindowTitle("Paint Application | Starlight | Mode 1: Star");
00420     else if (mode == 2)
00421         glutSetWindowTitle("Paint Application | Starlight | Mode 2: Cross");
00422     else if (mode == 3)
00423         glutSetWindowTitle("Paint Application | Starlight | Mode 3: X");
00424     else if (mode == 4)
00425         glutSetWindowTitle("Paint Application | Starlight | Mode 4: Colorized Star");
00426     else if (mode == 5)
00427         glutSetWindowTitle("Paint Application | Starlight | Mode 5: Colorized Cross");
00428     else if (mode == 6)
00429         glutSetWindowTitle("Paint Application | Starlight | Mode 6: Colorized X");
00430         
00431     if (!LBpressed)
00432     {
00433         LBpressed = true;
00434         this->LBAction();
00435         LBpressed = false;
00436     }
00437     else
00438         this->LBAction();
00439 }
00440 
00442 // Shine                                                                     //
00444 shine::shine(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00445 {
00446     glutSetWindowTitle("Paint Application | Shine");
00447 
00448     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00449 
00450     value1 = 15;
00451     limitValue1.set(0, 200);
00452     value2 = 40;
00453     limitValue2.set(0, 255);
00454 
00455     strength = 10;
00456     imageRgbaCopy(img, temp);
00457 
00458     bColorMenu = true;
00459     myColor = (Rgba){230, 155, 0, 255};
00460 
00461     numModes = 2;
00462 
00463     this->changeMode(1);
00464 }
00465 
00466 void shine::LBAction()
00467 {
00468     if (LBpressed)
00469     {
00470         imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
00471         float newStrength = ((float)strength / 10)*((float)strength / 10);
00472         int location, MAX;
00473         for (int y = lowArea.y; y <= highArea.y; y++)
00474         {
00475             for (int x = lowArea.x; x <= highArea.x; x++)
00476             {
00477                 location = x + img->width * y;
00478 
00479                 MAX = temp->data[location].r;
00480                 if (temp->data[location].g > MAX)
00481                     MAX = temp->data[location].g;
00482                 if (temp->data[location].b > MAX)
00483                     MAX = temp->data[location].b;
00484 
00485                 if (MAX >= (255-value2))
00486                 {
00487                     if (mode == 1)
00488                         temp2->data[location] = temp->data[location];
00489                     else if (mode == 2)
00490                         temp2->data[location] = myColor;
00491                     temp2->data[location].a = 255;
00492                 }
00493                 else
00494                     temp2->data[location] = (Rgba){0,0,0,0};
00495             }
00496         }
00497 
00498         // radial blur
00499         int newX, newY;
00500         imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
00501         float radius, angle;
00502         int maxY;
00503         int newValue1;
00504         int oldValue1, olderValue1;
00505 
00506         int R, G, B, A, count;
00507         point middle = mouse;
00508 
00509         // upper left quadrant
00510         for (int x = lowArea.x; x <= middle.x; x++)
00511         {
00512             if (x != lowArea.x)
00513                 maxY = lowArea.y;
00514             else
00515                 maxY = middle.y;
00516 
00517             for (int y = lowArea.y; y <= maxY; y++)
00518             {
00519                 newX = (middle.x - x);
00520                 newY = (middle.y - y);
00521                 radius = sqrt(newX*newX + newY*newY);
00522                 angle = atan((float)abs(newX) / abs(newY));
00523                 newValue1 = 0;
00524                 for (int r = 0; r <= (radius + value1); r++)
00525                 {
00526                     olderValue1 = oldValue1;
00527                     oldValue1 = newValue1;
00528                     newValue1 = int((float)r / (radius + value1) * value1);
00529                     if (r == 0)
00530                     {
00531                         R = 0;
00532                         G = 0;
00533                         B = 0;
00534                         A = 0;
00535                         count = 0;
00536                     }
00537                     else if (r >= newValue1 && olderValue1 == newValue1)
00538                     {
00539                         // SUBTRACT
00540                         int r2 = r - 1;
00541                         newX = int(middle.x - sin(angle)*(r2-2*newValue1));
00542                         newY = int(middle.y - cos(angle)*(r2-2*newValue1));
00543                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00544                         {
00545                             location = newX + img->width * newY;
00546                             count--;
00547                             R -= temp2->data[location].r;
00548                             G -= temp2->data[location].g;
00549                             B -= temp2->data[location].b;
00550                             A -= temp2->data[location].a;
00551                         }
00552                     }
00553 
00554                     if (r <= sqrt(int((highArea.x - lowArea.x + 1)/2)*int((highArea.x - lowArea.x + 1)/2) + int((highArea.y - lowArea.y + 1)/2)*int((highArea.y - lowArea.y + 1)/2)));
00555                     {
00556                         // ADD
00557                         newX = int(middle.x - sin(angle)*r);
00558                         newY = int(middle.y - cos(angle)*r);
00559                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00560                         {
00561                             location = newX + img->width * newY;
00562                             count++;
00563                             R += temp2->data[location].r;
00564                             G += temp2->data[location].g;
00565                             B += temp2->data[location].b;
00566                             A += temp2->data[location].a;
00567                         }
00568                         // DRAW
00569                         newX = int(middle.x - sin(angle)*(r-0*newValue1));
00570                         newY = int(middle.y - cos(angle)*(r-0*newValue1));
00571                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00572                         {
00573                             location = newX + img->width * newY;
00574                             if (count != 0)
00575                                 img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), limitRGBA.intForceLimit(A / count)};
00576                         }
00577                     }
00578                 }
00579             }
00580         }
00581 
00582         // lower left quadrant
00583         for (int x = lowArea.x; x <= middle.x; x++)
00584         {
00585             if (x != lowArea.x)
00586                 maxY = highArea.y;
00587             else
00588                 maxY = middle.y;
00589 
00590             for (int y = highArea.y; y >= maxY; y--)
00591             {
00592                 newX = (middle.x - x);
00593                 newY = (middle.y - y);
00594                 radius = sqrt(newX*newX + newY*newY);
00595                 angle = atan((float)abs(newX) / abs(newY));
00596                 newValue1 = 0;
00597                 for (int r = 0; r <= (radius + value1); r++)
00598                 {
00599                     olderValue1 = oldValue1;
00600                     oldValue1 = newValue1;
00601                     newValue1 = int((float)r / (radius + value1) * value1);
00602                     if (r == 0)
00603                     {
00604                         R = 0;
00605                         G = 0;
00606                         B = 0;
00607                         A = 0;
00608                         count = 0;
00609                     }
00610                     else if (r >= newValue1 && olderValue1 == newValue1)
00611                     {
00612                         // SUBTRACT
00613                         int r2 = r - 1;
00614                         newX = int(middle.x - sin(angle)*(r2-2*newValue1));
00615                         newY = int(middle.y + cos(angle)*(r2-2*newValue1));
00616                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00617                         {
00618                             location = newX + img->width * newY;
00619                             count--;
00620                             R -= temp2->data[location].r;
00621                             G -= temp2->data[location].g;
00622                             B -= temp2->data[location].b;
00623                             A -= temp2->data[location].a;
00624                         }
00625                     }
00626 
00627                     if (r <= sqrt(int((highArea.x - lowArea.x + 1)/2)*int((highArea.x - lowArea.x + 1)/2) + int((highArea.y - lowArea.y + 1)/2)*int((highArea.y - lowArea.y + 1)/2)));
00628                     {
00629                         // ADD
00630                         newX = int(middle.x - sin(angle)*r);
00631                         newY = int(middle.y + cos(angle)*r);
00632                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00633                         {
00634                             location = newX + img->width * newY;
00635                             count++;
00636                             R += temp2->data[location].r;
00637                             G += temp2->data[location].g;
00638                             B += temp2->data[location].b;
00639                             A += temp2->data[location].a;
00640                         }
00641                         // DRAW
00642                         newX = int(middle.x - sin(angle)*(r-0*newValue1));
00643                         newY = int(middle.y + cos(angle)*(r-0*newValue1));
00644                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00645                         {
00646                             location = newX + img->width * newY;
00647                             if (count != 0)
00648                                 img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), limitRGBA.intForceLimit(A / count)};
00649                         }
00650                     }
00651                 }
00652             }
00653         }
00654 
00655         // upper right quadrant
00656         for (int x = highArea.x; x >= middle.x; x--)
00657         {
00658             if (x != highArea.x)
00659                 maxY = lowArea.y;
00660             else
00661                 maxY = middle.y;
00662 
00663             for (int y = lowArea.y; y <= maxY; y++)
00664             {
00665                 newX = (middle.x - x);
00666                 newY = (middle.y - y);
00667                 radius = sqrt(newX*newX + newY*newY);
00668                 angle = atan((float)abs(newX) / abs(newY));
00669                 newValue1 = 0;
00670                 for (int r = 0; r <= (radius + value1); r++)
00671                 {
00672                     olderValue1 = oldValue1;
00673                     oldValue1 = newValue1;
00674                     newValue1 = int((float)r / (radius + value1) * value1);
00675                     if (r == 0)
00676                     {
00677                         R = 0;
00678                         G = 0;
00679                         B = 0;
00680                         A = 0;
00681                         count = 0;
00682                     }
00683                     else if (r >= newValue1 && olderValue1 == newValue1)
00684                     {
00685                         // SUBTRACT
00686                         int r2 = r - 1;
00687                         newX = int(middle.x + sin(angle)*(r2-2*newValue1));
00688                         newY = int(middle.y - cos(angle)*(r2-2*newValue1));
00689                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00690                         {
00691                             location = newX + img->width * newY;
00692                             count--;
00693                             R -= temp2->data[location].r;
00694                             G -= temp2->data[location].g;
00695                             B -= temp2->data[location].b;
00696                             A -= temp2->data[location].a;
00697                         }
00698                     }
00699 
00700                     if (r <= sqrt(int((highArea.x - lowArea.x + 1)/2)*int((highArea.x - lowArea.x + 1)/2) + int((highArea.y - lowArea.y + 1)/2)*int((highArea.y - lowArea.y + 1)/2)));
00701                     {
00702                         // ADD
00703                         newX = int(middle.x + sin(angle)*r);
00704                         newY = int(middle.y - cos(angle)*r);
00705                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00706                         {
00707                             location = newX + img->width * newY;
00708                             count++;
00709                             R += temp2->data[location].r;
00710                             G += temp2->data[location].g;
00711                             B += temp2->data[location].b;
00712                             A += temp2->data[location].a;
00713                         }
00714                         // DRAW
00715                         newX = int(middle.x + sin(angle)*(r-0*newValue1));
00716                         newY = int(middle.y - cos(angle)*(r-0*newValue1));
00717                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00718                         {
00719                             location = newX + img->width * newY;
00720                             if (count != 0)
00721                                 img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), limitRGBA.intForceLimit(A / count)};
00722                         }
00723                     }
00724                 }
00725             }
00726         }
00727 
00728         // lower right quadrant
00729         for (int x = highArea.x; x >= middle.x; x--)
00730         {
00731             if (x != highArea.x)
00732                 maxY = highArea.y;
00733             else
00734                 maxY = middle.y;
00735 
00736             for (int y = highArea.y; y >= maxY; y--)
00737             {
00738                 newX = (middle.x - x);
00739                 newY = (middle.y - y);
00740                 radius = sqrt(newX*newX + newY*newY);
00741                 angle = atan((float)abs(newX) / abs(newY));
00742                 newValue1 = 0;
00743                 for (int r = 0; r <= (radius + value1); r++)
00744                 {
00745                     olderValue1 = oldValue1;
00746                     oldValue1 = newValue1;
00747                     newValue1 = int((float)r / (radius + value1) * value1);
00748                     if (r == 0)
00749                     {
00750                         R = 0;
00751                         G = 0;
00752                         B = 0;
00753                         A = 0;
00754                         count = 0;
00755                     }
00756                     else if (r >= newValue1 && olderValue1 == newValue1)
00757                     {
00758                         // SUBTRACT
00759                         int r2 = r - 1;
00760                         newX = int(middle.x + sin(angle)*(r2-2*newValue1));
00761                         newY = int(middle.y + cos(angle)*(r2-2*newValue1));
00762                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00763                         {
00764                             location = newX + img->width * newY;
00765                             count--;
00766                             R -= temp2->data[location].r;
00767                             G -= temp2->data[location].g;
00768                             B -= temp2->data[location].b;
00769                             A -= temp2->data[location].a;
00770                         }
00771                     }
00772 
00773                     if (r <= sqrt(int((highArea.x - lowArea.x + 1)/2)*int((highArea.x - lowArea.x + 1)/2) + int((highArea.y - lowArea.y + 1)/2)*int((highArea.y - lowArea.y + 1)/2)));
00774                     {
00775                         // ADD
00776                         newX = int(middle.x + sin(angle)*r);
00777                         newY = int(middle.y + cos(angle)*r);
00778                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00779                         {
00780                             location = newX + img->width * newY;
00781                             count++;
00782                             R += temp2->data[location].r;
00783                             G += temp2->data[location].g;
00784                             B += temp2->data[location].b;
00785                             A += temp2->data[location].a;
00786                         }
00787                         // DRAW
00788                         newX = int(middle.x + sin(angle)*(r-0*newValue1));
00789                         newY = int(middle.y + cos(angle)*(r-0*newValue1));
00790                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00791                         {
00792                             location = newX + img->width * newY;
00793                             if (count != 0)
00794                                 img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), limitRGBA.intForceLimit(A / count)};
00795                         }
00796                     }
00797                 }
00798             }
00799         }
00800 
00801         // fehlerkorrektur
00802         for (int y = lowArea.y; y <= highArea.y; y++)
00803         {
00804             for (int x = lowArea.x; x <= highArea.x; x++)
00805             {
00806                 location = x + img->width * y;
00807                 if (img->data[location].a == 0)
00808                 {
00809                     R = 0; G = 0; B = 0; A = 0; count = 0;
00810                     for (int iy = -1; iy <= 1; iy++)
00811                     {
00812                         for (int ix = -1; ix <= 1; ix++)
00813                         {
00814                             newX = x + ix;
00815                             newY = y + iy;
00816                             location = newX + img->width * newY;
00817                             if ((!((ix == 0) && (iy == 0))) && newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00818                             {
00819                                 location = newX + img->width * newY;
00820                                 R += img->data[location].r;
00821                                 G += img->data[location].g;
00822                                 B += img->data[location].b;
00823                                 A += img->data[location].a;
00824                                 count++;
00825                             }
00826                         }
00827                     }
00828                     location = x + img->width * y;
00829                     if (count > 0)
00830                     {
00831                         location = x + img->width * y;
00832                         img->data[location].r = limitRGBA.intForceLimit((float)R / count);
00833                         img->data[location].g = limitRGBA.intForceLimit((float)G / count);
00834                         img->data[location].b = limitRGBA.intForceLimit((float)B / count);
00835                         img->data[location].a = limitRGBA.intForceLimit((float)A / count);
00836                     }
00837                 }
00838             }
00839         }
00840 
00841         gaussian(temp2, img, lowArea.x, lowArea.y, highArea.x, highArea.y, 2, 2);
00842 
00843         // finalize
00844         for (int y = lowArea.y; y <= highArea.y; y++)
00845         {
00846             for (int x = lowArea.x; x <= highArea.x; x++)
00847             {
00848                 location = x + img->width * y;
00849                 img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + ((float)(temp2->data[location].a)/255) * newStrength * img->data[location].r);
00850                 img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + ((float)(temp2->data[location].a)/255) * newStrength * img->data[location].g);
00851                 img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + ((float)(temp2->data[location].a)/255) * newStrength * img->data[location].b);
00852                 img->data[location].a = 255;
00853             }
00854         }
00855         display = img;
00856         this->refreshImage();
00857     }
00858 }
00859 
00860 void shine::changeMode(char _mode)
00861 {
00862     mode = _mode;
00863     if (mode == 1)
00864         glutSetWindowTitle("Paint Application | Shine | Mode 1: Normal");
00865     else if (mode == 2)
00866         glutSetWindowTitle("Paint Application | Shine | Mode 2: Colorized");
00867 
00868     if (!LBpressed)
00869     {
00870         LBpressed = true;
00871         this->LBAction();
00872         LBpressed = false;
00873     }
00874     else
00875         this->LBAction();
00876 }
00877 
00879 // Brush                                                                     //
00881 brush::brush(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00882 {
00883     glutSetWindowTitle("Paint Application | Brush");
00884 
00885     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00886 
00887     value1 = 10;
00888     limitValue1.set(5, 30);
00889     value2 = 2;
00890     limitValue2.set(1, 5);
00891     
00892     imageRgbaCopy(img, temp);
00893    
00894     LBpressed = true;
00895     this->LBAction();
00896     LBpressed = false;
00897 }
00898 
00899 void brush::LBAction()
00900 {
00901     if (LBpressed)
00902     {
00903         int highest = 0;
00904         int R = 0, G = 0, B = 0, count = 0;
00905         int newX, newY;
00906         int width = int(value2 * 2 + 1);
00907         int numElements = width * width;
00908         Rgba *color = new Rgba[width*width];
00909         
00910         for (int x = lowArea.x; x <= highArea.x; x++)
00911         {
00912             for (int y = int(lowArea.y - width); y <= highArea.y; y++)
00913             {
00914 /*
00915                 newX = int(x - value2);
00916                 newY = int(y + value2);
00917                 if (newX < lowArea.x) newX = lowArea.x;
00918                 if (newY < lowArea.y) newY = lowArea.y;
00919                 if (newX > (highArea.x - width)) newX = (highArea.x - width);
00920                 if (newY > highArea.y) newY = highArea.y;
00921 
00922                 //positionY = int(y - lowArea.y + width) % width;
00923                 positionY = (y + width) % width;
00924                 memcpy(&color[width * positionY], &temp->data[newX + img->width * newY], width * sizeof(Rgba));
00925 */
00926 /*
00927                 for (int iy = int(-value2); iy <= value2; iy++)
00928                 {
00929                     newX = int(x - value2);
00930                     newY = int(y + iy);
00931                     if (newX < lowArea.x) newX = lowArea.x;
00932                     if (newY < lowArea.y) newY = lowArea.y;
00933                     if (newX > (highArea.x - width)) newX = (highArea.x - width);
00934                     if (newY > highArea.y) newY = highArea.y;
00935 
00936                     positionY = int(iy + value2);
00937                     memcpy(&color[width * positionY], &temp->data[newX + img->width * newY], width * sizeof(Rgba));
00938                 }
00939 */
00940                 for (int iy = int(-value2); iy <= value2; iy++)
00941                 {
00942                     for (int ix = int(-value2); ix <= value2; ix++)
00943                     {
00944                         newX = x + ix;
00945                         newY = y + iy;
00946                         if (newX < lowArea.x) newX = lowArea.x;
00947                         if (newY < lowArea.y) newY = lowArea.y;
00948                         if (newX > highArea.x) newX = highArea.x;
00949                         if (newY > highArea.y) newY = highArea.y;
00950 
00951                         color[int(ix + value2) + width * int(iy + value2)] = temp->data[newX + img->width * newY];
00952 //                        memcpy(&color[width * positionY], &temp->data[newX + img->width * newY], width * sizeof(Rgba));
00953                     }
00954                 }
00955 
00956                 if (y >= 0)
00957                 {
00958                     for (int i = 0; i < numElements; i++)
00959                     {
00960                         if (color[i].a != 0)
00961                         {
00962                             color[i].a = 0;
00963                             for (int ii = i+1; ii < numElements; ii++)
00964                             {
00965                                 if (color[ii].a != 0)
00966                                 {
00967                                     if (abs(color[i].r - color[ii].r) <= value1 && abs(color[i].g - color[ii].g) <= value1 && abs(color[i].b - color[ii].b) <= value1)
00968                                     {
00969                                         color[ii].a = 0;
00970                                         color[i].a++;
00971                                     }
00972                                 }
00973                             }
00974                         }
00975                     }
00976                     highest = 0;
00977                     for (int i = 0; i < numElements; i++)
00978                     {
00979                         if (color[i].a > highest)
00980                             highest = color[i].a;
00981                     }
00982                     R = 0;
00983                     G = 0;
00984                     B = 0;
00985                     count = 0;
00986                     for (int i = 0; i < numElements; i++)
00987                     {
00988                         if (color[i].a == highest)
00989                         {
00990                             R += color[i].r;
00991                             G += color[i].g;
00992                             B += color[i].b;
00993                             count++;
00994                         }
00995                     }
00996                     img->data[x + img->width * y] = (Rgba){ limitRGBA.intForceLimit((float)R / count),
00997                                                             limitRGBA.intForceLimit((float)G / count),
00998                                                             limitRGBA.intForceLimit((float)B / count),
00999                                                             255 };
01000                 }
01001             }
01002         }
01003         delete color;
01004 
01005     }
01006 }
01007 
01009 // Spatter                                                                   //
01011 spatter::spatter(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01012 {
01013     glutSetWindowTitle("Paint Application | Spatter");
01014 
01015     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01016 
01017     value1 = 10;
01018     limitValue1.set(5, 30);
01019     value2 = 2;
01020     limitValue2.set(1, 5);
01021 
01022     imageRgbaCopy(img, temp);
01023 
01024     LBpressed = true;
01025     this->LBAction();
01026     LBpressed = false;
01027 }
01028 
01029 void spatter::LBAction()
01030 {
01031     if (LBpressed)
01032     {
01033         int newX, newY;
01034 
01035         for (int x = lowArea.x; x <= highArea.x; x++)
01036         {
01037             for (int y = lowArea.y; y <= highArea.y; y++)
01038             {
01039                 newX = x + rand() % int(value1 * 2) - int(value1);
01040                 newY = y + rand() % int(value1 * 2) - int(value1);
01041 
01042                 if (newX < lowArea.x) newX = lowArea.x;
01043                 if (newY < lowArea.y) newY = lowArea.y;
01044                 if (newX > highArea.x) newX = highArea.x;
01045                 if (newY > highArea.y) newY = highArea.y;
01046 
01047                 img->data[x + img->width * y] = temp->data[newX + img->width * newY];
01048             }
01049         }
01050     }
01051 }
01052 
01054 // Cutout                                                                    //
01056 cutout::cutout(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01057 {
01058     glutSetWindowTitle("Paint Application | Cutout");
01059 
01060     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01061 
01062     strength = 2;
01063 
01064     value1 = 3;
01065     limitValue1.set(2, 100);
01066     value2 = 20;
01067     limitValue2.set(5, 30);
01068 
01069     imageRgbaCopy(img, temp);
01070 
01071     LBpressed = true;
01072     this->LBAction();
01073     LBpressed = false;
01074 }
01075 
01076 void cutout::LBAction()
01077 {
01078     if (LBpressed)
01079     {
01080         /*
01081         imageRgbaCopy(temp, img);
01082         Rgba color[int(value1)];
01083         int highest[int(value1)];
01084         int numElements = img->width * img->height;
01085         int count[numElements];
01086         int currentDif, maxDif, min;
01087 
01088         if (strength > 0)
01089             gaussian(temp2, img, lowArea.x, lowArea.y, highArea.x, highArea.y, strength, 2);
01090         else
01091             imageRgbaCopy(temp, temp2);
01092 
01093         for (int i = 0; i < numElements; i++)
01094             count[i] = 1;
01095             
01096 
01097         for (int i = 0; i < numElements; i++)
01098         {
01099             if (count[i] != 0)
01100             {
01101                 count[i] = 0;
01102                 for (int ii = i+1; ii < numElements; ii++)
01103                 {
01104                     if (count[ii] != 0)
01105                     {
01106                         if (abs(temp2->data[i].r - temp2->data[ii].r) <= value2 && abs(temp2->data[i].g - temp2->data[ii].g) <= value2 && abs(temp2->data[i].b - temp2->data[ii].b) <= value2)
01107                         {
01108                             count[ii] = 0;
01109                             count[i]++;
01110                         }
01111                     }
01112                 }
01113             }
01114         }
01115 
01116         for (int k = 0; k < int(value1); k++)
01117             highest[k] = 0;
01118             
01119         for (int i = 0; i < numElements; i++)
01120             holdHighest(highest, int(value1), count[i]);
01121             
01122         for (int i = 0; i < numElements; i++)
01123             if (count[i] > 0)
01124                 for (int k = 0; k < int(value1); k++)
01125                     if (count[i] == highest[k])
01126                         color[k] = temp2->data[i];
01127 
01128         for (int k = 0; k < int(value1); k++)
01129             log(highest[k]);
01130             
01131 
01132         for (int newX, newY, i = 0; i < numElements; i++)
01133         {
01134             newX = i % img->width;
01135             newY = int(i / img->width);
01136 
01137             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
01138             {
01139                 min = 0;
01140                 for (int k = 0; k < int(value1); k++)
01141                 {
01142                     maxDif = abs(temp2->data[i].r - color[k].r);
01143                     currentDif = abs(temp2->data[i].g - color[k].g);
01144                     if (currentDif > maxDif) maxDif = currentDif;
01145                     currentDif = abs(temp2->data[i].b - color[k].b);
01146                     if (currentDif > maxDif) maxDif = currentDif;
01147 
01148                     highest[k] = maxDif;
01149                     if (highest[k] < highest[min]) min = k;
01150                 }
01151                 img->data[i] = color[min];
01152             }
01153         }
01154         */
01155         imageRgbaCopy(temp, img);
01156         Rgba color[int(value1)];
01157         int highest[int(value1)];
01158         int numElements = (highArea.x - lowArea.x + 1) * (highArea.y - lowArea.y + 1);
01159         int count[numElements];
01160         int currentDif, maxDif, min;
01161 
01162         if (strength > 0)
01163             gaussian(temp2, img, lowArea.x, lowArea.y, highArea.x, highArea.y, strength, 2);
01164         else
01165             imageRgbaCopy(temp, temp2);
01166 
01167         for (int i = 0; i < numElements; i++)
01168             count[i] = 1;
01169 
01170 
01171         for (int n, i = 0; i < numElements; i++)
01172         {
01173             n = (lowArea.x + (i % (highArea.x - lowArea.x + 1))) + img->width * (lowArea.y  + int(i / (highArea.x - lowArea.x + 1)));
01174             if (count[i] != 0)
01175             {
01176                 count[i] = 0;
01177                 for (int nn, ii = i+1; ii < numElements; ii++)
01178                 {
01179                     nn = (lowArea.x + (ii % (highArea.x - lowArea.x + 1))) + img->width * (lowArea.y  + int(ii / (highArea.x - lowArea.x + 1)));
01180                     if (count[ii] != 0)
01181                     {
01182                         if (abs(temp2->data[n].r - temp2->data[nn].r) <= value2 && abs(temp2->data[n].g - temp2->data[nn].g) <= value2 && abs(temp2->data[n].b - temp2->data[nn].b) <= value2)
01183                         {
01184                             count[ii] = 0;
01185                             count[i]++;
01186                         }
01187                     }
01188                 }
01189             }
01190         }
01191 
01192         for (int k = 0; k < int(value1); k++)
01193             highest[k] = 0;
01194 
01195         for (int i = 0; i < numElements; i++)
01196             holdHighest(highest, int(value1), count[i]);
01197 
01198         for (int i = 0; i < numElements; i++)
01199             if (count[i] > 0)
01200                 for (int k = 0; k < int(value1); k++)
01201                     if (count[i] == highest[k])
01202                         color[k] = temp2->data[(lowArea.x + (i % (highArea.x - lowArea.x + 1))) + img->width * (lowArea.y  + int(i / (highArea.x - lowArea.x + 1)))];
01203 
01204         for (int k = 0; k < int(value1); k++)
01205             log(highest[k]);
01206 
01207 
01208         for (int n, i = 0; i < numElements; i++)
01209         {
01210             n = (lowArea.x + (i % (highArea.x - lowArea.x + 1))) + img->width * (lowArea.y  + int(i / (highArea.x - lowArea.x + 1)));
01211 
01212             min = 0;
01213             for (int k = 0; k < int(value1); k++)
01214             {
01215                 maxDif = abs(temp2->data[n].r - color[k].r);
01216                 currentDif = abs(temp2->data[n].g - color[k].g);
01217                 if (currentDif > maxDif) maxDif = currentDif;
01218                 currentDif = abs(temp2->data[n].b - color[k].b);
01219                 if (currentDif > maxDif) maxDif = currentDif;
01220 
01221                 highest[k] = maxDif;
01222                 if (highest[k] < highest[min]) min = k;
01223             }
01224             img->data[n] = color[min];
01225         }
01226     }
01227 }
01228 
01230 // Strokes                                                                   //
01232 strokes::strokes(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01233 {
01234     glutSetWindowTitle("Paint Application | Strokes");
01235 
01236     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01237 
01238     strength = 2;
01239 
01240     value1 = 7;
01241     limitValue1.set(2, 30);
01242     value2 = 3;
01243     limitValue2.set(2, 15);
01244 
01245     imageRgbaCopy(img, temp);
01246 
01247     LBpressed = true;
01248     this->LBAction();
01249     LBpressed = false;
01250 }
01251 
01252 void strokes::LBAction()
01253 {
01254     if (LBpressed)
01255     {
01256         int newX, newY;
01257         int angle;
01258         float newAngle;
01259         
01260         if (strength > 0)
01261         {
01262             imageRgbaCopy(temp, img);
01263             gaussian(temp2, img, lowArea.x, lowArea.y, highArea.x, highArea.y, strength, 2);
01264         }
01265         else
01266             imageRgbaCopy(temp, temp2);
01267 
01268         imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
01269 
01270         for (int r = 0; r < 2; r++)
01271         {
01272             for (int y = lowArea.y; y <= highArea.y; y++)
01273             {
01274                 for (int x = lowArea.x; x <= highArea.x; x++)
01275                 {
01276                     if (img->data[x + img->width * y].a == 0)
01277                     {
01278                         newX = x;
01279                         newY = y;
01280                         angle = rand() % 360;
01281 
01282                         for (int j = 0; j < 3; j++)
01283                         {
01284                             for (int k = -int(value2 - (rand() % int(value2/2))); k < (value2 - (rand() % int(value2/2))); k++)
01285                             {
01286                                 newAngle = (float)(angle + (rand() % 30) - 15) / 180 * M_PI;
01287                                 imageRgbaDrawLine(img, int(newX + j + sin(newAngle) * (value1 - (rand() % int(value1/2))) + sin(newAngle + M_PI / 2) * k),
01288                                                        int(newY + cos(newAngle) * (value1 - (rand() % int(value1/2))) + cos(newAngle + M_PI / 2) * k),
01289                                                        int(newX + j - sin(newAngle) * (value1 - (rand() % int(value1/2))) + sin(newAngle + M_PI / 2) * k),
01290                                                        int(newY - cos(newAngle) * (value1 - (rand() % int(value1/2))) + cos(newAngle + M_PI / 2) * k),
01291                                                        temp2->data[newX + img->width * newY],
01292                                                        lowArea.x, lowArea.y, highArea.x, highArea.y);
01293                             }
01294                         }
01295                     }
01296                 }
01297             }
01298         }
01299         int randomCount = int((float)(img->width * img->height) / (2*value1 * 2*value2));
01300         for (int i = 0; i < randomCount; i++)
01301         {
01302             newX = lowArea.x + rand() % (highArea.x - lowArea.x);
01303             newY = lowArea.y + rand() % (highArea.y - lowArea.y);
01304             angle = rand() % 360;
01305 
01306             for (int j = 0; j < 3; j++)
01307             {
01308                 for (int k = -int(value2 - (rand() % int(value2/2))); k < (value2 - (rand() % int(value2/2))); k++)
01309                 {
01310                     newAngle = (float)(angle + (rand() % 30) - 15) / 180 * M_PI;
01311                     imageRgbaDrawLine(img, int(newX + j + sin(newAngle) * (value1 - (rand() % int(value1/2))) + sin(newAngle + M_PI / 2) * k),
01312                                            int(newY + cos(newAngle) * (value1 - (rand() % int(value1/2))) + cos(newAngle + M_PI / 2) * k),
01313                                            int(newX + j - sin(newAngle) * (value1 - (rand() % int(value1/2))) + sin(newAngle + M_PI / 2) * k),
01314                                            int(newY - cos(newAngle) * (value1 - (rand() % int(value1/2))) + cos(newAngle + M_PI / 2) * k),
01315                                            temp2->data[newX + img->width * newY],
01316                                            lowArea.x, lowArea.y, highArea.x, highArea.y);
01317                 }
01318             }
01319         }
01320     }
01321 }

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