root/ImageMagick/trunk/tests/validate.c

Revision 448, 50.3 KB (checked in by cristy, 4 weeks ago)
Line 
1/*
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%                                                                             %
21%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
22%  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>
44#include <string.h>
45#include <math.h>
46#include "wand/MagickWand.h"
47#include "validate.h"
48
49/*
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51%                                                                             %
52%                                                                             %
53%                                                                             %
54%   V a l i d a t e C o m p a r e C o m m a n d                               %
55%                                                                             %
56%                                                                             %
57%                                                                             %
58%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59%
60%  ValidateCompareCommand() validates the ImageMagick compare command line
61%  program and returns the number of validation tests that passed and failed.
62%
63%  The format of the ValidateCompareCommand method is:
64%
65%      unsigned long ValidateCompareCommand(ImageInfo *image_info,
66%        const char *reference_filename,const char *output_filename,
67%        unsigned long *fail,ExceptionInfo *exception)
68%
69%  A description of each parameter follows:
70%
71%    o image_info: the image info.
72%
73%    o reference_filename: the reference image filename.
74%
75%    o output_filename: the output image filename.
76%
77%    o fail: return the number of validation tests that pass.
78%
79%    o exception: return any errors or warnings in this structure.
80%
81*/
82static unsigned long ValidateCompareCommand(ImageInfo *image_info,
83  const char *reference_filename,const char *output_filename,
84  unsigned long *fail,ExceptionInfo *exception)
85{
86  char
87    **arguments,
88    command[MaxTextExtent];
89
90  int
91    number_arguments;
92
93  MagickBooleanType
94    status;
95
96  register long
97    i,
98    j;
99
100  unsigned long
101    test;
102
103  test=0;
104  (void) fprintf(stdout,"validate compare command line program:\n");
105  for (i=0; compare_options[i] != (char *) NULL; i++)
106  {
107    CatchException(exception);
108    (void) fprintf(stdout,"  test %lu: %s",test++,compare_options[i]);
109    (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
110      compare_options[i],reference_filename,reference_filename,output_filename);
111    arguments=StringToArgv(command,&number_arguments);
112    if (arguments == (char **) NULL)
113      {
114        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
115        (*fail)++;
116        continue;
117      }
118    status=CompareImageCommand(image_info,number_arguments,arguments,
119      (char **) NULL,exception);
120    for (j=0; j < number_arguments; j++)
121      arguments[j]=DestroyString(arguments[j]);
122    arguments=(char **) RelinquishMagickMemory(arguments);
123    if (status != MagickFalse)
124      {
125        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
126        (*fail)++;
127        continue;
128      }
129    (void) fprintf(stdout,"... pass.\n");
130  }
131  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
132    test,test-(*fail),*fail);
133  return(test);
134}
135
136/*
137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138%                                                                             %
139%                                                                             %
140%                                                                             %
141%   V a l i d a t e C o m p o s i t e C o m m a n d                           %
142%                                                                             %
143%                                                                             %
144%                                                                             %
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146%
147%  ValidateCompositeCommand() validates the ImageMagick composite command line
148%  program and returns the number of validation tests that passed and failed.
149%
150%  The format of the ValidateCompositeCommand method is:
151%
152%      unsigned long ValidateCompositeCommand(ImageInfo *image_info,
153%        const char *reference_filename,const char *output_filename,
154%        unsigned long *fail,ExceptionInfo *exception)
155%
156%  A description of each parameter follows:
157%
158%    o image_info: the image info.
159%
160%    o reference_filename: the reference image filename.
161%
162%    o output_filename: the output image filename.
163%
164%    o fail: return the number of validation tests that pass.
165%
166%    o exception: return any errors or warnings in this structure.
167%
168*/
169static unsigned long ValidateCompositeCommand(ImageInfo *image_info,
170  const char *reference_filename,const char *output_filename,
171  unsigned long *fail,ExceptionInfo *exception)
172{
173  char
174    **arguments,
175    command[MaxTextExtent];
176
177  int
178    number_arguments;
179
180  MagickBooleanType
181    status;
182
183  register long
184    i,
185    j;
186
187  unsigned long
188    test;
189
190  test=0;
191  (void) fprintf(stdout,"validate composite command line program:\n");
192  for (i=0; composite_options[i] != (char *) NULL; i++)
193  {
194    CatchException(exception);
195    (void) fprintf(stdout,"  test %lu: %s",test++,composite_options[i]);
196    (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
197      reference_filename,composite_options[i],reference_filename,
198      output_filename);
199    arguments=StringToArgv(command,&number_arguments);
200    if (arguments == (char **) NULL)
201      {
202        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
203        (*fail)++;
204        continue;
205      }
206    status=CompositeImageCommand(image_info,number_arguments,arguments,
207      (char **) NULL,exception);
208    for (j=0; j < number_arguments; j++)
209      arguments[j]=DestroyString(arguments[j]);
210    arguments=(char **) RelinquishMagickMemory(arguments);
211    if (status != MagickFalse)
212      {
213        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
214        (*fail)++;
215        continue;
216      }
217    (void) fprintf(stdout,"... pass.\n");
218  }
219  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
220    test,test-(*fail),*fail);
221  return(test);
222}
223
224/*
225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226%                                                                             %
227%                                                                             %
228%                                                                             %
229%   V a l i d a t e C o n v e r t C o m m a n d                               %
230%                                                                             %
231%                                                                             %
232%                                                                             %
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234%
235%  ValidateConvertCommand() validates the ImageMagick convert command line
236%  program and returns the number of validation tests that passed and failed.
237%
238%  The format of the ValidateConvertCommand method is:
239%
240%      unsigned long ValidateConvertCommand(ImageInfo *image_info,
241%        const char *reference_filename,const char *output_filename,
242%        unsigned long *fail,ExceptionInfo *exception)
243%
244%  A description of each parameter follows:
245%
246%    o image_info: the image info.
247%
248%    o reference_filename: the reference image filename.
249%
250%    o output_filename: the output image filename.
251%
252%    o fail: return the number of validation tests that pass.
253%
254%    o exception: return any errors or warnings in this structure.
255%
256*/
257static unsigned long ValidateConvertCommand(ImageInfo *image_info,
258  const char *reference_filename,const char *output_filename,
259  unsigned long *fail,ExceptionInfo *exception)
260{
261  char
262    **arguments,
263    command[MaxTextExtent];
264
265  int
266    number_arguments;
267
268  MagickBooleanType
269    status;
270
271  register long
272    i,
273    j;
274
275  unsigned long
276    test;
277
278  test=0;
279  (void) fprintf(stdout,"validate convert command line program:\n");
280  for (i=0; convert_options[i] != (char *) NULL; i++)
281  {
282    CatchException(exception);
283    (void) fprintf(stdout,"  test %lu: %s",test++,convert_options[i]);
284    (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
285      reference_filename,convert_options[i],reference_filename,output_filename);
286    arguments=StringToArgv(command,&number_arguments);
287    if (arguments == (char **) NULL)
288      {
289        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
290        (*fail)++;
291        continue;
292      }
293    status=ConvertImageCommand(image_info,number_arguments,arguments,
294      (char **) NULL,exception);
295    for (j=0; j < number_arguments; j++)
296      arguments[j]=DestroyString(arguments[j]);
297    arguments=(char **) RelinquishMagickMemory(arguments);
298    if (status != MagickFalse)
299      {
300        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
301        (*fail)++;
302        continue;
303      }
304    (void) fprintf(stdout,"... pass.\n");
305  }
306  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
307    test,test-(*fail),*fail);
308  return(test);
309}
310
311/*
312%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313%                                                                             %
314%                                                                             %
315%                                                                             %
316%   V a l i d a t e I d e n t i f y C o m m a n d                             %
317%                                                                             %
318%                                                                             %
319%                                                                             %
320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321%
322%  ValidateIdentifyCommand() validates the ImageMagick identify command line
323%  program and returns the number of validation tests that passed and failed.
324%
325%  The format of the ValidateIdentifyCommand method is:
326%
327%      unsigned long ValidateIdentifyCommand(ImageInfo *image_info,
328%        const char *reference_filename,const char *output_filename,
329%        unsigned long *fail,ExceptionInfo *exception)
330%
331%  A description of each parameter follows:
332%
333%    o image_info: the image info.
334%
335%    o reference_filename: the reference image filename.
336%
337%    o output_filename: the output image filename.
338%
339%    o fail: return the number of validation tests that pass.
340%
341%    o exception: return any errors or warnings in this structure.
342%
343*/
344static unsigned long ValidateIdentifyCommand(ImageInfo *image_info,
345  const char *reference_filename,const char *output_filename,
346  unsigned long *fail,ExceptionInfo *exception)
347{
348  char
349    **arguments,
350    command[MaxTextExtent];
351
352  int
353    number_arguments;
354
355  MagickBooleanType
356    status;
357
358  register long
359    i,
360    j;
361
362  unsigned long
363    test;
364
365  (void) output_filename;
366  test=0;
367  (void) fprintf(stdout,"validate identify command line program:\n");
368  for (i=0; identify_options[i] != (char *) NULL; i++)
369  {
370    CatchException(exception);
371    (void) fprintf(stdout,"  test %lu: %s",test++,identify_options[i]);
372    (void) FormatMagickString(command,MaxTextExtent,"%s %s",
373      identify_options[i],reference_filename);
374    arguments=StringToArgv(command,&number_arguments);
375    if (arguments == (char **) NULL)
376      {
377        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
378        (*fail)++;
379        continue;
380      }
381    status=IdentifyImageCommand(image_info,number_arguments,arguments,
382      (char **) NULL,exception);
383    for (j=0; j < number_arguments; j++)
384      arguments[j]=DestroyString(arguments[j]);
385    arguments=(char **) RelinquishMagickMemory(arguments);
386    if (status != MagickFalse)
387      {
388        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
389        (*fail)++;
390        continue;
391      }
392    (void) fprintf(stdout,"... pass.\n");
393  }
394  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
395    test,test-(*fail),*fail);
396  return(test);
397}
398
399/*
400%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401%                                                                             %
402%                                                                             %
403%                                                                             %
404%   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                   %
405%                                                                             %
406%                                                                             %
407%                                                                             %
408%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409%
410%  ValidateImageFormatsInMemory() validates the ImageMagick image formats in
411%  memory and returns the number of validation tests that passed and failed.
412%
413%  The format of the ValidateImageFormatsInMemory method is:
414%
415%      unsigned long ValidateImageFormatsInMemory(ImageInfo *image_info,
416%        const char *reference_filename,const char *output_filename,
417%        unsigned long *fail,ExceptionInfo *exception)
418%
419%  A description of each parameter follows:
420%
421%    o image_info: the image info.
422%
423%    o reference_filename: the reference image filename.
424%
425%    o output_filename: the output image filename.
426%
427%    o fail: return the number of validation tests that pass.
428%
429%    o exception: return any errors or warnings in this structure.
430%
431*/
432static unsigned long ValidateImageFormatsInMemory(ImageInfo *image_info,
433  const char *reference_filename,const char *output_filename,
434  unsigned long *fail,ExceptionInfo *exception)
435{
436  char
437    size[MaxTextExtent];
438
439  const MagickInfo
440    *magick_info;
441
442  double
443    distortion,
444    fuzz;
445
446  Image
447    *difference_image,
448    *reference_image,
449    *reconstruct_image;
450
451  MagickBooleanType
452    status;
453
454  register long
455    i,
456    j;
457
458  size_t
459    length;
460
461  unsigned char
462    *blob;
463
464  unsigned long
465    test;
466
467  test=0;
468  (void) fprintf(stdout,"validate image formats in memory:\n");
469  for (i=0; reference_formats[i].magick != (char *) NULL; i++)
470  {
471    magick_info=GetMagickInfo(reference_formats[i].magick,exception);
472    if ((magick_info == (const MagickInfo *) NULL) ||
473        (magick_info->decoder == (DecodeImageHandler *) NULL) ||
474        (magick_info->encoder == (EncodeImageHandler *) NULL))
475      continue;
476    for (j=0; reference_types[j].type != UndefinedType; j++)
477    {
478      /*
479        Generate reference image.
480      */
481      CatchException(exception);
482      (void) fprintf(stdout,"  test %lu: %s/%s/%s/%lu-bits",test++,
483        reference_formats[i].magick,MagickOptionToMnemonic(
484        MagickCompressOptions,reference_formats[i].compression),
485        MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
486        reference_types[j].depth);
487      (void) CopyMagickString(image_info->filename,reference_filename,
488        MaxTextExtent);
489      reference_image=ReadImage(image_info,exception);
490      if (reference_image == (Image *) NULL)
491        {
492          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
493          (*fail)++;
494          continue;
495        }
496      /*
497        Write reference image.
498      */
499      (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",
500        reference_image->columns,reference_image->rows);
501      (void) CloneString(&image_info->size,size);
502      image_info->depth=reference_types[j].depth;
503      (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
504        reference_formats[i].magick,output_filename);
505      status=SetImageType(reference_image,reference_types[j].type);
506      InheritException(exception,&reference_image->exception);
507      if (status == MagickFalse)
508        {
509          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
510          (*fail)++;
511          reference_image=DestroyImage(reference_image);
512          continue;
513        }
514      status=SetImageDepth(reference_image,reference_types[j].depth);
515      InheritException(exception,&reference_image->exception);
516      if (status == MagickFalse)
517        {
518          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
519          (*fail)++;
520          reference_image=DestroyImage(reference_image);
521          continue;
522        }
523      reference_image->compression=reference_formats[i].compression;
524      status=WriteImage(image_info,reference_image);
525      InheritException(exception,&reference_image->exception);
526      reference_image=DestroyImage(reference_image);
527      if (status == MagickFalse)
528        {
529          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
530          (*fail)++;
531          continue;
532        }
533      /*
534        Read reference image.
535      */
536      (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
537        reference_formats[i].magick,output_filename);
538      reference_image=ReadImage(image_info,exception);
539      if (reference_image == (Image *) NULL)
540        {
541          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
542          (*fail)++;
543          continue;
544        }
545      /*
546        Write reference image.
547      */
548      (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
549        reference_formats[i].magick,output_filename);
550      (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
551        MaxTextExtent);
552      reference_image->depth=reference_types[j].depth;
553      reference_image->compression=reference_formats[i].compression;
554      length=8192;
555      blob=ImageToBlob(image_info,reference_image,&length,exception);
556      if (blob == (unsigned char *) NULL)
557        {
558          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
559          (*fail)++;
560          reference_image=DestroyImage(reference_image);
561          continue;
562        }
563      /*
564        Read reconstruct image.
565      */
566      (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
567        reference_formats[i].magick,output_filename);
568      reconstruct_image=BlobToImage(image_info,blob,length,exception);
569      blob=(unsigned char *) RelinquishMagickMemory(blob);
570      if (reconstruct_image == (Image *) NULL)
571        {
572          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
573          (*fail)++;
574          reference_image=DestroyImage(reference_image);
575          continue;
576        }
577      /*
578        Compare reference to reconstruct image.
579      */
580      fuzz=0.0;
581      if (reference_formats[i].fuzz != 0.0)
582        fuzz=reference_formats[i].fuzz;
583#if defined(MAGICKCORE_HDRI_SUPPORT)
584      fuzz+=0.003;
585#endif
586      if (reference_image->colorspace != RGBColorspace)
587        fuzz+=0.3;
588      fuzz+=MagickEpsilon;
589      difference_image=CompareImageChannels(reference_image,reconstruct_image,
590        AllChannels,MeanSquaredErrorMetric,&distortion,exception);
591      reconstruct_image=DestroyImage(reconstruct_image);
592      reference_image=DestroyImage(reference_image);
593      if (difference_image == (Image *) NULL)
594        {
595          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
596          (*fail)++;
597          continue;
598        }
599      difference_image=DestroyImage(difference_image);
600      if ((distortion/QuantumRange) > fuzz)
601        {
602          (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
603            QuantumRange);
604          (*fail)++;
605          continue;
606        }
607      (void) fprintf(stdout,"... pass.\n");
608    }
609  }
610  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
611    test,test-(*fail),*fail);
612  return(test);
613}
614
615/*
616%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617%                                                                             %
618%                                                                             %
619%                                                                             %
620%   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                       %
621%                                                                             %
622%                                                                             %
623%                                                                             %
624%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625%
626%  ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
627%  and returns the number of validation tests that passed and failed.
628%
629%  The format of the ValidateImageFormatsOnDisk method is:
630%
631%      unsigned long ValidateImageFormatsOnDisk(ImageInfo *image_info,
632%        const char *reference_filename,const char *output_filename,
633%        unsigned long *fail,ExceptionInfo *exception)
634%
635%  A description of each parameter follows:
636%
637%    o image_info: the image info.
638%
639%    o reference_filename: the reference image filename.
640%
641%    o output_filename: the output image filename.
642%
643%    o fail: return the number of validation tests that pass.
644%
645%    o exception: return any errors or warnings in this structure.
646%
647*/
648static unsigned long ValidateImageFormatsOnDisk(ImageInfo *image_info,
649  const char *reference_filename,const char *output_filename,
650  unsigned long *fail,ExceptionInfo *exception)
651{
652  char
653    size[MaxTextExtent];
654
655  const MagickInfo
656    *magick_info;
657
658  double
659    distortion,
660    fuzz;
661
662  Image
663    *difference_image,
664    *reference_image,
665    *reconstruct_image;
666
667  MagickBooleanType
668    status;
669
670  register long
671    i,
672    j;
673
674  unsigned long
675    test;
676
677  test=0;
678  (void) fprintf(stdout,"validate image formats on disk:\n");
679  for (i=0; reference_formats[i].magick != (char *) NULL; i++)
680  {
681    magick_info=GetMagickInfo(reference_formats[i].magick,exception);
682    if ((magick_info == (const MagickInfo *) NULL) ||
683        (magick_info->decoder == (DecodeImageHandler *) NULL) ||
684        (magick_info->encoder == (EncodeImageHandler *) NULL))
685      continue;
686    for (j=0; reference_types[j].type != UndefinedType; j++)
687    {
688      /*
689        Generate reference image.
690      */
691      CatchException(exception);
692      (void) fprintf(stdout,"  test %lu: %s/%s/%s/%lu-bits",test++,
693        reference_formats[i].magick,MagickOptionToMnemonic(
694        MagickCompressOptions,reference_formats[i].compression),
695        MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
696        reference_types[j].depth);
697      (void) CopyMagickString(image_info->filename,reference_filename,
698        MaxTextExtent);
699      reference_image=ReadImage(image_info,exception);
700      if (reference_image == (Image *) NULL)
701        {
702          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
703          (*fail)++;
704          continue;
705        }
706      /*
707        Write reference image.
708      */
709      (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",
710        reference_image->columns,reference_image->rows);
711      (void) CloneString(&image_info->size,size);
712      image_info->depth=reference_types[j].depth;
713      (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
714        reference_formats[i].magick,output_filename);
715      status=SetImageType(reference_image,reference_types[j].type);
716      InheritException(exception,&reference_image->exception);
717      if (status == MagickFalse)
718        {
719          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
720          (*fail)++;
721          reference_image=DestroyImage(reference_image);
722          continue;
723        }
724      status=SetImageDepth(reference_image,reference_types[j].depth);
725      InheritException(exception,&reference_image->exception);
726      if (status == MagickFalse)
727        {
728          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
729          (*fail)++;
730          reference_image=DestroyImage(reference_image);
731          continue;
732        }
733      reference_image->compression=reference_formats[i].compression;
734      status=WriteImage(image_info,reference_image);
735      InheritException(exception,&reference_image->exception);
736      reference_image=DestroyImage(reference_image);
737      if (status == MagickFalse)
738        {
739          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
740          (*fail)++;
741          continue;
742        }
743      /*
744        Read reference image.
745      */
746      (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
747        reference_formats[i].magick,output_filename);
748      reference_image=ReadImage(image_info,exception);
749      if (reference_image == (Image *) NULL)
750        {
751          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
752          (*fail)++;
753          continue;
754        }
755      /*
756        Write reference image.
757      */
758      (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
759        reference_formats[i].magick,output_filename);
760      reference_image->depth=reference_types[j].depth;
761      reference_image->compression=reference_formats[i].compression;
762      status=WriteImage(image_info,reference_image);
763      InheritException(exception,&reference_image->exception);
764      if (status == MagickFalse)
765        {
766          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
767          (*fail)++;
768          reference_image=DestroyImage(reference_image);
769          continue;
770        }
771      /*
772        Read reconstruct image.
773      */
774      (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
775        reference_formats[i].magick,output_filename);
776      reconstruct_image=ReadImage(image_info,exception);
777      if (reconstruct_image == (Image *) NULL)
778        {
779          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
780          (*fail)++;
781          reference_image=DestroyImage(reference_image);
782          continue;
783        }
784      /*
785        Compare reference to reconstruct image.
786      */
787      fuzz=0.0;
788      if (reference_formats[i].fuzz != 0.0)
789        fuzz=reference_formats[i].fuzz;
790#if defined(MAGICKCORE_HDRI_SUPPORT)
791      fuzz+=0.003;
792#endif
793      if (reference_image->colorspace != RGBColorspace)
794        fuzz+=0.3;
795      fuzz+=MagickEpsilon;
796      difference_image=CompareImageChannels(reference_image,reconstruct_image,
797        AllChannels,MeanSquaredErrorMetric,&distortion,exception);
798      reconstruct_image=DestroyImage(reconstruct_image);
799      reference_image=DestroyImage(reference_image);
800      if (difference_image == (Image *) NULL)
801        {
802          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
803          (*fail)++;
804          continue;
805        }
806      difference_image=DestroyImage(difference_image);
807      if ((distortion/QuantumRange) > fuzz)
808        {
809          (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
810            QuantumRange);
811          (*fail)++;
812          continue;
813        }
814      (void) fprintf(stdout,"... pass.\n");
815    }
816  }
817  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
818    test,test-(*fail),*fail);
819  return(test);
820}
821
822/*
823%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824%                                                                             %
825%                                                                             %
826%                                                                             %
827%   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                       %
828%                                                                             %
829%                                                                             %
830%                                                                             %
831%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
832%
833%  ValidateImportExportPixels() validates the pixel import and export methods.
834%  It returns the number of validation tests that passed and failed.
835%
836%  The format of the ValidateImportExportPixels method is:
837%
838%      unsigned long ValidateImportExportPixels(ImageInfo *image_info,
839%        const char *reference_filename,const char *output_filename,
840%        unsigned long *fail,ExceptionInfo *exception)
841%
842%  A description of each parameter follows:
843%
844%    o image_info: the image info.
845%
846%    o reference_filename: the reference image filename.
847%
848%    o output_filename: the output image filename.
849%
850%    o fail: return the number of validation tests that pass.
851%
852%    o exception: return any errors or warnings in this structure.
853%
854*/
855static unsigned long ValidateImportExportPixels(ImageInfo *image_info,
856  const char *reference_filename,const char *output_filename,
857  unsigned long *fail,ExceptionInfo *exception)
858{
859  double
860    distortion;
861
862  Image
863    *difference_image,
864    *reference_image,
865    *reconstruct_image;
866
867  MagickBooleanType
868    status;
869
870  register long
871    i,
872    j;
873
874  size_t
875    length;
876
877  unsigned char
878    *pixels;
879
880  unsigned long
881    test;
882
883  (void) output_filename;
884  test=0;
885  (void) fprintf(stdout,"validate the import and export of image pixels:\n");
886  for (i=0; reference_map[i] != (char *) NULL; i++)
887  {
888    for (j=0; reference_storage[j].type != UndefinedPixel; j++)
889    {
890      /*
891        Generate reference image.
892      */
893      CatchException(exception);
894      (void) fprintf(stdout,"  test %lu: %s/%s",test++,
895        reference_map[i],MagickOptionToMnemonic(MagickStorageOptions,
896        reference_storage[j].type));
897      (void) CopyMagickString(image_info->filename,reference_filename,
898        MaxTextExtent);
899      reference_image=ReadImage(image_info,exception);
900      if (reference_image == (Image *) NULL)
901        {
902          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
903          (*fail)++;
904          continue;
905        }
906      if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
907        (void) TransformImageColorspace(reference_image,CMYKColorspace);
908      length=strlen(reference_map[i])*reference_image->columns*
909        reference_image->rows*reference_storage[j].quantum;
910      pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
911      if (pixels == (unsigned char *) NULL)
912        {
913          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
914          (*fail)++;
915          reference_image=DestroyImage(reference_image);
916          continue;
917        }
918      (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
919      status=ExportImagePixels(reference_image,0,0,reference_image->columns,
920        reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
921        exception);
922      if (status == MagickFalse)
923        {
924          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
925          (*fail)++;
926          pixels=(unsigned char *) RelinquishMagickMemory(pixels);
927          reference_image=DestroyImage(reference_image);
928          continue;
929        }
930      (void) SetImageBackgroundColor(reference_image);
931      status=ImportImagePixels(reference_image,0,0,reference_image->columns,
932        reference_image->rows,reference_map[i],reference_storage[j].type,
933        pixels);
934      InheritException(exception,&reference_image->exception);
935      if (status == MagickFalse)
936        {
937          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
938          (*fail)++;
939           pixels=(unsigned char *) RelinquishMagickMemory(pixels);
940          reference_image=DestroyImage(reference_image);
941          continue;
942        }
943      /*
944        Read reconstruct image.
945      */
946      reconstruct_image=AcquireImage(image_info);
947      (void) SetImageExtent(reconstruct_image,reference_image->columns,
948        reference_image->rows);
949      (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
950      (void) SetImageBackgroundColor(reconstruct_image);
951      status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
952        reconstruct_image->rows,reference_map[i],reference_storage[j].type,
953        pixels);
954      InheritException(exception,&reconstruct_image->exception);
955      pixels=(unsigned char *) RelinquishMagickMemory(pixels);
956      if (status == MagickFalse)
957        {
958          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
959          (*fail)++;
960          reference_image=DestroyImage(reference_image);
961          continue;
962        }
963      /*
964        Compare reference to reconstruct image.
965      */
966      difference_image=CompareImageChannels(reference_image,reconstruct_image,
967        AllChannels,MeanSquaredErrorMetric,&distortion,exception);
968      reconstruct_image=DestroyImage(reconstruct_image);
969      reference_image=DestroyImage(reference_image);
970      if (difference_image == (Image *) NULL)
971        {
972          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
973          (*fail)++;
974          continue;
975        }
976      difference_image=DestroyImage(difference_image);
977      if ((distortion/QuantumRange) > 0.0)
978        {
979          (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
980            QuantumRange);
981          (*fail)++;
982          continue;
983        }
984      (void) fprintf(stdout,"... pass.\n");
985    }
986  }
987  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
988    test,test-(*fail),*fail);
989  return(test);
990}
991
992/*
993%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994%                                                                             %
995%                                                                             %
996%                                                                             %
997%   V a l i d a t e M o n t a g e C o m m a n d                               %
998%                                                                             %
999%                                                                             %
1000%                                                                             %
1001%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002%
1003%  ValidateMontageCommand() validates the ImageMagick montage command line
1004%  program and returns the number of validation tests that passed and failed.
1005%
1006%  The format of the ValidateMontageCommand method is:
1007%
1008%      unsigned long ValidateMontageCommand(ImageInfo *image_info,
1009%        const char *reference_filename,const char *output_filename,
1010%        unsigned long *fail,ExceptionInfo *exception)
1011%
1012%  A description of each parameter follows:
1013%
1014%    o image_info: the image info.
1015%
1016%    o reference_filename: the reference image filename.
1017%
1018%    o output_filename: the output image filename.
1019%
1020%    o fail: return the number of validation tests that pass.
1021%
1022%    o exception: return any errors or warnings in this structure.
1023%
1024*/
1025static unsigned long ValidateMontageCommand(ImageInfo *image_info,
1026  const char *reference_filename,const char *output_filename,
1027  unsigned long *fail,ExceptionInfo *exception)
1028{
1029  char
1030    **arguments,
1031    command[MaxTextExtent];
1032
1033  int
1034    number_arguments;
1035
1036  MagickBooleanType
1037    status;
1038
1039  register long
1040    i,
1041    j;
1042
1043  unsigned long
1044    test;
1045
1046  test=0;
1047  (void) fprintf(stdout,"validate montage command line program:\n");
1048  for (i=0; montage_options[i] != (char *) NULL; i++)
1049  {
1050    CatchException(exception);
1051    (void) fprintf(stdout,"  test %lu: %s",test++,montage_options[i]);
1052    (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
1053      reference_filename,montage_options[i],reference_filename,
1054      output_filename);
1055    arguments=StringToArgv(command,&number_arguments);
1056    if (arguments == (char **) NULL)
1057      {
1058        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1059        (*fail)++;
1060        continue;
1061      }
1062    status=MontageImageCommand(image_info,number_arguments,arguments,
1063      (char **) NULL,exception);
1064    for (j=0; j < number_arguments; j++)
1065      arguments[j]=DestroyString(arguments[j]);
1066    arguments=(char **) RelinquishMagickMemory(arguments);
1067    if (status != MagickFalse)
1068      {
1069        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1070        (*fail)++;
1071        continue;
1072      }
1073    (void) fprintf(stdout,"... pass.\n");
1074  }
1075  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
1076    test,test-(*fail),*fail);
1077  return(test);
1078}
1079
1080/*
1081%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082%                                                                             %
1083%                                                                             %
1084%                                                                             %
1085%   V a l i d a t e S t r e a m C o m m a n d                                 %
1086%                                                                             %
1087%                                                                             %
1088%                                                                             %
1089%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090%
1091%  ValidateStreamCommand() validates the ImageMagick stream command line
1092%  program and returns the number of validation tests that passed and failed.
1093%
1094%  The format of the ValidateStreamCommand method is:
1095%
1096%      unsigned long ValidateStreamCommand(ImageInfo *image_info,
1097%        const char *reference_filename,const char *output_filename,
1098%        unsigned long *fail,ExceptionInfo *exception)
1099%
1100%  A description of each parameter follows:
1101%
1102%    o image_info: the image info.
1103%
1104%    o reference_filename: the reference image filename.
1105%
1106%    o output_filename: the output image filename.
1107%
1108%    o fail: return the number of validation tests that pass.
1109%
1110%    o exception: return any errors or warnings in this structure.
1111%
1112*/
1113static unsigned long ValidateStreamCommand(ImageInfo *image_info,
1114  const char *reference_filename,const char *output_filename,
1115  unsigned long *fail,ExceptionInfo *exception)
1116{
1117  char
1118    **arguments,
1119    command[MaxTextExtent];
1120
1121  int
1122    number_arguments;
1123
1124  MagickBooleanType
1125    status;
1126
1127  register long
1128    i,
1129    j;
1130
1131  unsigned long
1132    test;
1133
1134  test=0;
1135  (void) fprintf(stdout,"validate stream command line program:\n");
1136  for (i=0; stream_options[i] != (char *) NULL; i++)
1137  {
1138    CatchException(exception);
1139    (void) fprintf(stdout,"  test %lu: %s",test++,stream_options[i]);
1140    (void) FormatMagickString(command,MaxTextExtent,"%s %s %s",
1141      stream_options[i],reference_filename,output_filename);
1142    arguments=StringToArgv(command,&number_arguments);
1143    if (arguments == (char **) NULL)
1144      {
1145        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1146        (*fail)++;
1147        continue;
1148      }
1149    status=StreamImageCommand(image_info,number_arguments,arguments,
1150      (char **) NULL,exception);
1151    for (j=0; j < number_arguments; j++)
1152      arguments[j]=DestroyString(arguments[j]);
1153    arguments=(char **) RelinquishMagickMemory(arguments);
1154    if (status != MagickFalse)
1155      {
1156        (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1157        (*fail)++;
1158        continue;
1159      }
1160    (void) fprintf(stdout,"... pass.\n");
1161  }
1162  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
1163    test,test-(*fail),*fail);
1164  return(test);
1165}
1166
1167/*
1168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1169%                                                                             %
1170%                                                                             %
1171%                                                                             %
1172%  M a i n                                                                    %
1173%                                                                             %
1174%                                                                             %
1175%                                                                             %
1176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1177%
1178%
1179*/
1180
1181static MagickBooleanType ValidateUsage(void)
1182{
1183  const char
1184    **p;
1185
1186  static const char
1187    *miscellaneous[]=
1188    {
1189      "-debug events        display copious debugging information",
1190      "-help                print program options",
1191      "-log format          format of debugging information",
1192      "-validate type       validation type",
1193      "-version             print version information",
1194      (char *) NULL
1195    },
1196    *settings[]=
1197    {
1198      "-regard-warnings     pay attention to warning messages",
1199      "-verbose             print detailed information about the image",
1200      (char *) NULL
1201    };
1202
1203  (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
1204  (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1205  (void) printf("Features: %s\n",GetMagickFeatures());
1206  (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1207  (void) printf("\nValidate Settings:\n");
1208  for (p=settings; *p != (char *) NULL; p++)
1209    (void) printf("  %s\n",*p);
1210  (void) printf("\nMiscellaneous Options:\n");
1211  for (p=miscellaneous; *p != (char *) NULL; p++)
1212    (void) printf("  %s\n",*p);
1213  return(MagickTrue);
1214}
1215
1216int main(int argc,char **argv)
1217{
1218#define DestroyValidate() \
1219{ \
1220  image_info=DestroyImageInfo(image_info); \
1221  exception=DestroyExceptionInfo(exception); \
1222}
1223#define ThrowValidateException(asperity,tag,option) \
1224{ \
1225  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1226    option); \
1227  CatchException(exception); \
1228  DestroyValidate(); \
1229  return(MagickFalse); \
1230}
1231
1232  char
1233    output_filename[MaxTextExtent],
1234    reference_filename[MaxTextExtent],
1235    *option;
1236
1237  double
1238    elapsed_time,
1239    user_time;
1240
1241  ExceptionInfo
1242    *exception;
1243
1244  Image
1245    *reference_image;
1246
1247  ImageInfo
1248    *image_info;
1249
1250  MagickBooleanType
1251    regard_warnings,
1252    status;
1253
1254  register long
1255    i;
1256
1257  TimerInfo
1258    *timer;
1259
1260  unsigned long
1261    fail,
1262    iterations,
1263    tests;
1264
1265  ValidateType
1266    type;
1267
1268  /*
1269    Validate the ImageMagick image processing suite.
1270  */
1271  MagickCoreGenesis(*argv,MagickFalse);
1272  iterations=1;
1273  status=MagickFalse;
1274  type=AllValidate;
1275  regard_warnings=MagickFalse;
1276  exception=AcquireExceptionInfo();
1277  image_info=AcquireImageInfo();
1278  (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1279  for (i=1; i < (long) argc; i++)
1280  {
1281    option=argv[i];
1282    if (IsMagickOption(option) == MagickFalse)
1283      {
1284        (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1285        continue;
1286      }
1287    switch (*(option+1))
1288    {
1289      case 'b':
1290      {
1291        if (LocaleCompare("bench",option+1) == 0)
1292          {
1293            iterations=(unsigned long) atol(argv[++i]);
1294            break;
1295          }
1296        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1297      }
1298      case 'd':
1299      {
1300        if (LocaleCompare("debug",option+1) == 0)
1301          {
1302            (void) SetLogEventMask(argv[++i]);
1303            break;
1304          }
1305        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1306      }
1307      case 'h':
1308      {
1309        if (LocaleCompare("help",option+1) == 0)
1310          {
1311            (void) ValidateUsage();
1312            return(0);
1313          }
1314        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1315      }
1316      case 'l':
1317      {
1318        if (LocaleCompare("log",option+1) == 0)
1319          {
1320            if (*option != '+')
1321              (void) SetLogFormat(argv[i+1]);
1322            break;
1323          }
1324        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1325      }
1326      case 'r':
1327      {
1328        if (LocaleCompare("regard-warnings",option+1) == 0)
1329          {
1330            regard_warnings=MagickTrue;
1331            break;
1332          }
1333        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1334      }
1335      case 'v':
1336      {
1337        if (LocaleCompare("validate",option+1) == 0)
1338          {
1339            long
1340              validate;
1341
1342            if (*option == '+')
1343              break;
1344            i++;
1345            if (i == (long) argc)
1346              ThrowValidateException(OptionError,"MissingArgument",option);
1347            validate=ParseMagickOption(MagickValidateOptions,MagickFalse,
1348              argv[i]);
1349            if (validate < 0)
1350              ThrowValidateException(OptionError,"UnrecognizedValidateType",
1351                argv[i]);
1352            type=(ValidateType) validate;
1353            break;
1354          }
1355        if ((LocaleCompare("version",option+1) == 0) ||
1356            (LocaleCompare("-version",option+1) == 0))
1357          {
1358            (void) fprintf(stdout,"Version: %s\n",
1359              GetMagickVersion((unsigned long *) NULL));
1360            (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright());
1361            (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
1362            return(0);
1363          }
1364        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1365      }
1366      default:
1367        ThrowValidateException(OptionError,"UnrecognizedOption",option)
1368    }
1369  }
1370  timer=(TimerInfo *) NULL;
1371  if (iterations > 1)
1372    timer=AcquireTimerInfo();
1373  reference_image=ReadImage(image_info,exception);
1374  tests=0;
1375  fail=0;
1376  if (reference_image == (Image *) NULL)
1377    fail++;
1378  else
1379    {
1380      if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1381        (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1382          MaxTextExtent);
1383      (void) AcquireUniqueFilename(reference_filename);
1384      (void) AcquireUniqueFilename(output_filename);
1385      (void) CopyMagickString(reference_image->filename,reference_filename,
1386        MaxTextExtent);
1387      status=WriteImage(image_info,reference_image);
1388      InheritException(exception,&reference_image->exception);
1389      reference_image=DestroyImage(reference_image);
1390      if (status == MagickFalse)
1391        fail++;
1392      else
1393        {
1394          (void) fprintf(stdout,"Version: %s\n",
1395            GetMagickVersion((unsigned long *) NULL));
1396          (void) fprintf(stdout,"Copyright: %s\n\n",
1397            GetMagickCopyright());
1398          (void) fprintf(stdout,"ImageMagick Validation Suite (%s)\n\n",
1399            MagickOptionToMnemonic(MagickValidateOptions,(long) type));
1400          if ((type & CompareValidate) != 0)
1401            tests+=ValidateCompareCommand(image_info,reference_filename,
1402              output_filename,&fail,exception);
1403          if ((type & CompositeValidate) != 0)
1404            tests+=ValidateCompositeCommand(image_info,reference_filename,
1405              output_filename,&fail,exception);
1406          if ((type & ConvertValidate) != 0)
1407            tests+=ValidateConvertCommand(image_info,reference_filename,
1408              output_filename,&fail,exception);
1409          if ((type & FormatsInMemoryValidate) != 0)
1410            tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1411              output_filename,&fail,exception);
1412          if ((type & FormatsOnDiskValidate) != 0)
1413            tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1414              output_filename,&fail,exception);
1415          if ((type & IdentifyValidate) != 0)
1416            tests+=ValidateIdentifyCommand(image_info,reference_filename,
1417              output_filename,&fail,exception);
1418          if ((type & ImportExportValidate) != 0)
1419            tests+=ValidateImportExportPixels(image_info,reference_filename,
1420              output_filename,&fail,exception);
1421          if ((type & MontageValidate) != 0)
1422            tests+=ValidateMontageCommand(image_info,reference_filename,
1423              output_filename,&fail,exception);
1424          if ((type & StreamValidate) != 0)
1425            tests+=ValidateStreamCommand(image_info,reference_filename,
1426              output_filename,&fail,exception);
1427          (void) fprintf(stdout,"validation suite: %lu tests; %lu passed; "
1428            "%lu failed.\n",tests,tests-fail,fail);
1429        }
1430      (void) RelinquishUniqueFileResource(output_filename);
1431      (void) RelinquishUniqueFileResource(reference_filename);
1432    }
1433  if (exception->severity != UndefinedException)
1434    CatchException(exception);
1435  if (iterations > 1)
1436    {
1437      elapsed_time=GetElapsedTime(timer);
1438      user_time=GetUserTime(timer);
1439      (void) fprintf(stderr,"Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",
1440        iterations,1.0*iterations/elapsed_time,user_time,(long)
1441        (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1442        (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1443      timer=DestroyTimerInfo(timer);
1444    }
1445  DestroyValidate();
1446  MagickCoreTerminus();
1447  return(fail == 0 ? 0 : 1);
1448}
Note: See TracBrowser for help on using the browser.