1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
3 ** Handle Template Class Test
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include <ETL/boxblur>
33 //#include <ETL/gaussian>
36 /* === M A C R O S ========================================================= */
41 #define DEBUGPOINT() fprintf(stderr,__FILE__":%d: Debugpoint\n",__LINE__)
43 /* === C L A S S E S ======================================================= */
45 int generic_pen_test(int w, int h)
47 printf("generic_pen(w:%d,h:%d): ",w,h);
49 auto_ptr<float> data(new float[w*h]);
52 printf("Um..... malloc failure on line %d of "__FILE__"...\n",__LINE__);
56 generic_pen<float> pen(data.get(),w,h);
57 generic_pen<float> pen2;
61 printf("FAILURE! "__FILE__"@%d: On pen bool test\n",__LINE__);
65 if(&pen.x()[2]!=&pen[0][2])
67 printf("FAILURE! "__FILE__"@%d: On request for horizontal iterator\n",__LINE__);
71 if(&pen.y()[2]!=&pen[2][0])
73 printf("FAILURE! "__FILE__"@%d: On request for vertical iterator\n",__LINE__);
82 printf("FAILURE! "__FILE__"@%d: On pen assignment or pen comparison\n",__LINE__);
87 generic_pen<float>::difference_type diff(pen2-pen);
89 if(diff.x!=w || diff.y!=h)
91 printf("FAILURE! "__FILE__"@%d: pen difference inconsistency ([%d,%d]!=[%d,%d])\n",__LINE__,diff.x,diff.y,w,h);
95 if(pen.end_x()-pen.x()!=w-1)
97 printf("FAILURE! "__FILE__"@%d: iterator_x inconsistency (%d!=%d)\n",__LINE__,pen.end_x()-pen.x(),w);
101 if(pen.end_y()-pen.y()!=h-1)
103 printf("FAILURE! "__FILE__"@%d: iterator_y inconsistency (%d!=%d)\n",__LINE__,pen.end_y()-pen.y(),h);
107 if(&pen.end_y()[-1]!=&pen.y()[(h-2)])
109 printf("FAILURE! "__FILE__"@%d: iterator_y inconsistency\n",__LINE__);
113 if(&pen.end_x()[-1]!=&pen.x()[(w-2)])
115 printf("FAILURE! "__FILE__"@%d: iterator_x inconsistency\n",__LINE__);
124 int alpha_pen_test(void)
126 printf("alpha_pen: ");
132 int bbox_pen_test(void)
134 printf("bbox_pen: ");
143 int display_pen(generic_pen<float> pen, int w, int h)
147 // print out the after pic
148 for(y=0;y<h;y++,pen.inc_y())
151 for(x=0;x<w;x++,pen.inc_x())
153 if(pen.get_value()>=2.0f)
155 else if(pen.get_value()>=1.0f)
157 else if(pen.get_value()>=0.8f)
159 else if(pen.get_value()>=0.6f)
161 else if(pen.get_value()>=0.4f)
163 else if(pen.get_value()>=0.2f)
165 else if(pen.get_value()>=-0.0001f)
177 int display_pen(generic_pen<double> pen, int w, int h)
181 // print out the after pic
182 for(y=0;y<h;y++,pen.inc_y())
185 for(x=0;x<w;x++,pen.inc_x())
187 if(pen.get_value()>=2.0f)
189 else if(pen.get_value()>=1.0f)
191 else if(pen.get_value()>=0.8f)
193 else if(pen.get_value()>=0.6f)
195 else if(pen.get_value()>=0.4f)
197 else if(pen.get_value()>=0.2f)
199 else if(pen.get_value()>=-0.0001f)
211 void emptyfunction(int v)
213 static int stupid = 0;
215 //printf("Called... %d\n",v);
218 int box_blur_test(void)
220 typedef float boxblur_float;
222 printf("box_blur: ");
226 auto_ptr<boxblur_float> data(new boxblur_float[w*h]);
227 auto_ptr<boxblur_float> data2(new boxblur_float[w*h]);
230 printf("Um..... malloc failure on line %d of "__FILE__"...\n",__LINE__);
234 generic_pen<boxblur_float> pen(data.get(),w,h);
235 generic_pen<boxblur_float> pen2;
237 generic_pen<boxblur_float> pen3(data2.get(),w,h);
240 for(y=0;y<h;y++,pen.inc_y())
242 for(x=0;x<w;x++,pen.inc_x())
244 if(x-y<=1 && y-x<=1 || y==h/2 || x==w/2)
255 printf("\nBEFORE BOX BLUR:\n");
257 // print out the before pic
258 display_pen(pen,w,h);
260 // Pen 2 will be the end
265 vbox_blur(pen,pen2,2,pen3);
266 printf("\n VBLUR ONLY:\n");
267 display_pen(pen3,w,h);
269 // box_blur(pen,w,h,4);
270 hbox_blur(pen,pen2,2,pen3);
272 printf("\n HBLUR ONLY:\n");
273 display_pen(pen3,w,h);
277 vbox_blur(pen3,pen2,2,pen);
279 printf("\nAFTER BOX BLUR:\n");
281 // print out the after pic
282 bad_values=display_pen(pen,w,h);
286 printf("FAILURE! "__FILE__"@%d: blur result contained %d bad values\n",__LINE__,bad_values);
291 printf("CHECK BOXBLUR RESULTS %d,%d:\n",pen.diff_begin().x, pen.diff_begin().y);
292 for(y=0;y<h;y++,pen.inc_y())
294 for(x=0;x<w;x++,pen.inc_x())
298 for(int oy=-2; oy <= 2; ++oy)
302 if(iy >= h) iy = h-1;
304 for(int ox=-2; ox <= 2; ++ox)
308 if(ix >= w) ix = w-1;
310 if(ix-iy<=1 && iy-ix<=1 || iy==h/2 || ix==w/2)
315 //print out if the relative error is high
317 float rf = pen.get_value() - f/25;
320 printf("pixel (%d,%d) off by %f\n",x,y,rf);
322 boxblur_float diff = fabs(pen.get_value() - f/25);
323 if(diff > max) max = diff;
324 pen.put_value(f/25); //if length = 2 then dim = 5.. area = 25
332 for(y=0;y<h;y++,pen.inc_y())
334 for(x=0;x<w;x++,pen.inc_x())
336 pen.put_value(pen.get_value()/max);
343 //printf("\nHBOXBLUR ERROR (max = %e):\n",max);
344 printf("\nCorrect results:\n");
345 display_pen(pen,w,h);
364 |::.:::O%@@@@@%O::::::::::|
365 |::.::::O%@@@@@%::::::::::|
366 |::.:::::OO@@@@@%O::::::::|
367 |::.:::::::%@@@@@%O:::::::|
368 |::.::::::.O%@@@@@%O::::::|
391 |.....:O%@@@@@%O..........|
392 |......:O%@@@@@%::........|
393 |.......:OO@@@@@OO:.......|
394 |........::%@@@@@%O:......|
395 |..........O%@@@@@%O:.....|
410 int gaussian_blur_test(void)
412 printf("gaussian_blur: ");
417 auto_ptr<float> data(new float[w*h]);
420 printf("Um..... malloc failure on line %d of "__FILE__"...\n",__LINE__);
424 generic_pen<float> pen(data.get(),w,h);
425 generic_pen<float> pen2;
428 for(y=0;y<h;y++,pen.inc_y())
430 for(x=0;x<w;x++,pen.inc_x())
432 if((x-y<=1 && y-x<=1) || y==h/2)
441 printf("\nBEFORE GAUSSIAN BLUR:\n");
443 // print out the before pic
444 for(y=0;y<h;y++,pen.inc_y())
447 for(x=0;x<w;x++,pen.inc_x())
449 if(pen.get_value()>=2.0f)
451 else if(pen.get_value()>=1.0f)
453 else if(pen.get_value()>=0.8f)
455 else if(pen.get_value()>=0.6f)
457 else if(pen.get_value()>=0.4f)
459 else if(pen.get_value()>=0.2f)
461 else if(pen.get_value()>=0.0f)
464 printf("X"),bad_values++;
471 // Pen 2 will be the end
476 gaussian_blur_5x5(pen,pen2);
477 gaussian_blur_5x5(pen,pen2);
478 gaussian_blur_5x5(pen,pen2);
482 gaussian_blur_3x3(pen,pen2);
483 gaussian_blur_3x3(pen,pen2);
484 gaussian_blur_3x3(pen,pen2);
485 gaussian_blur_3x3(pen,pen2);
486 gaussian_blur_3x3(pen,pen2);
489 // gaussian_blur(pen,pen2,15);
490 gaussian_blur(pen,pen2,10,10);
492 printf("\nAFTER GAUSSIAN BLUR:\n");
494 // print out the after pic
495 for(y=0;y<h;y++,pen.inc_y())
498 for(x=0;x<w;x++,pen.inc_x())
500 if(pen.get_value()>=2.0f)
502 else if(pen.get_value()>=1.0f)
504 else if(pen.get_value()>=0.8f)
506 else if(pen.get_value()>=0.6f)
508 else if(pen.get_value()>=0.4f)
510 else if(pen.get_value()>=0.2f)
512 else if(pen.get_value()>=0.0f)
515 printf("X"),bad_values++;
524 printf("FAILURE! "__FILE__"@%d: blur result contained bad values\n",__LINE__);
533 /* === E N T R Y P O I N T ================================================= */
539 error+=generic_pen_test(40,40);
540 error+=generic_pen_test(10,40);
541 error+=generic_pen_test(40,10);
542 if(error)return error;
543 error+=alpha_pen_test();
544 error+=bbox_pen_test();
545 error+=box_blur_test();
546 if(error)return error;
547 error+=gaussian_blur_test();