00001 #include "effects.h"
00002
00004
00006
00007 {
00008 start.set(0, 0);
00009 glutSetWindowTitle("Paint Application | Scrolling");
00010
00011 startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00012 imageRgbaCopy(img, temp2);
00013 inActionState = false;
00014 this->idleAction();
00015
00016 }
00017
00018 void scroll::LBAction()
00019 {
00020 if (LBpressed)
00021 start = mouse;
00022 }
00023
00024 void scroll::RBAction()
00025 {
00026 if (RBpressed)
00027 imageRgbaCopy(temp2, img);
00028 }
00029
00030 void scroll::idleAction()
00031 {
00032 if (LBpressed)
00033 {
00034 ImageRGBA *swap;
00035
00036 int dX, dY;
00037 dX = int(start.x - mouse.x);
00038 dY = int(start.y - mouse.y);
00039 while (dX < lowArea.x)
00040 dX += (highArea.x - lowArea.x + 1);
00041 while (dY < lowArea.y)
00042 dY += (highArea.y - lowArea.y + 1);
00043
00044 while (dX > (highArea.x - lowArea.x))
00045 dX -= (highArea.x - lowArea.x + 1);
00046 while (dY > (highArea.y - lowArea.y))
00047 dY -= (highArea.y - lowArea.y + 1);
00048
00049
00050 if (!bArea)
00051 {
00052 for (int row = 0; row < img->height; row++)
00053 {
00054 if (row < dY)
00055 {
00056 memcpy(&temp->data[0 + (img->height - dY + row) * img->width], &img->data[dX + row * img->width], (img->width - dX) * sizeof(Rgba));
00057 memcpy(&temp->data[(img->width - dX) + (img->height - dY + row) * img->width], &img->data[0 + row * img->width], dX * sizeof(Rgba));
00058 }
00059 else
00060 {
00061 memcpy(&temp->data[0 + (row - dY) * img->width], &img->data[dX + row * img->width], (img->width - dX) * sizeof(Rgba));
00062 memcpy(&temp->data[(img->width - dX) + (row - dY) * img->width], &img->data[0 + row * img->width], dX * sizeof(Rgba));
00063 }
00064 }
00065 }
00066 else
00067 {
00068
00069 memcpy(&temp->data[0], &img->data[0], img->width * lowArea.y * sizeof(Rgba));
00070 for (int row = 0; row <= (highArea.y - lowArea.y); row++)
00071 {
00072
00073 if (row < dY)
00074 {
00075
00076 memcpy(&temp->data[lowArea.x + ((highArea.y + 1) - dY + row) * img->width], &img->data[(lowArea.x + dX) + (lowArea.y + row) * img->width], ((highArea.x + 1) - lowArea.x - dX) * sizeof(Rgba));
00077 memcpy(&temp->data[((highArea.x + 1) - dX) + ((highArea.y + 1) - dY + row) * img->width], &img->data[lowArea.x + (lowArea.y + row) * img->width], (dX) * sizeof(Rgba));
00078 }
00079 else
00080 {
00081 memcpy(&temp->data[lowArea.x + (lowArea.y + row - dY) * img->width], &img->data[(lowArea.x + dX) + (lowArea.y + row) * img->width], ((highArea.x + 1) - lowArea.x - dX) * sizeof(Rgba));
00082 memcpy(&temp->data[((highArea.x + 1) - dX) + (lowArea.y + row - dY) * img->width], &img->data[lowArea.x + (lowArea.y + row) * img->width], (dX)* sizeof(Rgba));
00083 }
00084 memcpy(&temp->data[img->width * (lowArea.y + row)], &img->data[img->width * (lowArea.y + row)], lowArea.x * sizeof(Rgba));
00085 memcpy(&temp->data[(highArea.x + 1) + img->width * (lowArea.y + row)], &img->data[(highArea.x + 1) + img->width * (lowArea.y + row)], (img->width - (highArea.x + 1)) * sizeof(Rgba));
00086 }
00087 memcpy(&temp->data[img->width * (highArea.y + 1)], &img->data[img->width * (highArea.y + 1)], img->width * (img->height - (highArea.y + 1)) * sizeof(Rgba));
00088 }
00089
00090 swap = img;
00091 img = temp;
00092 temp = swap;
00093
00094 fwkSetDisplayImage(img);
00095
00096 start = mouse;
00097 }
00098 }
00099
00101
00103
00104 {
00105 glutSetWindowTitle("Paint Application | Selection");
00106
00107 startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00108 }
00109
00110 void selection::LBAction()
00111 {
00112 if (LBpressed)
00113 {
00114 startArea = mouse;
00115 endArea = mouse;
00116 }
00117 }
00118
00119 void selection::RBAction()
00120 {
00121 if (RBpressed)
00122 {
00123 lowArea.set(0, 0);
00124 highArea.set(img->width - 1, img->height - 1);
00125 bArea = false;
00126 }
00127 }
00128
00129 void selection::moveAction()
00130 {
00131 if (LBpressed)
00132 {
00133 bArea = true;
00134 endArea = mouse;
00135
00136 if (startArea.x <= endArea.x)
00137 {
00138 lowArea.x = startArea.x;
00139 highArea.x = endArea.x;
00140 }
00141 else
00142 {
00143 lowArea.x = endArea.x;
00144 highArea.x = startArea.x;
00145 }
00146
00147 if (startArea.y <= endArea.y)
00148 {
00149 lowArea.y = startArea.y;
00150 highArea.y = endArea.y;
00151 }
00152 else
00153 {
00154 lowArea.y = endArea.y;
00155 highArea.y = startArea.y;
00156 }
00157
00158 lowArea.x = int(limitX.forceLimit(lowArea.x));
00159 lowArea.y = int(limitY.forceLimit(lowArea.y));
00160 highArea.x = int(limitX.forceLimit(highArea.x));
00161 highArea.y = int(limitY.forceLimit(highArea.y));
00162 }
00163 }
00164
00165
00167
00169
00170 {
00171 glutSetWindowTitle("Paint Application | Draw");
00172
00173 startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00174
00175 imageRgbaCopy(img, temp2);
00176
00177 inActionState = false;
00178 numModes = 6;
00179 start.set(0, 0);
00180 end.set(0, 0);
00181 finalDraw = false;
00182 breakDraw = true;
00183 bColorMenu = true;
00184 myColor = (Rgba){255, 255, 255, 255};
00185
00186 imageRgbaCopy(img, temp);
00187 this->changeMode(5);
00188 }
00189
00190 void draw::colorChangeAction()
00191 {
00192 this->RBAction();
00193 }
00194
00195 void draw::idleAction()
00196 {
00197 if (LBpressed || finalDraw || breakDraw)
00198 {
00199
00200 if (mode == 1 && mouse.x >= 0 && mouse.y >= 0 && mouse.x < img->width && mouse.y < img->height)
00201 {
00202 if (!finalDraw)
00203 myColor = img->data[mouse.x + img->width * mouse.y];
00204 }
00205
00206
00207 if (mode == 2)
00208 {
00209 if (!breakDraw)
00210 imageRgbaDrawLine(img, end.x, end.y, int(mouse.x), int(mouse.y), myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00211 }
00212
00213
00214 else if (mode == 3)
00215 {
00216 if (!breakDraw)
00217 {
00218 imageRgbaInvertLine(img, start.x, start.y, end.x, end.y);
00219 imageRgbaInvertLine(img, start.x, start.y, int(mouse.x), int(mouse.y));
00220 }
00221 else
00222 {
00223 imageRgbaCopy(temp, img);
00224 if (finalDraw)
00225 imageRgbaDrawLine(img, start.x, start.y, end.x, end.y, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00226 }
00227 }
00228
00229
00230 else if (mode == 4)
00231 {
00232 if (!breakDraw)
00233 {
00234 imageRgbaInvertLine(img, start.x, start.y, start.x, end.y);
00235 imageRgbaInvertLine(img, start.x, start.y, end.x, start.y);
00236 imageRgbaInvertLine(img, end.x, start.y, end.x, end.y);
00237 imageRgbaInvertLine(img, start.x, end.y, end.x, end.y);
00238
00239 imageRgbaDrawInvertedPoint(img, start.x, start.y);
00240 imageRgbaDrawInvertedPoint(img, start.x, end.y);
00241 imageRgbaDrawInvertedPoint(img, end.x, start.y);
00242 imageRgbaDrawInvertedPoint(img, end.x, end.y);
00243
00244 imageRgbaInvertLine(img, start.x, start.y, start.x, int(mouse.y));
00245 imageRgbaInvertLine(img, start.x, start.y, int(mouse.x), start.y);
00246 imageRgbaInvertLine(img, int(mouse.x), start.y, int(mouse.x), int(mouse.y));
00247 imageRgbaInvertLine(img, start.x, int(mouse.y), int(mouse.x), int(mouse.y));
00248
00249 imageRgbaDrawInvertedPoint(img, start.x, start.y);
00250 imageRgbaDrawInvertedPoint(img, start.x, int(mouse.y));
00251 imageRgbaDrawInvertedPoint(img, int(mouse.x), start.y);
00252 imageRgbaDrawInvertedPoint(img, int(mouse.x), int(mouse.y));
00253 }
00254 else
00255 {
00256 imageRgbaCopy(temp, img);
00257 if (finalDraw)
00258 {
00259 imageRgbaDrawLine(img, start.x, start.y, start.x, end.y, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00260 imageRgbaDrawLine(img, start.x, start.y, end.x, start.y, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00261 imageRgbaDrawLine(img, end.x, start.y, end.x, end.y, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00262 imageRgbaDrawLine(img, start.x, end.y, end.x, end.y, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00263 }
00264 }
00265 }
00266
00267
00268 else if (mode == 5)
00269 {
00270 int a1 = int((end.x - start.x) / 2.0);
00271 int b1 = int((end.y - start.y) / 2.0);
00272
00273 int a2 = int((int(mouse.x) - start.x) / 2.0);
00274 int b2 = int((int(mouse.y) - start.y) / 2.0);
00275
00276 if (!breakDraw)
00277 {
00278 imageRgbaInvertEllipse(img, start.x + a1, start.y + b1, a1, b1);
00279 imageRgbaInvertEllipse(img, start.x + a2, start.y + b2, a2, b2);
00280 }
00281 else
00282 {
00283 imageRgbaCopy(temp, img);
00284 if (finalDraw)
00285 imageRgbaDrawEllipse(img, start.x + a1, start.y + b1, a1, b1, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00286 }
00287 }
00288
00289
00290 else if (mode == 6)
00291 {
00292 int a1 = int(sqrt((end.x - start.x)*(end.x - start.x) + (end.y - start.y)*(end.y - start.y)));
00293 int a2 = int(sqrt((int(mouse.x) - start.x)*(int(mouse.x) - start.x) + (int(mouse.y) - start.y)*(int(mouse.y) - start.y)));
00294
00295 if (!breakDraw)
00296 {
00297 imageRgbaInvertEllipse(img, start.x, start.y, a1, a1);
00298 imageRgbaInvertEllipse(img, start.x, start.y, a2, a2);
00299 }
00300 else
00301 {
00302 imageRgbaCopy(temp, img);
00303 if (finalDraw)
00304 imageRgbaDrawEllipse(img, start.x, start.y, a1, a1, myColor, lowArea.x, lowArea.y, highArea.x, highArea.y);
00305 }
00306 }
00307
00308 breakDraw = false;
00309 if (finalDraw)
00310 {
00311 imageRgbaCopy(img, temp);
00312 finalDraw = false;
00313 }
00314 end = mouse;
00315 }
00316
00317 }
00318
00319 void draw::LB(bool _state)
00320 {
00321 bool buttonPressed = false;
00322 if (bMenu && _state)
00323 buttonPressed = this->useMenu(true);
00324
00325 if (!buttonPressed)
00326 {
00327 if (_state)
00328 {
00329 imageRgbaCopy(img, temp);
00330 start = mouse;
00331 end = mouse;
00332 LBpressed = true;
00333 }
00334 else
00335 {
00336 if (LBpressed)
00337 {
00338 breakDraw = true;
00339 finalDraw = true;
00340 LBpressed = false;
00341 }
00342 }
00343 }
00344 }
00345
00346 void draw::RBAction()
00347 {
00348 if (RBpressed)
00349 {
00350 if (LBpressed)
00351 {
00352 breakDraw = true;
00353 finalDraw = false;
00354 LBpressed = false;
00355 }
00356 else
00357 imageRgbaCopy(temp2, img);
00358 }
00359 }
00360
00361 void draw::changeMode(char _mode)
00362 {
00363 if (LBpressed)
00364 {
00365 breakDraw = true;
00366 finalDraw = false;
00367 this->idleAction();
00368 start = mouse;
00369 end = mouse;
00370 imageRgbaCopy(img, temp);
00371 }
00372
00373 mode = _mode;
00374 if (mode == 1)
00375 glutSetWindowTitle("Paint Application | Draw | Mode 1: Pipette");
00376 else if (mode == 2)
00377 glutSetWindowTitle("Paint Application | Draw | Mode 2: Point");
00378 else if (mode == 3)
00379 glutSetWindowTitle("Paint Application | Draw | Mode 3: Line");
00380 else if (mode == 4)
00381 glutSetWindowTitle("Paint Application | Draw | Mode 4: Rectangle");
00382 else if (mode == 5)
00383 glutSetWindowTitle("Paint Application | Draw | Mode 5: Ellipse");
00384 else if (mode == 6)
00385 glutSetWindowTitle("Paint Application | Draw | Mode 6: Circle");
00386 }
00388
00390
00391 {
00392 start.set(0, 0);
00393 glutSetWindowTitle("Paint Application | Telescope");
00394
00395 startup(_img, _temp, _temp2, _hud, _menu, _bArea, _lowArea, _highArea);
00396 imageRgbaCopy(img, temp);
00397 inActionState = false;
00398
00399 value1 = 100;
00400 limitValue1.set(10, 250);
00401 value2 = 2;
00402 limitValue2.set(2, 10);
00403
00404 M[0] = new matrix ((float[9]) { 1, 2, 1,
00405 2, 4, 2,
00406 1, 2, 1 }, 1, 16);
00407
00408 M[1] = new matrix ((float[9]) { 0, 1, 0,
00409 1, -4, 1,
00410 0, 1, 0 }, 1, 1);
00411
00412 M[2] = new matrix ((float[9]) { 1, 0, -1,
00413 2, 0, -2,
00414 1, 0, -1 }, 1, 1);
00415
00416 M[3] = new matrix ((float[9]) { 1, 2, 1,
00417 0, 0, 0,
00418 -1, -2, -1 }, 1, 1);
00419
00420
00421 numModes = 7;
00422 this->changeMode(1);
00423 }
00424
00425 void telescope::LBAction()
00426 {
00427 if (LBpressed)
00428 {
00429 start = mouse;
00430 imageRgbaCopy(img, temp);
00431 imageRgbaInvertEllipse(img, start.x, start.y, int(value1), int(value1));
00432 }
00433 else
00434 {
00435 imageRgbaInvertEllipse(img, start.x, start.y, int(value1), int(value1));
00436 imageRgbaCopy(temp, img);
00437 }
00438 }
00439
00440 void telescope::idleAction()
00441 {
00442 if (LBpressed)
00443 {
00444 imageRgbaInvertEllipse(img, start.x, start.y, int(value1), int(value1));
00445 for (int y = int(start.y - int(value1) - 1); y < int(start.y + int(value1) + 1); y++)
00446 {
00447 int xValue = int(sqrt((int(value1)*int(value1)) - ((y - start.y)*(y - start.y))));
00448 for (int x = int(start.x - xValue - 1); x < int(start.x + xValue + 1); x++)
00449 {
00450 if ((x >= 0) && (x < img->width) && (y >= 0) && (y < img->height))
00451 img->data[x + img->width * y] = temp->data[x + img->width * y];
00452 }
00453 }
00454 for (int y = int(mouse.y - int(value1)); y < int(mouse.y + int(value1)); y++)
00455 {
00456 int xValue = int(sqrt((int(value1)*int(value1)) - ((y - mouse.y)*(y - mouse.y))));
00457 for (int x = (mouse.x - xValue); x < (mouse.x + xValue); x++)
00458 {
00459 if ((x >= 0) && (x < img->width) && (y >= 0) && (y < img->height))
00460 {
00461 if (mode == 1)
00462 {
00463 float newX, newY;
00464
00465 newX = x - int(mouse.x);
00466 newY = y - int(mouse.y);
00467
00468 if (value2 != 0)
00469 {
00470 newX = int(mouse.x) + ((float)newX / value2);
00471 newY = int(mouse.y) + ((float)newY / value2);
00472 }
00473 else
00474 {
00475 newX = int(mouse.x) + newX;
00476 newY = int(mouse.y) + newY;
00477 }
00478 if ((newX >= 0) && (newX < img->width) && (newY >= 0) && (newY < img->height))
00479 img->data[x + img->width * y] = imageRgbaInterpolate(temp, newX, newY);
00480 else
00481 img->data[x + img->width * y] = (Rgba){0, 0, 0, 255};
00482 }
00483 if (mode == 2)
00484 {
00485 img->data[x + img->width * y] = applyMatrix(temp, M[0], x, y, point(0, 0), point(img->width, img->height));
00486 }
00487 if (mode == 3)
00488 {
00489 Rgba color1 = temp->data[x + img->width * y];
00490 Rgba color2 = applyMatrix(temp, M[0], x, y, point(0, 0), point(img->width, img->height));
00491 img->data[x + img->width * y] = (Rgba) { limitRGBA.intForceLimit(2 * color1.r - color2.r),
00492 limitRGBA.intForceLimit(2 * color1.g - color2.g),
00493 limitRGBA.intForceLimit(2 * color1.b - color2.b),
00494 255 };
00495 }
00496 if (mode == 4)
00497 {
00498 img->data[x + img->width * y] = applyMatrix(temp, M[1], x, y, point(0, 0), point(img->width, img->height));
00499 }
00500 if (mode == 5)
00501 {
00502 Rgba color1 = applyMatrix(temp, M[2], x, y, point(0, 0), point(img->width, img->height));
00503 Rgba color2 = applyMatrix(temp, M[3], x, y, point(0, 0), point(img->width, img->height));
00504 img->data[x + img->width * y] = (Rgba) { limitRGBA.intForceLimit(color1.r + color2.r),
00505 limitRGBA.intForceLimit(color1.g + color2.g),
00506 limitRGBA.intForceLimit(color1.b + color2.b),
00507 255 };
00508 }
00509 if (mode == 6)
00510 img->data[x + img->width * y] = applyMatrix(temp, M[2], x, y, point(0, 0), point(img->width, img->height));
00511 if (mode == 7)
00512 img->data[x + img->width * y] = applyMatrix(temp, M[3], x, y, point(0, 0), point(img->width, img->height));
00513 }
00514 }
00515 }
00516 start = mouse;
00517 imageRgbaInvertEllipse(img, start.x, start.y, int(value1), int(value1));
00518 }
00519 }
00520
00521 void telescope::changeMode(char _mode)
00522 {
00523 mode = _mode;
00524 if (mode == 1)
00525 glutSetWindowTitle("Paint Application | Telescope | Mode 1: Zoom");
00526 else if (mode == 2)
00527 glutSetWindowTitle("Paint Application | Telescope | Mode 2: Gaussian Blur");
00528 else if (mode == 3)
00529 glutSetWindowTitle("Paint Application | Telescope | Mode 3: Gaussian Sharpen");
00530 else if (mode == 4)
00531 glutSetWindowTitle("Paint Application | Telescope | Mode 4: Laplace");
00532 else if (mode == 5)
00533 glutSetWindowTitle("Paint Application | Telescope | Mode 5: Sobel Combined");
00534 else if (mode == 6)
00535 glutSetWindowTitle("Paint Application | Telescope | Mode 6: Sobel Horizontal");
00536 else if (mode == 7)
00537 glutSetWindowTitle("Paint Application | Telescope | Mode 7: Sobel Vertical");
00538 }
00539
00540 void telescope::changeValue(char _key)
00541 {
00542 if (_key == GLUT_KEY_UP)
00543 value2 += 1;
00544 else if (_key == GLUT_KEY_DOWN)
00545 value2 -= 1;
00546 else if (_key == GLUT_KEY_RIGHT)
00547 value1 += 2;
00548 else if (_key == GLUT_KEY_LEFT)
00549 value1 -= 2;
00550
00551 value1 = limitValue1.intForceLimit(value1);
00552 value2 = limitValue2.intForceLimit(value2);
00553
00554 if (_key)
00555 {
00556 LB(false);
00557 LB(true);
00558 }
00559 }