cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % IIIII DDDD EEEEE N N TTTTT IIIII FFFFF Y Y % |
| 7 | % I D D E NN N T I F Y Y % |
| 8 | % I D D EEE N N N T I FFF Y % |
| 9 | % I D D E N NN T I F Y % |
| 10 | % IIIII DDDD EEEEE N N T IIIII F Y % |
| 11 | % % |
| 12 | % % |
| 13 | % Identify an Image Format and Characteristics. % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % September 1994 % |
| 18 | % % |
| 19 | % % |
| 20 | % Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization % |
| 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % Identify describes the format and characteristics of one or more image |
| 37 | % files. It will also report if an image is incomplete or corrupt. |
| 38 | % |
| 39 | % |
| 40 | */ |
| 41 | |
| 42 | /* |
| 43 | Include declarations. |
| 44 | */ |
| 45 | #include <stdio.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <string.h> |
| 48 | #include <math.h> |
| 49 | #include <time.h> |
| 50 | #include "wand/MagickWand.h" |
| 51 | #if defined(__WINDOWS__) |
| 52 | #include <windows.h> |
| 53 | #endif |
| 54 | |
| 55 | /* |
| 56 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 57 | % % |
| 58 | % % |
| 59 | % % |
| 60 | % M a i n % |
| 61 | % % |
| 62 | % % |
| 63 | % % |
| 64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 65 | % |
| 66 | % |
| 67 | */ |
| 68 | int main(int argc,char **argv) |
| 69 | { |
| 70 | char |
| 71 | *metadata, |
| 72 | *option; |
| 73 | |
| 74 | double |
| 75 | elapsed_time, |
| 76 | user_time; |
| 77 | |
| 78 | ExceptionInfo |
| 79 | *exception; |
| 80 | |
| 81 | ImageInfo |
| 82 | *image_info; |
| 83 | |
| 84 | MagickBooleanType |
| 85 | regard_warnings, |
| 86 | status; |
| 87 | |
| 88 | register long |
| 89 | i; |
| 90 | |
| 91 | TimerInfo |
| 92 | timer; |
| 93 | |
| 94 | unsigned long |
| 95 | iterations; |
| 96 | |
| 97 | MagickCoreGenesis(*argv,MagickTrue); |
| 98 | exception=AcquireExceptionInfo(); |
| 99 | iterations=1; |
| 100 | status=MagickFalse; |
| 101 | regard_warnings=MagickFalse; |
| 102 | for (i=1; i < (long) (argc-1); i++) |
| 103 | { |
| 104 | option=argv[i]; |
| 105 | if ((strlen(option) == 1) || ((*option != '-') && (*option != '+'))) |
| 106 | continue; |
| 107 | if (LocaleCompare("bench",option+1) == 0) |
| 108 | iterations=(unsigned long) atol(argv[++i]); |
| 109 | if (LocaleCompare("debug",option+1) == 0) |
| 110 | (void) SetLogEventMask(argv[++i]); |
| 111 | if (LocaleCompare("regard-warnings",option+1) == 0) |
| 112 | regard_warnings=MagickTrue; |
| 113 | } |
| 114 | GetTimerInfo(&timer); |
| 115 | for (i=0; i < (long) iterations; i++) |
| 116 | { |
| 117 | image_info=AcquireImageInfo(); |
| 118 | metadata=(char *) NULL; |
| 119 | status=IdentifyImageCommand(image_info,argc,argv,&metadata,exception); |
| 120 | if (exception->severity != UndefinedException) |
| 121 | { |
| 122 | if ((exception->severity > ErrorException) || |
| 123 | (regard_warnings != MagickFalse)) |
| 124 | status=MagickTrue; |
| 125 | CatchException(exception); |
| 126 | } |
| 127 | if (metadata != (char *) NULL) |
| 128 | { |
| 129 | (void) fputs(metadata,stdout); |
| 130 | (void) fputc('\n',stdout); |
| 131 | metadata=DestroyString(metadata); |
| 132 | } |
| 133 | image_info=DestroyImageInfo(image_info); |
| 134 | } |
| 135 | if (iterations > 1) |
| 136 | { |
| 137 | elapsed_time=GetElapsedTime(&timer); |
| 138 | user_time=GetUserTime(&timer); |
| 139 | (void) fprintf(stderr,"Performance: %lui %gips %0.3fu %ld:%02ld\n", |
| 140 | iterations,1.0*iterations/elapsed_time,user_time,(long) |
| 141 | (elapsed_time/60.0+0.5),(long) ceil(fmod(elapsed_time,60.0))); |
| 142 | } |
| 143 | exception=DestroyExceptionInfo(exception); |
| 144 | MagickCoreTerminus(); |
| 145 | return(status == MagickFalse ? 0 : 1); |
| 146 | } |