blob: 2c52689c0a86fe587f7bbefdd4cb6da10c77d5f2 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% %
7% V V AAA L IIIII DDDD AAA TTTTT EEEEE %
8% V V A A L I D D A A T E %
9% V V AAAAA L I D D AAAAA T EEE %
10% V V A A L I D D A A T E %
11% V A A LLLLL IIIII DDDD A A T EEEEE %
12% %
13% %
14% ImageMagick Validation Suite %
15% %
16% Software Design %
17% John Cristy %
18% March 2001 %
19% %
20% %
cristy1454be72011-12-19 01:52:48 +000021% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000022% dedicated to making software imaging solutions freely available. %
23% %
24% You may not use this file except in compliance with the License. You may %
25% obtain a copy of the License at %
26% %
27% http://www.imagemagick.org/script/license.php %
28% %
29% Unless required by applicable law or agreed to in writing, software %
30% distributed under the License is distributed on an "AS IS" BASIS, %
31% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32% see the License for the specific language governing permissions and %
33% limitations under the License. %
34% %
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
43#include <stdio.h>
cristy5e8e9812009-12-17 15:13:38 +000044#include <stdlib.h>
cristy3ed852e2009-09-05 21:47:34 +000045#include <string.h>
cristy5e8e9812009-12-17 15:13:38 +000046#include <ctype.h>
cristy3ed852e2009-09-05 21:47:34 +000047#include <math.h>
cristy9883b452011-07-01 23:37:21 +000048#include "MagickWand/MagickWand.h"
cristy510d06a2011-07-06 23:43:54 +000049#include "MagickCore/colorspace-private.h"
cristy9883b452011-07-01 23:37:21 +000050#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000051#include "validate.h"
52
53/*
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55% %
56% %
57% %
58% V a l i d a t e C o m p a r e C o m m a n d %
59% %
60% %
61% %
62%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63%
64% ValidateCompareCommand() validates the ImageMagick compare command line
65% program and returns the number of validation tests that passed and failed.
66%
67% The format of the ValidateCompareCommand method is:
68%
cristybb503372010-05-27 20:51:26 +000069% size_t ValidateCompareCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +000070% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +000071% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000072%
73% A description of each parameter follows:
74%
75% o image_info: the image info.
76%
77% o reference_filename: the reference image filename.
78%
79% o output_filename: the output image filename.
80%
81% o fail: return the number of validation tests that pass.
82%
83% o exception: return any errors or warnings in this structure.
84%
85*/
cristybb503372010-05-27 20:51:26 +000086static size_t ValidateCompareCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +000087 const char *reference_filename,const char *output_filename,size_t *fail,
88 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000089{
90 char
91 **arguments,
92 command[MaxTextExtent];
93
94 int
95 number_arguments;
96
97 MagickBooleanType
98 status;
99
cristybb503372010-05-27 20:51:26 +0000100 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000101 i,
102 j;
103
cristybb503372010-05-27 20:51:26 +0000104 size_t
cristy3ed852e2009-09-05 21:47:34 +0000105 test;
106
107 test=0;
cristyb51dff52011-05-19 16:55:47 +0000108 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +0000109 for (i=0; compare_options[i] != (char *) NULL; i++)
110 {
111 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +0000112 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +0000113 compare_options[i]);
cristyb51dff52011-05-19 16:55:47 +0000114 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +0000115 compare_options[i],reference_filename,reference_filename,output_filename);
116 arguments=StringToArgv(command,&number_arguments);
117 if (arguments == (char **) NULL)
118 {
cristy1e604812011-05-19 18:07:50 +0000119 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
120 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000121 (*fail)++;
122 continue;
123 }
cristy8a9106f2011-07-05 14:39:26 +0000124 status=CompareImagesCommand(image_info,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +0000125 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +0000126 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +0000127 arguments[j]=DestroyString(arguments[j]);
128 arguments=(char **) RelinquishMagickMemory(arguments);
129 if (status != MagickFalse)
130 {
cristy1e604812011-05-19 18:07:50 +0000131 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
132 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000133 (*fail)++;
134 continue;
135 }
cristyb51dff52011-05-19 16:55:47 +0000136 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +0000137 }
cristyb51dff52011-05-19 16:55:47 +0000138 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +0000139 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
140 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +0000141 return(test);
142}
143
144/*
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146% %
147% %
148% %
149% V a l i d a t e C o m p o s i t e C o m m a n d %
150% %
151% %
152% %
153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154%
155% ValidateCompositeCommand() validates the ImageMagick composite command line
156% program and returns the number of validation tests that passed and failed.
157%
158% The format of the ValidateCompositeCommand method is:
159%
cristybb503372010-05-27 20:51:26 +0000160% size_t ValidateCompositeCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000161% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +0000162% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000163%
164% A description of each parameter follows:
165%
166% o image_info: the image info.
167%
168% o reference_filename: the reference image filename.
169%
170% o output_filename: the output image filename.
171%
172% o fail: return the number of validation tests that pass.
173%
174% o exception: return any errors or warnings in this structure.
175%
176*/
cristybb503372010-05-27 20:51:26 +0000177static size_t ValidateCompositeCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +0000178 const char *reference_filename,const char *output_filename,size_t *fail,
179 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000180{
181 char
182 **arguments,
183 command[MaxTextExtent];
184
185 int
186 number_arguments;
187
188 MagickBooleanType
189 status;
190
cristybb503372010-05-27 20:51:26 +0000191 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000192 i,
193 j;
194
cristybb503372010-05-27 20:51:26 +0000195 size_t
cristy3ed852e2009-09-05 21:47:34 +0000196 test;
197
198 test=0;
cristyb51dff52011-05-19 16:55:47 +0000199 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +0000200 for (i=0; composite_options[i] != (char *) NULL; i++)
201 {
202 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +0000203 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +0000204 composite_options[i]);
cristyb51dff52011-05-19 16:55:47 +0000205 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +0000206 reference_filename,composite_options[i],reference_filename,
207 output_filename);
208 arguments=StringToArgv(command,&number_arguments);
209 if (arguments == (char **) NULL)
210 {
cristy1e604812011-05-19 18:07:50 +0000211 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
212 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000213 (*fail)++;
214 continue;
215 }
216 status=CompositeImageCommand(image_info,number_arguments,arguments,
217 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +0000218 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +0000219 arguments[j]=DestroyString(arguments[j]);
220 arguments=(char **) RelinquishMagickMemory(arguments);
221 if (status != MagickFalse)
222 {
cristy1e604812011-05-19 18:07:50 +0000223 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
224 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000225 (*fail)++;
226 continue;
227 }
cristyb51dff52011-05-19 16:55:47 +0000228 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +0000229 }
cristyb51dff52011-05-19 16:55:47 +0000230 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +0000231 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
232 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +0000233 return(test);
234}
235
236/*
237%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238% %
239% %
240% %
241% V a l i d a t e C o n v e r t C o m m a n d %
242% %
243% %
244% %
245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246%
247% ValidateConvertCommand() validates the ImageMagick convert command line
248% program and returns the number of validation tests that passed and failed.
249%
250% The format of the ValidateConvertCommand method is:
251%
cristybb503372010-05-27 20:51:26 +0000252% size_t ValidateConvertCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000253% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +0000254% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000255%
256% A description of each parameter follows:
257%
258% o image_info: the image info.
259%
260% o reference_filename: the reference image filename.
261%
262% o output_filename: the output image filename.
263%
264% o fail: return the number of validation tests that pass.
265%
266% o exception: return any errors or warnings in this structure.
267%
268*/
cristybb503372010-05-27 20:51:26 +0000269static size_t ValidateConvertCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +0000270 const char *reference_filename,const char *output_filename,size_t *fail,
271 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000272{
273 char
274 **arguments,
275 command[MaxTextExtent];
276
277 int
278 number_arguments;
279
280 MagickBooleanType
281 status;
282
cristybb503372010-05-27 20:51:26 +0000283 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000284 i,
285 j;
286
cristybb503372010-05-27 20:51:26 +0000287 size_t
cristy3ed852e2009-09-05 21:47:34 +0000288 test;
289
290 test=0;
cristyb51dff52011-05-19 16:55:47 +0000291 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +0000292 for (i=0; convert_options[i] != (char *) NULL; i++)
293 {
294 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +0000295 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
cristy6aa47ad2010-05-28 19:32:32 +0000296 convert_options[i]);
cristyb51dff52011-05-19 16:55:47 +0000297 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +0000298 reference_filename,convert_options[i],reference_filename,output_filename);
299 arguments=StringToArgv(command,&number_arguments);
300 if (arguments == (char **) NULL)
301 {
cristy1e604812011-05-19 18:07:50 +0000302 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
303 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000304 (*fail)++;
305 continue;
306 }
307 status=ConvertImageCommand(image_info,number_arguments,arguments,
308 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +0000309 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +0000310 arguments[j]=DestroyString(arguments[j]);
311 arguments=(char **) RelinquishMagickMemory(arguments);
312 if (status != MagickFalse)
313 {
cristy1e604812011-05-19 18:07:50 +0000314 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
315 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000316 (*fail)++;
317 continue;
318 }
cristyb51dff52011-05-19 16:55:47 +0000319 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +0000320 }
cristyb51dff52011-05-19 16:55:47 +0000321 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +0000322 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
323 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +0000324 return(test);
325}
326
327/*
328%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329% %
330% %
331% %
332% V a l i d a t e I d e n t i f y C o m m a n d %
333% %
334% %
335% %
336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337%
338% ValidateIdentifyCommand() validates the ImageMagick identify command line
339% program and returns the number of validation tests that passed and failed.
340%
341% The format of the ValidateIdentifyCommand method is:
342%
cristybb503372010-05-27 20:51:26 +0000343% size_t ValidateIdentifyCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000344% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +0000345% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000346%
347% A description of each parameter follows:
348%
349% o image_info: the image info.
350%
351% o reference_filename: the reference image filename.
352%
353% o output_filename: the output image filename.
354%
355% o fail: return the number of validation tests that pass.
356%
357% o exception: return any errors or warnings in this structure.
358%
359*/
cristybb503372010-05-27 20:51:26 +0000360static size_t ValidateIdentifyCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +0000361 const char *reference_filename,const char *output_filename,size_t *fail,
362 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000363{
364 char
365 **arguments,
366 command[MaxTextExtent];
367
368 int
369 number_arguments;
370
371 MagickBooleanType
372 status;
373
cristybb503372010-05-27 20:51:26 +0000374 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000375 i,
376 j;
377
cristybb503372010-05-27 20:51:26 +0000378 size_t
cristy3ed852e2009-09-05 21:47:34 +0000379 test;
380
381 (void) output_filename;
382 test=0;
cristyb51dff52011-05-19 16:55:47 +0000383 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +0000384 for (i=0; identify_options[i] != (char *) NULL; i++)
385 {
386 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +0000387 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
cristy6aa47ad2010-05-28 19:32:32 +0000388 identify_options[i]);
cristyb51dff52011-05-19 16:55:47 +0000389 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
cristy3ed852e2009-09-05 21:47:34 +0000390 identify_options[i],reference_filename);
391 arguments=StringToArgv(command,&number_arguments);
392 if (arguments == (char **) NULL)
393 {
cristy1e604812011-05-19 18:07:50 +0000394 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
395 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000396 (*fail)++;
397 continue;
398 }
399 status=IdentifyImageCommand(image_info,number_arguments,arguments,
400 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +0000401 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +0000402 arguments[j]=DestroyString(arguments[j]);
403 arguments=(char **) RelinquishMagickMemory(arguments);
404 if (status != MagickFalse)
405 {
cristy1e604812011-05-19 18:07:50 +0000406 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
407 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000408 (*fail)++;
409 continue;
410 }
cristyb51dff52011-05-19 16:55:47 +0000411 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +0000412 }
cristyb51dff52011-05-19 16:55:47 +0000413 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +0000414 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
415 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +0000416 return(test);
417}
418
419/*
420%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421% %
422% %
423% %
424% V a l i d a t e I m a g e F o r m a t s I n M e m o r y %
425% %
426% %
427% %
428%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429%
430% ValidateImageFormatsInMemory() validates the ImageMagick image formats in
431% memory and returns the number of validation tests that passed and failed.
432%
433% The format of the ValidateImageFormatsInMemory method is:
434%
cristybb503372010-05-27 20:51:26 +0000435% size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000436% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +0000437% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000438%
439% A description of each parameter follows:
440%
441% o image_info: the image info.
442%
443% o reference_filename: the reference image filename.
444%
445% o output_filename: the output image filename.
446%
447% o fail: return the number of validation tests that pass.
448%
449% o exception: return any errors or warnings in this structure.
450%
451*/
cristybb503372010-05-27 20:51:26 +0000452static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +0000453 const char *reference_filename,const char *output_filename,size_t *fail,
454 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000455{
456 char
457 size[MaxTextExtent];
458
459 const MagickInfo
460 *magick_info;
461
462 double
463 distortion,
464 fuzz;
465
466 Image
467 *difference_image,
cristy2c404222012-06-10 15:36:30 +0000468 *ping_image,
cristy6b9ae3f2012-06-10 15:39:34 +0000469 *reconstruct_image,
cristy100b8d92012-01-08 00:32:49 +0000470 *reference_image;
cristy3ed852e2009-09-05 21:47:34 +0000471
472 MagickBooleanType
473 status;
474
cristybb503372010-05-27 20:51:26 +0000475 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000476 i,
477 j;
478
479 size_t
cristy100b8d92012-01-08 00:32:49 +0000480 length,
481 test;
cristy3ed852e2009-09-05 21:47:34 +0000482
483 unsigned char
484 *blob;
485
cristy3ed852e2009-09-05 21:47:34 +0000486 test=0;
cristyb51dff52011-05-19 16:55:47 +0000487 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
cristy3ed852e2009-09-05 21:47:34 +0000488 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
489 {
490 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
491 if ((magick_info == (const MagickInfo *) NULL) ||
492 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
493 (magick_info->encoder == (EncodeImageHandler *) NULL))
494 continue;
cristy5f1c1ff2010-12-23 21:38:06 +0000495 for (j=0; reference_types[j].type != UndefinedType; j++)
cristy3ed852e2009-09-05 21:47:34 +0000496 {
497 /*
498 Generate reference image.
499 */
500 CatchException(exception);
cristy1e604812011-05-19 18:07:50 +0000501 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
502 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
cristy7998e5f2009-10-08 02:45:33 +0000503 MagickCompressOptions,reference_formats[i].compression),
cristy042ee782011-04-22 18:48:30 +0000504 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
cristy75a26232010-06-03 17:15:02 +0000505 (double) reference_types[j].depth);
cristy3ed852e2009-09-05 21:47:34 +0000506 (void) CopyMagickString(image_info->filename,reference_filename,
507 MaxTextExtent);
508 reference_image=ReadImage(image_info,exception);
509 if (reference_image == (Image *) NULL)
510 {
cristy1e604812011-05-19 18:07:50 +0000511 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
512 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000513 (*fail)++;
514 continue;
515 }
516 /*
517 Write reference image.
518 */
cristyb51dff52011-05-19 16:55:47 +0000519 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
cristy75a26232010-06-03 17:15:02 +0000520 (double) reference_image->columns,(double) reference_image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000521 (void) CloneString(&image_info->size,size);
522 image_info->depth=reference_types[j].depth;
cristyb51dff52011-05-19 16:55:47 +0000523 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000524 reference_formats[i].magick,output_filename);
cristy018f07f2011-09-04 21:15:19 +0000525 status=SetImageType(reference_image,reference_types[j].type,exception);
cristy3ed852e2009-09-05 21:47:34 +0000526 if (status == MagickFalse)
527 {
cristy1e604812011-05-19 18:07:50 +0000528 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
529 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000530 (*fail)++;
531 reference_image=DestroyImage(reference_image);
532 continue;
533 }
cristy8a11cb12011-10-19 23:53:34 +0000534 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
cristy3ed852e2009-09-05 21:47:34 +0000535 if (status == MagickFalse)
536 {
cristy1e604812011-05-19 18:07:50 +0000537 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
538 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000539 (*fail)++;
540 reference_image=DestroyImage(reference_image);
541 continue;
542 }
cristy7998e5f2009-10-08 02:45:33 +0000543 reference_image->compression=reference_formats[i].compression;
cristy6f9e0d32011-08-28 16:32:09 +0000544 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000545 reference_image=DestroyImage(reference_image);
546 if (status == MagickFalse)
547 {
cristy1e604812011-05-19 18:07:50 +0000548 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
549 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000550 (*fail)++;
551 continue;
552 }
553 /*
cristy2c404222012-06-10 15:36:30 +0000554 Ping reference image.
cristy3ed852e2009-09-05 21:47:34 +0000555 */
cristyb51dff52011-05-19 16:55:47 +0000556 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000557 reference_formats[i].magick,output_filename);
cristy2c404222012-06-10 15:36:30 +0000558 ping_image=PingImage(image_info,exception);
559 if (ping_image == (Image *) NULL)
560 {
561 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
562 GetMagickModule());
563 (*fail)++;
564 continue;
565 }
566 ping_image=DestroyImage(ping_image);
567 /*
568 Read reference image.
569 */
cristy3ed852e2009-09-05 21:47:34 +0000570 reference_image=ReadImage(image_info,exception);
571 if (reference_image == (Image *) NULL)
572 {
cristy1e604812011-05-19 18:07:50 +0000573 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
574 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000575 (*fail)++;
576 continue;
577 }
578 /*
579 Write reference image.
580 */
cristyb51dff52011-05-19 16:55:47 +0000581 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000582 reference_formats[i].magick,output_filename);
583 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
584 MaxTextExtent);
585 reference_image->depth=reference_types[j].depth;
cristy7998e5f2009-10-08 02:45:33 +0000586 reference_image->compression=reference_formats[i].compression;
cristy3ed852e2009-09-05 21:47:34 +0000587 length=8192;
588 blob=ImageToBlob(image_info,reference_image,&length,exception);
589 if (blob == (unsigned char *) NULL)
590 {
cristy1e604812011-05-19 18:07:50 +0000591 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
592 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000593 (*fail)++;
594 reference_image=DestroyImage(reference_image);
595 continue;
596 }
597 /*
cristy2c404222012-06-10 15:36:30 +0000598 Ping reference blob.
599 */
600 ping_image=PingBlob(image_info,blob,length,exception);
601 if (ping_image == (Image *) NULL)
602 {
603 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
604 GetMagickModule());
605 (*fail)++;
606 blob=(unsigned char *) RelinquishMagickMemory(blob);
607 continue;
608 }
609 ping_image=DestroyImage(ping_image);
610 /*
cristy3ed852e2009-09-05 21:47:34 +0000611 Read reconstruct image.
612 */
cristyb51dff52011-05-19 16:55:47 +0000613 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000614 reference_formats[i].magick,output_filename);
615 reconstruct_image=BlobToImage(image_info,blob,length,exception);
616 blob=(unsigned char *) RelinquishMagickMemory(blob);
617 if (reconstruct_image == (Image *) NULL)
618 {
cristy1e604812011-05-19 18:07:50 +0000619 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
620 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000621 (*fail)++;
622 reference_image=DestroyImage(reference_image);
623 continue;
624 }
625 /*
626 Compare reference to reconstruct image.
627 */
628 fuzz=0.0;
629 if (reference_formats[i].fuzz != 0.0)
630 fuzz=reference_formats[i].fuzz;
631#if defined(MAGICKCORE_HDRI_SUPPORT)
632 fuzz+=0.003;
633#endif
cristy501c5592012-04-18 12:45:09 +0000634 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000635 fuzz+=0.3;
cristy7e9255b2012-06-22 13:45:51 +0000636 fuzz+=MagickEpsilon;
cristy8a9106f2011-07-05 14:39:26 +0000637 difference_image=CompareImages(reference_image,reconstruct_image,
cristy864c6a82012-06-19 16:45:22 +0000638 RootMeanSquaredErrorMetric,&distortion,exception);
cristy3ed852e2009-09-05 21:47:34 +0000639 reconstruct_image=DestroyImage(reconstruct_image);
640 reference_image=DestroyImage(reference_image);
641 if (difference_image == (Image *) NULL)
642 {
cristy1e604812011-05-19 18:07:50 +0000643 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
644 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000645 (*fail)++;
646 continue;
647 }
648 difference_image=DestroyImage(difference_image);
cristy14154222012-06-15 23:21:49 +0000649 if ((QuantumScale*distortion) > fuzz)
cristy3ed852e2009-09-05 21:47:34 +0000650 {
cristyb51dff52011-05-19 16:55:47 +0000651 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
cristy14154222012-06-15 23:21:49 +0000652 QuantumScale*distortion);
cristy3ed852e2009-09-05 21:47:34 +0000653 (*fail)++;
654 continue;
655 }
cristyb51dff52011-05-19 16:55:47 +0000656 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +0000657 }
658 }
cristyb51dff52011-05-19 16:55:47 +0000659 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +0000660 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
661 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +0000662 return(test);
663}
664
665/*
666%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667% %
668% %
669% %
670% V a l i d a t e I m a g e F o r m a t s O n D i s k %
671% %
672% %
673% %
674%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675%
676% ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
677% and returns the number of validation tests that passed and failed.
678%
679% The format of the ValidateImageFormatsOnDisk method is:
680%
cristybb503372010-05-27 20:51:26 +0000681% size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000682% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +0000683% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000684%
685% A description of each parameter follows:
686%
687% o image_info: the image info.
688%
689% o reference_filename: the reference image filename.
690%
691% o output_filename: the output image filename.
692%
693% o fail: return the number of validation tests that pass.
694%
695% o exception: return any errors or warnings in this structure.
696%
697*/
cristybb503372010-05-27 20:51:26 +0000698static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +0000699 const char *reference_filename,const char *output_filename,size_t *fail,
700 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000701{
702 char
703 size[MaxTextExtent];
704
705 const MagickInfo
706 *magick_info;
707
708 double
709 distortion,
710 fuzz;
711
712 Image
713 *difference_image,
714 *reference_image,
715 *reconstruct_image;
716
717 MagickBooleanType
718 status;
719
cristybb503372010-05-27 20:51:26 +0000720 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000721 i,
722 j;
723
cristybb503372010-05-27 20:51:26 +0000724 size_t
cristy3ed852e2009-09-05 21:47:34 +0000725 test;
726
727 test=0;
cristyb51dff52011-05-19 16:55:47 +0000728 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
cristy3ed852e2009-09-05 21:47:34 +0000729 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
730 {
731 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
732 if ((magick_info == (const MagickInfo *) NULL) ||
733 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
734 (magick_info->encoder == (EncodeImageHandler *) NULL))
735 continue;
cristy5f1c1ff2010-12-23 21:38:06 +0000736 for (j=0; reference_types[j].type != UndefinedType; j++)
cristy3ed852e2009-09-05 21:47:34 +0000737 {
738 /*
739 Generate reference image.
740 */
741 CatchException(exception);
cristy1e604812011-05-19 18:07:50 +0000742 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
743 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
cristy7998e5f2009-10-08 02:45:33 +0000744 MagickCompressOptions,reference_formats[i].compression),
cristy042ee782011-04-22 18:48:30 +0000745 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
cristy75a26232010-06-03 17:15:02 +0000746 (double) reference_types[j].depth);
cristy3ed852e2009-09-05 21:47:34 +0000747 (void) CopyMagickString(image_info->filename,reference_filename,
748 MaxTextExtent);
749 reference_image=ReadImage(image_info,exception);
750 if (reference_image == (Image *) NULL)
751 {
cristy1e604812011-05-19 18:07:50 +0000752 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
753 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000754 (*fail)++;
755 continue;
756 }
757 /*
758 Write reference image.
759 */
cristyb51dff52011-05-19 16:55:47 +0000760 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
cristy75a26232010-06-03 17:15:02 +0000761 (double) reference_image->columns,(double) reference_image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000762 (void) CloneString(&image_info->size,size);
763 image_info->depth=reference_types[j].depth;
cristyb51dff52011-05-19 16:55:47 +0000764 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000765 reference_formats[i].magick,output_filename);
cristy018f07f2011-09-04 21:15:19 +0000766 status=SetImageType(reference_image,reference_types[j].type,exception);
cristy3ed852e2009-09-05 21:47:34 +0000767 if (status == MagickFalse)
768 {
cristy1e604812011-05-19 18:07:50 +0000769 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
770 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000771 (*fail)++;
772 reference_image=DestroyImage(reference_image);
773 continue;
774 }
cristy8a11cb12011-10-19 23:53:34 +0000775 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
cristy3ed852e2009-09-05 21:47:34 +0000776 if (status == MagickFalse)
777 {
cristy1e604812011-05-19 18:07:50 +0000778 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
779 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000780 (*fail)++;
781 reference_image=DestroyImage(reference_image);
782 continue;
783 }
cristy7998e5f2009-10-08 02:45:33 +0000784 reference_image->compression=reference_formats[i].compression;
cristy6f9e0d32011-08-28 16:32:09 +0000785 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000786 reference_image=DestroyImage(reference_image);
787 if (status == MagickFalse)
788 {
cristy1e604812011-05-19 18:07:50 +0000789 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
790 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000791 (*fail)++;
792 continue;
793 }
794 /*
795 Read reference image.
796 */
cristyb51dff52011-05-19 16:55:47 +0000797 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000798 reference_formats[i].magick,output_filename);
799 reference_image=ReadImage(image_info,exception);
800 if (reference_image == (Image *) NULL)
801 {
cristy1e604812011-05-19 18:07:50 +0000802 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
803 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000804 (*fail)++;
805 continue;
806 }
807 /*
808 Write reference image.
809 */
cristyb51dff52011-05-19 16:55:47 +0000810 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000811 reference_formats[i].magick,output_filename);
812 reference_image->depth=reference_types[j].depth;
cristy7998e5f2009-10-08 02:45:33 +0000813 reference_image->compression=reference_formats[i].compression;
cristy6f9e0d32011-08-28 16:32:09 +0000814 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000815 if (status == MagickFalse)
816 {
cristy1e604812011-05-19 18:07:50 +0000817 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
818 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000819 (*fail)++;
820 reference_image=DestroyImage(reference_image);
821 continue;
822 }
823 /*
824 Read reconstruct image.
825 */
cristyb51dff52011-05-19 16:55:47 +0000826 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +0000827 reference_formats[i].magick,output_filename);
828 reconstruct_image=ReadImage(image_info,exception);
829 if (reconstruct_image == (Image *) NULL)
830 {
cristy1e604812011-05-19 18:07:50 +0000831 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
832 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000833 (*fail)++;
834 reference_image=DestroyImage(reference_image);
835 continue;
836 }
837 /*
838 Compare reference to reconstruct image.
839 */
840 fuzz=0.0;
841 if (reference_formats[i].fuzz != 0.0)
842 fuzz=reference_formats[i].fuzz;
843#if defined(MAGICKCORE_HDRI_SUPPORT)
844 fuzz+=0.003;
845#endif
cristy6abd4192012-06-22 13:42:48 +0000846 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000847 fuzz+=0.3;
cristy7e9255b2012-06-22 13:45:51 +0000848 fuzz+=MagickEpsilon;
cristy8a9106f2011-07-05 14:39:26 +0000849 difference_image=CompareImages(reference_image,reconstruct_image,
cristy864c6a82012-06-19 16:45:22 +0000850 RootMeanSquaredErrorMetric,&distortion,exception);
cristy3ed852e2009-09-05 21:47:34 +0000851 reconstruct_image=DestroyImage(reconstruct_image);
852 reference_image=DestroyImage(reference_image);
853 if (difference_image == (Image *) NULL)
854 {
cristy1e604812011-05-19 18:07:50 +0000855 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
856 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000857 (*fail)++;
858 continue;
859 }
860 difference_image=DestroyImage(difference_image);
cristy14154222012-06-15 23:21:49 +0000861 if ((QuantumScale*distortion) > fuzz)
cristy3ed852e2009-09-05 21:47:34 +0000862 {
cristyb51dff52011-05-19 16:55:47 +0000863 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
cristy14154222012-06-15 23:21:49 +0000864 QuantumScale*distortion);
cristy3ed852e2009-09-05 21:47:34 +0000865 (*fail)++;
866 continue;
867 }
cristyb51dff52011-05-19 16:55:47 +0000868 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +0000869 }
870 }
cristyb51dff52011-05-19 16:55:47 +0000871 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +0000872 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
873 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +0000874 return(test);
875}
876
877/*
878%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
879% %
880% %
881% %
882% V a l i d a t e I m p o r t E x p o r t P i x e l s %
883% %
884% %
885% %
886%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887%
888% ValidateImportExportPixels() validates the pixel import and export methods.
889% It returns the number of validation tests that passed and failed.
890%
891% The format of the ValidateImportExportPixels method is:
892%
cristybb503372010-05-27 20:51:26 +0000893% size_t ValidateImportExportPixels(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +0000894% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +0000895% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000896%
897% A description of each parameter follows:
898%
899% o image_info: the image info.
900%
901% o reference_filename: the reference image filename.
902%
903% o output_filename: the output image filename.
904%
905% o fail: return the number of validation tests that pass.
906%
907% o exception: return any errors or warnings in this structure.
908%
909*/
cristybb503372010-05-27 20:51:26 +0000910static size_t ValidateImportExportPixels(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +0000911 const char *reference_filename,const char *output_filename,size_t *fail,
912 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000913{
914 double
915 distortion;
916
917 Image
918 *difference_image,
919 *reference_image,
920 *reconstruct_image;
921
922 MagickBooleanType
923 status;
924
cristybb503372010-05-27 20:51:26 +0000925 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000926 i,
927 j;
928
929 size_t
930 length;
931
932 unsigned char
933 *pixels;
934
cristybb503372010-05-27 20:51:26 +0000935 size_t
cristy3ed852e2009-09-05 21:47:34 +0000936 test;
937
938 (void) output_filename;
939 test=0;
cristy1e604812011-05-19 18:07:50 +0000940 (void) FormatLocaleFile(stdout,
941 "validate the import and export of image pixels:\n");
cristy3ed852e2009-09-05 21:47:34 +0000942 for (i=0; reference_map[i] != (char *) NULL; i++)
943 {
944 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
945 {
946 /*
947 Generate reference image.
948 */
949 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +0000950 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
cristy042ee782011-04-22 18:48:30 +0000951 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
cristy3ed852e2009-09-05 21:47:34 +0000952 reference_storage[j].type));
953 (void) CopyMagickString(image_info->filename,reference_filename,
954 MaxTextExtent);
955 reference_image=ReadImage(image_info,exception);
956 if (reference_image == (Image *) NULL)
957 {
cristy1e604812011-05-19 18:07:50 +0000958 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
959 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000960 (*fail)++;
961 continue;
962 }
963 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
cristy2c404222012-06-10 15:36:30 +0000964 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000965 length=strlen(reference_map[i])*reference_image->columns*
966 reference_image->rows*reference_storage[j].quantum;
967 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
968 if (pixels == (unsigned char *) NULL)
969 {
cristy1e604812011-05-19 18:07:50 +0000970 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
971 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000972 (*fail)++;
973 reference_image=DestroyImage(reference_image);
974 continue;
975 }
976 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
977 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
978 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
979 exception);
980 if (status == MagickFalse)
981 {
cristy1e604812011-05-19 18:07:50 +0000982 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
983 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000984 (*fail)++;
985 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
986 reference_image=DestroyImage(reference_image);
987 continue;
988 }
cristyd55c9352011-10-20 15:29:22 +0000989 (void) SetImageBackgroundColor(reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000990 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
991 reference_image->rows,reference_map[i],reference_storage[j].type,
cristy018f07f2011-09-04 21:15:19 +0000992 pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000993 if (status == MagickFalse)
994 {
cristy1e604812011-05-19 18:07:50 +0000995 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
996 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +0000997 (*fail)++;
998 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
999 reference_image=DestroyImage(reference_image);
1000 continue;
1001 }
1002 /*
1003 Read reconstruct image.
1004 */
cristy9950d572011-10-01 18:22:35 +00001005 reconstruct_image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00001006 (void) SetImageExtent(reconstruct_image,reference_image->columns,
cristy655a8d12011-08-05 19:24:28 +00001007 reference_image->rows,exception);
1008 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
1009 exception);
cristyd55c9352011-10-20 15:29:22 +00001010 (void) SetImageBackgroundColor(reconstruct_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001011 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
1012 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
cristy018f07f2011-09-04 21:15:19 +00001013 pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001014 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1015 if (status == MagickFalse)
1016 {
cristy1e604812011-05-19 18:07:50 +00001017 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1018 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001019 (*fail)++;
1020 reference_image=DestroyImage(reference_image);
1021 continue;
1022 }
1023 /*
1024 Compare reference to reconstruct image.
1025 */
cristy8a9106f2011-07-05 14:39:26 +00001026 difference_image=CompareImages(reference_image,reconstruct_image,
cristy864c6a82012-06-19 16:45:22 +00001027 RootMeanSquaredErrorMetric,&distortion,exception);
cristy3ed852e2009-09-05 21:47:34 +00001028 reconstruct_image=DestroyImage(reconstruct_image);
1029 reference_image=DestroyImage(reference_image);
1030 if (difference_image == (Image *) NULL)
1031 {
cristy1e604812011-05-19 18:07:50 +00001032 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1033 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001034 (*fail)++;
1035 continue;
1036 }
1037 difference_image=DestroyImage(difference_image);
cristy14154222012-06-15 23:21:49 +00001038 if ((QuantumScale*distortion) > 0.0)
cristy3ed852e2009-09-05 21:47:34 +00001039 {
cristyb51dff52011-05-19 16:55:47 +00001040 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
cristy14154222012-06-15 23:21:49 +00001041 QuantumScale*distortion);
cristy3ed852e2009-09-05 21:47:34 +00001042 (*fail)++;
1043 continue;
1044 }
cristyb51dff52011-05-19 16:55:47 +00001045 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001046 }
1047 }
cristyb51dff52011-05-19 16:55:47 +00001048 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001049 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1050 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001051 return(test);
1052}
1053
1054/*
1055%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056% %
1057% %
1058% %
1059% V a l i d a t e M o n t a g e C o m m a n d %
1060% %
1061% %
1062% %
1063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064%
1065% ValidateMontageCommand() validates the ImageMagick montage command line
1066% program and returns the number of validation tests that passed and failed.
1067%
1068% The format of the ValidateMontageCommand method is:
1069%
cristybb503372010-05-27 20:51:26 +00001070% size_t ValidateMontageCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001071% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001072% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001073%
1074% A description of each parameter follows:
1075%
1076% o image_info: the image info.
1077%
1078% o reference_filename: the reference image filename.
1079%
1080% o output_filename: the output image filename.
1081%
1082% o fail: return the number of validation tests that pass.
1083%
1084% o exception: return any errors or warnings in this structure.
1085%
1086*/
cristybb503372010-05-27 20:51:26 +00001087static size_t ValidateMontageCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001088 const char *reference_filename,const char *output_filename,size_t *fail,
1089 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001090{
1091 char
1092 **arguments,
1093 command[MaxTextExtent];
1094
1095 int
1096 number_arguments;
1097
1098 MagickBooleanType
1099 status;
1100
cristybb503372010-05-27 20:51:26 +00001101 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001102 i,
1103 j;
1104
cristybb503372010-05-27 20:51:26 +00001105 size_t
cristy3ed852e2009-09-05 21:47:34 +00001106 test;
1107
1108 test=0;
cristyb51dff52011-05-19 16:55:47 +00001109 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00001110 for (i=0; montage_options[i] != (char *) NULL; i++)
1111 {
1112 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00001113 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +00001114 montage_options[i]);
cristyb51dff52011-05-19 16:55:47 +00001115 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00001116 reference_filename,montage_options[i],reference_filename,
1117 output_filename);
1118 arguments=StringToArgv(command,&number_arguments);
1119 if (arguments == (char **) NULL)
1120 {
cristy1e604812011-05-19 18:07:50 +00001121 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1122 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001123 (*fail)++;
1124 continue;
1125 }
1126 status=MontageImageCommand(image_info,number_arguments,arguments,
1127 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00001128 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00001129 arguments[j]=DestroyString(arguments[j]);
1130 arguments=(char **) RelinquishMagickMemory(arguments);
1131 if (status != MagickFalse)
1132 {
cristy1e604812011-05-19 18:07:50 +00001133 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1134 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001135 (*fail)++;
1136 continue;
1137 }
cristyb51dff52011-05-19 16:55:47 +00001138 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001139 }
cristyb51dff52011-05-19 16:55:47 +00001140 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001141 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1142 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001143 return(test);
1144}
1145
1146/*
1147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148% %
1149% %
1150% %
1151% V a l i d a t e S t r e a m C o m m a n d %
1152% %
1153% %
1154% %
1155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1156%
1157% ValidateStreamCommand() validates the ImageMagick stream command line
1158% program and returns the number of validation tests that passed and failed.
1159%
1160% The format of the ValidateStreamCommand method is:
1161%
cristybb503372010-05-27 20:51:26 +00001162% size_t ValidateStreamCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001163% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001164% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001165%
1166% A description of each parameter follows:
1167%
1168% o image_info: the image info.
1169%
1170% o reference_filename: the reference image filename.
1171%
1172% o output_filename: the output image filename.
1173%
1174% o fail: return the number of validation tests that pass.
1175%
1176% o exception: return any errors or warnings in this structure.
1177%
1178*/
cristybb503372010-05-27 20:51:26 +00001179static size_t ValidateStreamCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001180 const char *reference_filename,const char *output_filename,size_t *fail,
1181 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001182{
1183 char
1184 **arguments,
1185 command[MaxTextExtent];
1186
1187 int
1188 number_arguments;
1189
1190 MagickBooleanType
1191 status;
1192
cristybb503372010-05-27 20:51:26 +00001193 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001194 i,
1195 j;
1196
cristybb503372010-05-27 20:51:26 +00001197 size_t
cristy3ed852e2009-09-05 21:47:34 +00001198 test;
1199
1200 test=0;
cristyb51dff52011-05-19 16:55:47 +00001201 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00001202 for (i=0; stream_options[i] != (char *) NULL; i++)
1203 {
1204 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00001205 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +00001206 stream_options[i]);
cristyb51dff52011-05-19 16:55:47 +00001207 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00001208 stream_options[i],reference_filename,output_filename);
1209 arguments=StringToArgv(command,&number_arguments);
1210 if (arguments == (char **) NULL)
1211 {
cristy1e604812011-05-19 18:07:50 +00001212 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1213 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001214 (*fail)++;
1215 continue;
1216 }
1217 status=StreamImageCommand(image_info,number_arguments,arguments,
1218 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00001219 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00001220 arguments[j]=DestroyString(arguments[j]);
1221 arguments=(char **) RelinquishMagickMemory(arguments);
1222 if (status != MagickFalse)
1223 {
cristy1e604812011-05-19 18:07:50 +00001224 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1225 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001226 (*fail)++;
1227 continue;
1228 }
cristyb51dff52011-05-19 16:55:47 +00001229 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001230 }
cristyb51dff52011-05-19 16:55:47 +00001231 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001232 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1233 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001234 return(test);
1235}
1236
1237/*
1238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1239% %
1240% %
1241% %
1242% M a i n %
1243% %
1244% %
1245% %
1246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1247%
1248%
1249*/
1250
1251static MagickBooleanType ValidateUsage(void)
1252{
1253 const char
1254 **p;
1255
1256 static const char
1257 *miscellaneous[]=
1258 {
1259 "-debug events display copious debugging information",
1260 "-help print program options",
1261 "-log format format of debugging information",
1262 "-validate type validation type",
1263 "-version print version information",
1264 (char *) NULL
1265 },
1266 *settings[]=
1267 {
1268 "-regard-warnings pay attention to warning messages",
1269 "-verbose print detailed information about the image",
1270 (char *) NULL
1271 };
1272
cristybb503372010-05-27 20:51:26 +00001273 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001274 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
cristyb28d6472009-10-17 20:13:35 +00001275 (void) printf("Features: %s\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00001276 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1277 (void) printf("\nValidate Settings:\n");
1278 for (p=settings; *p != (char *) NULL; p++)
1279 (void) printf(" %s\n",*p);
1280 (void) printf("\nMiscellaneous Options:\n");
1281 for (p=miscellaneous; *p != (char *) NULL; p++)
1282 (void) printf(" %s\n",*p);
1283 return(MagickTrue);
1284}
1285
1286int main(int argc,char **argv)
1287{
1288#define DestroyValidate() \
1289{ \
cristy3ed852e2009-09-05 21:47:34 +00001290 image_info=DestroyImageInfo(image_info); \
1291 exception=DestroyExceptionInfo(exception); \
1292}
1293#define ThrowValidateException(asperity,tag,option) \
1294{ \
1295 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1296 option); \
1297 CatchException(exception); \
1298 DestroyValidate(); \
1299 return(MagickFalse); \
1300}
1301
1302 char
1303 output_filename[MaxTextExtent],
1304 reference_filename[MaxTextExtent],
1305 *option;
1306
1307 double
1308 elapsed_time,
1309 user_time;
1310
1311 ExceptionInfo
1312 *exception;
1313
1314 Image
1315 *reference_image;
1316
1317 ImageInfo
1318 *image_info;
1319
1320 MagickBooleanType
1321 regard_warnings,
1322 status;
1323
cristy9cafe592012-11-17 21:17:59 +00001324 MagickSizeType
1325 memory_resource,
1326 map_resource;
1327
cristybb503372010-05-27 20:51:26 +00001328 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001329 i;
1330
1331 TimerInfo
1332 *timer;
1333
cristybb503372010-05-27 20:51:26 +00001334 size_t
cristy3ed852e2009-09-05 21:47:34 +00001335 fail,
1336 iterations,
1337 tests;
1338
1339 ValidateType
1340 type;
1341
1342 /*
1343 Validate the ImageMagick image processing suite.
1344 */
1345 MagickCoreGenesis(*argv,MagickFalse);
1346 iterations=1;
1347 status=MagickFalse;
1348 type=AllValidate;
1349 regard_warnings=MagickFalse;
cristyd8862902011-02-20 21:12:27 +00001350 (void) regard_warnings;
cristy3ed852e2009-09-05 21:47:34 +00001351 exception=AcquireExceptionInfo();
1352 image_info=AcquireImageInfo();
1353 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
cristybb503372010-05-27 20:51:26 +00001354 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00001355 {
1356 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00001357 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001358 {
1359 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1360 continue;
1361 }
1362 switch (*(option+1))
1363 {
1364 case 'b':
1365 {
1366 if (LocaleCompare("bench",option+1) == 0)
1367 {
cristye27293e2009-12-18 02:53:20 +00001368 iterations=StringToUnsignedLong(argv[++i]);
cristy3ed852e2009-09-05 21:47:34 +00001369 break;
1370 }
1371 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1372 }
1373 case 'd':
1374 {
1375 if (LocaleCompare("debug",option+1) == 0)
1376 {
1377 (void) SetLogEventMask(argv[++i]);
1378 break;
1379 }
1380 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1381 }
1382 case 'h':
1383 {
1384 if (LocaleCompare("help",option+1) == 0)
1385 {
1386 (void) ValidateUsage();
1387 return(0);
1388 }
1389 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1390 }
1391 case 'l':
1392 {
1393 if (LocaleCompare("log",option+1) == 0)
1394 {
1395 if (*option != '+')
1396 (void) SetLogFormat(argv[i+1]);
1397 break;
1398 }
1399 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1400 }
1401 case 'r':
1402 {
1403 if (LocaleCompare("regard-warnings",option+1) == 0)
1404 {
1405 regard_warnings=MagickTrue;
1406 break;
1407 }
1408 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1409 }
1410 case 'v':
1411 {
1412 if (LocaleCompare("validate",option+1) == 0)
1413 {
cristybb503372010-05-27 20:51:26 +00001414 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001415 validate;
1416
1417 if (*option == '+')
1418 break;
1419 i++;
cristybb503372010-05-27 20:51:26 +00001420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001421 ThrowValidateException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001422 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001423 argv[i]);
1424 if (validate < 0)
1425 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1426 argv[i]);
1427 type=(ValidateType) validate;
1428 break;
1429 }
1430 if ((LocaleCompare("version",option+1) == 0) ||
1431 (LocaleCompare("-version",option+1) == 0))
1432 {
cristyb51dff52011-05-19 16:55:47 +00001433 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00001434 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00001435 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1436 GetMagickCopyright());
1437 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1438 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00001439 return(0);
1440 }
1441 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1442 }
1443 default:
1444 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1445 }
1446 }
cristy205e21f2009-09-28 19:01:46 +00001447 timer=(TimerInfo *) NULL;
cristy8b76e552009-09-28 18:20:20 +00001448 if (iterations > 1)
1449 timer=AcquireTimerInfo();
cristy3ed852e2009-09-05 21:47:34 +00001450 reference_image=ReadImage(image_info,exception);
1451 tests=0;
1452 fail=0;
1453 if (reference_image == (Image *) NULL)
1454 fail++;
1455 else
1456 {
1457 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1458 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1459 MaxTextExtent);
1460 (void) AcquireUniqueFilename(reference_filename);
1461 (void) AcquireUniqueFilename(output_filename);
1462 (void) CopyMagickString(reference_image->filename,reference_filename,
1463 MaxTextExtent);
cristy6f9e0d32011-08-28 16:32:09 +00001464 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001465 reference_image=DestroyImage(reference_image);
1466 if (status == MagickFalse)
1467 fail++;
1468 else
1469 {
cristyb51dff52011-05-19 16:55:47 +00001470 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00001471 GetMagickVersion((size_t *) NULL));
cristyb51dff52011-05-19 16:55:47 +00001472 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
cristy3ed852e2009-09-05 21:47:34 +00001473 GetMagickCopyright());
cristy1e604812011-05-19 18:07:50 +00001474 (void) FormatLocaleFile(stdout,
1475 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1476 MagickValidateOptions,(ssize_t) type));
cristy3ed852e2009-09-05 21:47:34 +00001477 if ((type & CompareValidate) != 0)
1478 tests+=ValidateCompareCommand(image_info,reference_filename,
1479 output_filename,&fail,exception);
1480 if ((type & CompositeValidate) != 0)
1481 tests+=ValidateCompositeCommand(image_info,reference_filename,
1482 output_filename,&fail,exception);
1483 if ((type & ConvertValidate) != 0)
1484 tests+=ValidateConvertCommand(image_info,reference_filename,
1485 output_filename,&fail,exception);
1486 if ((type & FormatsInMemoryValidate) != 0)
cristyf044a4d2012-11-17 21:10:20 +00001487 {
1488 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
1489 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1490 output_filename,&fail,exception);
1491 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
cristy9cafe592012-11-17 21:17:59 +00001492 memory_resource=SetMagickResourceLimit(MemoryResource,0);
cristyf044a4d2012-11-17 21:10:20 +00001493 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1494 output_filename,&fail,exception);
1495 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
cristy9cafe592012-11-17 21:17:59 +00001496 map_resource=SetMagickResourceLimit(MapResource,0);
cristyf044a4d2012-11-17 21:10:20 +00001497 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1498 output_filename,&fail,exception);
cristy9cafe592012-11-17 21:17:59 +00001499 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
1500 (void) SetMagickResourceLimit(MapResource,map_resource);
cristyf044a4d2012-11-17 21:10:20 +00001501 }
cristy3ed852e2009-09-05 21:47:34 +00001502 if ((type & FormatsOnDiskValidate) != 0)
cristybda201a2012-11-08 16:44:00 +00001503 {
cristy34c290f2012-11-09 00:44:12 +00001504 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
cristybda201a2012-11-08 16:44:00 +00001505 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1506 output_filename,&fail,exception);
cristy34c290f2012-11-09 00:44:12 +00001507 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
cristy9cafe592012-11-17 21:17:59 +00001508 memory_resource=SetMagickResourceLimit(MemoryResource,0);
cristybda201a2012-11-08 16:44:00 +00001509 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1510 output_filename,&fail,exception);
cristy34c290f2012-11-09 00:44:12 +00001511 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
cristy9cafe592012-11-17 21:17:59 +00001512 map_resource=SetMagickResourceLimit(MapResource,0);
cristybda201a2012-11-08 16:44:00 +00001513 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1514 output_filename,&fail,exception);
cristy9cafe592012-11-17 21:17:59 +00001515 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
1516 (void) SetMagickResourceLimit(MapResource,map_resource);
cristybda201a2012-11-08 16:44:00 +00001517 }
cristy3ed852e2009-09-05 21:47:34 +00001518 if ((type & IdentifyValidate) != 0)
1519 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1520 output_filename,&fail,exception);
1521 if ((type & ImportExportValidate) != 0)
1522 tests+=ValidateImportExportPixels(image_info,reference_filename,
1523 output_filename,&fail,exception);
1524 if ((type & MontageValidate) != 0)
1525 tests+=ValidateMontageCommand(image_info,reference_filename,
1526 output_filename,&fail,exception);
1527 if ((type & StreamValidate) != 0)
1528 tests+=ValidateStreamCommand(image_info,reference_filename,
1529 output_filename,&fail,exception);
cristyb51dff52011-05-19 16:55:47 +00001530 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001531 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1532 (double) tests,(double) (tests-fail),(double) fail);
cristy3ed852e2009-09-05 21:47:34 +00001533 }
1534 (void) RelinquishUniqueFileResource(output_filename);
1535 (void) RelinquishUniqueFileResource(reference_filename);
1536 }
1537 if (exception->severity != UndefinedException)
1538 CatchException(exception);
1539 if (iterations > 1)
1540 {
1541 elapsed_time=GetElapsedTime(timer);
1542 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +00001543 (void) FormatLocaleFile(stderr,
cristy75a26232010-06-03 17:15:02 +00001544 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
cristy6aa47ad2010-05-28 19:32:32 +00001545 iterations,1.0*iterations/elapsed_time,user_time,(long)
1546 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1547 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy8b76e552009-09-28 18:20:20 +00001548 timer=DestroyTimerInfo(timer);
cristy3ed852e2009-09-05 21:47:34 +00001549 }
1550 DestroyValidate();
1551 MagickCoreTerminus();
1552 return(fail == 0 ? 0 : 1);
1553}