1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
48 /* Testing parameters */
49 static char test_desc[] = "Image Creation & access";
50 static char func_name[] = "cvCreateImage cvCreateImageHeader cvSetImageROI cvGetImageROI "
51 "cvSetImageCOI cvCreateImageData cvReleaseImageData "
52 "cvSetImageData cvCloneImage cvCopyImage cvInitImageHeader";
54 static int depths[] = { IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
55 IPL_DEPTH_32S, IPL_DEPTH_32F, IPL_DEPTH_64F, 0};
56 static int channels[] = {1, 2, 3, 4, 0};
58 static char* imageData = (char*)cvAlloc(10000);
62 static int foaImage( void )
64 CvSize size = cvSize(320, 200);
67 //Creating new image with different channels & depths
68 for( i = 0; depths[i] != 0; i++ ) // cycle for depths
69 for(j = 0; channels[j] != 0; j++) // cycle for channels
71 if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
72 continue; // all non 1 channels
73 IplImage* image = cvCreateImage( size, depths[i], channels[j] );
74 if( image->width != size.width || image->height != size.height )
76 trsWrite( ATS_CON | ATS_LST,
77 "cvCreateImage: Size mismatch: act %d x %d exp %d x %d\n",
78 image->width, image->height, size.width, size.height );
81 if( size.width * (depths[i] & IPL_DEPTH_MASK) / 8 > image->widthStep ||
82 (image->widthStep & 3) )
84 trsWrite( ATS_CON | ATS_LST, "cvCreateImage: Wrong widthStep: act %d\n",
89 cvReleaseImage( &image );
91 trsWrite( ATS_CON, "cvCreateImage: ... done\n" );
93 //Creating new image header with different channels & depths
94 for( i = 0; depths[i] != 0; i++ ) // cycle for depths
95 for(j = 0; channels[j] != 0; j++) // cycle for channels
97 if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
98 continue; // all non 1 channels
99 if( depths[i] == (int)IPL_DEPTH_8S )
101 IplImage* image = cvCreateImageHeader( size, depths[i], channels[j] );
102 if( image->width != size.width || image->height != size.height )
104 trsWrite( ATS_CON | ATS_LST,
105 "cvCreateImageHeader: Size mismatch: act %d x %d exp %d x %d\n",
106 image->width, image->height, size.width, size.height );
109 if( size.width * (depths[i] & IPL_DEPTH_MASK) / 8 > image->widthStep ||
110 (image->widthStep & 3) )
112 trsWrite( ATS_CON | ATS_LST, "cvCreateImageHeader: Wrong widthStep: act %d\n",
116 if( image->imageData )
118 trsWrite( ATS_CON | ATS_LST, "cvCreateImageHeader: imageData created :(\n" );
122 cvSetImageROI( image, cvRect(1, 1, size.width - 1, size.height - 1) );
123 if( image->roi->coi )
125 trsWrite( ATS_CON | ATS_LST, "cvSetImageROI: coi non zero\n" );
129 CvRect rect = cvGetImageROI( image );
130 if( rect.x != 1 || rect.y != 1 ||
131 rect.width != size.width - 1 || rect.height != size.height - 1 )
133 trsWrite( ATS_CON | ATS_LST,
134 "cvGetImageROI: wrong rect: act %d x %d x %d x %d "
135 "exp %d x %d x %d x %d\n",
136 rect.x, rect.y, rect.width, rect.height,
137 1, 1, size.width - 1, size.height - 1 );
141 cvSetImageCOI( image, 1 );
142 if( image->roi->coi != 1 )
144 trsWrite( ATS_CON | ATS_LST, "cvSetImageCOI: soi non 1\n" );
147 if( image->roi->xOffset != 1 || image->roi->yOffset != 1 ||
148 image->roi->width != size.width - 1 ||
149 image->roi->height != size.height - 1)
151 trsWrite( ATS_CON | ATS_LST,
152 "cvCreateImageHeader: Size mismatch: act %d x %d x %d x %d"
153 "exp %d x %d x %d x %d\n",
154 image->roi->xOffset, image->roi->yOffset,
155 image->roi->width, image->roi->height,
156 1, 1, size.width - 1, size.height - 1 );
160 cvCreateImageData( image );
161 if( !image->imageData )
163 trsWrite( ATS_CON | ATS_LST,
164 "cvCreateImageData: Wow :)... where is imageData ?....\n" );
168 cvReleaseImageData( image );
169 if( image->imageData )
171 trsWrite( ATS_CON | ATS_LST, "cvReleaseImageData: imageData non zero :(\n" );
175 cvSetImageData( image, imageData, size.width * channels[j] * 8 ); // magic width step :)
176 if( image->imageData != imageData )
178 trsWrite( ATS_CON | ATS_LST,
179 "cvSetImageData: wrong pointer to imageData: act %x, exp %x\n",
180 image->imageData, imageData );
183 if( image->widthStep != size.width * channels[j] * 8 )
185 trsWrite( ATS_CON | ATS_LST, "cvSetImageData: wrong imageStep: act %d, exp %d\n",
186 image->widthStep, size.width * channels[j] * 8 );
190 cvReleaseImageHeader( &image );
192 trsWrite( ATS_CON, "cvCreateImageHeader: ... done\n" );
193 trsWrite( ATS_CON, "cvSetImageROI: ... done\n" );
194 trsWrite( ATS_CON, "cvGetImageROI: ... done\n" );
195 trsWrite( ATS_CON, "cvSetImageCOI: ... done\n" );
196 trsWrite( ATS_CON, "cvCreateImageData: ... done\n" );
197 trsWrite( ATS_CON, "cvReleaseImageData: ... done\n" );
198 trsWrite( ATS_CON, "cvSetImageData: ... done\n" );
200 for( i = 0; depths[i] != 0; i++ ) // cycle for depths
201 for(j = 0; channels[j] != 0; j++) // cycle for channels
203 if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
204 continue; // all non 1 channels
205 if( depths[i] == (int)IPL_DEPTH_8S )
207 IplImage* src = cvCreateImage( size, depths[i], channels[j] );
208 //IplImage* dst = cvCreateImage( size, depths[i], channels[j] );
212 cvSetImageROI( src, cvRect(1, 1, size.width - 1, size.height - 1) );
214 for( int k = 0; k < src->widthStep * src->height; k++ )
215 src->imageData[k] = (char)k;
217 //cvCopy/*Image*/( src, dst );
218 dst = cvCloneImage( src );
221 if( clone->width != dst->width || clone->height != dst->height )
223 trsWrite( ATS_CON | ATS_LST,
224 "cvCopyImage/cvCloneImage: wrong destination size:"
225 "%d x %d <> %d %d\n",
226 clone->width, clone->height, dst->width, dst->height );
229 if( clone->widthStep != src->widthStep )
231 trsWrite( ATS_CON | ATS_LST,
232 "cvCloneImage: wrong width step: act %d exp %d\n",
233 clone->widthStep, src->widthStep );
238 trsWrite( ATS_CON | ATS_LST, "cvCloneImage: roi was lost\n" );
243 if( clone->roi->xOffset != 1 || clone->roi->yOffset != 1 ||
244 clone->roi->width != size.width - 1 ||
245 clone->roi->height != size.height - 1 )
247 trsWrite( ATS_CON | ATS_LST,
248 "cvCloneImage: Size mismatch: act %d x %d x %d x %d"
249 "exp %d x %d x %d x %d\n",
250 clone->roi->xOffset, clone->roi->yOffset,
251 clone->roi->width, clone->roi->height,
252 1, 1, size.width - 1, size.height - 1 );
257 if( depths[i] == IPL_DEPTH_32F )
259 src->depth = IPL_DEPTH_32S;
260 dst->depth = IPL_DEPTH_32S;
262 else if( depths[i] == IPL_DEPTH_64F )
264 src->depth = IPL_DEPTH_32S;
265 dst->depth = IPL_DEPTH_32S;
271 if( cvNorm( src, dst, CV_L1 ) )
273 trsWrite( ATS_CON | ATS_LST, "cvCopyImage: wrong destination image\n" );
276 /*if( cvNorm( src, clone, CV_L1 ) )
278 trsWrite( ATS_CON | ATS_LST, "cvCloneImage: wrong destination image\n" );
282 cvReleaseImage( &src );
283 cvReleaseImage( &clone );
285 trsWrite( ATS_CON, "cvCloneImage: ... done\n" );
286 //trsWrite( ATS_CON, "cvCopyImage: ... done\n" );
288 //Init new image header with different channels & depths
289 for( i = 0; depths[i] != 0; i++ ) // cycle for depths
290 for(j = 0; channels[j] != 0; j++) // cycle for channels
292 if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
293 continue; // all non 1 channels
295 cvInitImageHeader( &image, size, depths[i], channels[j], IPL_ORIGIN_TL, align );
296 if( image.width != size.width || image.height != size.height )
298 trsWrite( ATS_CON | ATS_LST,
299 "cvInitImageHeader: Size mismatch: act %d x %d exp %d x %d\n",
300 image.width, image.height, size.width, size.height );
303 if( ((size.width * channels[j] * (depths[i] & IPL_DEPTH_MASK) / 8 + align - 1) &
304 ~(align - 1)) != image.widthStep )
306 trsWrite( ATS_CON | ATS_LST,
307 "cvCreateImageHeader: Wrong widthStep: act %d exp: %d\n",
309 (size.width * (depths[i] & IPL_DEPTH_MASK) / 8 + align - 1) &
313 if( image.imageData )
315 trsWrite( ATS_CON | ATS_LST, "cvCreateImageHeader: imageData created :(\n" );
319 trsWrite( ATS_CON, "cvInitImageHeader: ... done\n" );
322 return trsResult( TRS_OK, "Ok" );
324 return trsResult( TRS_FAIL, "%d errors" );
331 /* Register test function */
332 trsReg( func_name, test_desc, atsAlgoClass, foaImage );