1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
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 ======================================================= */
25 #include <ETL/surface>
26 #include <ETL/gaussian>
29 /* === M A C R O S ========================================================= */
34 /* === C L A S S E S ======================================================= */
37 /* === P R O C E D U R E S ================================================= */
39 int display_pen(generic_pen<float> pen, int w, int h)
43 // print out the after pic
44 for(y=0;y<h;y++,pen.inc_y())
47 for(x=0;x<w;x++,pen.inc_x())
49 if(pen.get_value()>=2.0f)
51 else if(pen.get_value()>=1.0f)
53 else if(pen.get_value()>=0.8f)
55 else if(pen.get_value()>=0.6f)
57 else if(pen.get_value()>=0.4f)
59 else if(pen.get_value()>=0.2f)
61 else if(pen.get_value()>=-0.1f)
73 void make_pattern(generic_pen<float> pen, int w, int h)
76 for(y=0;y<h;y++,pen.inc_y())
78 for(x=0;x<w;x++,pen.inc_x())
80 if( (x-y<=1 && y-x<=1) || y==h/2 || x==w/2)
92 printf("Surface:basic_test(): Running...\n");
96 surface<float> my_surface(100,100);
98 gaussian_blur(my_surface.begin(),my_surface.end(),10,10);
100 surface<float> my_surface2(my_surface);
102 my_surface2.fill(0.5);
105 my_surface2=my_surface;
107 my_surface2.fill(0.5);
110 my_surface.fill(0.5);
113 surface<float> my_surface3;
114 my_surface3.mirror(my_surface2);
116 my_surface3.fill(0.5);
119 my_surface3=my_surface;
121 my_surface3.mirror(my_surface);
123 printf("Surface:basic_test(): %d errors.\n",ret);
128 int linear_sample_test()
130 printf("Surface:linear_sample_test(): Running...\n");
134 surface<float> my_surface(16,16);
136 my_surface.fill(0.0f);
138 make_pattern(my_surface.begin(),my_surface.get_w(),my_surface.get_h());
141 surface<float> dest(18+extra*2,18+extra*2);
144 for(x=-extra;x<dest.get_w()-extra;x++)
145 for(y=-extra;y<dest.get_h()-extra;y++)
147 dest[y+extra][x+extra]=my_surface.linear_sample(
148 float(x)/float(dest.get_w()-1-extra*2)*float(my_surface.get_w()-1),
149 float(y)/float(dest.get_h()-1-extra*2)*float(my_surface.get_h()-1)
153 display_pen(dest.begin(),dest.get_w(),dest.get_h());
155 printf("Surface:linear_sample_test(): %d errors.\n",ret);
160 int cubic_sample_test()
162 printf("Surface:cubic_sample_test(): Running...\n");
166 surface<float> my_surface(16,16);
168 my_surface.fill(0.0f);
170 make_pattern(my_surface.begin(),my_surface.get_w(),my_surface.get_h());
173 surface<float> dest(24,24);
176 for(x=0;x<dest.get_w();x++)
177 for(y=0;y<dest.get_h();y++)
179 dest[y][x]=my_surface.cubic_sample(
180 float(x)/float(dest.get_w()-1)*float(my_surface.get_w()-1),
181 float(y)/float(dest.get_h()-1)*float(my_surface.get_h()-1)
185 display_pen(dest.begin(),dest.get_w(),dest.get_h());
188 display_pen(my_surface.begin(),my_surface.get_w(),my_surface.get_h());
190 surface<float> dest(16,16);
193 for(x=0;x<dest.get_w();x++)
194 for(y=0;y<dest.get_h();y++)
196 dest[y][x]=my_surface.cubic_sample(
197 float(x)/float(dest.get_w()-1)*float(my_surface.get_w()-1),
198 float(y)/float(dest.get_h()-1)*float(my_surface.get_h()-1)
202 display_pen(dest.begin(),dest.get_w(),dest.get_h());
205 printf("Surface:cubic_sample_test(): %d errors.\n",ret);
210 /* === E N T R Y P O I N T ================================================= */
217 error+=linear_sample_test();
218 error+=cubic_sample_test();