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 /* === C L A S S E S ======================================================= */
43 int generic_pen_test(int w, int h)
45 printf("generic_pen(w:%d,h:%d): ",w,h);
47 auto_ptr<float> data(new float[w*h]);
50 printf("Um..... malloc failure on line %d of "__FILE__"...\n",__LINE__);
54 generic_pen<float> pen(data.get(),w,h);
55 generic_pen<float> pen2;
59 printf("FAILURE! "__FILE__"@%d: On pen bool test\n",__LINE__);
63 if(&pen.x()[2]!=&pen[0][2])
65 printf("FAILURE! "__FILE__"@%d: On request for horizontal iterator\n",__LINE__);
69 if(&pen.y()[2]!=&pen[2][0])
71 printf("FAILURE! "__FILE__"@%d: On request for vertical iterator\n",__LINE__);
80 printf("FAILURE! "__FILE__"@%d: On pen assignment or pen comparison\n",__LINE__);
85 generic_pen<float>::difference_type diff(pen2-pen);
87 if(diff.x!=w || diff.y!=h)
89 printf("FAILURE! "__FILE__"@%d: pen difference inconsistency ([%d,%d]!=[%d,%d])\n",__LINE__,diff.x,diff.y,w,h);
93 if(pen.end_x()-pen.x()!=w-1)
95 printf("FAILURE! "__FILE__"@%d: iterator_x inconsistency (%ld!=%d)\n",__LINE__,pen.end_x()-pen.x(),w);
99 if(pen.end_y()-pen.y()!=h-1)
101 printf("FAILURE! "__FILE__"@%d: iterator_y inconsistency (%d!=%d)\n",__LINE__,pen.end_y()-pen.y(),h);
105 if(&pen.end_y()[-1]!=&pen.y()[(h-2)])
107 printf("FAILURE! "__FILE__"@%d: iterator_y inconsistency\n",__LINE__);
111 if(&pen.end_x()[-1]!=&pen.x()[(w-2)])
113 printf("FAILURE! "__FILE__"@%d: iterator_x inconsistency\n",__LINE__);
122 int alpha_pen_test(void)
124 printf("alpha_pen: ");
130 int bbox_pen_test(void)
132 printf("bbox_pen: ");
141 int display_pen(generic_pen<float> pen, int w, int h)
145 // print out the after pic
146 for(y=0;y<h;y++,pen.inc_y())
149 for(x=0;x<w;x++,pen.inc_x())
151 if(pen.get_value()>=2.0f)
153 else if(pen.get_value()>=1.0f)
155 else if(pen.get_value()>=0.8f)
157 else if(pen.get_value()>=0.6f)
159 else if(pen.get_value()>=0.4f)
161 else if(pen.get_value()>=0.2f)
163 else if(pen.get_value()>=-0.0001f)
175 int display_pen(generic_pen<double> pen, int w, int h)
179 // print out the after pic
180 for(y=0;y<h;y++,pen.inc_y())
183 for(x=0;x<w;x++,pen.inc_x())
185 if(pen.get_value()>=2.0f)
187 else if(pen.get_value()>=1.0f)
189 else if(pen.get_value()>=0.8f)
191 else if(pen.get_value()>=0.6f)
193 else if(pen.get_value()>=0.4f)
195 else if(pen.get_value()>=0.2f)
197 else if(pen.get_value()>=-0.0001f)
209 void emptyfunction(int v)
211 static int stupid = 0;
213 //printf("Called... %d\n",v);
216 int box_blur_test(void)
218 typedef float boxblur_float;
220 printf("box_blur: ");
224 auto_ptr<boxblur_float> data(new boxblur_float[w*h]);
225 auto_ptr<boxblur_float> data2(new boxblur_float[w*h]);
228 printf("Um..... malloc failure on line %d of "__FILE__"...\n",__LINE__);
232 generic_pen<boxblur_float> pen(data.get(),w,h);
233 generic_pen<boxblur_float> pen2;
235 generic_pen<boxblur_float> pen3(data2.get(),w,h);
238 for(y=0;y<h;y++,pen.inc_y())
240 for(x=0;x<w;x++,pen.inc_x())
242 if( (x-y<=1 && y-x<=1) || y==h/2 || x==w/2)
253 printf("\nBEFORE BOX BLUR:\n");
255 // print out the before pic
256 display_pen(pen,w,h);
258 // Pen 2 will be the end
263 vbox_blur(pen,pen2,2,pen3);
264 printf("\n VBLUR ONLY:\n");
265 display_pen(pen3,w,h);
267 // box_blur(pen,w,h,4);
268 hbox_blur(pen,pen2,2,pen3);
270 printf("\n HBLUR ONLY:\n");
271 display_pen(pen3,w,h);
275 vbox_blur(pen3,pen2,2,pen);
277 printf("\nAFTER BOX BLUR:\n");
279 // print out the after pic
280 bad_values=display_pen(pen,w,h);
284 printf("FAILURE! "__FILE__"@%d: blur result contained %d bad values\n",__LINE__,bad_values);
289 printf("CHECK BOXBLUR RESULTS %d,%d:\n",pen.diff_begin().x, pen.diff_begin().y);
290 for(y=0;y<h;y++,pen.inc_y())
292 for(x=0;x<w;x++,pen.inc_x())
296 for(int oy=-2; oy <= 2; ++oy)
300 if(iy >= h) iy = h-1;
302 for(int ox=-2; ox <= 2; ++ox)
306 if(ix >= w) ix = w-1;
308 if( (ix-iy<=1 && iy-ix<=1) || iy==h/2 || ix==w/2)
313 //print out if the relative error is high
315 float rf = pen.get_value() - f/25;
318 printf("pixel (%d,%d) off by %f\n",x,y,rf);
320 boxblur_float diff = fabs(pen.get_value() - f/25);
321 if(diff > max) max = diff;
322 pen.put_value(f/25); //if length = 2 then dim = 5.. area = 25
330 for(y=0;y<h;y++,pen.inc_y())
332 for(x=0;x<w;x++,pen.inc_x())
334 pen.put_value(pen.get_value()/max);
341 //printf("\nHBOXBLUR ERROR (max = %e):\n",max);
342 printf("\nCorrect results:\n");
343 display_pen(pen,w,h);
362 |::.:::O%@@@@@%O::::::::::|
363 |::.::::O%@@@@@%::::::::::|
364 |::.:::::OO@@@@@%O::::::::|
365 |::.:::::::%@@@@@%O:::::::|
366 |::.::::::.O%@@@@@%O::::::|
389 |.....:O%@@@@@%O..........|
390 |......:O%@@@@@%::........|
391 |.......:OO@@@@@OO:.......|
392 |........::%@@@@@%O:......|
393 |..........O%@@@@@%O:.....|
408 int gaussian_blur_test(void)
410 printf("gaussian_blur: ");
415 auto_ptr<float> data(new float[w*h]);
418 printf("Um..... malloc failure on line %d of "__FILE__"...\n",__LINE__);
422 generic_pen<float> pen(data.get(),w,h);
423 generic_pen<float> pen2;
426 for(y=0;y<h;y++,pen.inc_y())
428 for(x=0;x<w;x++,pen.inc_x())
430 if((x-y<=1 && y-x<=1) || y==h/2)
439 printf("\nBEFORE GAUSSIAN BLUR:\n");
441 // print out the before pic
442 for(y=0;y<h;y++,pen.inc_y())
445 for(x=0;x<w;x++,pen.inc_x())
447 if(pen.get_value()>=2.0f)
449 else if(pen.get_value()>=1.0f)
451 else if(pen.get_value()>=0.8f)
453 else if(pen.get_value()>=0.6f)
455 else if(pen.get_value()>=0.4f)
457 else if(pen.get_value()>=0.2f)
459 else if(pen.get_value()>=0.0f)
462 printf("X"),bad_values++;
469 // Pen 2 will be the end
474 gaussian_blur_5x5(pen,pen2);
475 gaussian_blur_5x5(pen,pen2);
476 gaussian_blur_5x5(pen,pen2);
480 gaussian_blur_3x3(pen,pen2);
481 gaussian_blur_3x3(pen,pen2);
482 gaussian_blur_3x3(pen,pen2);
483 gaussian_blur_3x3(pen,pen2);
484 gaussian_blur_3x3(pen,pen2);
487 // gaussian_blur(pen,pen2,15);
488 gaussian_blur(pen,pen2,10,10);
490 printf("\nAFTER GAUSSIAN BLUR:\n");
492 // print out the after pic
493 for(y=0;y<h;y++,pen.inc_y())
496 for(x=0;x<w;x++,pen.inc_x())
498 if(pen.get_value()>=2.0f)
500 else if(pen.get_value()>=1.0f)
502 else if(pen.get_value()>=0.8f)
504 else if(pen.get_value()>=0.6f)
506 else if(pen.get_value()>=0.4f)
508 else if(pen.get_value()>=0.2f)
510 else if(pen.get_value()>=0.0f)
513 printf("X"),bad_values++;
522 printf("FAILURE! "__FILE__"@%d: blur result contained bad values\n",__LINE__);
531 /* === E N T R Y P O I N T ================================================= */
537 error+=generic_pen_test(40,40);
538 error+=generic_pen_test(10,40);
539 error+=generic_pen_test(40,10);
540 if(error)return error;
541 error+=alpha_pen_test();
542 error+=bbox_pen_test();
543 error+=box_blur_test();
544 if(error)return error;
545 error+=gaussian_blur_test();