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

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

Go to the documentation of this file.
00001 #include "matrices.h"
00002 
00004 // Blur                                                                      //
00006 blur::blur(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00007 {
00008     glutSetWindowTitle("Paint Application | Blur");
00009 
00010     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00011 
00012     imageRgbaCopy(img, temp);
00013     imageRgbaCopy(img, temp2);
00014 
00015     numModes = 7;
00016     this->changeMode(1);
00017 }
00018 
00019 void blur::LBAction()
00020 {
00021     if (LBpressed)
00022     {
00023         if (mode == 1 || mode == 2 || mode == 3 || mode == 4)
00024         {
00025             int loops = 1;
00026             float oldValue1 = value1;
00027             ImageRGBA *swap;
00028             
00029             imageRgbaCopy(temp, temp2);
00030 
00031             if (mode == 2)
00032                 loops = int(oldValue1);
00033 
00034             for (int l = 0; l < loops; l++)
00035             {
00036                 if (mode == 2 && l > 0)
00037                 {
00038                     value1 = int(exp((l*-l)/oldValue1) * oldValue1);
00039                     swap = img;
00040                     img = temp2;
00041                     temp2 = swap;
00042                 }
00043                 
00044                 if (value1 > 0)
00045                 {
00046                     // horizontal motion blur
00047                     if (mode == 1 ||  mode == 2 || mode == 3)
00048                     {
00049                         horizontal_blur(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
00050                     }
00051     
00052                     if (mode == 1 ||  mode == 2 || mode == 4)
00053                     {
00054                         if (mode != 4)
00055                         {
00056                             swap = img;
00057                             img = temp2;
00058                             temp2 = swap;
00059                         }
00060             
00061                         vertical_blur(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
00062                     }
00063                 }
00064             }
00065             value1 = oldValue1;
00066             display = img;
00067             this->refreshImage();
00068         }
00069         if (mode == 5) // motion
00070         {
00071             motion_blur(img, temp, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, value2, mode);
00072         }
00073         if (mode == 6) // radial
00074         {
00075 /*
00076             int newX, newY;
00077             imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
00078             point middle = point(int((highArea.x - lowArea.x)/2+1), int((highArea.y - lowArea.y)/2+1));
00079             float radius, angle;
00080             int R[4] = {0, 0, 0, 0};
00081             int G[4] = {0, 0, 0, 0};
00082             int B[4] = {0, 0, 0, 0};
00083             int count[4] = {0, 0, 0, 0};
00084             int maxY, location, location2;
00085             int newValue1;
00086             int oldValue1, olderValue1;
00087             
00088             int startX = 2 * (mouse.x - middle.x);
00089             int startY = 2 * (mouse.y - middle.y);
00090             if (startX > 0)
00091                 startX = 0;
00092             if (startY > 0)
00093                 startY = 0;
00094             middle = mouse;
00095 
00096             for (int x = startX; x <= middle.x; x++)
00097             {
00098                 if (x != startX)
00099                     maxY = startY;
00100                 else
00101                     maxY = middle.y;
00102 
00103                 for (int y = startY; y <= maxY; y++)
00104                 {
00105                     newX = (middle.x - x);
00106                     newY = (middle.y - y);
00107                     radius = sqrt(newX*newX + newY*newY);
00108                     angle = atan((float)abs(newX) / abs(newY));
00109                     newValue1 = 0;
00110                     for (int r = 0; r <= (radius + value1); r++)
00111                     {
00112                         olderValue1 = oldValue1;
00113                         oldValue1 = newValue1;
00114                         newValue1 = int((float)r / (radius + value1) * value1);
00115                         if (r == 0)
00116                         {
00117                             for (int i = 0; i < 4; i++)
00118                             {
00119                                 location = (lowArea.x + middle.x) + img->width * (lowArea.y + middle.y);
00120                                 newX =lowArea.x + middle.x;
00121                                 R[i] = 0;
00122                                 G[i] = 0;
00123                                 B[i] = 0;
00124                                 count[i] = 0;
00125                             }
00126                         }
00127                         else if (r >= newValue1 && olderValue1 == newValue1)
00128                         {
00129                             // SUBTRACT
00130                             int r2 = r - 1;
00131                             for (int i = 0; i < 4; i++)
00132                             {
00133                                 if (i == 0)
00134                                 {
00135                                     newX = lowArea.x + int(middle.x - sin(angle)*(r2-2*newValue1));
00136                                     newY = lowArea.y + int(middle.y - cos(angle)*(r2-2*newValue1));
00137                                 }
00138                                 if (i == 1)
00139                                 {
00140                                     newX = lowArea.x + int(middle.x - sin(angle)*(r2-2*newValue1));
00141                                     newY = lowArea.y + int(middle.y + cos(angle)*(r2-2*newValue1));
00142                                 }
00143                                 if (i == 2)
00144                                 {
00145                                     newX = lowArea.x + int(middle.x + sin(angle)*(r2-2*newValue1));
00146                                     newY = lowArea.y + int(middle.y + cos(angle)*(r2-2*newValue1));
00147                                 }
00148                                 if (i == 3)
00149                                 {
00150                                     newX = lowArea.x + int(middle.x + sin(angle)*(r2-2*newValue1));
00151                                     newY = lowArea.y + int(middle.y - cos(angle)*(r2-2*newValue1));
00152                                 }
00153                                 if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00154                                 {
00155                                     location = newX + img->width * newY;
00156                                     count[i]--;
00157                                     R[i] -= temp->data[location].r;
00158                                     G[i] -= temp->data[location].g;
00159                                     B[i] -= temp->data[location].b;
00160                                 }
00161                             }
00162                         }
00163     
00164                         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)));
00165                         {
00166                             // ADD
00167                             for (int i = 0; i < 4; i++)
00168                             {
00169                                 if (i == 0)
00170                                 {
00171                                     newX = lowArea.x + int(middle.x - sin(angle)*r);
00172                                     newY = lowArea.y + int(middle.y - cos(angle)*r);
00173                                 }
00174                                 if (i == 1)
00175                                 {
00176                                     newX = lowArea.x + int(middle.x - sin(angle)*r);
00177                                     newY = lowArea.y + int(middle.y + cos(angle)*r);
00178                                 }
00179                                 if (i == 2)
00180                                 {
00181                                     newX = lowArea.x + int(middle.x + sin(angle)*r);
00182                                     newY = lowArea.y + int(middle.y + cos(angle)*r);
00183                                 }
00184                                 if (i == 3)
00185                                 {
00186                                     newX = lowArea.x + int(middle.x + sin(angle)*r);
00187                                     newY = lowArea.y + int(middle.y - cos(angle)*r);
00188                                 }
00189                                 if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00190                                 {
00191                                     location = newX + img->width * newY;
00192                                     count[i]++;
00193                                     R[i] += temp->data[location].r;
00194                                     G[i] += temp->data[location].g;
00195                                     B[i] += temp->data[location].b;
00196                                 }
00197                             }
00198                             // DRAW
00199                             for (int i = 0; i < 4; i++)
00200                             {
00201                                 if (i == 0)
00202                                 {
00203                                     newX = lowArea.x + int(middle.x - sin(angle)*(r-newValue1));
00204                                     newY = lowArea.y + int(middle.y - cos(angle)*(r-newValue1));
00205                                 }
00206                                 if (i == 1)
00207                                 {
00208                                     newX = lowArea.x + int(middle.x - sin(angle)*(r-newValue1));
00209                                     newY = lowArea.y + int(middle.y + cos(angle)*(r-newValue1));
00210                                 }
00211                                 if (i == 2)
00212                                 {
00213                                     newX = lowArea.x + int(middle.x + sin(angle)*(r-newValue1));
00214                                     newY = lowArea.y + int(middle.y + cos(angle)*(r-newValue1));
00215                                 }
00216                                 if (i == 3)
00217                                 {
00218                                     newX = lowArea.x + int(middle.x + sin(angle)*(r-newValue1));
00219                                     newY = lowArea.y + int(middle.y - cos(angle)*(r-newValue1));
00220                                 }
00221                                 if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00222                                 {
00223                                     location = newX + img->width * newY;
00224                                     if (count != 0)
00225                                         img->data[location] = (Rgba){limitRGBA.intForceLimit(R[i] / count[i]), limitRGBA.intForceLimit(G[i] / count[i]), limitRGBA.intForceLimit(B[i] / count[i]), 255};
00226                                 }
00227                             }
00228                         }
00229                     }
00230                 }
00231             }
00232 */
00233 
00234             int newX, newY;
00235             imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
00236             float radius, angle;
00237             int maxY, location, location2;
00238             int newValue1;
00239             int oldValue1, olderValue1;
00240 
00241             int R, G, B, count;
00242             point middle = mouse;
00243 
00244             // upper left quadrant
00245             for (int x = lowArea.x; x <= middle.x; x++)
00246             {
00247                 if (x != lowArea.x)
00248                     maxY = lowArea.y;
00249                 else
00250                     maxY = middle.y;
00251 
00252                 for (int y = lowArea.y; y <= maxY; y++)
00253                 {
00254                     newX = (middle.x - x);
00255                     newY = (middle.y - y);
00256                     radius = sqrt(newX*newX + newY*newY);
00257                     angle = atan((float)abs(newX) / abs(newY));
00258                     newValue1 = 0;
00259                     for (int r = 0; r <= (radius + value1); r++)
00260                     {
00261                         olderValue1 = oldValue1;
00262                         oldValue1 = newValue1;
00263                         newValue1 = int((float)r / (radius + value1) * value1);
00264                         if (r == 0)
00265                         {
00266                             R = 0;
00267                             G = 0;
00268                             B = 0;
00269                             count = 0;
00270                         }
00271                         else if (r >= newValue1 && olderValue1 == newValue1)
00272                         {
00273                             // SUBTRACT
00274                             int r2 = r - 1;
00275                             newX = int(middle.x - sin(angle)*(r2-2*newValue1));
00276                             newY = int(middle.y - cos(angle)*(r2-2*newValue1));
00277                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00278                             {
00279                                 location = newX + img->width * newY;
00280                                 count--;
00281                                 R -= temp->data[location].r;
00282                                 G -= temp->data[location].g;
00283                                 B -= temp->data[location].b;
00284                             }
00285                         }
00286 
00287                         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)));
00288                         {
00289                             // ADD
00290                             newX = int(middle.x - sin(angle)*r);
00291                             newY = int(middle.y - cos(angle)*r);
00292                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00293                             {
00294                                 location = newX + img->width * newY;
00295                                 count++;
00296                                 R += temp->data[location].r;
00297                                 G += temp->data[location].g;
00298                                 B += temp->data[location].b;
00299                             }
00300                             // DRAW
00301                             newX = int(middle.x - sin(angle)*(r-1*newValue1));
00302                             newY = int(middle.y - cos(angle)*(r-1*newValue1));
00303                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00304                             {
00305                                 location = newX + img->width * newY;
00306                                 if (count != 0)
00307                                     img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), 255};
00308                             }
00309                         }
00310                     }
00311                 }
00312             }
00313 
00314             // lower left quadrant
00315             for (int x = lowArea.x; x <= middle.x; x++)
00316             {
00317                 if (x != lowArea.x)
00318                     maxY = highArea.y;
00319                 else
00320                     maxY = middle.y;
00321 
00322                 for (int y = highArea.y; y >= maxY; y--)
00323                 {
00324                     newX = (middle.x - x);
00325                     newY = (middle.y - y);
00326                     radius = sqrt(newX*newX + newY*newY);
00327                     angle = atan((float)abs(newX) / abs(newY));
00328                     newValue1 = 0;
00329                     for (int r = 0; r <= (radius + value1); r++)
00330                     {
00331                         olderValue1 = oldValue1;
00332                         oldValue1 = newValue1;
00333                         newValue1 = int((float)r / (radius + value1) * value1);
00334                         if (r == 0)
00335                         {
00336                             R = 0;
00337                             G = 0;
00338                             B = 0;
00339                             count = 0;
00340                         }
00341                         else if (r >= newValue1 && olderValue1 == newValue1)
00342                         {
00343                             // SUBTRACT
00344                             int r2 = r - 1;
00345                             newX = int(middle.x - sin(angle)*(r2-2*newValue1));
00346                             newY = int(middle.y + cos(angle)*(r2-2*newValue1));
00347                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00348                             {
00349                                 location = newX + img->width * newY;
00350                                 count--;
00351                                 R -= temp->data[location].r;
00352                                 G -= temp->data[location].g;
00353                                 B -= temp->data[location].b;
00354                             }
00355                         }
00356 
00357                         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)));
00358                         {
00359                             // ADD
00360                             newX = int(middle.x - sin(angle)*r);
00361                             newY = int(middle.y + cos(angle)*r);
00362                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00363                             {
00364                                 location = newX + img->width * newY;
00365                                 count++;
00366                                 R += temp->data[location].r;
00367                                 G += temp->data[location].g;
00368                                 B += temp->data[location].b;
00369                             }
00370                             // DRAW
00371                             newX = int(middle.x - sin(angle)*(r-1*newValue1));
00372                             newY = int(middle.y + cos(angle)*(r-1*newValue1));
00373                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00374                             {
00375                                 location = newX + img->width * newY;
00376                                 if (count != 0)
00377                                     img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), 255};
00378                             }
00379                         }
00380                     }
00381                 }
00382             }
00383 
00384             // upper right quadrant
00385             for (int x = highArea.x; x >= middle.x; x--)
00386             {
00387                 if (x != highArea.x)
00388                     maxY = lowArea.y;
00389                 else
00390                     maxY = middle.y;
00391 
00392                 for (int y = lowArea.y; y <= maxY; y++)
00393                 {
00394                     newX = (middle.x - x);
00395                     newY = (middle.y - y);
00396                     radius = sqrt(newX*newX + newY*newY);
00397                     angle = atan((float)abs(newX) / abs(newY));
00398                     newValue1 = 0;
00399                     for (int r = 0; r <= (radius + value1); r++)
00400                     {
00401                         olderValue1 = oldValue1;
00402                         oldValue1 = newValue1;
00403                         newValue1 = int((float)r / (radius + value1) * value1);
00404                         if (r == 0)
00405                         {
00406                             R = 0;
00407                             G = 0;
00408                             B = 0;
00409                             count = 0;
00410                         }
00411                         else if (r >= newValue1 && olderValue1 == newValue1)
00412                         {
00413                             // SUBTRACT
00414                             int r2 = r - 1;
00415                             newX = int(middle.x + sin(angle)*(r2-2*newValue1));
00416                             newY = int(middle.y - cos(angle)*(r2-2*newValue1));
00417                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00418                             {
00419                                 location = newX + img->width * newY;
00420                                 count--;
00421                                 R -= temp->data[location].r;
00422                                 G -= temp->data[location].g;
00423                                 B -= temp->data[location].b;
00424                             }
00425                         }
00426 
00427                         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)));
00428                         {
00429                             // ADD
00430                             newX = int(middle.x + sin(angle)*r);
00431                             newY = int(middle.y - cos(angle)*r);
00432                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00433                             {
00434                                 location = newX + img->width * newY;
00435                                 count++;
00436                                 R += temp->data[location].r;
00437                                 G += temp->data[location].g;
00438                                 B += temp->data[location].b;
00439                             }
00440                             // DRAW
00441                             newX = int(middle.x + sin(angle)*(r-1*newValue1));
00442                             newY = int(middle.y - cos(angle)*(r-1*newValue1));
00443                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00444                             {
00445                                 location = newX + img->width * newY;
00446                                 if (count != 0)
00447                                     img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), 255};
00448                             }
00449                         }
00450                     }
00451                 }
00452             }
00453 
00454             // lower right quadrant
00455             for (int x = highArea.x; x >= middle.x; x--)
00456             {
00457                 if (x != highArea.x)
00458                     maxY = highArea.y;
00459                 else
00460                     maxY = middle.y;
00461 
00462                 for (int y = highArea.y; y >= maxY; y--)
00463                 {
00464                     newX = (middle.x - x);
00465                     newY = (middle.y - y);
00466                     radius = sqrt(newX*newX + newY*newY);
00467                     angle = atan((float)abs(newX) / abs(newY));
00468                     newValue1 = 0;
00469                     for (int r = 0; r <= (radius + value1); r++)
00470                     {
00471                         olderValue1 = oldValue1;
00472                         oldValue1 = newValue1;
00473                         newValue1 = int((float)r / (radius + value1) * value1);
00474                         if (r == 0)
00475                         {
00476                             R = 0;
00477                             G = 0;
00478                             B = 0;
00479                             count = 0;
00480                         }
00481                         else if (r >= newValue1 && olderValue1 == newValue1)
00482                         {
00483                             // SUBTRACT
00484                             int r2 = r - 1;
00485                             newX = int(middle.x + sin(angle)*(r2-2*newValue1));
00486                             newY = int(middle.y + cos(angle)*(r2-2*newValue1));
00487                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00488                             {
00489                                 location = newX + img->width * newY;
00490                                 count--;
00491                                 R -= temp->data[location].r;
00492                                 G -= temp->data[location].g;
00493                                 B -= temp->data[location].b;
00494                             }
00495                         }
00496 
00497                         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)));
00498                         {
00499                             // ADD
00500                             newX = int(middle.x + sin(angle)*r);
00501                             newY = int(middle.y + cos(angle)*r);
00502                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00503                             {
00504                                 location = newX + img->width * newY;
00505                                 count++;
00506                                 R += temp->data[location].r;
00507                                 G += temp->data[location].g;
00508                                 B += temp->data[location].b;
00509                             }
00510                             // DRAW
00511                             newX = int(middle.x + sin(angle)*(r-1*newValue1));
00512                             newY = int(middle.y + cos(angle)*(r-1*newValue1));
00513                             if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00514                             {
00515                                 location = newX + img->width * newY;
00516                                 if (count != 0)
00517                                     img->data[location] = (Rgba){limitRGBA.intForceLimit(R / count), limitRGBA.intForceLimit(G / count), limitRGBA.intForceLimit(B / count), 255};
00518                             }
00519                         }
00520                     }
00521                 }
00522             }
00523 
00524             // fehlerkorrektur
00525             for (int y = lowArea.y; y <= highArea.y; y++)
00526             {
00527                 for (int x = lowArea.x; x <= highArea.x; x++)
00528                 {
00529                     location = x + img->width * y;
00530                     if (img->data[location].a == 0)
00531                     {
00532                         newX = (middle.x - (x - lowArea.x));
00533                         newY = (middle.y - (y - lowArea.y));
00534                         radius = sqrt(newX*newX + newY*newY);
00535                         angle = atan((float)abs(newX) / abs(newY));
00536                         int secondX, secondY;
00537                         for (int r = 0; r < radius; r++)
00538                         {
00539                             if (newX != 0)
00540                                 secondX = x + int((1.0 * newX / abs(newX)) * sin(angle)*r);
00541                             else
00542                                 secondX = x;
00543                             if (newY != 0)
00544                                 secondY = y + int((1.0 * newY / abs(newY)) * cos(angle)*r);
00545                             else
00546                                 secondY = y;
00547                                 
00548                             if (secondX >= lowArea.x && secondX <= highArea.x && secondY >= lowArea.y && secondY <= highArea.y)
00549                             {
00550                                 location2 = secondX + img->width * secondY;
00551                                 if (img->data[location2].a != 0)
00552                                 {
00553                                     img->data[location] = img->data[location2];
00554                                     break;
00555                                 }
00556                             }
00557                         }
00558                     }
00559                 }
00560             }
00561         }
00562         if (mode == 7) // spheric
00563         {
00564             int newX, newY;
00565             imageRgbaSetArea(img, lowArea.x, lowArea.y, highArea.x+1, highArea.y+1, (Rgba){0, 0, 0, 0});
00566             point middle = point(int((highArea.x - lowArea.x)/2+1), int((highArea.y - lowArea.y)/2+1));
00567 
00568             int positionX;
00569             if (mouse.x <= middle.x)
00570                 positionX = highArea.x - mouse.x;
00571             else
00572                 positionX = mouse.x;
00573 
00574             int positionY;
00575             if (mouse.y <= middle.y)
00576                 positionY = highArea.y - mouse.y;
00577             else
00578                 positionY = mouse.y;
00579 
00580             middle = mouse;
00581             
00582 //            int radius = int(sqrt(((highArea.x-lowArea.x+1)/2)*((highArea.x-lowArea.x+1)/2) + ((highArea.y-lowArea.y+1)/2)*((highArea.y-lowArea.y+1)/2)));
00583             int radius = int(sqrt(positionX*positionX + positionY*positionY));
00584             int R = 0, G = 0, B = 0, count = 0;
00585             int location;
00586             int newValue1;
00587             
00588             for (int r = 1; r <= radius; r++)
00589             {
00590                 R = 0;
00591                 G = 0;
00592                 B = 0;
00593                 count = 0;
00594                 float angleAdd = (atan((float)1 / r));
00595                 newValue1 = int((float) r / radius * value1);
00596                 for (int angle = 0; angle < ((2*M_PI)/angleAdd + 2*newValue1); angle++)
00597                 {
00598                     // remove
00599                     if ((angle - 2*newValue1 - angleAdd) >= 0)
00600                     {
00601                         newX = int(lowArea.x + middle.x + sin((angle - 2*newValue1 - 1) * angleAdd) * r);
00602                         newY = int(lowArea.y + middle.y + cos((angle - 2*newValue1 - 1) * angleAdd) * r);
00603                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00604                         {
00605                             location = newX + img->width * newY;
00606                             R -= temp->data[location].r;
00607                             G -= temp->data[location].g;
00608                             B -= temp->data[location].b;
00609                             count--;
00610                         }
00611                     }
00612 
00613                     // add
00614                     if (angle >= 0)
00615                     {
00616                         newX = int(lowArea.x + middle.x + sin((angle) * angleAdd) * r);
00617                         newY = int(lowArea.y + middle.y + cos((angle) * angleAdd) * r);
00618                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00619                         {
00620                             location = newX + img->width * newY;
00621                             R += temp->data[location].r;
00622                             G += temp->data[location].g;
00623                             B += temp->data[location].b;
00624                             count++;
00625                         }
00626                     }
00627                     
00628                     // draw
00629                     if ((angle - 2*newValue1) >= 0)
00630                     {
00631                         newX = int(lowArea.x + middle.x + sin((angle - newValue1) * angleAdd) * r);
00632                         newY = int(lowArea.y + middle.y + cos((angle - newValue1) * angleAdd) * r);
00633                         if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00634                         {
00635                             location = newX + img->width * newY;
00636                             if (count != 0)
00637                                 img->data[location] = (Rgba){
00638                                                             limitRGBA.intForceLimit(R / count),
00639                                                             limitRGBA.intForceLimit(G / count),
00640                                                             limitRGBA.intForceLimit(B / count),
00641                                                             255
00642                                                             };
00643                         }
00644                     }
00645                 }
00646             }
00647             
00648             // fehlerkorrektur
00649             float angle;
00650             for (int y = lowArea.y; y <= highArea.y; y++)
00651             {
00652                 for (int x = lowArea.x; x <= highArea.x; x++)
00653                 {
00654                     location = x + img->width * y;
00655                     if (img->data[location].a == 0)
00656                     {
00657                         if (img->data[x + img->width * y].a == 0)
00658                         {
00659                             newX = (middle.x - (x - lowArea.x));
00660                             newY = (middle.y - (y - lowArea.y));
00661                             radius = int(sqrt(newX*newX + newY*newY));
00662                             if (newY == 0 && newX > 0)
00663                                 angle = M_PI / 2;
00664                             else
00665                                 angle = atan((float)newX / newY);
00666                             
00667                             if (newX == 0 && newY == 0)
00668                                 angle = 0;
00669         
00670                             if (newY >= 0)
00671                                 angle += M_PI;
00672 
00673 
00674                             float angleAdd = atan((float)1 / radius);
00675                             for (; angle < (4*M_PI); angle += angleAdd)
00676                             {
00677                                 newX = int(lowArea.x + middle.x + sin(angle) * radius);
00678                                 newY = int(lowArea.y + middle.y + cos(angle) * radius);
00679                                 if (newX >= lowArea.x && newX <= highArea.x && newY >= lowArea.y && newY <= highArea.y)
00680                                 {
00681                                     if (img->data[newX + img->width * newY].a != 0)
00682                                     {
00683                                         img->data[x + img->width * y] = img->data[newX + img->width * newY];
00684                                         break;
00685                                     }
00686                                 }
00687                             }
00688                         }
00689                     }
00690                 }
00691             }
00692         }
00693     }
00694 }
00695 
00696 void blur::changeMode(char _mode)
00697 {
00698     mode = _mode;
00699     if (mode == 1)
00700     {
00701         glutSetWindowTitle("Paint Application | Blur | Mode 1: Simple Blur");
00702         limitValue1.set(1, 250);
00703         value1 = 10;
00704         limitValue2.set(0, 0);
00705         value2 = 0;
00706     }
00707     else if (mode == 2)
00708     {
00709         glutSetWindowTitle("Paint Application | Blur | Mode 2: Gaussian Blur");
00710         limitValue1.set(1, 100);
00711         value1 = 5;
00712         limitValue2.set(0, 0);
00713         value2 = 0;
00714     }
00715     else if (mode == 3)
00716     {
00717         glutSetWindowTitle("Paint Application | Blur | Mode 3: Motion Blur Horizontal");
00718         limitValue1.set(1, 250);
00719         value1 = 5;
00720         limitValue2.set(0, 0);
00721         value2 = 0;
00722     }
00723     else if (mode == 4)
00724     {
00725         glutSetWindowTitle("Paint Application | Blur | Mode 4: Motion Blur Vertical");
00726         limitValue1.set(1, 250);
00727         value1 = 5;
00728         limitValue2.set(0, 0);
00729         value2 = 0;
00730     }
00731     else if (mode == 5)
00732     {
00733         glutSetWindowTitle("Paint Application | Blur | Mode 5: Motion Blur");
00734         limitValue1.set(1, 250);
00735         value1 = 5;
00736         limitValue2.set(1, 179);
00737         value2 = 45;
00738     }
00739     else if (mode == 6)
00740     {
00741         glutSetWindowTitle("Paint Application | Blur | Mode 6: Radial Blur");
00742         limitValue1.set(1, int(sqrt(((highArea.x-lowArea.x+1)/2)*((highArea.x-lowArea.x+1)/2) + ((highArea.y-lowArea.y+1)/2)*((highArea.y-lowArea.y+1)/2))/2));
00743         value1 = 10;
00744         limitValue2.set(0, 0);
00745         value2 = 0;
00746     }
00747     else if (mode == 7)
00748     {
00749         glutSetWindowTitle("Paint Application | Blur | Mode 7: Spheric Blur");
00750         limitValue1.set(1, 250);
00751         value1 = 10;
00752         limitValue2.set(0, 0);
00753         value2 = 0;
00754     }
00755         
00756     LBpressed = true;
00757     this->LBAction();
00758     LBpressed = false;
00759 }
00760 
00761 void blur::changeValue(char _key)
00762 {
00763     if (_key == GLUT_KEY_UP)
00764         value1 += 1;
00765     else if (_key == GLUT_KEY_DOWN)
00766         value1 -= 1;
00767 
00768     if (_key == GLUT_KEY_LEFT)
00769         value2 -= 3;
00770     else if (_key == GLUT_KEY_RIGHT)
00771         value2 += 3;
00772 
00773     value1 = limitValue1.intForceLimit(value1);
00774     if (value2 > limitValue2.high)
00775         value2 = limitValue2.low;
00776     if (value2 < limitValue2.low)
00777         value2 = limitValue2.high;
00778 
00779     if (_key)
00780     {
00781         if (!LBpressed)
00782         {
00783             LBpressed = true;
00784             this->LBAction();
00785             LBpressed = false;
00786         }
00787         else
00788             this->LBAction();
00789     }
00790 }
00791 
00793 // Sharpen                                                                   //
00795 sharpen::sharpen(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00796 {
00797     glutSetWindowTitle("Paint Application | Sharpen");
00798 
00799     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00800 
00801     imageRgbaCopy(img, temp);
00802     imageRgbaCopy(img, temp2);
00803     
00804     M[0] = new matrix ((float[9]) { -0.1, -0.1, -0.1,
00805                                     -0.1, 1.8, -0.1,
00806                                     -0.1, -0.1, -0.1 }, 1, 1);
00807     M[1] = new matrix ((float[9]) { -0.2, -0.2, -0.2,
00808                                     -0.2, 2.6, -0.2,
00809                                     -0.2, -0.2, -0.2 }, 1, 1);
00810     M[2] = new matrix ((float[9]) { -0.3, -0.3, -0.3,
00811                                     -0.3, 3.4, -0.3,
00812                                     -0.3, -0.3, -0.3 }, 1, 1);
00813     M[3] = new matrix ((float[9]) { -0.4, -0.4, -0.4,
00814                                     -0.4, 4.2, -0.4,
00815                                     -0.4, -0.4, -0.4 }, 1, 1);
00816     M[4] = new matrix ((float[9]) { -0.5, -0.5, -0.5,
00817                                     -0.5, 5.0, -0.5,
00818                                     -0.5, -0.5, -0.5 }, 1, 1);
00819     M[5] = new matrix ((float[9]) { -0.7, -0.7, -0.7,
00820                                     -0.7, 6.6, -0.7,
00821                                     -0.7, -0.7, -0.7 }, 1, 1);
00822     M[6] = new matrix ((float[9]) { -0.9, -0.9, -0.9,
00823                                     -0.9, 8.2, -0.9,
00824                                     -0.9, -0.9, -0.9 }, 1, 1);
00825     M[7] = new matrix ((float[9]) { -1.1, -1.1, -1.1,
00826                                     -1.1, 9.8, -1.1,
00827                                     -1.1, -1.1, -1.1 }, 1, 1);
00828     M[8] = new matrix ((float[9]) { -1.4, -1.4, -1.4,
00829                                     -1.4, 12.2, -1.4,
00830                                     -1.4, -1.4, -1.4 }, 1, 1);
00831     M[9] = new matrix ((float[9]) { -1.8, -1.8, -1.8,
00832                                     -1.8, 15.4, -1.8,
00833                                     -1.8, -1.8, -1.8 }, 1, 1);
00834 
00835     numModes = 3;
00836     this->changeMode(1);
00837 }
00838 
00839 sharpen::~sharpen()
00840 {
00841     for (int i = 0; i < 10; i++)
00842         if (M[i])    
00843         {
00844             delete M[i];
00845             M[i] = 0;
00846         }
00847 
00848 }
00849 
00850 void sharpen::LBAction()
00851 {
00852     if (LBpressed)
00853     {
00854         int location;
00855         
00856         if (mode == 1 || mode == 2)
00857         {
00858             gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
00859 
00860             display = img;
00861             this->refreshImage();
00862             for (int y = lowArea.y; y <= highArea.y; y++)
00863             {
00864                 for (int x = lowArea.x; x <= highArea.x; x++)
00865                 {
00866                     location = x + img->width * y;
00867                     img->data[location].r = limitRGBA.intForceLimit(2 * temp->data[location].r - img->data[location].r);
00868                     img->data[location].g = limitRGBA.intForceLimit(2 * temp->data[location].g - img->data[location].g);
00869                     img->data[location].b = limitRGBA.intForceLimit(2 * temp->data[location].b - img->data[location].b);
00870                 }
00871             }
00872         }
00873         if (mode == 3)
00874         {
00875             for (int y = lowArea.y; y <= highArea.y; y++)
00876             {
00877                 for (int x = lowArea.x; x <= highArea.x; x++)
00878                 {
00879                     img->data[x + img->width * y] = applyMatrix(temp, M[int(value1)], x, y, lowArea, highArea);
00880                 }
00881             }            
00882         }
00883     }
00884 }
00885 
00886 void sharpen::changeMode(char _mode)
00887 {
00888     mode = _mode;
00889     if (mode == 1)
00890     {
00891         glutSetWindowTitle("Paint Application | Sharpen | Mode 1: Simple Sharpen");
00892         limitValue1.set(1, 250);
00893         value1 = 5;
00894     }
00895     else if (mode == 2)
00896     {
00897         glutSetWindowTitle("Paint Application | Sharpen | Mode 2: Gaussian Sharpen");
00898         limitValue1.set(1, 100);
00899         value1 = 5;
00900     }
00901     else if (mode == 3)
00902     {
00903         glutSetWindowTitle("Paint Application | Sharpen | Mode 3: Predefined Sharpen");
00904         limitValue1.set(0, 9);
00905         value1 = 1;
00906     }
00907 
00908         
00909     LBpressed = true;
00910     this->LBAction();
00911     LBpressed = false;
00912 }
00913 
00915 // Edge                                                                      //
00917 edge::edge(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
00918 {
00919     glutSetWindowTitle("Paint Application | Edge");
00920 
00921     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00922 
00923     imageRgbaCopy(img, temp);
00924     
00925     numModes = 8;
00926     this->changeMode(1);   
00927 }
00928 
00929 void edge::matrixAction(int _x, int _y)
00930 {
00931     if (mode != 3 && mode != 6 && mode != 7)
00932         img->data[_x + img->width * _y] = applyMatrix(temp, M[int(value1)], _x, _y, lowArea, highArea);
00933     else if (mode == 3)
00934     {
00935         int location = _x + img->width * _y;
00936         temp2->data[location] = applyMatrix(temp, M[int(value1)], _x, _y, lowArea, highArea);
00937         img->data[location] = applyMatrix(temp, M[int(value1)+5], _x, _y, lowArea, highArea);
00938         img->data[location].r = limitRGBA.intForceLimit(img->data[location].r + temp2->data[location].r);
00939         img->data[location].g = limitRGBA.intForceLimit(img->data[location].g + temp2->data[location].g);
00940         img->data[location].b = limitRGBA.intForceLimit(img->data[location].b + temp2->data[location].b);
00941     }
00942     else if (mode == 6)
00943     {
00944         int location = _x + img->width * _y;
00945         temp2->data[location] = applyMatrix(temp, M[int(value1)], _x, _y, lowArea, highArea);
00946         img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + temp2->data[location].r);
00947         img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + temp2->data[location].g);
00948         img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + temp2->data[location].b);
00949     }
00950     else if (mode == 7)
00951     {
00952         int location = _x + img->width * _y;
00953         temp2->data[location] = applyMatrix(temp, M[int(value1)], _x, _y, lowArea, highArea);
00954         img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r - temp2->data[location].r);
00955         img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g - temp2->data[location].g);
00956         img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b - temp2->data[location].b);
00957     }
00958 }
00959 
00960 edge::~edge()
00961 {
00962     for (int i = 0; i < 10; i++)
00963         if (M[i])    
00964         {
00965             delete M[i];
00966             M[i] = 0;
00967         }
00968 
00969 }
00970 
00971 void edge::changeMode(char _mode)
00972 {
00973     for (int i = 0; i < 10; i++)
00974         if (M[i])
00975         {
00976             delete M[i];
00977             M[i] = 0;
00978         }
00979     
00980     mode = _mode;
00981     if (mode == 1)
00982     {
00983         glutSetWindowTitle("Paint Application | Edge | Mode 1: Laplace");
00984         limitValue1.set(0, 4);
00985         value1 = 0;
00986     }
00987     if (mode == 2)
00988     {
00989         glutSetWindowTitle("Paint Application | Edge | Mode 2: Strong Laplace");
00990         limitValue1.set(0, 4);
00991         value1 = 0;
00992         M[0] = new matrix ((float[9]) { 1, 1, 1,
00993                                         1, -8, 1,
00994                                         1, 1, 1 }, 1, 1);
00995        
00996         M[1] = new matrix ((float[25]) { 0, 1, 1, 1, 0,
00997                                          1, 0, 0, 0, 1,
00998                                          1, 0, -12, 0, 1,
00999                                          1, 0, 0, 0, 1,
01000                                          0, 1, 1, 1, 0 }, 2, 1);
01001     
01002         M[2] = new matrix ((float[49]) { 0, 0, 1, 1, 1, 0, 0,
01003                                          0, 1, 0, 0, 0, 1, 0,
01004                                          1, 0, 0, 0, 0, 0, 1,
01005                                          1, 0, 0, -16, 0, 0, 1,
01006                                          1, 0, 0, 0, 0, 0, 1,
01007                                          0, 1, 0, 0, 0, 1, 0,
01008                                          0, 0, 1, 1, 1, 0, 0 }, 3, 1);
01009        
01010         M[3] = new matrix ((float[81]) { 0, 0, 1, 1, 1, 1, 1, 0, 0,
01011                                          0, 1, 0, 0, 0, 0, 0, 1, 0,
01012                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01013                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01014                                          1, 0, 0, 0, -24, 0, 0, 0, 1,
01015                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01016                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01017                                          0, 1, 0, 0, 0, 0, 0, 1, 0,
01018                                          0, 0, 1, 1, 1, 1, 1, 0, 0 }, 4, 1);
01019        
01020         M[4] = new matrix ((float[121]) { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
01021                                           0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
01022                                           0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
01023                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01024                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01025                                           1, 0, 0, 0, 0, -28, 0, 0, 0, 0, 1,
01026                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01027                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01028                                           0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
01029                                           0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
01030                                           0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 }, 5, 1);
01031     }
01032     else if (mode == 3)
01033     {
01034         glutSetWindowTitle("Paint Application | Edge | Mode 3: Sobel Combined");
01035         limitValue1.set(0, 4);
01036         value1 = 0;
01037     }
01038     else if (mode == 4)
01039     {
01040         glutSetWindowTitle("Paint Application | Edge | Mode 4: Sobel Horizontal");
01041         limitValue1.set(0, 4);
01042         value1 = 0;
01043     }
01044     else if (mode == 5)
01045     {
01046         glutSetWindowTitle("Paint Application | Edge | Mode 5: Sobel Vertical");
01047         limitValue1.set(5, 9);
01048         value1 = 5;
01049     }
01050     else if (mode == 6)
01051     {
01052         glutSetWindowTitle("Paint Application | Edge | Mode 6: Lighten Edges");
01053         limitValue1.set(0, 4);
01054         value1 = 0;
01055     }
01056     else if (mode == 7)
01057     {
01058         glutSetWindowTitle("Paint Application | Edge | Mode 7: Darken Edges");
01059         limitValue1.set(0, 4);
01060         value1 = 0;
01061     }
01062     else if (mode == 8)
01063     {
01064         glutSetWindowTitle("Paint Application | Edge | Mode 8: Ghost");
01065         limitValue1.set(0, 4);
01066         value1 = 0;
01067         M[0] = new matrix ((float[9]) { 1, 1, 1,
01068                                         1, -7, 1,
01069                                         1, 1, 1 }, 1, 1);
01070        
01071         M[1] = new matrix ((float[25]) { 0, 1, 1, 1, 0,
01072                                          1, 0, 0, 0, 1,
01073                                          1, 0, -11, 0, 1,
01074                                          1, 0, 0, 0, 1,
01075                                          0, 1, 1, 1, 0 }, 2, 1);
01076     
01077         M[2] = new matrix ((float[49]) { 0, 0, 1, 1, 1, 0, 0,
01078                                          0, 1, 0, 0, 0, 1, 0,
01079                                          1, 0, 0, 0, 0, 0, 1,
01080                                          1, 0, 0, -15, 0, 0, 1,
01081                                          1, 0, 0, 0, 0, 0, 1,
01082                                          0, 1, 0, 0, 0, 1, 0,
01083                                          0, 0, 1, 1, 1, 0, 0 }, 3, 1);
01084        
01085         M[3] = new matrix ((float[81]) { 0, 0, 1, 1, 1, 1, 1, 0, 0,
01086                                          0, 1, 0, 0, 0, 0, 0, 1, 0,
01087                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01088                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01089                                          1, 0, 0, 0, -23, 0, 0, 0, 1,
01090                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01091                                          1, 0, 0, 0, 0, 0, 0, 0, 1,
01092                                          0, 1, 0, 0, 0, 0, 0, 1, 0,
01093                                          0, 0, 1, 1, 1, 1, 1, 0, 0 }, 4, 1);
01094        
01095         M[4] = new matrix ((float[121]) { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
01096                                           0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
01097                                           0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
01098                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01099                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01100                                           1, 0, 0, 0, 0, -27, 0, 0, 0, 0, 1,
01101                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01102                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01103                                           0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
01104                                           0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
01105                                           0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 }, 5, 1);
01106     }
01107 
01108     if (mode == 3 || mode == 4 || mode == 5)
01109     {
01110         M[0] = new matrix ((float[9]) { -1, 0, 1,
01111                                         -2, 0, 2,
01112                                         -1, 0, 1 }, 1, 1);
01113        
01114         M[1] = new matrix ((float[25]) { -1, 0, 0, 0, 1,
01115                                          -1, 0, 0, 0, 1,
01116                                          -2, 0, 0, 0, 2,
01117                                          -1, 0, 0, 0, 1,
01118                                          -1, 0, 0, 0, 1 }, 2, 1);
01119     
01120         M[2] = new matrix ((float[49]) { -1, 0, 0, 0, 0, 0, 1,
01121                                          -1, 0, 0, 0, 0, 0, 1,
01122                                          -1, 0, 0, 0, 0, 0, 1,
01123                                          -2, 0, 0, 0, 0, 0, 2,
01124                                          -1, 0, 0, 0, 0, 0, 1,
01125                                          -1, 0, 0, 0, 0, 0, 1,
01126                                          -1, 0, 0, 0, 0, 0, 1 }, 3, 1);
01127        
01128         M[3] = new matrix ((float[81]) { -1, 0, 0, 0, 0, 0, 0, 0, 1,
01129                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01130                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01131                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01132                                          -2, 0, 0, 0, 0, 0, 0, 0, 2,
01133                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01134                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01135                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01136                                          -1, 0, 0, 0, 0, 0, 0, 0, 1 }, 4, 1);
01137        
01138         M[4] = new matrix ((float[121]) { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01139                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01140                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01141                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01142                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01143                                           -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
01144                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01145                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01146                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01147                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01148                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 5, 1);
01149                                           
01150         M[5] = new matrix ((float[9]) { -1, -2, -1,
01151                                         0, 0, 0,
01152                                         1, 2, 1 }, 1, 1);
01153        
01154         M[6] = new matrix ((float[25]) { -1, -1, -2, -1, -1,
01155                                          0, 0, 0, 0, 0,
01156                                          0, 0, 0, 0, 0,
01157                                          0, 0, 0, 0, 0,
01158                                          1, 1, 2, 1, 1 }, 2, 1);
01159     
01160         M[7] = new matrix ((float[49]) { -1, -1, -1, -2, -1, -1, -1,
01161                                          0, 0, 0, 0, 0, 0, 0,
01162                                          0, 0, 0, 0, 0, 0, 0,
01163                                          0, 0, 0, 0, 0, 0, 0,
01164                                          0, 0, 0, 0, 0, 0, 0,
01165                                          0, 0, 0, 0, 0, 0, 0,
01166                                          1, 1, 1, 2, 1, 1, 1 }, 3, 1);
01167        
01168         M[8] = new matrix ((float[81]) { -1, -1, -1, -1, -2, -1, -1, -1, -1,
01169                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01170                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01171                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01172                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01173                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01174                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01175                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01176                                          1, 1, 1, 1, 2, 1, 1, 1, 1 }, 4, 1);
01177        
01178         M[9] = new matrix ((float[121]) { -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1,
01179                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01180                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01181                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01182                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01183                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01184                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01185                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01186                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01187                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01188                                           1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1 }, 5, 1);
01189         
01190     }
01191     if (mode == 1 || mode == 6 || mode == 7)
01192     {
01193         M[0] = new matrix ((float[9]) { 0, 1, 0,
01194                                         1, -4, 1,
01195                                         0, 1, 0 }, 1, 1);
01196        
01197         M[1] = new matrix ((float[25]) { 0, 0, 1, 0, 0,
01198                                          0, 0, 0, 0, 0,
01199                                          1, 0, -4, 0, 1,
01200                                          0, 0, 0, 0, 0,
01201                                          0, 0, 1, 0, 0 }, 2, 1);
01202     
01203         M[2] = new matrix ((float[49]) { 0, 0, 0, 1, 0, 0, 0,
01204                                          0, 0, 0, 0, 0, 0, 0,
01205                                          0, 0, 0, 0, 0, 0, 0,
01206                                          1, 0, 0, -4, 0, 0, 1,
01207                                          0, 0, 0, 0, 0, 0, 0,
01208                                          0, 0, 0, 0, 0, 0, 0,
01209                                          0, 0, 0, 1, 0, 0, 0 }, 3, 1);
01210        
01211         M[3] = new matrix ((float[81]) { 0, 0, 0, 0, 1, 0, 0, 0, 0,
01212                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01213                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01214                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01215                                          1, 0, 0, 0, -4, 0, 0, 0, 1,
01216                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01217                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01218                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01219                                          0, 0, 0, 0, 1, 0, 0, 0, 0 }, 4, 1);
01220        
01221         M[4] = new matrix ((float[121]) { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
01222                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01223                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01224                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01225                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01226                                           1, 0, 0, 0, 0, -4, 0, 0, 0, 0, 1,
01227                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01228                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01229                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01230                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01231                                           0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, 5, 1);
01232     }
01233         
01234     LBpressed = true;
01235     this->LBAction();
01236     LBpressed = false;
01237 }
01238 
01240 // Emboss                                                                    //
01242 emboss::emboss(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01243 {
01244     glutSetWindowTitle("Paint Application | Emboss");
01245 
01246     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01247 
01248     imageRgbaCopy(img, temp);
01249     
01250     limitValue1.set(0, 4);
01251     value1 = 0;
01252 
01253     numModes = 8;
01254     this->changeMode(1);   
01255 }
01256 
01257 emboss::~emboss()
01258 {
01259     for (int i = 0; i < 10; i++)
01260         if (M[i])    
01261         {
01262             delete M[i];
01263             M[i] = 0;
01264         }
01265 }
01266 
01267 void emboss::changeMode(char _mode)
01268 {
01269     for (int i = 0; i < 10; i++)
01270         if (M[i])    
01271         {
01272             delete M[i];
01273             M[i] = 0;
01274         }
01275 
01276     mode = _mode;
01277     if (mode == 1)
01278     {
01279         glutSetWindowTitle("Paint Application | Emboss | Mode 1: Right");
01280         M[0] = new matrix ((float[9]) { 1, 0, -1,
01281                                         2, 1, -2,
01282                                         1, 0, -1 }, 1, 1);
01283        
01284         M[1] = new matrix ((float[25]) { 1, 0, 0, 0, -1,
01285                                          1, 0, 0, 0, -1,
01286                                          2, 0, 1, 0, -2,
01287                                          1, 0, 0, 0, -1,
01288                                          1, 0, 0, 0, -1 }, 2, 1);
01289     
01290         M[2] = new matrix ((float[49]) { 1, 0, 0, 0, 0, 0, -1,
01291                                          1, 0, 0, 0, 0, 0, -1,
01292                                          1, 0, 0, 0, 0, 0, -1,
01293                                          2, 0, 0, 1, 0, 0, -2,
01294                                          1, 0, 0, 0, 0, 0, -1,
01295                                          1, 0, 0, 0, 0, 0, -1,
01296                                          1, 0, 0, 0, 0, 0, -1 }, 3, 1);
01297        
01298         M[3] = new matrix ((float[81]) { 1, 0, 0, 0, 0, 0, 0, 0, -1,
01299                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01300                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01301                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01302                                          2, 0, 0, 0, 1, 0, 0, 0, -2,
01303                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01304                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01305                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01306                                          1, 0, 0, 0, 0, 0, 0, 0, -1 }, 4, 1);
01307        
01308         M[4] = new matrix ((float[121]) { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01309                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01310                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01311                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01312                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01313                                           2, 0, 0, 0, 0, 1, 0, 0, 0, 0, -2,
01314                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01315                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01316                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01317                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01318                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 }, 5, 1);
01319     }
01320     if (mode == 2)
01321     {
01322         glutSetWindowTitle("Paint Application | Emboss | Mode 2: Right-Up");
01323         M[0] = new matrix ((float[9]) { 1, -2, -1,
01324                                         2, 1, -2,
01325                                         1, 2, -1 }, 1, 1);
01326        
01327         M[1] = new matrix ((float[25]) { 1, -1, -2, -1, -1,
01328                                          1, 0, 0, 0, -1,
01329                                          2, 0, 1, 0, -2,
01330                                          1, 0, 0, 0, -1,
01331                                          1, 1, 2, 1, -1 }, 2, 1);
01332     
01333         M[2] = new matrix ((float[49]) { 1, -1, -1, -2, -1, -1, -1,
01334                                          1, 0, 0, 0, 0, 0, -1,
01335                                          1, 0, 0, 0, 0, 0, -1,
01336                                          2, 0, 0, 1, 0, 0, -2,
01337                                          1, 0, 0, 0, 0, 0, -1,
01338                                          1, 0, 0, 0, 0, 0, -1,
01339                                          1, 1, 1, 2, 1, 1, -1 }, 3, 1);
01340        
01341         M[3] = new matrix ((float[81]) { 1, -1, -1, -1, -2, -1, -1, -1, -1,
01342                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01343                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01344                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01345                                          2, 0, 0, 0, 1, 0, 0, 0, -2,
01346                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01347                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01348                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01349                                          1, 1, 1, 1, 2, 1, 1, 1, -1 }, 4, 1);
01350        
01351         M[4] = new matrix ((float[121]) { 1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1,
01352                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01353                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01354                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01355                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01356                                           2, 0, 0, 0, 0, 1, 0, 0, 0, 0, -2,
01357                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01358                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01359                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01360                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01361                                           1, 1, 1, 1, 1, 2, 1, 1, 1, 1, -1 }, 5, 1);
01362     }
01363     if (mode == 3)
01364     {
01365         glutSetWindowTitle("Paint Application | Emboss | Mode 3: Up");
01366         M[0] = new matrix ((float[9]) { -1, -2, -1,
01367                                         0, 1, 0,
01368                                         1, 2, 1 }, 1, 1);
01369        
01370         M[1] = new matrix ((float[25]) { -1, -1, -2, -1, -1,
01371                                          0, 0, 0, 0, 0,
01372                                          0, 0, 1, 0, 0,
01373                                          0, 0, 0, 0, 0,
01374                                          1, 1, 2, 1, 1 }, 2, 1);
01375     
01376         M[2] = new matrix ((float[49]) { -1, -1, -1, -2, -1, -1, -1,
01377                                          0, 0, 0, 0, 0, 0, 0,
01378                                          0, 0, 0, 0, 0, 0, 0,
01379                                          0, 0, 0, 1, 0, 0, 0,
01380                                          0, 0, 0, 0, 0, 0, 0,
01381                                          0, 0, 0, 0, 0, 0, 0,
01382                                          1, 1, 1, 2, 1, 1, 1 }, 3, 1);
01383        
01384         M[3] = new matrix ((float[81]) { -1, -1, -1, -1, -2, -1, -1, -1, -1,
01385                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01386                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01387                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01388                                          0, 0, 0, 0, 1, 0, 0, 0, 0,
01389                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01390                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01391                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01392                                          1, 1, 1, 1, 2, 1, 1, 1, 1 }, 4, 1);
01393        
01394         M[4] = new matrix ((float[121]) { -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1,
01395                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01396                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01397                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01398                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01399                                           0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
01400                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01401                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01402                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01403                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01404                                           1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1 }, 5, 1);
01405         
01406     }
01407     if (mode == 4)
01408     {
01409         glutSetWindowTitle("Paint Application | Emboss | Mode 4: Left-Up");
01410         M[0] = new matrix ((float[9]) { -1, -2, -1,
01411                                         -2, 1, 2,
01412                                         1, 2, 1 }, 1, 1);
01413        
01414         M[1] = new matrix ((float[25]) { -1, -1, -2, -1, -1,
01415                                          -1, 0, 0, 0, 1,
01416                                          -2, 0, 1, 0, 2,
01417                                          -1, 0, 0, 0, 1,
01418                                          1, 1, 2, 1, 1 }, 2, 1);
01419     
01420         M[2] = new matrix ((float[49]) { -1, -1, -1, -2, -1, -1, -1,
01421                                          -1, 0, 0, 0, 0, 0, 1,
01422                                          -1, 0, 0, 0, 0, 0, 1,
01423                                          -2, 0, 0, 1, 0, 0, 2,
01424                                          -1, 0, 0, 0, 0, 0, 1,
01425                                          -1, 0, 0, 0, 0, 0, 1,
01426                                          1, 1, 1, 2, 1, 1, 1 }, 3, 1);
01427        
01428         M[3] = new matrix ((float[81]) { -1, -1, -1, -1, -2, -1, -1, -1, -1,
01429                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01430                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01431                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01432                                          -2, 0, 0, 0, 1, 0, 0, 0, 2,
01433                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01434                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01435                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01436                                          1, 1, 1, 1, 2, 1, 1, 1, 1 }, 4, 1);
01437        
01438         M[4] = new matrix ((float[121]) { -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1,
01439                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01440                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01441                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01442                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01443                                           -2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2,
01444                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01445                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01446                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01447                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01448                                           1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1 }, 5, 1);
01449         
01450     }
01451     if (mode == 5)
01452     {
01453         glutSetWindowTitle("Paint Application | Emboss | Mode 5: Left");
01454         M[0] = new matrix ((float[9]) { -1, 0, 1,
01455                                         -2, 1, 2,
01456                                         -1, 0, 1 }, 1, 1);
01457        
01458         M[1] = new matrix ((float[25]) { -1, 0, 0, 0, 1,
01459                                          -1, 0, 0, 0, 1,
01460                                          -2, 0, 1, 0, 2,
01461                                          -1, 0, 0, 0, 1,
01462                                          -1, 0, 0, 0, 1 }, 2, 1);
01463     
01464         M[2] = new matrix ((float[49]) { -1, 0, 0, 0, 0, 1, 0,
01465                                          -1, 0, 0, 0, 0, 1, 0,
01466                                          -1, 0, 0, 0, 0, 1, 0,
01467                                          -2, 0, 0, 1, 0, 2, 0,
01468                                          -1, 0, 0, 0, 0, 1, 0,
01469                                          -1, 0, 0, 0, 0, 1, 0,
01470                                          -1, 0, 0, 0, 0, 1, 0 }, 3, 1);
01471        
01472         M[3] = new matrix ((float[81]) { -1, 0, 0, 0, 0, 0, 0, 0, 1,
01473                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01474                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01475                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01476                                          -2, 0, 0, 0, 1, 0, 0, 0, 2,
01477                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01478                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01479                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01480                                          -1, 0, 0, 0, 0, 0, 0, 0, 1 }, 4, 1);
01481        
01482         M[4] = new matrix ((float[121]) { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01483                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01484                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01485                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01486                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01487                                           -2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2,
01488                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01489                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01490                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01491                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01492                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 5, 1);
01493     }
01494     if (mode == 6)
01495     {
01496         glutSetWindowTitle("Paint Application | Emboss | Mode 6: Left-Down");
01497         M[0] = new matrix ((float[9]) { 1, 2, 1,
01498                                         -2, 1, 2,
01499                                         -1, -2, -1 }, 1, 1);
01500        
01501         M[1] = new matrix ((float[25]) { 1, 1, 2, 1, 1,
01502                                          -1, 0, 0, 0, 1,
01503                                          -2, 0, 1, 0, 2,
01504                                          -1, 0, 0, 0, 1,
01505                                          -1, -1, -2, -1, -1 }, 2, 1);
01506     
01507         M[2] = new matrix ((float[49]) { 1, 1, 1, 2, 1, 1, 1,
01508                                          -1, 0, 0, 0, 0, 0, 1,
01509                                          -1, 0, 0, 0, 0, 0, 1,
01510                                          -2, 0, 0, 1, 0, 0, 2,
01511                                          -1, 0, 0, 0, 0, 0, 1,
01512                                          -1, 0, 0, 0, 0, 0, 1,
01513                                          -1, -1, -1, -2, -1, -1, -1 }, 3, 1);
01514        
01515         M[3] = new matrix ((float[81]) { 1, 1, 1, 1, 2, 1, 1, 1, 1,
01516                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01517                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01518                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01519                                          -2, 0, 0, 0, 1, 0, 0, 0, 2,
01520                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01521                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01522                                          -1, 0, 0, 0, 0, 0, 0, 0, 1,
01523                                          -1, -1, -1, -1, -2, -1, -1, -1, -1 }, 4, 1);
01524        
01525         M[4] = new matrix ((float[121]) { 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
01526                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01527                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01528                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01529                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01530                                           -2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2,
01531                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01532                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01533                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01534                                           -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01535                                           -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1 }, 5, 1);
01536     }
01537     if (mode == 7)
01538     {
01539         glutSetWindowTitle("Paint Application | Emboss | Mode 7: Down");
01540         M[0] = new matrix ((float[9]) { 1, 2, 1,
01541                                         0, 1, 0,
01542                                         -1, -2, -1 }, 1, 1);
01543        
01544         M[1] = new matrix ((float[25]) { 1, 1, 2, 1, 1,
01545                                          0, 0, 0, 0, 0,
01546                                          0, 0, 1, 0, 0,
01547                                          0, 0, 0, 0, 0,
01548                                          -1, -1, -2, -1, -1 }, 2, 1);
01549     
01550         M[2] = new matrix ((float[49]) { 1, 1, 1, 2, 1, 1, 1,
01551                                          0, 0, 0, 0, 0, 0, 0,
01552                                          0, 0, 0, 0, 0, 0, 0,
01553                                          0, 0, 0, 1, 0, 0, 0,
01554                                          0, 0, 0, 0, 0, 0, 0,
01555                                          0, 0, 0, 0, 0, 0, 0,
01556                                          -1, -1, -1, -2, -1, -1, -1 }, 3, 1);
01557        
01558         M[3] = new matrix ((float[81]) { 1, 1, 1, 1, 2, 1, 1, 1, 1,
01559                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01560                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01561                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01562                                          0, 0, 0, 0, 1, 0, 0, 0, 0,
01563                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01564                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01565                                          0, 0, 0, 0, 0, 0, 0, 0, 0,
01566                                          -1, -1, -1, -1, -2, -1, -1, -1, -1 }, 4, 1);
01567        
01568         M[4] = new matrix ((float[121]) { 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
01569                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01570                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01571                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01572                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01573                                           0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
01574                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01575                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01576                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01577                                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01578                                           -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1 }, 5, 1);
01579         
01580     }
01581     if (mode == 8)
01582     {
01583         glutSetWindowTitle("Paint Application | Emboss | Mode 8: Right-Down");
01584         M[0] = new matrix ((float[9]) { 1, 2, -1,
01585                                         2, 1, -2,
01586                                         1, -2, -1 }, 1, 1);
01587        
01588         M[1] = new matrix ((float[25]) { 1, 1, 2, 1, -1,
01589                                          1, 0, 0, 0, -1,
01590                                          2, 0, 1, 0, -2,
01591                                          1, 0, 0, 0, -1,
01592                                          1, -1, -2, -1, -1 }, 2, 1);
01593     
01594         M[2] = new matrix ((float[49]) { 1, 1, 1, 2, 1, 1, -1,
01595                                          1, 0, 0, 0, 0, 0, -1,
01596                                          1, 0, 0, 0, 0, 0, -1,
01597                                          2, 0, 0, 1, 0, 0, -2,
01598                                          1, 0, 0, 0, 0, 0, -1,
01599                                          1, 0, 0, 0, 0, 0, -1,
01600                                          1, -1, -1, -2, -1, -1, -1 }, 3, 1);
01601        
01602         M[3] = new matrix ((float[81]) { 1, 1, 1, 1, 2, 1, 1, 1, -1,
01603                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01604                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01605                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01606                                          2, 0, 0, 0, 1, 0, 0, 0, -2,
01607                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01608                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01609                                          1, 0, 0, 0, 0, 0, 0, 0, -1,
01610                                          1, -1, -1, -1, -2, -1, -1, -1, -1 }, 4, 1);
01611        
01612         M[4] = new matrix ((float[121]) { 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, -1,
01613                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01614                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01615                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01616                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01617                                           2, 0, 0, 0, 0, 1, 0, 0, 0, 0, -2,
01618                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01619                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01620                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01621                                           1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
01622                                           1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1 }, 5, 1);
01623     }
01624 
01625     LBpressed = true;
01626     this->LBAction();
01627     LBpressed = false;
01628 }
01629 
01631 // Separate                                                                  //
01633 separate::separate(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01634 {
01635     glutSetWindowTitle("Paint Application | Separate");
01636 
01637     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01638 
01639     imageRgbaCopy(img, temp);
01640     
01641     limitValue1.set(0, 4);
01642     value1 = 1;
01643     
01644     M[0] = new matrix ((float[9]) { 1, 0, 1,
01645                                     0, 0, 0,
01646                                     1, 0, 1 }, 1, 4);
01647    
01648     M[1] = new matrix ((float[25]) { 1, 0, 0, 0, 1,
01649                                      0, 0, 0, 0, 0,
01650                                      0, 0, 0, 0, 0,
01651                                      0, 0, 0, 0, 0,
01652                                      1, 0, 0, 0, 1 }, 2, 4);
01653 
01654     M[2] = new matrix ((float[49]) { 1, 0, 0, 0, 0, 0, 1,
01655                                      0, 0, 0, 0, 0, 0, 0,
01656                                      0, 0, 0, 0, 0, 0, 0,
01657                                      0, 0, 0, 0, 0, 0, 0,
01658                                      0, 0, 0, 0, 0, 0, 0,
01659                                      0, 0, 0, 0, 0, 0, 0,
01660                                      1, 0, 0, 0, 0, 0, 1 }, 3, 4);
01661    
01662     M[3] = new matrix ((float[81]) { 1, 0, 0, 0, 0, 0, 0, 0, 1,
01663                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01664                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01665                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01666                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01667                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01668                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01669                                      0, 0, 0, 0, 0, 0, 0, 0, 0,
01670                                      1, 0, 0, 0, 0, 0, 0, 0, 1 }, 4, 4);
01671    
01672     M[4] = new matrix ((float[121]) { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
01673                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01674                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01675                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01676                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01677                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01678                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01679                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01680                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01681                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
01682                                       1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 5, 4);
01683    
01684     LBpressed = true;
01685     this->LBAction();
01686     LBpressed = false;
01687 }
01688 
01689 separate::~separate()
01690 {
01691     for (int i = 0; i < 10; i++)
01692         if (M[i])    
01693         {
01694             delete M[i];
01695             M[i] = 0;
01696         }
01697 }
01698 
01700 // Halfblur                                                                  //
01702 halfblur::halfblur(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01703 {
01704     glutSetWindowTitle("Paint Application | Halfblur");
01705 
01706     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01707 
01708     imageRgbaCopy(img, temp);
01709     
01710     limitValue1.set(1, 100);
01711     value1 = 10;
01712     limitValue2.set(0, 100);
01713     value2 = 50;
01714     
01715     numModes = 2;
01716     this->changeMode(1);
01717 }
01718 
01719 void halfblur::LBAction()
01720 {
01721     if (LBpressed)
01722     {
01723         int location;
01724         
01725         imageRgbaCopy(temp, temp2);
01726 
01727         gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
01728 
01729         for (int y = lowArea.y; y <= highArea.y; y++)
01730         {
01731             for (int x = lowArea.x; x <= highArea.x; x++)
01732             {
01733                 location = x + img->width * y;
01734                 img->data[location].r = limitRGBA.intForceLimit(((float)(100-value2)/100) * temp->data[location].r + ((float)(value2)/100) * temp2->data[location].r);
01735                 img->data[location].g = limitRGBA.intForceLimit(((float)(100-value2)/100) * temp->data[location].g + ((float)(value2)/100) * temp2->data[location].g);
01736                 img->data[location].b = limitRGBA.intForceLimit(((float)(100-value2)/100) * temp->data[location].b + ((float)(value2)/100) * temp2->data[location].b);
01737                 img->data[location].a = 255;
01738             }
01739         }
01740 
01741         display = img;
01742         this->refreshImage();
01743     }
01744 }
01745 
01746 void halfblur::changeMode(char _mode)
01747 {
01748     mode = _mode;
01749     if (mode == 1)
01750         glutSetWindowTitle("Paint Application | Halfblur | Mode 1: Simple");
01751     else if (mode == 2)
01752         glutSetWindowTitle("Paint Application | Halfblur | Mode 2: Gaussian");
01753         
01754     LBpressed = true;
01755     this->LBAction();
01756     LBpressed = false;
01757 }
01758 
01760 // Whiteblur                                                                 //
01762 whiteblur::whiteblur(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01763 {
01764     glutSetWindowTitle("Paint Application | Whiteblur");
01765 
01766     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01767 
01768     imageRgbaCopy(img, temp);
01769     
01770     limitValue1.set(1, 200);
01771     value1 = 40;
01772     limitValue2.set(0, 255);
01773     value2 = 40;
01774     
01775     strength = 10;
01776     
01777     numModes = 2;
01778     this->changeMode(1);
01779 }
01780 
01781 void whiteblur::LBAction()
01782 {
01783     if (LBpressed)
01784     {
01785         float newStrength = ((float)strength / 10)*((float)strength / 10);
01786         int location, MAX;
01787         
01788         for (int y = lowArea.y; y <= highArea.y; y++)
01789         {
01790             for (int x = lowArea.x; x <= highArea.x; x++)
01791             {
01792                 location = x + img->width * y;
01793                 MAX = temp->data[location].r;
01794                 if (temp->data[location].g > MAX)
01795                     MAX = temp->data[location].g;
01796                 if (temp->data[location].b > MAX)
01797                     MAX = temp->data[location].b;
01798                     
01799                 if (MAX >= (255-value2))
01800                 {
01801                     temp2->data[location] = temp->data[location];
01802                     temp2->data[location].a = 255;
01803                 }
01804                 else
01805                     temp2->data[location].a = 0;
01806             }
01807         }
01808 
01809         gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
01810 
01811         for (int y = lowArea.y; y <= highArea.y; y++)
01812         {
01813             for (int x = lowArea.x; x <= highArea.x; x++)
01814             {
01815                 location = x + img->width * y;
01816                 img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r + ((float)(temp2->data[location].a)/255) * newStrength * temp2->data[location].r);
01817                 img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g + ((float)(temp2->data[location].a)/255) * newStrength * temp2->data[location].g);
01818                 img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b + ((float)(temp2->data[location].a)/255) * newStrength * temp2->data[location].b);
01819                 img->data[location].a = 255;
01820             }
01821         }
01822 
01823         display = img;
01824         this->refreshImage();
01825     }
01826 }
01827 
01828 void whiteblur::changeMode(char _mode)
01829 {
01830     mode = _mode;
01831     if (mode == 1)
01832         glutSetWindowTitle("Paint Application | Whiteblur | Mode 1: Simple");
01833     else if (mode == 2)
01834         glutSetWindowTitle("Paint Application | Whiteblur | Mode 2: Gaussian");
01835         
01836     LBpressed = true;
01837     this->LBAction();
01838     LBpressed = false;
01839 }
01840     
01842 // Blackblur                                                                 //
01844 blackblur::blackblur(ImageRGBA *_img, ImageRGBA *_temp, ImageRGBA *_temp2, ImageRGBA *_hud, ImageRGBA *_menu, bool _bArea, point _lowArea, point _highArea)
01845 {
01846     glutSetWindowTitle("Paint Application | Whiteblur");
01847 
01848     startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
01849 
01850     imageRgbaCopy(img, temp);
01851     
01852     limitValue1.set(1, 200);
01853     value1 = 40;
01854     limitValue2.set(0, 255);
01855     value2 = 150;
01856 
01857     strength = 10;
01858     
01859     numModes = 2;
01860     this->changeMode(1);
01861 }
01862 
01863 void blackblur::LBAction()
01864 {
01865     if (LBpressed)
01866     {
01867         float newStrength = ((float)strength / 10)*((float)strength / 10);
01868         int location, MAX;
01869         
01870         for (int y = lowArea.y; y <= highArea.y; y++)
01871         {
01872             for (int x = lowArea.x; x <= highArea.x; x++)
01873             {
01874                 location = x + img->width * y;
01875                 MAX = temp->data[location].r;
01876                 if (temp->data[location].g > MAX)
01877                     MAX = temp->data[location].g;
01878                 if (temp->data[location].b > MAX)
01879                     MAX = temp->data[location].b;
01880                     
01881                 if (MAX <= value2)
01882                 {
01883                     temp2->data[location] = temp->data[location];
01884                     temp2->data[location].a = 255;
01885                 }
01886                 else
01887                     temp2->data[location].a = 0;
01888             }
01889         }
01890 
01891         gaussian(img, temp2, lowArea.x, lowArea.y, highArea.x, highArea.y, value1, mode);
01892 
01893         for (int y = lowArea.y; y <= highArea.y; y++)
01894         {
01895             for (int x = lowArea.x; x <= highArea.x; x++)
01896             {
01897                 location = x + img->width * y;
01898                 img->data[location].r = limitRGBA.intForceLimit(temp->data[location].r - ((float)(temp2->data[location].a)/255) * newStrength * temp2->data[location].r);
01899                 img->data[location].g = limitRGBA.intForceLimit(temp->data[location].g - ((float)(temp2->data[location].a)/255) * newStrength * temp2->data[location].g);
01900                 img->data[location].b = limitRGBA.intForceLimit(temp->data[location].b - ((float)(temp2->data[location].a)/255) * newStrength * temp2->data[location].b);
01901                 img->data[location].a = 255;
01902             }
01903         }
01904 
01905         display = img;
01906         this->refreshImage();
01907     }
01908 }
01909 
01910 void blackblur::changeMode(char _mode)
01911 {
01912     mode = _mode;
01913     if (mode == 1)
01914         glutSetWindowTitle("Paint Application | Blackblur | Mode 1: Simple");
01915     else if (mode == 2)
01916         glutSetWindowTitle("Paint Application | Blackblur | Mode 2: Gaussian");
01917         
01918     LBpressed = true;
01919     this->LBAction();
01920     LBpressed = false;
01921 }
01922     

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