00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stdlib.h>
00010 #include <iostream.h>
00011 #include <math.h>
00012 #include <fstream.h>
00013
00014 #ifndef M_PI
00015 # define M_PI 3.14159265358979323846 // in case pi wasn't defined in math.h
00016 #endif
00017
00018
00019 #include <framewk.h>
00020 #include "painter.h"
00021 #include "effects/classes.h"
00022 #include "effects/effects.h"
00023 #include "effects/color.h"
00024 #include "effects/geometric.h"
00025 #include "effects/distort.h"
00026 #include "effects/matrices.h"
00027 #include "effects/artistic.h"
00028
00029
00030
00031
00032
00033 fstream logfile;
00034 effect *E = 0;
00035 ImageRGBA *original = 0;
00036
00038
00040
00041 void keyboardCB(unsigned char key, float x, float y)
00042 {
00043 E->setXY(x, y);
00044 if (!E->inAction)
00045 E->key(key);
00046
00047 switch (key)
00048 {
00049 case 's':
00050 imageRgbaWriteTIFF("out.tif", E->img);
00051 break;
00052
00053
00054
00055 case '+':
00056 case '=':
00057 fwkSetDisplayZoom(2 * fwkGetDisplayZoom());
00058 break;
00059
00060 case '-':
00061 fwkSetDisplayZoom(0.5 * fwkGetDisplayZoom());
00062 break;
00063
00064 case 13:
00065 imageRgbaCopy(E->img, E->temp);
00066 imageRgbaCopy(E->img, E->temp2);
00067 break;
00068
00069 case 8:
00070 resetImage();
00071 break;
00072
00073 case 27:
00074 case 'q':
00075 exit(0);
00076 break;
00077
00078 case '?':
00079 cout
00080 << "Keyboard Shortcuts:" << endl
00081 << "-------------------------------------------------------------------------------" << endl
00082 << " s Save image as `out.tif'." << endl
00083 << " +/- Zoom in/out." << endl
00084 << " q Quit this application." << endl
00085 << " ? This help." << endl;
00086 break;
00087 }
00088 }
00089
00090 void specialCB(int key, float x, float y)
00091 {
00092 E->setXY(x, y);
00093 if (!E->inAction)
00094 E->specialKey(key);
00095 }
00096
00097 void mouseCB(int button, int state, float x, float y)
00098 {
00099 E->setXY(x, y);
00100
00101 if (button == GLUT_LEFT_BUTTON)
00102 E->LB(state == GLUT_DOWN);
00103 if (button == GLUT_RIGHT_BUTTON)
00104 E->RB(state == GLUT_DOWN);
00105 }
00106
00107 void motionCB(float x, float y)
00108 {
00109 E->setXY(x, y);
00110 if (!E->inAction)
00111 E->move();
00112 }
00113
00114 void idleCB(void)
00115 {
00116 if (!E->inAction)
00117 E->idle();
00118
00119
00120
00121
00122
00123
00124
00125
00126 fwkPostRedisplay();
00127 E->inAction = false;
00128 }
00129
00131
00132 void resetImage()
00133 {
00134 if (E->img)
00135 imageRgbaCopy(original, E->img);
00136 }
00137
00138 void changeEffect(int number)
00139 {
00140
00141 if (E->img)
00142 {
00143 ImageRGBA *I1 = E->img, *I2 = E->temp, *I3 = E->temp2, *I4 = E->hud, *I5 = E->menu;
00144 bool B6 = E->bArea;
00145 point P7 = E->lowArea, P8 = E->highArea;
00146 delete E;
00147
00148
00149
00150 if (number == 3)
00151 E = new draw (I1, I2, I3, I4, I5, B6, P7, P8);
00152 else if (number == 4)
00153 E = new selection (I1, I2, I3, I4, I5, B6, P7, P8);
00154 else if (number == 5)
00155 E = new scroll (I1, I2, I3, I4, I5, B6, P7, P8);
00156 else if (number == 6)
00157 E = new telescope (I1, I2, I3, I4, I5, B6, P7, P8);
00158 else if (number == 9)
00159 E = new brightness (I1, I2, I3, I4, I5, B6, P7, P8);
00160 else if (number == 10)
00161 E = new contrast (I1, I2, I3, I4, I5, B6, P7, P8);
00162 else if (number == 11)
00163 E = new saturation (I1, I2, I3, I4, I5, B6, P7, P8);
00164 else if (number == 12)
00165 E = new hue (I1, I2, I3, I4, I5, B6, P7, P8);
00166 else if (number == 13)
00167 E = new colorize (I1, I2, I3, I4, I5, B6, P7, P8);
00168 else if (number == 14)
00169 E = new channel (I1, I2, I3, I4, I5, B6, P7, P8);
00170 else if (number == 15)
00171 E = new gray (I1, I2, I3, I4, I5, B6, P7, P8);
00172 else if (number == 16)
00173 E = new invert (I1, I2, I3, I4, I5, B6, P7, P8);
00174 else if (number == 17)
00175 E = new posterize (I1, I2, I3, I4, I5, B6, P7, P8);
00176 else if (number == 18)
00177 E = new solarize (I1, I2, I3, I4, I5, B6, P7, P8);
00178 else if (number == 19)
00179 E = new ripple (I1, I2, I3, I4, I5, B6, P7, P8);
00180 else if (number == 20)
00181 E = new bubble (I1, I2, I3, I4, I5, B6, P7, P8);
00182 else if (number == 21)
00183 E = new twirl (I1, I2, I3, I4, I5, B6, P7, P8);
00184 else if (number == 22)
00185 E = new lens (I1, I2, I3, I4, I5, B6, P7, P8);
00186 else if (number == 23)
00187 E = new wave (I1, I2, I3, I4, I5, B6, P7, P8);
00188 else if (number == 24)
00189 E = new buttonize (I1, I2, I3, I4, I5, B6, P7, P8);
00190 else if (number == 25)
00191 E = new glass (I1, I2, I3, I4, I5, B6, P7, P8);
00192 else if (number == 26)
00193 E = new mosaic (I1, I2, I3, I4, I5, B6, P7, P8);
00194 else if (number == 27)
00195 E = new box (I1, I2, I3, I4, I5, B6, P7, P8);
00196 else if (number == 28)
00197 E = new comb (I1, I2, I3, I4, I5, B6, P7, P8);
00198 else if (number == 29)
00199 E = new dots (I1, I2, I3, I4, I5, B6, P7, P8);
00200 else if (number == 30)
00201 E = new lines (I1, I2, I3, I4, I5, B6, P7, P8);
00202 else if (number == 31)
00203 E = new rgbdots (I1, I2, I3, I4, I5, B6, P7, P8);
00204 else if (number == 32)
00205 E = new noise (I1, I2, I3, I4, I5, B6, P7, P8);
00206 else if (number == 33)
00207 E = new blur (I1, I2, I3, I4, I5, B6, P7, P8);
00208 else if (number == 34)
00209 E = new sharpen (I1, I2, I3, I4, I5, B6, P7, P8);
00210 else if (number == 35)
00211 E = new edge (I1, I2, I3, I4, I5, B6, P7, P8);
00212 else if (number == 36)
00213 E = new emboss (I1, I2, I3, I4, I5, B6, P7, P8);
00214 else if (number == 37)
00215 E = new separate (I1, I2, I3, I4, I5, B6, P7, P8);
00216 else if (number == 38)
00217 E = new halfblur (I1, I2, I3, I4, I5, B6, P7, P8);
00218 else if (number == 39)
00219 E = new whiteblur (I1, I2, I3, I4, I5, B6, P7, P8);
00220 else if (number == 40)
00221 E = new blackblur (I1, I2, I3, I4, I5, B6, P7, P8);
00222 else if (number == 41)
00223 E = new chrome (I1, I2, I3, I4, I5, B6, P7, P8);
00224 else if (number == 42)
00225 E = new bw (I1, I2, I3, I4, I5, B6, P7, P8);
00226 else if (number == 43)
00227 E = new relief (I1, I2, I3, I4, I5, B6, P7, P8);
00228 else if (number == 44)
00229 E = new cutout (I1, I2, I3, I4, I5, B6, P7, P8);
00230 else if (number == 45)
00231 E = new brush (I1, I2, I3, I4, I5, B6, P7, P8);
00232 else if (number == 46)
00233 E = new spatter (I1, I2, I3, I4, I5, B6, P7, P8);
00234 else if (number == 47)
00235 E = new strokes (I1, I2, I3, I4, I5, B6, P7, P8);
00236 else if (number == 48)
00237 E = new starlight (I1, I2, I3, I4, I5, B6, P7, P8);
00238 else if (number == 49)
00239 E = new shine (I1, I2, I3, I4, I5, B6, P7, P8);
00240 else
00241 E = new effect (I1, I2, I3, I4, I5, B6, P7, P8);
00242
00243 }
00244 }
00245
00246 void log(float output)
00247 { logfile << "LOG: " << output << endl; }
00248
00249 void log(int output)
00250 { logfile << "LOG: " << output << endl; }
00251
00252 void log(ImageRGBA *output)
00253 { logfile << "LOG: " << output << endl; }
00254
00256
00258
00259 int main(int argc, const char *argv[], const char *arg1[], const char *arg2[], const char *arg3[], const char *arg4[])
00260 {
00261
00262 fwkInit(&argc, argv);
00263 logfile.open("log.txt", ios::out);
00264
00265 int numButtons = 113;
00266 ImageRGBA *menu = imageRgbaNew((20 * 20), numButtons);
00267 ImageRGBA *button = imageRgbaNew(20, 20);
00268 for (int i = 0; i < numButtons; i++)
00269 {
00270 if (i == 0)
00271 button = imageRgbaReadTIFF("menu/save.tif");
00272 else if (i == 1)
00273 button = imageRgbaReadTIFF("menu/backwards.tif");
00274 else if (i == 2)
00275 button = imageRgbaReadTIFF("menu/close.tif");
00276 else if (i == 3)
00277 button = imageRgbaReadTIFF("menu/paint.tif");
00278 else if (i == 4)
00279 button = imageRgbaReadTIFF("menu/selection.tif");
00280 else if (i == 5)
00281 button = imageRgbaReadTIFF("menu/scroll.tif");
00282 else if (i == 6)
00283 button = imageRgbaReadTIFF("menu/telescope.tif");
00284 else if (i == 7)
00285 button = imageRgbaReadTIFF("menu/zoomin.tif");
00286 else if (i == 8)
00287 button = imageRgbaReadTIFF("menu/zoomout.tif");
00288 else if (i == 9)
00289 button = imageRgbaReadTIFF("menu/brightness.tif");
00290 else if (i == 10)
00291 button = imageRgbaReadTIFF("menu/contrast.tif");
00292 else if (i == 11)
00293 button = imageRgbaReadTIFF("menu/saturation.tif");
00294 else if (i == 12)
00295 button = imageRgbaReadTIFF("menu/hue.tif");
00296 else if (i == 13)
00297 button = imageRgbaReadTIFF("menu/colorize.tif");
00298 else if (i == 14)
00299 button = imageRgbaReadTIFF("menu/channel.tif");
00300 else if (i == 15)
00301 button = imageRgbaReadTIFF("menu/gray.tif");
00302 else if (i == 16)
00303 button = imageRgbaReadTIFF("menu/invert.tif");
00304 else if (i == 17)
00305 button = imageRgbaReadTIFF("menu/posterize.tif");
00306 else if (i == 18)
00307 button = imageRgbaReadTIFF("menu/solarize.tif");
00308 else if (i == 19)
00309 button = imageRgbaReadTIFF("menu/ripple.tif");
00310 else if (i == 20)
00311 button = imageRgbaReadTIFF("menu/bubble.tif");
00312 else if (i == 21)
00313 button = imageRgbaReadTIFF("menu/twirl.tif");
00314 else if (i == 22)
00315 button = imageRgbaReadTIFF("menu/lens.tif");
00316 else if (i == 23)
00317 button = imageRgbaReadTIFF("menu/wave.tif");
00318 else if (i == 24)
00319 button = imageRgbaReadTIFF("menu/buttonize.tif");
00320 else if (i == 25)
00321 button = imageRgbaReadTIFF("menu/glass.tif");
00322 else if (i == 26)
00323 button = imageRgbaReadTIFF("menu/mosaic.tif");
00324 else if (i == 27)
00325 button = imageRgbaReadTIFF("menu/box.tif");
00326 else if (i == 28)
00327 button = imageRgbaReadTIFF("menu/comb.tif");
00328 else if (i == 29)
00329 button = imageRgbaReadTIFF("menu/dots.tif");
00330 else if (i == 30)
00331 button = imageRgbaReadTIFF("menu/lines.tif");
00332 else if (i == 31)
00333 button = imageRgbaReadTIFF("menu/rgbdots.tif");
00334 else if (i == 32)
00335 button = imageRgbaReadTIFF("menu/noise.tif");
00336 else if (i == 33)
00337 button = imageRgbaReadTIFF("menu/blur.tif");
00338 else if (i == 34)
00339 button = imageRgbaReadTIFF("menu/sharpen.tif");
00340 else if (i == 35)
00341 button = imageRgbaReadTIFF("menu/edge.tif");
00342 else if (i == 36)
00343 button = imageRgbaReadTIFF("menu/emboss.tif");
00344 else if (i == 37)
00345 button = imageRgbaReadTIFF("menu/separate.tif");
00346 else if (i == 38)
00347 button = imageRgbaReadTIFF("menu/halfblur.tif");
00348 else if (i == 39)
00349 button = imageRgbaReadTIFF("menu/whiteblur.tif");
00350 else if (i == 40)
00351 button = imageRgbaReadTIFF("menu/blackblur.tif");
00352 else if (i == 41)
00353 button = imageRgbaReadTIFF("menu/chrome.tif");
00354 else if (i == 42)
00355 button = imageRgbaReadTIFF("menu/bw.tif");
00356 else if (i == 43)
00357 button = imageRgbaReadTIFF("menu/relief.tif");
00358 else if (i == 44)
00359 button = imageRgbaReadTIFF("menu/cutout.tif");
00360 else if (i == 45)
00361 button = imageRgbaReadTIFF("menu/brush.tif");
00362 else if (i == 46)
00363 button = imageRgbaReadTIFF("menu/spatter.tif");
00364 else if (i == 47)
00365 button = imageRgbaReadTIFF("menu/strokes.tif");
00366 else if (i == 48)
00367 button = imageRgbaReadTIFF("menu/starlight.tif");
00368 else if (i == 49)
00369 button = imageRgbaReadTIFF("menu/shine.tif");
00370 else if (i == 93)
00371 button = imageRgbaReadTIFF("menu/glass_texture8.tif");
00372 else if (i == 94)
00373 button = imageRgbaReadTIFF("menu/glass_texture7.tif");
00374 else if (i == 95)
00375 button = imageRgbaReadTIFF("menu/glass_texture6.tif");
00376 else if (i == 96)
00377 button = imageRgbaReadTIFF("menu/glass_texture5.tif");
00378 else if (i == 97)
00379 button = imageRgbaReadTIFF("menu/glass_texture4.tif");
00380 else if (i == 98)
00381 button = imageRgbaReadTIFF("menu/glass_texture3.tif");
00382 else if (i == 99)
00383 button = imageRgbaReadTIFF("menu/glass_texture2.tif");
00384 else if (i == 100)
00385 button = imageRgbaReadTIFF("menu/glass_texture1.tif");
00386 else if (i == 101)
00387 button = imageRgbaReadTIFF("menu/1.tif");
00388 else if (i == 102)
00389 button = imageRgbaReadTIFF("menu/2.tif");
00390 else if (i == 103)
00391 button = imageRgbaReadTIFF("menu/3.tif");
00392 else if (i == 104)
00393 button = imageRgbaReadTIFF("menu/4.tif");
00394 else if (i == 105)
00395 button = imageRgbaReadTIFF("menu/5.tif");
00396 else if (i == 106)
00397 button = imageRgbaReadTIFF("menu/6.tif");
00398 else if (i == 107)
00399 button = imageRgbaReadTIFF("menu/7.tif");
00400 else if (i == 108)
00401 button = imageRgbaReadTIFF("menu/8.tif");
00402 else if (i == 109)
00403 button = imageRgbaReadTIFF("menu/regler_start.tif");
00404 else if (i == 110)
00405 button = imageRgbaReadTIFF("menu/regler_mid.tif");
00406 else if (i == 111)
00407 button = imageRgbaReadTIFF("menu/regler_end.tif");
00408 else if (i == 112)
00409 button = imageRgbaReadTIFF("menu/regler.tif");
00410 else
00411 {
00412 button = imageRgbaNew(20, 20);
00413 imageRgbaSet(button, 0, 0, 0, 255);
00414 }
00415
00416 for (int y = 0; y < 20; y++)
00417 {
00418 for (int x = 0; x < 20; x++)
00419 {
00420 menu->data[i*400 + x+y*20] = button->data[x + y*20];
00421 }
00422 }
00423
00424 imageRgbaFree(button);
00425 }
00426
00427 if (argc == 2)
00428 original = imageRgbaReadTIFF(argv[1]);
00429 else
00430 original = imageRgbaReadTIFF("in.tif");
00431 E = new effect (imageRgbaClone(original), imageRgbaNew(original->width, original->height), imageRgbaNew(original->width, original->height), imageRgbaNew(original->width, original->height), menu);
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 fwkSetDisplayImage(E->display);
00445
00446
00447 fwkMainLoop();
00448
00449 logfile.close();
00450 return 1;
00451 }
00452
00454
00455 void batch()
00456 {
00457 const char *path = "output/";
00458 const char *outfilename = "out.tif";
00459 char imagenr[5];
00460 char url[512];
00461
00462 char counter[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
00463
00464 for (int nr = 0; nr < 20; nr++)
00465 {
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 changeEffect(44);
00483 E->mode = 4;
00484 E->value1 = 20 + (nr * 2);
00485 E->myColor = (Rgba){230, 0, 90, 255};
00486 (dynamic_cast< starlight *> ( E ))->strength = 10 + nr;
00487 E->LB(true);
00488
00489 imagenr[0] = counter[nr % 10];
00490 imagenr[1] = counter[int((float)nr / 10) % 10];
00491 imagenr[2] = counter[int((float)nr / 100) % 10];
00492 imagenr[3] = counter[int((float)nr / 1000) % 10];
00493 imagenr[4] = counter[int((float)nr / 10000) % 10];
00494
00495
00496
00497 strcpy(url, path);
00498 for (int s = 0; s < 5; s++)
00499 {
00500 strncat(url, &imagenr[(4 - s)], 1);
00501 }
00502 strcat(url, outfilename);
00503 logfile << url << endl;
00504
00505 imageRgbaWriteTIFF(url, E->img);
00506 resetImage();
00507 }
00508 exit(0);
00509 }