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.
52 #define PROC_M5 (1<<23) /* mmx */
53 #define PROC_M6 ((1<<15)|(1<<23)) /* cmov + mmx */
54 #define PROC_A6 ((1<<25)|PROC_M6) /* --||-- + xmm */
55 #define PROC_W7 ((1<<26)|PROC_A6) /* --||-- + emm */
59 #pragma warning( disable: 4996 )
63 determine processor type
66 get_processor_type( void )
75 GetSystemInfo( &sys );
77 if( sys.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL &&
78 sys.dwProcessorType == PROCESSOR_INTEL_PENTIUM )
80 int version = 0, features = 0, family = 0;
82 #if _MSC_VER >= 1200 || defined __ICL || defined __BORLANDC__
105 #elif defined __GNUC__
126 family = (version >> 8) & 15;
127 if( family >= 5 && (features & PROC_M6) != 0 ) /* Pentium II or higher */
129 proc_type = features & PROC_W7;
139 get_flavor( const char* name )
141 const char* ptr = strrchr( name, '.' );
145 strncpy( buffer, ptr - 2, 2 );
146 buffer[0] = (char)toupper(buffer[0]);
147 buffer[1] = (char)toupper(buffer[1]);
150 if( !strcmp( buffer, "PL" ))
152 if( !strcmp( buffer, "W7" ))
153 return "PIV-optimized";
154 else if( !strcmp( buffer, "A6" ))
155 return "PIII-optimized";
156 else if( !strcmp( buffer, "M6" ))
157 return "PII-optimized";
158 else if( !strcmp( buffer, "M5" ))
159 return "Pentium MMX-optimized";
160 else if( !strcmp( buffer, "P6" ))
161 return "Pentium Pro-optimized";
162 else if( !strcmp( buffer, "P5" ))
163 return "Pentium-optimized";
164 else if( !strcmp( buffer, "PX" ))
165 return "Generic IA32";
166 else if( !strcmp( buffer, "IX" ))
167 return "Generic IA64";
168 else if( !strcmp( buffer, "I7" ))
169 return "Itanium-optimized";
175 tryLoadOpenCV( const char* name )
177 const char* version = 0;
178 HINSTANCE dll = LoadLibrary( name );
182 if( GetProcAddress( dll, "cvAccMask" ) != 0 ) // alpha 3 had cvAccMask function
183 version = "alpha 3.x";
184 else if( GetProcAddress( dll, "cvmAdd" ) != 0 ) // till beta 2.x OpenCV had separate cvm* functions
185 version = "beta 1.5 (a.k.a. 0.0.7)";
186 else if( GetProcAddress( dll, "cvHoughLinesP" ) != 0 )
187 version = "beta 2.x (a.k.a. 0.9.3)"; // beta 2 had separate functions for different variations of Hough transform
188 else if( GetProcAddress( dll, "cvEigenProjection" ) != 0 )
189 version = "beta 3 (a.k.a 0.9.4) or beta 3.1 (a.k.a 0.9.5)"; // beta 3.x had cvEigenProjection and related functions
190 else if( GetProcAddress( dll, "cvHoughCircles" ) == 0 )
191 version = "beta 4.x (a.k.a. 0.9.5 or 0.9.6)";
192 else if( GetProcAddress( dll, "cvWatershed" ) == 0 )
193 version = "beta 5.x (a.k.a. 0.9.7)";
194 else if( GetProcAddress( dll, "cvInpaint" ) == 0 )
195 version = "1.0rc1 (a.k.a. 0.9.9)";
197 version = "1.0 or later";
205 typedef struct _IPLLibVersion
207 int major; /*e.g. 2 */
208 int minor; /*e.g. 0 */
209 int build; /*e.g. 1 */
210 const char* Name; /*"ipl6l.lib","iplm5.dll"*/
211 const char* Version; /*e.g."v2.00" */
212 const char* InternalVersion; /*e.g. "[2.00.01.023,01/01/99]" */
213 const char* BuildDate;/*e.g. "Jan199"*/
214 const char* CallConv;
218 typedef const IPLLibVersion* (__stdcall* IplGetLibVersion)(void);
221 load_file( const char* name, int* _size )
223 FILE* f = fopen( name, "rb" );
229 fseek( f, 0, SEEK_END );
231 fseek( f, 0, SEEK_SET );
233 buffer = (char*)malloc( size );
234 if( fread( buffer, 1, size, f ) != (unsigned)size )
251 find_signature( char* buffer, int size, const char* signature )
254 int sig_length = (int)strlen(signature);
256 while( ptr < buffer + size )
258 ptr = (char*)memchr( ptr, signature[0], buffer + size - ptr );
259 if( !ptr || buffer + size - ptr < sig_length )
265 if( !memcmp( ptr, signature, sig_length )) // found!
274 // convert date from string "/mm/dd/yyyy" or "mm/dd/yy" to time_t.
275 static time_t date( const char* str )
278 int month, day, year;
280 if( sscanf( str, "%d/%d/%d", &month, &day, &year ) != 3 )
283 memset( &t, 0, sizeof(t));
286 t.tm_mon = month - 1;
287 t.tm_year = year - (year > 100 ? 1900 : 0);
294 tryLoadIPL( const char* name )
296 //time_t ipl_2_1_date = date("01/01/2000");
297 //time_t ipl_2_2_date = date("01/20/2000");
298 //time_t ipl_2_5_date = date("10/09/2000");
301 const char* version = 0;
302 const char* dotptr = strrchr( name, '.' );
303 assert( dotptr != 0 );
304 if( dotptr[-1] == 'l' || dotptr[-1] == 'L' ) // switcher
307 char* buffer = load_file( name, &size );
309 if( find_signature( buffer, size, "IPLW7.DLL" ))
310 version = "2.5 or later";
311 else if( find_signature( buffer, size, "iplNoiseImage" ))
314 version = "2.1 or earlier";
321 dll = LoadLibrary( name );
323 if( dll ) // if it is not just a switcher, we can use iplGetLibVersion
325 IplGetLibVersion getLibVersion =
326 (IplGetLibVersion)GetProcAddress(dll, "iplGetLibVersion");
329 version = getLibVersion()->InternalVersion;
331 version = "[ERROR - iplGetLibVersion could not be found]";
334 version = "[ERROR - dll could not be loaded]";
342 tryLoadIppCV( const char* /*name*/, _finddata_t* finddata )
345 // IppCV and OptCV: functionality is approximately the same,
346 // so the function checks modification time of the DLL to determine its version.
348 time_t ippcv_alpha_3_4 = date("01/01/2001");
349 time_t ippcv_beta_1_5 = date("06/01/2000");
350 time_t ippcv_beta_2 = date("01/10/2000");
352 if( finddata->time_write < ippcv_alpha_3_4 )
354 else if( finddata->time_write < ippcv_beta_1_5 )
356 else if( finddata->time_write < ippcv_beta_2 )
363 void scan_folder( char* folder, int length )
365 const char* cv_names[] = { "cv", "cv096", "cv097", "cv099", "cv100", 0 };
367 _finddata_t finddata;
375 const char* version = 0;
377 if( folder[length - 1] != '/' && folder[length - 1] != '\\' )
380 folder[length] = '\\';
381 folder[++length] = '0';
384 for( i = 0; cv_names[i] != 0; i++ )
387 sprintf( folder + length, "%s.dll", cv_names[i] );
388 version = tryLoadOpenCV( folder );
392 printf("%s:\n\t OpenCV version %s\n", folder, version );
395 sprintf( folder + length, "%sd.dll", cv_names[i] );
396 version = tryLoadOpenCV( folder );
400 printf("%s:\n\t OpenCV (Debug) version %s\n", folder, version );
405 strcpy( folder + length, "ipl*.dll" );
406 search_id = _findfirst( folder, &finddata );
412 strcpy( folder + length, finddata.name );
413 version = tryLoadIPL( folder );
417 printf("%s:\n\t IPL %s version %s\n", folder, get_flavor( folder ),
421 while( _findnext( search_id, &finddata ) >= 0 );
425 strcpy( folder + length, "ippcv*.dll" );
426 search_id = _findfirst( folder, &finddata );
432 strcpy( folder + length, finddata.name );
433 version = tryLoadIppCV( folder, &finddata );
437 printf("%s:\n\t IppCV %s version %s\n", folder, get_flavor( folder ),
441 while( _findnext( search_id, &finddata ) >= 0 );
445 strcpy( folder + length, "optcv*.dll" );
446 search_id = _findfirst( folder, &finddata );
452 strcpy( folder + length, finddata.name );
453 version = tryLoadIppCV( folder, &finddata );
457 printf("%s:\n\t IppCV %s version %s\n", folder, get_flavor( folder ),
461 while( _findnext( search_id, &finddata ) >= 0 );
467 char* path = getenv( "PATH" );
468 char* folder_start = path;
470 int proc_type = get_processor_type();
472 printf("Processor: %s or compatible\n", proc_type == PROC_M7 ? "EM64T-compatible" :
473 proc_type == PROC_W7 ? "Pentium IV" :
474 proc_type == PROC_A6 ? "Pentium III" :
475 proc_type == PROC_M6 ? "Pentium II" :
476 "Generic IA32 processor" );
478 for( ; *path != '\0'; path++ )
482 int length = (int)(path - folder_start);
483 strncpy( folder, folder_start, length );
484 folder[length] = '\0';
485 //printf( "%s\n", buffer );
486 scan_folder( folder, length );
487 folder_start = path + 1;