blob: 4ea102e624c2b46261a8d0ec66eaef59ce7f00fd [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC OOO M M PPPP AAA RRRR EEEEE %
7% C O O MM MM P P A A R R E %
8% C O O M M M PPPP AAAAA RRRR EEE %
9% C O O M M P A A R R E %
10% CCCC OOO M M P A A R R EEEEE %
11% %
12% %
13% Image Comparison Methods %
14% %
15% Software Design %
16% John Cristy %
17% December 2003 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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% Use the compare program to mathematically and visually annotate the
cristy6a917d92009-10-06 19:23:54 +000037% difference between an image and its reconstruction.
cristy3ed852e2009-09-05 21:47:34 +000038%
39*/
40
41/*
42 Include declarations.
43*/
cristy4c08aed2011-07-01 19:47:50 +000044#include "MagickWand/studio.h"
45#include "MagickWand/MagickWand.h"
46#include "MagickWand/mogrify-private.h"
47#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000048
49/*
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51% %
52% %
53% %
54% C o m p a r e I m a g e C o m m a n d %
55% %
56% %
57% %
58%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59%
cristy8a9106f2011-07-05 14:39:26 +000060% CompareImagesCommand() compares two images and returns the difference between
cristy3ed852e2009-09-05 21:47:34 +000061% them as a distortion metric and as a new image visually annotating their
62% differences.
63%
cristy8a9106f2011-07-05 14:39:26 +000064% The format of the CompareImagesCommand method is:
cristy3ed852e2009-09-05 21:47:34 +000065%
cristy8a9106f2011-07-05 14:39:26 +000066% MagickBooleanType CompareImagesCommand(ImageInfo *image_info,int argc,
cristy3ed852e2009-09-05 21:47:34 +000067% char **argv,char **metadata,ExceptionInfo *exception)
68%
69% A description of each parameter follows:
70%
71% o image_info: the image info.
72%
73% o argc: the number of elements in the argument vector.
74%
75% o argv: A text array containing the command line arguments.
76%
77% o metadata: any metadata is returned here.
78%
79% o exception: return any errors or warnings in this structure.
80%
81*/
82
83static MagickBooleanType CompareUsage(void)
84{
85 const char
86 **p;
87
88 static const char
89 *miscellaneous[]=
90 {
91 "-debug events display copious debugging information",
92 "-help print program options",
93 "-list type print a list of supported option arguments",
94 "-log format format of debugging information",
95 (char *) NULL
96 },
97 *settings[]=
98 {
99 "-alpha option on, activate, off, deactivate, set, opaque, copy",
100 " transparent, extract, background, or shape",
101 "-authenticate password",
102 " decipher image with this password",
103 "-channel type apply option to select image channels",
104 "-colorspace type alternate image colorspace",
105 "-compose operator set image composite operator",
106 "-compress type type of pixel compression when writing the image",
107 "-decipher filename convert cipher pixels to plain pixels",
108 "-define format:option",
109 " define one or more image format options",
110 "-density geometry horizontal and vertical density of the image",
111 "-depth value image depth",
112 "-dissimilarity-threshold value",
cristyba029a52010-11-27 02:18:26 +0000113 " maximum distortion for (sub)image match",
cristy3ed852e2009-09-05 21:47:34 +0000114 "-encipher filename convert plain pixels to cipher pixels",
115 "-extract geometry extract area from image",
116 "-format \"string\" output formatted image characteristics",
117 "-fuzz distance colors within this distance are considered equal",
118 "-highlight-color color",
119 " empasize pixel differences with this color",
120 "-identify identify the format and characteristics of the image",
121 "-interlace type type of image interlacing scheme",
122 "-limit type value pixel cache resource limit",
123 "-lowlight-color color",
124 " de-emphasize pixel differences with this color",
125 "-metric type measure differences between images with this metric",
126 "-monitor monitor progress",
127 "-passphrase filename get the passphrase from this file",
128 "-profile filename add, delete, or apply an image profile",
129 "-quality value JPEG/MIFF/PNG compression level",
130 "-quiet suppress all warning messages",
131 "-quantize colorspace reduce colors in this colorspace",
132 "-regard-warnings pay attention to warning messages",
133 "-respect-parentheses settings remain in effect until parenthesis boundary",
134 "-sampling-factor geometry",
135 " horizontal and vertical sampling factor",
136 "-seed value seed a new sequence of pseudo-random numbers",
137 "-set attribute value set an image attribute",
138 "-quality value JPEG/MIFF/PNG compression level",
139 "-size geometry width and height of image",
cristyb9498042010-08-09 01:14:07 +0000140 "-subimage-search search for subimage",
cristy3ed852e2009-09-05 21:47:34 +0000141 "-transparent-color color",
142 " transparent color",
143 "-type type image type",
144 "-verbose print detailed information about the image",
145 "-version print version information",
146 "-virtual-pixel method",
147 " virtual pixel access method",
148 (char *) NULL
149 };
150
cristybb503372010-05-27 20:51:26 +0000151 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +0000152 (void) printf("Copyright: %s\n",GetMagickCopyright());
153 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +0000154 (void) printf("Usage: %s [options ...] image reconstruct difference\n",
155 GetClientName());
156 (void) printf("\nImage Settings:\n");
157 for (p=settings; *p != (char *) NULL; p++)
158 (void) printf(" %s\n",*p);
159 (void) printf("\nMiscellaneous Options:\n");
160 for (p=miscellaneous; *p != (char *) NULL; p++)
161 (void) printf(" %s\n",*p);
162 (void) printf(
163 "\nBy default, the image format of `file' is determined by its magic\n");
164 (void) printf(
165 "number. To specify a particular image format, precede the filename\n");
166 (void) printf(
167 "with an image format name and a colon (i.e. ps:image) or specify the\n");
168 (void) printf(
169 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
170 (void) printf("'-' for standard input or output.\n");
171 return(MagickFalse);
172}
173
cristy8a9106f2011-07-05 14:39:26 +0000174WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000175 int argc,char **argv,char **metadata,ExceptionInfo *exception)
176{
cristy2b70e802009-11-23 19:40:25 +0000177#define DefaultDissimilarityThreshold 0.31830988618379067154
cristy3ed852e2009-09-05 21:47:34 +0000178#define DestroyCompare() \
179{ \
180 if (similarity_image != (Image *) NULL) \
181 similarity_image=DestroyImageList(similarity_image); \
182 if (difference_image != (Image *) NULL) \
183 difference_image=DestroyImageList(difference_image); \
184 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +0000185 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +0000186 argv[i]=DestroyString(argv[i]); \
187 argv=(char **) RelinquishMagickMemory(argv); \
188}
189#define ThrowCompareException(asperity,tag,option) \
190{ \
191 if (exception->severity < (asperity)) \
192 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \
193 "`%s'",option); \
194 DestroyCompare(); \
195 return(MagickFalse); \
196}
197#define ThrowCompareInvalidArgumentException(option,argument) \
198{ \
199 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
200 "InvalidArgument","`%s': %s",option,argument); \
201 DestroyCompare(); \
202 return(MagickFalse); \
203}
204
205 char
206 *filename,
207 *option;
208
209 const char
210 *format;
211
cristy3ed852e2009-09-05 21:47:34 +0000212 double
213 dissimilarity_threshold,
214 distortion,
215 similarity_metric;
216
217 Image
218 *difference_image,
219 *image,
220 *reconstruct_image,
221 *similarity_image;
222
223 ImageStack
224 image_stack[MaxImageStackDepth+1];
225
cristy3ed852e2009-09-05 21:47:34 +0000226 MagickBooleanType
227 fire,
cristyae6203d2010-08-09 01:12:14 +0000228 pend,
cristyebbcfea2011-02-25 02:43:54 +0000229 respect_parenthesis,
cristyae6203d2010-08-09 01:12:14 +0000230 subimage_search;
cristy3ed852e2009-09-05 21:47:34 +0000231
232 MagickStatusType
233 status;
234
235 MetricType
236 metric;
237
238 RectangleInfo
239 offset;
240
cristybb503372010-05-27 20:51:26 +0000241 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000242 i;
243
cristyae6203d2010-08-09 01:12:14 +0000244 ssize_t
245 j,
246 k;
247
cristy3ed852e2009-09-05 21:47:34 +0000248 /*
249 Set defaults.
250 */
251 assert(image_info != (ImageInfo *) NULL);
252 assert(image_info->signature == MagickSignature);
253 if (image_info->debug != MagickFalse)
254 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
255 assert(exception != (ExceptionInfo *) NULL);
256 if (argc == 2)
257 {
258 option=argv[1];
259 if ((LocaleCompare("version",option+1) == 0) ||
260 (LocaleCompare("-version",option+1) == 0))
261 {
cristyb51dff52011-05-19 16:55:47 +0000262 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +0000263 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +0000264 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
265 GetMagickCopyright());
266 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
267 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +0000268 return(MagickFalse);
269 }
270 }
271 if (argc < 3)
cristy13e61a12010-02-04 20:19:00 +0000272 return(CompareUsage());
cristy3ed852e2009-09-05 21:47:34 +0000273 difference_image=NewImageList();
274 similarity_image=NewImageList();
275 dissimilarity_threshold=DefaultDissimilarityThreshold;
276 distortion=0.0;
277 format=(char *) NULL;
278 j=1;
279 k=0;
280 metric=UndefinedMetric;
281 NewImageStack();
282 option=(char *) NULL;
283 pend=MagickFalse;
284 reconstruct_image=NewImageList();
cristyebbcfea2011-02-25 02:43:54 +0000285 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000286 status=MagickTrue;
cristyae6203d2010-08-09 01:12:14 +0000287 subimage_search=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000288 /*
289 Compare an image.
290 */
291 ReadCommandlLine(argc,&argv);
292 status=ExpandFilenames(&argc,&argv);
293 if (status == MagickFalse)
294 ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
295 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +0000296 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3ed852e2009-09-05 21:47:34 +0000297 {
298 option=argv[i];
299 if (LocaleCompare(option,"(") == 0)
300 {
301 FireImageStack(MagickTrue,MagickTrue,pend);
302 if (k == MaxImageStackDepth)
303 ThrowCompareException(OptionError,"ParenthesisNestedTooDeeply",
304 option);
305 PushImageStack();
306 continue;
307 }
308 if (LocaleCompare(option,")") == 0)
309 {
310 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
311 if (k == 0)
312 ThrowCompareException(OptionError,"UnableToParseExpression",option);
313 PopImageStack();
314 continue;
315 }
cristy042ee782011-04-22 18:48:30 +0000316 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000317 {
318 Image
319 *images;
320
321 /*
322 Read input image.
323 */
324 FireImageStack(MagickFalse,MagickFalse,pend);
325 filename=argv[i];
cristycee97112010-05-28 00:44:52 +0000326 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +0000327 filename=argv[++i];
cristy1b58f252012-03-01 01:41:41 +0000328 images=ReadImages(image_info,filename,exception);
cristy3ed852e2009-09-05 21:47:34 +0000329 status&=(images != (Image *) NULL) &&
330 (exception->severity < ErrorException);
331 if (images == (Image *) NULL)
332 continue;
333 AppendImageStack(images);
334 continue;
335 }
336 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
337 switch (*(option+1))
338 {
339 case 'a':
340 {
341 if (LocaleCompare("alpha",option+1) == 0)
342 {
cristybb503372010-05-27 20:51:26 +0000343 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000344 type;
345
346 if (*option == '+')
347 break;
348 i++;
cristybb503372010-05-27 20:51:26 +0000349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000350 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000351 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000352 if (type < 0)
353 ThrowCompareException(OptionError,"UnrecognizedAlphaChannelType",
354 argv[i]);
355 break;
356 }
357 if (LocaleCompare("authenticate",option+1) == 0)
358 {
359 if (*option == '+')
360 break;
361 i++;
cristybb503372010-05-27 20:51:26 +0000362 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000363 ThrowCompareException(OptionError,"MissingArgument",option);
364 break;
365 }
366 ThrowCompareException(OptionError,"UnrecognizedOption",option);
367 }
368 case 'c':
369 {
370 if (LocaleCompare("cache",option+1) == 0)
371 {
372 if (*option == '+')
373 break;
374 i++;
cristybb503372010-05-27 20:51:26 +0000375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000376 ThrowCompareException(OptionError,"MissingArgument",option);
377 if (IsGeometry(argv[i]) == MagickFalse)
378 ThrowCompareInvalidArgumentException(option,argv[i]);
379 break;
380 }
381 if (LocaleCompare("channel",option+1) == 0)
382 {
cristybb503372010-05-27 20:51:26 +0000383 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000384 channel;
385
386 if (*option == '+')
387 break;
388 i++;
cristybb503372010-05-27 20:51:26 +0000389 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000390 ThrowCompareException(OptionError,"MissingArgument",option);
391 channel=ParseChannelOption(argv[i]);
392 if (channel < 0)
393 ThrowCompareException(OptionError,"UnrecognizedChannelType",
394 argv[i]);
cristye2a912b2011-12-05 20:02:07 +0000395 SetPixelChannelMapMask(image,(ChannelType) channel);
cristy3ed852e2009-09-05 21:47:34 +0000396 break;
397 }
398 if (LocaleCompare("colorspace",option+1) == 0)
399 {
cristybb503372010-05-27 20:51:26 +0000400 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000401 colorspace;
402
403 if (*option == '+')
404 break;
405 i++;
cristybb503372010-05-27 20:51:26 +0000406 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000407 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000408 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000409 argv[i]);
410 if (colorspace < 0)
411 ThrowCompareException(OptionError,"UnrecognizedColorspace",
412 argv[i]);
413 break;
414 }
415 if (LocaleCompare("compose",option+1) == 0)
416 {
cristybb503372010-05-27 20:51:26 +0000417 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000418 compose;
419
420 if (*option == '+')
421 break;
422 i++;
cristybb503372010-05-27 20:51:26 +0000423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000424 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000425 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000426 argv[i]);
427 if (compose < 0)
428 ThrowCompareException(OptionError,"UnrecognizedComposeOperator",
429 argv[i]);
430 break;
431 }
432 if (LocaleCompare("compress",option+1) == 0)
433 {
cristybb503372010-05-27 20:51:26 +0000434 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000435 compress;
436
437 if (*option == '+')
438 break;
439 i++;
cristybb503372010-05-27 20:51:26 +0000440 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000441 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000442 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000443 argv[i]);
444 if (compress < 0)
445 ThrowCompareException(OptionError,"UnrecognizedImageCompression",
446 argv[i]);
447 break;
448 }
cristy22879752009-10-25 23:55:40 +0000449 if (LocaleCompare("concurrent",option+1) == 0)
450 break;
cristy3ed852e2009-09-05 21:47:34 +0000451 ThrowCompareException(OptionError,"UnrecognizedOption",option)
452 }
453 case 'd':
454 {
455 if (LocaleCompare("debug",option+1) == 0)
456 {
457 LogEventType
458 event_mask;
459
460 if (*option == '+')
461 break;
462 i++;
cristybb503372010-05-27 20:51:26 +0000463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000464 ThrowCompareException(OptionError,"MissingArgument",option);
465 event_mask=SetLogEventMask(argv[i]);
466 if (event_mask == UndefinedEvents)
467 ThrowCompareException(OptionError,"UnrecognizedEventType",
468 argv[i]);
469 break;
470 }
471 if (LocaleCompare("decipher",option+1) == 0)
472 {
473 if (*option == '+')
474 break;
475 i++;
cristybb503372010-05-27 20:51:26 +0000476 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000477 ThrowCompareException(OptionError,"MissingArgument",option);
478 break;
479 }
480 if (LocaleCompare("define",option+1) == 0)
481 {
482 i++;
cristybb503372010-05-27 20:51:26 +0000483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000484 ThrowCompareException(OptionError,"MissingArgument",option);
485 if (*option == '+')
486 {
487 const char
488 *define;
489
490 define=GetImageOption(image_info,argv[i]);
491 if (define == (const char *) NULL)
492 ThrowCompareException(OptionError,"NoSuchOption",argv[i]);
493 break;
494 }
495 break;
496 }
497 if (LocaleCompare("density",option+1) == 0)
498 {
499 if (*option == '+')
500 break;
501 i++;
cristybb503372010-05-27 20:51:26 +0000502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000503 ThrowCompareException(OptionError,"MissingArgument",option);
504 if (IsGeometry(argv[i]) == MagickFalse)
505 ThrowCompareInvalidArgumentException(option,argv[i]);
506 break;
507 }
508 if (LocaleCompare("depth",option+1) == 0)
509 {
510 if (*option == '+')
511 break;
512 i++;
cristybb503372010-05-27 20:51:26 +0000513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000514 ThrowCompareException(OptionError,"MissingArgument",option);
515 if (IsGeometry(argv[i]) == MagickFalse)
516 ThrowCompareInvalidArgumentException(option,argv[i]);
517 break;
518 }
519 if (LocaleCompare("dissimilarity-threshold",option+1) == 0)
520 {
521 if (*option == '+')
522 break;
523 i++;
cristybb503372010-05-27 20:51:26 +0000524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000525 ThrowCompareException(OptionError,"MissingArgument",option);
526 if (IsGeometry(argv[i]) == MagickFalse)
527 ThrowCompareInvalidArgumentException(option,argv[i]);
528 if (*option == '+')
529 dissimilarity_threshold=DefaultDissimilarityThreshold;
530 else
cristy9b34e302011-11-05 02:15:45 +0000531 dissimilarity_threshold=StringToDouble(argv[i],(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000532 break;
533 }
cristy22879752009-10-25 23:55:40 +0000534 if (LocaleCompare("duration",option+1) == 0)
535 {
536 if (*option == '+')
537 break;
538 i++;
cristybb503372010-05-27 20:51:26 +0000539 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +0000540 ThrowCompareException(OptionError,"MissingArgument",option);
541 if (IsGeometry(argv[i]) == MagickFalse)
542 ThrowCompareInvalidArgumentException(option,argv[i]);
543 break;
544 }
cristy3ed852e2009-09-05 21:47:34 +0000545 ThrowCompareException(OptionError,"UnrecognizedOption",option)
546 }
547 case 'e':
548 {
549 if (LocaleCompare("encipher",option+1) == 0)
550 {
551 if (*option == '+')
552 break;
553 i++;
cristybb503372010-05-27 20:51:26 +0000554 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000555 ThrowCompareException(OptionError,"MissingArgument",option);
556 break;
557 }
558 if (LocaleCompare("extract",option+1) == 0)
559 {
560 if (*option == '+')
561 break;
562 i++;
cristybb503372010-05-27 20:51:26 +0000563 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000564 ThrowCompareException(OptionError,"MissingArgument",option);
565 if (IsGeometry(argv[i]) == MagickFalse)
566 ThrowCompareInvalidArgumentException(option,argv[i]);
567 break;
568 }
569 ThrowCompareException(OptionError,"UnrecognizedOption",option)
570 }
571 case 'f':
572 {
573 if (LocaleCompare("format",option+1) == 0)
574 {
575 if (*option == '+')
576 break;
577 i++;
cristybb503372010-05-27 20:51:26 +0000578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000579 ThrowCompareException(OptionError,"MissingArgument",option);
580 format=argv[i];
581 break;
582 }
583 if (LocaleCompare("fuzz",option+1) == 0)
584 {
585 if (*option == '+')
586 break;
587 i++;
cristybb503372010-05-27 20:51:26 +0000588 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000589 ThrowCompareException(OptionError,"MissingArgument",option);
590 if (IsGeometry(argv[i]) == MagickFalse)
591 ThrowCompareInvalidArgumentException(option,argv[i]);
592 break;
593 }
594 ThrowCompareException(OptionError,"UnrecognizedOption",option)
595 }
596 case 'h':
597 {
598 if ((LocaleCompare("help",option+1) == 0) ||
599 (LocaleCompare("-help",option+1) == 0))
600 return(CompareUsage());
601 if (LocaleCompare("highlight-color",option+1) == 0)
602 {
603 if (*option == '+')
604 break;
605 i++;
cristybb503372010-05-27 20:51:26 +0000606 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000607 ThrowCompareException(OptionError,"MissingArgument",option);
608 break;
609 }
610 ThrowCompareException(OptionError,"UnrecognizedOption",option)
611 }
612 case 'i':
613 {
614 if (LocaleCompare("identify",option+1) == 0)
615 break;
616 if (LocaleCompare("interlace",option+1) == 0)
617 {
cristybb503372010-05-27 20:51:26 +0000618 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000619 interlace;
620
621 if (*option == '+')
622 break;
623 i++;
cristybb503372010-05-27 20:51:26 +0000624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000625 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000626 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000627 argv[i]);
628 if (interlace < 0)
629 ThrowCompareException(OptionError,"UnrecognizedInterlaceType",
630 argv[i]);
631 break;
632 }
633 ThrowCompareException(OptionError,"UnrecognizedOption",option)
634 }
635 case 'l':
636 {
637 if (LocaleCompare("limit",option+1) == 0)
638 {
639 char
640 *p;
641
642 double
643 value;
644
cristybb503372010-05-27 20:51:26 +0000645 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000646 resource;
647
648 if (*option == '+')
649 break;
650 i++;
cristybb503372010-05-27 20:51:26 +0000651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000652 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000653 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000654 argv[i]);
655 if (resource < 0)
656 ThrowCompareException(OptionError,"UnrecognizedResourceType",
657 argv[i]);
658 i++;
cristybb503372010-05-27 20:51:26 +0000659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000660 ThrowCompareException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +0000661 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +0000662 (void) value;
cristy3ed852e2009-09-05 21:47:34 +0000663 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
664 ThrowCompareInvalidArgumentException(option,argv[i]);
665 break;
666 }
667 if (LocaleCompare("list",option+1) == 0)
668 {
cristybb503372010-05-27 20:51:26 +0000669 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000670 list;
671
672 if (*option == '+')
673 break;
674 i++;
cristybb503372010-05-27 20:51:26 +0000675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000676 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000677 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000678 if (list < 0)
679 ThrowCompareException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +0000680 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +0000681 argv+j,exception);
682 DestroyCompare();
cristyaeb2cbc2010-05-07 13:28:58 +0000683 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +0000684 }
685 if (LocaleCompare("log",option+1) == 0)
686 {
687 if (*option == '+')
688 break;
689 i++;
cristybb503372010-05-27 20:51:26 +0000690 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000691 ThrowCompareException(OptionError,"MissingArgument",option);
692 break;
693 }
694 if (LocaleCompare("lowlight-color",option+1) == 0)
695 {
696 if (*option == '+')
697 break;
698 i++;
cristybb503372010-05-27 20:51:26 +0000699 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000700 ThrowCompareException(OptionError,"MissingArgument",option);
701 break;
702 }
703 ThrowCompareException(OptionError,"UnrecognizedOption",option)
704 }
705 case 'm':
706 {
707 if (LocaleCompare("matte",option+1) == 0)
708 break;
709 if (LocaleCompare("metric",option+1) == 0)
710 {
cristybb503372010-05-27 20:51:26 +0000711 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000712 type;
713
714 if (*option == '+')
715 break;
716 i++;
cristybb503372010-05-27 20:51:26 +0000717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000718 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000719 type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000720 if (type < 0)
721 ThrowCompareException(OptionError,"UnrecognizedMetricType",
722 argv[i]);
723 metric=(MetricType) type;
724 break;
725 }
726 if (LocaleCompare("monitor",option+1) == 0)
727 break;
728 ThrowCompareException(OptionError,"UnrecognizedOption",option)
729 }
730 case 'p':
731 {
cristy3ed852e2009-09-05 21:47:34 +0000732 if (LocaleCompare("profile",option+1) == 0)
733 {
734 i++;
cristybb503372010-05-27 20:51:26 +0000735 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000736 ThrowCompareException(OptionError,"MissingArgument",option);
737 break;
738 }
739 ThrowCompareException(OptionError,"UnrecognizedOption",option)
740 }
741 case 'q':
742 {
743 if (LocaleCompare("quality",option+1) == 0)
744 {
745 if (*option == '+')
746 break;
747 i++;
cristybb503372010-05-27 20:51:26 +0000748 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000749 ThrowCompareException(OptionError,"MissingArgument",option);
750 if (IsGeometry(argv[i]) == MagickFalse)
751 ThrowCompareInvalidArgumentException(option,argv[i]);
752 break;
753 }
754 if (LocaleCompare("quantize",option+1) == 0)
755 {
cristybb503372010-05-27 20:51:26 +0000756 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000757 colorspace;
758
759 if (*option == '+')
760 break;
761 i++;
cristybb503372010-05-27 20:51:26 +0000762 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000763 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000764 colorspace=ParseCommandOption(MagickColorspaceOptions,
cristy3ed852e2009-09-05 21:47:34 +0000765 MagickFalse,argv[i]);
766 if (colorspace < 0)
767 ThrowCompareException(OptionError,"UnrecognizedColorspace",
768 argv[i]);
769 break;
770 }
771 if (LocaleCompare("quiet",option+1) == 0)
772 break;
773 ThrowCompareException(OptionError,"UnrecognizedOption",option)
774 }
775 case 'r':
776 {
777 if (LocaleCompare("regard-warnings",option+1) == 0)
778 break;
779 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
780 {
781 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
782 break;
783 }
784 ThrowCompareException(OptionError,"UnrecognizedOption",option)
785 }
786 case 's':
787 {
788 if (LocaleCompare("sampling-factor",option+1) == 0)
789 {
790 if (*option == '+')
791 break;
792 i++;
cristybb503372010-05-27 20:51:26 +0000793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000794 ThrowCompareException(OptionError,"MissingArgument",option);
795 if (IsGeometry(argv[i]) == MagickFalse)
796 ThrowCompareInvalidArgumentException(option,argv[i]);
797 break;
798 }
799 if (LocaleCompare("seed",option+1) == 0)
800 {
801 if (*option == '+')
802 break;
803 i++;
cristybb503372010-05-27 20:51:26 +0000804 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000805 ThrowCompareException(OptionError,"MissingArgument",option);
806 if (IsGeometry(argv[i]) == MagickFalse)
807 ThrowCompareInvalidArgumentException(option,argv[i]);
808 break;
809 }
810 if (LocaleCompare("set",option+1) == 0)
811 {
812 i++;
cristybb503372010-05-27 20:51:26 +0000813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000814 ThrowCompareException(OptionError,"MissingArgument",option);
815 if (*option == '+')
816 break;
817 i++;
cristybb503372010-05-27 20:51:26 +0000818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000819 ThrowCompareException(OptionError,"MissingArgument",option);
820 break;
821 }
822 if (LocaleCompare("size",option+1) == 0)
823 {
824 if (*option == '+')
825 break;
826 i++;
cristybb503372010-05-27 20:51:26 +0000827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000828 ThrowCompareException(OptionError,"MissingArgument",option);
829 if (IsGeometry(argv[i]) == MagickFalse)
830 ThrowCompareInvalidArgumentException(option,argv[i]);
831 break;
832 }
cristyae6203d2010-08-09 01:12:14 +0000833 if (LocaleCompare("subimage-search",option+1) == 0)
834 {
835 if (*option == '+')
836 {
837 subimage_search=MagickFalse;
838 break;
839 }
840 subimage_search=MagickTrue;
841 break;
842 }
cristyd9a29192010-10-16 16:49:53 +0000843 if (LocaleCompare("synchronize",option+1) == 0)
844 break;
cristy3ed852e2009-09-05 21:47:34 +0000845 ThrowCompareException(OptionError,"UnrecognizedOption",option)
846 }
847 case 't':
848 {
cristyd9a29192010-10-16 16:49:53 +0000849 if (LocaleCompare("taint",option+1) == 0)
850 break;
cristy3ed852e2009-09-05 21:47:34 +0000851 if (LocaleCompare("transparent-color",option+1) == 0)
852 {
853 if (*option == '+')
854 break;
855 i++;
cristybb503372010-05-27 20:51:26 +0000856 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000857 ThrowCompareException(OptionError,"MissingArgument",option);
858 break;
859 }
860 if (LocaleCompare("type",option+1) == 0)
861 {
cristybb503372010-05-27 20:51:26 +0000862 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000863 type;
864
865 if (*option == '+')
866 break;
867 i++;
cristybb503372010-05-27 20:51:26 +0000868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000869 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000870 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000871 if (type < 0)
872 ThrowCompareException(OptionError,"UnrecognizedImageType",
873 argv[i]);
874 break;
875 }
876 ThrowCompareException(OptionError,"UnrecognizedOption",option)
877 }
878 case 'v':
879 {
880 if (LocaleCompare("verbose",option+1) == 0)
881 break;
882 if ((LocaleCompare("version",option+1) == 0) ||
883 (LocaleCompare("-version",option+1) == 0))
884 {
cristyb51dff52011-05-19 16:55:47 +0000885 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +0000886 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +0000887 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
888 GetMagickCopyright());
889 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
890 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +0000891 break;
892 }
893 if (LocaleCompare("virtual-pixel",option+1) == 0)
894 {
cristybb503372010-05-27 20:51:26 +0000895 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000896 method;
897
898 if (*option == '+')
899 break;
900 i++;
cristybb503372010-05-27 20:51:26 +0000901 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000902 ThrowCompareException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000903 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000904 argv[i]);
905 if (method < 0)
906 ThrowCompareException(OptionError,
907 "UnrecognizedVirtualPixelMethod",argv[i]);
908 break;
909 }
910 ThrowCompareException(OptionError,"UnrecognizedOption",option)
911 }
912 case '?':
913 break;
914 default:
915 ThrowCompareException(OptionError,"UnrecognizedOption",option)
916 }
cristy042ee782011-04-22 18:48:30 +0000917 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
918 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +0000919 if (fire != MagickFalse)
920 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
921 }
922 if (k != 0)
923 ThrowCompareException(OptionError,"UnbalancedParenthesis",argv[i]);
cristybb503372010-05-27 20:51:26 +0000924 if (i-- != (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +0000925 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
926 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
927 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
928 FinalizeImageSettings(image_info,image,MagickTrue);
cristy94f20072009-09-12 02:12:36 +0000929 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
930 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000931 image=GetImageFromList(image,0);
932 reconstruct_image=GetImageFromList(image,1);
cristy83330932010-08-14 20:48:24 +0000933 if (subimage_search != MagickFalse)
934 {
cristy09136812011-10-18 15:24:30 +0000935 similarity_image=SimilarityImage(image,reconstruct_image,metric,&offset,
cristy83330932010-08-14 20:48:24 +0000936 &similarity_metric,exception);
937 if (similarity_metric > dissimilarity_threshold)
938 ThrowCompareException(ImageError,"ImagesTooDissimilar",image->filename);
939 }
cristy3ed852e2009-09-05 21:47:34 +0000940 if ((reconstruct_image->columns == image->columns) &&
941 (reconstruct_image->rows == image->rows))
cristy8a9106f2011-07-05 14:39:26 +0000942 difference_image=CompareImages(image,reconstruct_image,metric,&distortion,
943 exception);
cristy3ed852e2009-09-05 21:47:34 +0000944 else
cristyfdad9052010-08-15 20:15:35 +0000945 if (similarity_image == (Image *) NULL)
946 ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer",
947 image->filename)
948 else
cristy83330932010-08-14 20:48:24 +0000949 {
950 Image
951 *composite_image;
cristy3ed852e2009-09-05 21:47:34 +0000952
cristy83330932010-08-14 20:48:24 +0000953 /*
954 Determine if reconstructed image is a subimage of the image.
955 */
956 composite_image=CloneImage(image,0,0,MagickTrue,exception);
957 if (composite_image == (Image *) NULL)
cristy8a9106f2011-07-05 14:39:26 +0000958 difference_image=CompareImages(image,reconstruct_image,metric,
959 &distortion,exception);
cristy83330932010-08-14 20:48:24 +0000960 else
961 {
962 (void) CompositeImage(composite_image,CopyCompositeOp,
cristye941a752011-10-15 01:52:48 +0000963 reconstruct_image,offset.x,offset.y,exception);
cristy8a9106f2011-07-05 14:39:26 +0000964 difference_image=CompareImages(image,composite_image,metric,
965 &distortion,exception);
cristy83330932010-08-14 20:48:24 +0000966 if (difference_image != (Image *) NULL)
967 {
968 difference_image->page.x=offset.x;
969 difference_image->page.y=offset.y;
970 }
971 composite_image=DestroyImage(composite_image);
972 }
973 if (difference_image != (Image *) NULL)
974 {
975 AppendImageToList(&difference_image,similarity_image);
976 similarity_image=(Image *) NULL;
977 }
978 }
cristy3ed852e2009-09-05 21:47:34 +0000979 if (difference_image == (Image *) NULL)
980 status=0;
981 else
982 {
983 if (image_info->verbose != MagickFalse)
cristy018f07f2011-09-04 21:15:19 +0000984 (void) IsImagesEqual(image,reconstruct_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000985 if (*difference_image->magick == '\0')
986 (void) CopyMagickString(difference_image->magick,image->magick,
987 MaxTextExtent);
988 if (image_info->verbose == MagickFalse)
989 {
990 switch (metric)
991 {
cristy343eee92010-12-11 02:17:57 +0000992 case FuzzErrorMetric:
cristy3ed852e2009-09-05 21:47:34 +0000993 case MeanAbsoluteErrorMetric:
994 case MeanSquaredErrorMetric:
995 case RootMeanSquaredErrorMetric:
996 case PeakAbsoluteErrorMetric:
997 {
cristyb51dff52011-05-19 16:55:47 +0000998 (void) FormatLocaleFile(stderr,"%g (%g)",QuantumRange*distortion,
cristy8cd5b312010-01-07 01:10:24 +0000999 (double) distortion);
cristy3ed852e2009-09-05 21:47:34 +00001000 if ((reconstruct_image->columns != image->columns) ||
1001 (reconstruct_image->rows != image->rows))
cristyb51dff52011-05-19 16:55:47 +00001002 (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
cristye8c25f92010-06-03 00:53:06 +00001003 difference_image->page.x,(double) difference_image->page.y);
cristyb51dff52011-05-19 16:55:47 +00001004 (void) FormatLocaleFile(stderr,"\n");
cristy3ed852e2009-09-05 21:47:34 +00001005 break;
1006 }
1007 case AbsoluteErrorMetric:
cristy4c929a72010-11-24 18:54:42 +00001008 case NormalizedCrossCorrelationErrorMetric:
cristy3ed852e2009-09-05 21:47:34 +00001009 case PeakSignalToNoiseRatioMetric:
1010 {
cristyb51dff52011-05-19 16:55:47 +00001011 (void) FormatLocaleFile(stderr,"%g",distortion);
cristy3ed852e2009-09-05 21:47:34 +00001012 if ((reconstruct_image->columns != image->columns) ||
1013 (reconstruct_image->rows != image->rows))
cristyb51dff52011-05-19 16:55:47 +00001014 (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
cristye8c25f92010-06-03 00:53:06 +00001015 difference_image->page.x,(double) difference_image->page.y);
cristyb51dff52011-05-19 16:55:47 +00001016 (void) FormatLocaleFile(stderr,"\n");
cristy3ed852e2009-09-05 21:47:34 +00001017 break;
1018 }
1019 case MeanErrorPerPixelMetric:
1020 {
cristyb51dff52011-05-19 16:55:47 +00001021 (void) FormatLocaleFile(stderr,"%g (%g, %g)",distortion,
cristy3ed852e2009-09-05 21:47:34 +00001022 image->error.normalized_mean_error,
1023 image->error.normalized_maximum_error);
1024 if ((reconstruct_image->columns != image->columns) ||
1025 (reconstruct_image->rows != image->rows))
cristyb51dff52011-05-19 16:55:47 +00001026 (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
cristye8c25f92010-06-03 00:53:06 +00001027 difference_image->page.x,(double) difference_image->page.y);
cristyb51dff52011-05-19 16:55:47 +00001028 (void) FormatLocaleFile(stderr,"\n");
cristy3ed852e2009-09-05 21:47:34 +00001029 break;
1030 }
1031 case UndefinedMetric:
1032 break;
1033 }
1034 }
1035 else
1036 {
1037 double
1038 *channel_distortion;
1039
cristy8a9106f2011-07-05 14:39:26 +00001040 channel_distortion=GetImageDistortions(image,reconstruct_image,
cristyc82a27b2011-10-21 01:07:16 +00001041 metric,exception);
cristyb51dff52011-05-19 16:55:47 +00001042 (void) FormatLocaleFile(stderr,"Image: %s\n",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00001043 if ((reconstruct_image->columns != image->columns) ||
1044 (reconstruct_image->rows != image->rows))
cristyb51dff52011-05-19 16:55:47 +00001045 (void) FormatLocaleFile(stderr,"Offset: %.20g,%.20g\n",(double)
cristye8c25f92010-06-03 00:53:06 +00001046 difference_image->page.x,(double) difference_image->page.y);
cristyb51dff52011-05-19 16:55:47 +00001047 (void) FormatLocaleFile(stderr," Channel distortion: %s\n",
cristy042ee782011-04-22 18:48:30 +00001048 CommandOptionToMnemonic(MagickMetricOptions,(ssize_t) metric));
cristy3ed852e2009-09-05 21:47:34 +00001049 switch (metric)
1050 {
cristy343eee92010-12-11 02:17:57 +00001051 case FuzzErrorMetric:
cristy3ed852e2009-09-05 21:47:34 +00001052 case MeanAbsoluteErrorMetric:
1053 case MeanSquaredErrorMetric:
1054 case RootMeanSquaredErrorMetric:
1055 case PeakAbsoluteErrorMetric:
1056 {
1057 switch (image->colorspace)
1058 {
1059 case RGBColorspace:
1060 default:
1061 {
cristyb51dff52011-05-19 16:55:47 +00001062 (void) FormatLocaleFile(stderr," red: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001063 QuantumRange*channel_distortion[RedPixelChannel],
1064 channel_distortion[RedPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001065 (void) FormatLocaleFile(stderr," green: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001066 QuantumRange*channel_distortion[GreenPixelChannel],
1067 channel_distortion[GreenPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001068 (void) FormatLocaleFile(stderr," blue: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001069 QuantumRange*channel_distortion[BluePixelChannel],
1070 channel_distortion[BluePixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001071 if (image->matte != MagickFalse)
cristyb51dff52011-05-19 16:55:47 +00001072 (void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001073 QuantumRange*channel_distortion[AlphaPixelChannel],
1074 channel_distortion[AlphaPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001075 break;
1076 }
1077 case CMYKColorspace:
1078 {
cristyb51dff52011-05-19 16:55:47 +00001079 (void) FormatLocaleFile(stderr," cyan: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001080 QuantumRange*channel_distortion[CyanPixelChannel],
1081 channel_distortion[CyanPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001082 (void) FormatLocaleFile(stderr," magenta: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001083 QuantumRange*channel_distortion[MagentaPixelChannel],
1084 channel_distortion[MagentaPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001085 (void) FormatLocaleFile(stderr," yellow: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001086 QuantumRange*channel_distortion[YellowPixelChannel],
1087 channel_distortion[YellowPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001088 (void) FormatLocaleFile(stderr," black: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001089 QuantumRange*channel_distortion[BlackPixelChannel],
1090 channel_distortion[BlackPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001091 if (image->matte != MagickFalse)
cristyb51dff52011-05-19 16:55:47 +00001092 (void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001093 QuantumRange*channel_distortion[AlphaPixelChannel],
1094 channel_distortion[AlphaPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001095 break;
1096 }
1097 case GRAYColorspace:
1098 {
cristyb51dff52011-05-19 16:55:47 +00001099 (void) FormatLocaleFile(stderr," gray: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001100 QuantumRange*channel_distortion[GrayPixelChannel],
1101 channel_distortion[GrayPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001102 if (image->matte != MagickFalse)
cristyb51dff52011-05-19 16:55:47 +00001103 (void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001104 QuantumRange*channel_distortion[AlphaPixelChannel],
1105 channel_distortion[AlphaPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001106 break;
1107 }
1108 }
cristyb51dff52011-05-19 16:55:47 +00001109 (void) FormatLocaleFile(stderr," all: %g (%g)\n",
cristyd3090f92011-10-18 00:05:15 +00001110 QuantumRange*channel_distortion[MaxPixelChannels],
1111 channel_distortion[MaxPixelChannels]);
cristy3ed852e2009-09-05 21:47:34 +00001112 break;
1113 }
1114 case AbsoluteErrorMetric:
cristy4c929a72010-11-24 18:54:42 +00001115 case NormalizedCrossCorrelationErrorMetric:
cristy3ed852e2009-09-05 21:47:34 +00001116 case PeakSignalToNoiseRatioMetric:
1117 {
1118 switch (image->colorspace)
1119 {
1120 case RGBColorspace:
1121 default:
1122 {
cristyb51dff52011-05-19 16:55:47 +00001123 (void) FormatLocaleFile(stderr," red: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001124 channel_distortion[RedPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001125 (void) FormatLocaleFile(stderr," green: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001126 channel_distortion[GreenPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001127 (void) FormatLocaleFile(stderr," blue: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001128 channel_distortion[BluePixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001129 if (image->matte != MagickFalse)
cristyb51dff52011-05-19 16:55:47 +00001130 (void) FormatLocaleFile(stderr," alpha: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001131 channel_distortion[AlphaPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001132 break;
1133 }
1134 case CMYKColorspace:
1135 {
cristyb51dff52011-05-19 16:55:47 +00001136 (void) FormatLocaleFile(stderr," cyan: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001137 channel_distortion[CyanPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001138 (void) FormatLocaleFile(stderr," magenta: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001139 channel_distortion[MagentaPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001140 (void) FormatLocaleFile(stderr," yellow: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001141 channel_distortion[YellowPixelChannel]);
cristyb51dff52011-05-19 16:55:47 +00001142 (void) FormatLocaleFile(stderr," black: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001143 channel_distortion[BlackPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001144 if (image->matte != MagickFalse)
cristyb51dff52011-05-19 16:55:47 +00001145 (void) FormatLocaleFile(stderr," alpha: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001146 channel_distortion[AlphaPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001147 break;
1148 }
1149 case GRAYColorspace:
1150 {
cristyb51dff52011-05-19 16:55:47 +00001151 (void) FormatLocaleFile(stderr," gray: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001152 channel_distortion[GrayPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001153 if (image->matte != MagickFalse)
cristyb51dff52011-05-19 16:55:47 +00001154 (void) FormatLocaleFile(stderr," alpha: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001155 channel_distortion[AlphaPixelChannel]);
cristy3ed852e2009-09-05 21:47:34 +00001156 break;
1157 }
1158 }
cristyb51dff52011-05-19 16:55:47 +00001159 (void) FormatLocaleFile(stderr," all: %g\n",
cristyd3090f92011-10-18 00:05:15 +00001160 channel_distortion[MaxPixelChannels]);
cristy3ed852e2009-09-05 21:47:34 +00001161 break;
1162 }
1163 case MeanErrorPerPixelMetric:
1164 {
cristyb51dff52011-05-19 16:55:47 +00001165 (void) FormatLocaleFile(stderr," %g (%g, %g)\n",
cristyd3090f92011-10-18 00:05:15 +00001166 channel_distortion[MaxPixelChannels],
cristy3ed852e2009-09-05 21:47:34 +00001167 image->error.normalized_mean_error,
1168 image->error.normalized_maximum_error);
1169 break;
1170 }
1171 case UndefinedMetric:
1172 break;
1173 }
1174 channel_distortion=(double *) RelinquishMagickMemory(
1175 channel_distortion);
1176 }
1177 status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
1178 if ((metadata != (char **) NULL) && (format != (char *) NULL))
1179 {
1180 char
1181 *text;
1182
cristy018f07f2011-09-04 21:15:19 +00001183 text=InterpretImageProperties(image_info,difference_image,format,
1184 exception);
cristy3ed852e2009-09-05 21:47:34 +00001185 if (text == (char *) NULL)
1186 ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
1187 GetExceptionMessage(errno));
1188 (void) ConcatenateString(&(*metadata),text);
1189 (void) ConcatenateString(&(*metadata),"\n");
1190 text=DestroyString(text);
1191 }
1192 difference_image=DestroyImageList(difference_image);
1193 }
1194 DestroyCompare();
1195 return(status != 0 ? MagickTrue : MagickFalse);
1196}