2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 %
14 % ImageMagick Validation Suite %
21 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
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. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 #include "magick/string-private.h"
49 #include "wand/MagickWand.h"
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 % V a l i d a t e C o m p a r e C o m m a n d %
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 % ValidateCompareCommand() validates the ImageMagick compare command line
64 % program and returns the number of validation tests that passed and failed.
66 % The format of the ValidateCompareCommand method is:
68 % unsigned long ValidateCompareCommand(ImageInfo *image_info,
69 % const char *reference_filename,const char *output_filename,
70 % unsigned long *fail,ExceptionInfo *exception)
72 % A description of each parameter follows:
74 % o image_info: the image info.
76 % o reference_filename: the reference image filename.
78 % o output_filename: the output image filename.
80 % o fail: return the number of validation tests that pass.
82 % o exception: return any errors or warnings in this structure.
85 static unsigned long ValidateCompareCommand(ImageInfo *image_info,
86 const char *reference_filename,const char *output_filename,
87 unsigned long *fail,ExceptionInfo *exception)
91 command[MaxTextExtent];
107 (void) fprintf(stdout,"validate compare command line program:\n");
108 for (i=0; compare_options[i] != (char *) NULL; i++)
110 CatchException(exception);
111 (void) fprintf(stdout," test %lu: %s",test++,compare_options[i]);
112 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
113 compare_options[i],reference_filename,reference_filename,output_filename);
114 arguments=StringToArgv(command,&number_arguments);
115 if (arguments == (char **) NULL)
117 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
121 status=CompareImageCommand(image_info,number_arguments,arguments,
122 (char **) NULL,exception);
123 for (j=0; j < number_arguments; j++)
124 arguments[j]=DestroyString(arguments[j]);
125 arguments=(char **) RelinquishMagickMemory(arguments);
126 if (status != MagickFalse)
128 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
132 (void) fprintf(stdout,"... pass.\n");
134 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
135 test,test-(*fail),*fail);
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 % V a l i d a t e C o m p o s i t e C o m m a n d %
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 % ValidateCompositeCommand() validates the ImageMagick composite command line
151 % program and returns the number of validation tests that passed and failed.
153 % The format of the ValidateCompositeCommand method is:
155 % unsigned long ValidateCompositeCommand(ImageInfo *image_info,
156 % const char *reference_filename,const char *output_filename,
157 % unsigned long *fail,ExceptionInfo *exception)
159 % A description of each parameter follows:
161 % o image_info: the image info.
163 % o reference_filename: the reference image filename.
165 % o output_filename: the output image filename.
167 % o fail: return the number of validation tests that pass.
169 % o exception: return any errors or warnings in this structure.
172 static unsigned long ValidateCompositeCommand(ImageInfo *image_info,
173 const char *reference_filename,const char *output_filename,
174 unsigned long *fail,ExceptionInfo *exception)
178 command[MaxTextExtent];
194 (void) fprintf(stdout,"validate composite command line program:\n");
195 for (i=0; composite_options[i] != (char *) NULL; i++)
197 CatchException(exception);
198 (void) fprintf(stdout," test %lu: %s",test++,composite_options[i]);
199 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
200 reference_filename,composite_options[i],reference_filename,
202 arguments=StringToArgv(command,&number_arguments);
203 if (arguments == (char **) NULL)
205 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
209 status=CompositeImageCommand(image_info,number_arguments,arguments,
210 (char **) NULL,exception);
211 for (j=0; j < number_arguments; j++)
212 arguments[j]=DestroyString(arguments[j]);
213 arguments=(char **) RelinquishMagickMemory(arguments);
214 if (status != MagickFalse)
216 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
220 (void) fprintf(stdout,"... pass.\n");
222 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
223 test,test-(*fail),*fail);
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % V a l i d a t e C o n v e r t C o m m a n d %
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % ValidateConvertCommand() validates the ImageMagick convert command line
239 % program and returns the number of validation tests that passed and failed.
241 % The format of the ValidateConvertCommand method is:
243 % unsigned long ValidateConvertCommand(ImageInfo *image_info,
244 % const char *reference_filename,const char *output_filename,
245 % unsigned long *fail,ExceptionInfo *exception)
247 % A description of each parameter follows:
249 % o image_info: the image info.
251 % o reference_filename: the reference image filename.
253 % o output_filename: the output image filename.
255 % o fail: return the number of validation tests that pass.
257 % o exception: return any errors or warnings in this structure.
260 static unsigned long ValidateConvertCommand(ImageInfo *image_info,
261 const char *reference_filename,const char *output_filename,
262 unsigned long *fail,ExceptionInfo *exception)
266 command[MaxTextExtent];
282 (void) fprintf(stdout,"validate convert command line program:\n");
283 for (i=0; convert_options[i] != (char *) NULL; i++)
285 CatchException(exception);
286 (void) fprintf(stdout," test %lu: %s",test++,convert_options[i]);
287 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
288 reference_filename,convert_options[i],reference_filename,output_filename);
289 arguments=StringToArgv(command,&number_arguments);
290 if (arguments == (char **) NULL)
292 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
296 status=ConvertImageCommand(image_info,number_arguments,arguments,
297 (char **) NULL,exception);
298 for (j=0; j < number_arguments; j++)
299 arguments[j]=DestroyString(arguments[j]);
300 arguments=(char **) RelinquishMagickMemory(arguments);
301 if (status != MagickFalse)
303 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
307 (void) fprintf(stdout,"... pass.\n");
309 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
310 test,test-(*fail),*fail);
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 % V a l i d a t e I d e n t i f y C o m m a n d %
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 % ValidateIdentifyCommand() validates the ImageMagick identify command line
326 % program and returns the number of validation tests that passed and failed.
328 % The format of the ValidateIdentifyCommand method is:
330 % unsigned long ValidateIdentifyCommand(ImageInfo *image_info,
331 % const char *reference_filename,const char *output_filename,
332 % unsigned long *fail,ExceptionInfo *exception)
334 % A description of each parameter follows:
336 % o image_info: the image info.
338 % o reference_filename: the reference image filename.
340 % o output_filename: the output image filename.
342 % o fail: return the number of validation tests that pass.
344 % o exception: return any errors or warnings in this structure.
347 static unsigned long ValidateIdentifyCommand(ImageInfo *image_info,
348 const char *reference_filename,const char *output_filename,
349 unsigned long *fail,ExceptionInfo *exception)
353 command[MaxTextExtent];
368 (void) output_filename;
370 (void) fprintf(stdout,"validate identify command line program:\n");
371 for (i=0; identify_options[i] != (char *) NULL; i++)
373 CatchException(exception);
374 (void) fprintf(stdout," test %lu: %s",test++,identify_options[i]);
375 (void) FormatMagickString(command,MaxTextExtent,"%s %s",
376 identify_options[i],reference_filename);
377 arguments=StringToArgv(command,&number_arguments);
378 if (arguments == (char **) NULL)
380 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
384 status=IdentifyImageCommand(image_info,number_arguments,arguments,
385 (char **) NULL,exception);
386 for (j=0; j < number_arguments; j++)
387 arguments[j]=DestroyString(arguments[j]);
388 arguments=(char **) RelinquishMagickMemory(arguments);
389 if (status != MagickFalse)
391 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
395 (void) fprintf(stdout,"... pass.\n");
397 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
398 test,test-(*fail),*fail);
403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 % 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 %
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
414 % memory and returns the number of validation tests that passed and failed.
416 % The format of the ValidateImageFormatsInMemory method is:
418 % unsigned long ValidateImageFormatsInMemory(ImageInfo *image_info,
419 % const char *reference_filename,const char *output_filename,
420 % unsigned long *fail,ExceptionInfo *exception)
422 % A description of each parameter follows:
424 % o image_info: the image info.
426 % o reference_filename: the reference image filename.
428 % o output_filename: the output image filename.
430 % o fail: return the number of validation tests that pass.
432 % o exception: return any errors or warnings in this structure.
435 static unsigned long ValidateImageFormatsInMemory(ImageInfo *image_info,
436 const char *reference_filename,const char *output_filename,
437 unsigned long *fail,ExceptionInfo *exception)
471 (void) fprintf(stdout,"validate image formats in memory:\n");
472 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
474 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
475 if ((magick_info == (const MagickInfo *) NULL) ||
476 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
477 (magick_info->encoder == (EncodeImageHandler *) NULL))
479 for (j=0; reference_types[j].type != UndefinedType; j++)
482 Generate reference image.
484 CatchException(exception);
485 (void) fprintf(stdout," test %lu: %s/%s/%s/%lu-bits",test++,
486 reference_formats[i].magick,MagickOptionToMnemonic(
487 MagickCompressOptions,reference_formats[i].compression),
488 MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
489 reference_types[j].depth);
490 (void) CopyMagickString(image_info->filename,reference_filename,
492 reference_image=ReadImage(image_info,exception);
493 if (reference_image == (Image *) NULL)
495 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
500 Write reference image.
502 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",
503 reference_image->columns,reference_image->rows);
504 (void) CloneString(&image_info->size,size);
505 image_info->depth=reference_types[j].depth;
506 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
507 reference_formats[i].magick,output_filename);
508 status=SetImageType(reference_image,reference_types[j].type);
509 InheritException(exception,&reference_image->exception);
510 if (status == MagickFalse)
512 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
514 reference_image=DestroyImage(reference_image);
517 status=SetImageDepth(reference_image,reference_types[j].depth);
518 InheritException(exception,&reference_image->exception);
519 if (status == MagickFalse)
521 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
523 reference_image=DestroyImage(reference_image);
526 reference_image->compression=reference_formats[i].compression;
527 status=WriteImage(image_info,reference_image);
528 InheritException(exception,&reference_image->exception);
529 reference_image=DestroyImage(reference_image);
530 if (status == MagickFalse)
532 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
537 Read reference image.
539 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
540 reference_formats[i].magick,output_filename);
541 reference_image=ReadImage(image_info,exception);
542 if (reference_image == (Image *) NULL)
544 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
549 Write reference image.
551 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
552 reference_formats[i].magick,output_filename);
553 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
555 reference_image->depth=reference_types[j].depth;
556 reference_image->compression=reference_formats[i].compression;
558 blob=ImageToBlob(image_info,reference_image,&length,exception);
559 if (blob == (unsigned char *) NULL)
561 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
563 reference_image=DestroyImage(reference_image);
567 Read reconstruct image.
569 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
570 reference_formats[i].magick,output_filename);
571 reconstruct_image=BlobToImage(image_info,blob,length,exception);
572 blob=(unsigned char *) RelinquishMagickMemory(blob);
573 if (reconstruct_image == (Image *) NULL)
575 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
577 reference_image=DestroyImage(reference_image);
581 Compare reference to reconstruct image.
584 if (reference_formats[i].fuzz != 0.0)
585 fuzz=reference_formats[i].fuzz;
586 #if defined(MAGICKCORE_HDRI_SUPPORT)
589 if (reference_image->colorspace != RGBColorspace)
592 difference_image=CompareImageChannels(reference_image,reconstruct_image,
593 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
594 reconstruct_image=DestroyImage(reconstruct_image);
595 reference_image=DestroyImage(reference_image);
596 if (difference_image == (Image *) NULL)
598 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
602 difference_image=DestroyImage(difference_image);
603 if ((distortion/QuantumRange) > fuzz)
605 (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
610 (void) fprintf(stdout,"... pass.\n");
613 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
614 test,test-(*fail),*fail);
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % 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 %
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
630 % and returns the number of validation tests that passed and failed.
632 % The format of the ValidateImageFormatsOnDisk method is:
634 % unsigned long ValidateImageFormatsOnDisk(ImageInfo *image_info,
635 % const char *reference_filename,const char *output_filename,
636 % unsigned long *fail,ExceptionInfo *exception)
638 % A description of each parameter follows:
640 % o image_info: the image info.
642 % o reference_filename: the reference image filename.
644 % o output_filename: the output image filename.
646 % o fail: return the number of validation tests that pass.
648 % o exception: return any errors or warnings in this structure.
651 static unsigned long ValidateImageFormatsOnDisk(ImageInfo *image_info,
652 const char *reference_filename,const char *output_filename,
653 unsigned long *fail,ExceptionInfo *exception)
681 (void) fprintf(stdout,"validate image formats on disk:\n");
682 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
684 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
685 if ((magick_info == (const MagickInfo *) NULL) ||
686 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
687 (magick_info->encoder == (EncodeImageHandler *) NULL))
689 for (j=0; reference_types[j].type != UndefinedType; j++)
692 Generate reference image.
694 CatchException(exception);
695 (void) fprintf(stdout," test %lu: %s/%s/%s/%lu-bits",test++,
696 reference_formats[i].magick,MagickOptionToMnemonic(
697 MagickCompressOptions,reference_formats[i].compression),
698 MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
699 reference_types[j].depth);
700 (void) CopyMagickString(image_info->filename,reference_filename,
702 reference_image=ReadImage(image_info,exception);
703 if (reference_image == (Image *) NULL)
705 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
710 Write reference image.
712 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",
713 reference_image->columns,reference_image->rows);
714 (void) CloneString(&image_info->size,size);
715 image_info->depth=reference_types[j].depth;
716 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
717 reference_formats[i].magick,output_filename);
718 status=SetImageType(reference_image,reference_types[j].type);
719 InheritException(exception,&reference_image->exception);
720 if (status == MagickFalse)
722 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
724 reference_image=DestroyImage(reference_image);
727 status=SetImageDepth(reference_image,reference_types[j].depth);
728 InheritException(exception,&reference_image->exception);
729 if (status == MagickFalse)
731 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
733 reference_image=DestroyImage(reference_image);
736 reference_image->compression=reference_formats[i].compression;
737 status=WriteImage(image_info,reference_image);
738 InheritException(exception,&reference_image->exception);
739 reference_image=DestroyImage(reference_image);
740 if (status == MagickFalse)
742 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
747 Read reference image.
749 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
750 reference_formats[i].magick,output_filename);
751 reference_image=ReadImage(image_info,exception);
752 if (reference_image == (Image *) NULL)
754 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
759 Write reference image.
761 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
762 reference_formats[i].magick,output_filename);
763 reference_image->depth=reference_types[j].depth;
764 reference_image->compression=reference_formats[i].compression;
765 status=WriteImage(image_info,reference_image);
766 InheritException(exception,&reference_image->exception);
767 if (status == MagickFalse)
769 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
771 reference_image=DestroyImage(reference_image);
775 Read reconstruct image.
777 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
778 reference_formats[i].magick,output_filename);
779 reconstruct_image=ReadImage(image_info,exception);
780 if (reconstruct_image == (Image *) NULL)
782 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
784 reference_image=DestroyImage(reference_image);
788 Compare reference to reconstruct image.
791 if (reference_formats[i].fuzz != 0.0)
792 fuzz=reference_formats[i].fuzz;
793 #if defined(MAGICKCORE_HDRI_SUPPORT)
796 if (reference_image->colorspace != RGBColorspace)
799 difference_image=CompareImageChannels(reference_image,reconstruct_image,
800 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
801 reconstruct_image=DestroyImage(reconstruct_image);
802 reference_image=DestroyImage(reference_image);
803 if (difference_image == (Image *) NULL)
805 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
809 difference_image=DestroyImage(difference_image);
810 if ((distortion/QuantumRange) > fuzz)
812 (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
817 (void) fprintf(stdout,"... pass.\n");
820 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
821 test,test-(*fail),*fail);
826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830 % 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 %
834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
836 % ValidateImportExportPixels() validates the pixel import and export methods.
837 % It returns the number of validation tests that passed and failed.
839 % The format of the ValidateImportExportPixels method is:
841 % unsigned long ValidateImportExportPixels(ImageInfo *image_info,
842 % const char *reference_filename,const char *output_filename,
843 % unsigned long *fail,ExceptionInfo *exception)
845 % A description of each parameter follows:
847 % o image_info: the image info.
849 % o reference_filename: the reference image filename.
851 % o output_filename: the output image filename.
853 % o fail: return the number of validation tests that pass.
855 % o exception: return any errors or warnings in this structure.
858 static unsigned long ValidateImportExportPixels(ImageInfo *image_info,
859 const char *reference_filename,const char *output_filename,
860 unsigned long *fail,ExceptionInfo *exception)
886 (void) output_filename;
888 (void) fprintf(stdout,"validate the import and export of image pixels:\n");
889 for (i=0; reference_map[i] != (char *) NULL; i++)
891 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
894 Generate reference image.
896 CatchException(exception);
897 (void) fprintf(stdout," test %lu: %s/%s",test++,
898 reference_map[i],MagickOptionToMnemonic(MagickStorageOptions,
899 reference_storage[j].type));
900 (void) CopyMagickString(image_info->filename,reference_filename,
902 reference_image=ReadImage(image_info,exception);
903 if (reference_image == (Image *) NULL)
905 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
909 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
910 (void) TransformImageColorspace(reference_image,CMYKColorspace);
911 length=strlen(reference_map[i])*reference_image->columns*
912 reference_image->rows*reference_storage[j].quantum;
913 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
914 if (pixels == (unsigned char *) NULL)
916 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
918 reference_image=DestroyImage(reference_image);
921 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
922 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
923 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
925 if (status == MagickFalse)
927 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
929 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
930 reference_image=DestroyImage(reference_image);
933 (void) SetImageBackgroundColor(reference_image);
934 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
935 reference_image->rows,reference_map[i],reference_storage[j].type,
937 InheritException(exception,&reference_image->exception);
938 if (status == MagickFalse)
940 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
942 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
943 reference_image=DestroyImage(reference_image);
947 Read reconstruct image.
949 reconstruct_image=AcquireImage(image_info);
950 (void) SetImageExtent(reconstruct_image,reference_image->columns,
951 reference_image->rows);
952 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
953 (void) SetImageBackgroundColor(reconstruct_image);
954 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
955 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
957 InheritException(exception,&reconstruct_image->exception);
958 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
959 if (status == MagickFalse)
961 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
963 reference_image=DestroyImage(reference_image);
967 Compare reference to reconstruct image.
969 difference_image=CompareImageChannels(reference_image,reconstruct_image,
970 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
971 reconstruct_image=DestroyImage(reconstruct_image);
972 reference_image=DestroyImage(reference_image);
973 if (difference_image == (Image *) NULL)
975 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
979 difference_image=DestroyImage(difference_image);
980 if ((distortion/QuantumRange) > 0.0)
982 (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
987 (void) fprintf(stdout,"... pass.\n");
990 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
991 test,test-(*fail),*fail);
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 % V a l i d a t e M o n t a g e C o m m a n d %
1004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 % ValidateMontageCommand() validates the ImageMagick montage command line
1007 % program and returns the number of validation tests that passed and failed.
1009 % The format of the ValidateMontageCommand method is:
1011 % unsigned long ValidateMontageCommand(ImageInfo *image_info,
1012 % const char *reference_filename,const char *output_filename,
1013 % unsigned long *fail,ExceptionInfo *exception)
1015 % A description of each parameter follows:
1017 % o image_info: the image info.
1019 % o reference_filename: the reference image filename.
1021 % o output_filename: the output image filename.
1023 % o fail: return the number of validation tests that pass.
1025 % o exception: return any errors or warnings in this structure.
1028 static unsigned long ValidateMontageCommand(ImageInfo *image_info,
1029 const char *reference_filename,const char *output_filename,
1030 unsigned long *fail,ExceptionInfo *exception)
1034 command[MaxTextExtent];
1050 (void) fprintf(stdout,"validate montage command line program:\n");
1051 for (i=0; montage_options[i] != (char *) NULL; i++)
1053 CatchException(exception);
1054 (void) fprintf(stdout," test %lu: %s",test++,montage_options[i]);
1055 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
1056 reference_filename,montage_options[i],reference_filename,
1058 arguments=StringToArgv(command,&number_arguments);
1059 if (arguments == (char **) NULL)
1061 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1065 status=MontageImageCommand(image_info,number_arguments,arguments,
1066 (char **) NULL,exception);
1067 for (j=0; j < number_arguments; j++)
1068 arguments[j]=DestroyString(arguments[j]);
1069 arguments=(char **) RelinquishMagickMemory(arguments);
1070 if (status != MagickFalse)
1072 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1076 (void) fprintf(stdout,"... pass.\n");
1078 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
1079 test,test-(*fail),*fail);
1084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 % V a l i d a t e S t r e a m C o m m a n d %
1092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1094 % ValidateStreamCommand() validates the ImageMagick stream command line
1095 % program and returns the number of validation tests that passed and failed.
1097 % The format of the ValidateStreamCommand method is:
1099 % unsigned long ValidateStreamCommand(ImageInfo *image_info,
1100 % const char *reference_filename,const char *output_filename,
1101 % unsigned long *fail,ExceptionInfo *exception)
1103 % A description of each parameter follows:
1105 % o image_info: the image info.
1107 % o reference_filename: the reference image filename.
1109 % o output_filename: the output image filename.
1111 % o fail: return the number of validation tests that pass.
1113 % o exception: return any errors or warnings in this structure.
1116 static unsigned long ValidateStreamCommand(ImageInfo *image_info,
1117 const char *reference_filename,const char *output_filename,
1118 unsigned long *fail,ExceptionInfo *exception)
1122 command[MaxTextExtent];
1138 (void) fprintf(stdout,"validate stream command line program:\n");
1139 for (i=0; stream_options[i] != (char *) NULL; i++)
1141 CatchException(exception);
1142 (void) fprintf(stdout," test %lu: %s",test++,stream_options[i]);
1143 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s",
1144 stream_options[i],reference_filename,output_filename);
1145 arguments=StringToArgv(command,&number_arguments);
1146 if (arguments == (char **) NULL)
1148 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1152 status=StreamImageCommand(image_info,number_arguments,arguments,
1153 (char **) NULL,exception);
1154 for (j=0; j < number_arguments; j++)
1155 arguments[j]=DestroyString(arguments[j]);
1156 arguments=(char **) RelinquishMagickMemory(arguments);
1157 if (status != MagickFalse)
1159 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1163 (void) fprintf(stdout,"... pass.\n");
1165 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
1166 test,test-(*fail),*fail);
1171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1184 static MagickBooleanType ValidateUsage(void)
1192 "-debug events display copious debugging information",
1193 "-help print program options",
1194 "-log format format of debugging information",
1195 "-validate type validation type",
1196 "-version print version information",
1201 "-regard-warnings pay attention to warning messages",
1202 "-verbose print detailed information about the image",
1206 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
1207 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1208 (void) printf("Features: %s\n",GetMagickFeatures());
1209 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1210 (void) printf("\nValidate Settings:\n");
1211 for (p=settings; *p != (char *) NULL; p++)
1212 (void) printf(" %s\n",*p);
1213 (void) printf("\nMiscellaneous Options:\n");
1214 for (p=miscellaneous; *p != (char *) NULL; p++)
1215 (void) printf(" %s\n",*p);
1219 int main(int argc,char **argv)
1221 #define DestroyValidate() \
1223 image_info=DestroyImageInfo(image_info); \
1224 exception=DestroyExceptionInfo(exception); \
1226 #define ThrowValidateException(asperity,tag,option) \
1228 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1230 CatchException(exception); \
1231 DestroyValidate(); \
1232 return(MagickFalse); \
1236 output_filename[MaxTextExtent],
1237 reference_filename[MaxTextExtent],
1272 Validate the ImageMagick image processing suite.
1274 MagickCoreGenesis(*argv,MagickFalse);
1278 regard_warnings=MagickFalse;
1279 exception=AcquireExceptionInfo();
1280 image_info=AcquireImageInfo();
1281 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1282 for (i=1; i < (long) argc; i++)
1285 if (IsMagickOption(option) == MagickFalse)
1287 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1290 switch (*(option+1))
1294 if (LocaleCompare("bench",option+1) == 0)
1296 iterations=StringToUnsignedLong(argv[++i]);
1299 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1303 if (LocaleCompare("debug",option+1) == 0)
1305 (void) SetLogEventMask(argv[++i]);
1308 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1312 if (LocaleCompare("help",option+1) == 0)
1314 (void) ValidateUsage();
1317 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1321 if (LocaleCompare("log",option+1) == 0)
1324 (void) SetLogFormat(argv[i+1]);
1327 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1331 if (LocaleCompare("regard-warnings",option+1) == 0)
1333 regard_warnings=MagickTrue;
1336 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1340 if (LocaleCompare("validate",option+1) == 0)
1348 if (i == (long) argc)
1349 ThrowValidateException(OptionError,"MissingArgument",option);
1350 validate=ParseMagickOption(MagickValidateOptions,MagickFalse,
1353 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1355 type=(ValidateType) validate;
1358 if ((LocaleCompare("version",option+1) == 0) ||
1359 (LocaleCompare("-version",option+1) == 0))
1361 (void) fprintf(stdout,"Version: %s\n",
1362 GetMagickVersion((unsigned long *) NULL));
1363 (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright());
1364 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
1367 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1370 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1373 timer=(TimerInfo *) NULL;
1375 timer=AcquireTimerInfo();
1376 reference_image=ReadImage(image_info,exception);
1379 if (reference_image == (Image *) NULL)
1383 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1384 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1386 (void) AcquireUniqueFilename(reference_filename);
1387 (void) AcquireUniqueFilename(output_filename);
1388 (void) CopyMagickString(reference_image->filename,reference_filename,
1390 status=WriteImage(image_info,reference_image);
1391 InheritException(exception,&reference_image->exception);
1392 reference_image=DestroyImage(reference_image);
1393 if (status == MagickFalse)
1397 (void) fprintf(stdout,"Version: %s\n",
1398 GetMagickVersion((unsigned long *) NULL));
1399 (void) fprintf(stdout,"Copyright: %s\n\n",
1400 GetMagickCopyright());
1401 (void) fprintf(stdout,"ImageMagick Validation Suite (%s)\n\n",
1402 MagickOptionToMnemonic(MagickValidateOptions,(long) type));
1403 if ((type & CompareValidate) != 0)
1404 tests+=ValidateCompareCommand(image_info,reference_filename,
1405 output_filename,&fail,exception);
1406 if ((type & CompositeValidate) != 0)
1407 tests+=ValidateCompositeCommand(image_info,reference_filename,
1408 output_filename,&fail,exception);
1409 if ((type & ConvertValidate) != 0)
1410 tests+=ValidateConvertCommand(image_info,reference_filename,
1411 output_filename,&fail,exception);
1412 if ((type & FormatsInMemoryValidate) != 0)
1413 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1414 output_filename,&fail,exception);
1415 if ((type & FormatsOnDiskValidate) != 0)
1416 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1417 output_filename,&fail,exception);
1418 if ((type & IdentifyValidate) != 0)
1419 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1420 output_filename,&fail,exception);
1421 if ((type & ImportExportValidate) != 0)
1422 tests+=ValidateImportExportPixels(image_info,reference_filename,
1423 output_filename,&fail,exception);
1424 if ((type & MontageValidate) != 0)
1425 tests+=ValidateMontageCommand(image_info,reference_filename,
1426 output_filename,&fail,exception);
1427 if ((type & StreamValidate) != 0)
1428 tests+=ValidateStreamCommand(image_info,reference_filename,
1429 output_filename,&fail,exception);
1430 (void) fprintf(stdout,"validation suite: %lu tests; %lu passed; "
1431 "%lu failed.\n",tests,tests-fail,fail);
1433 (void) RelinquishUniqueFileResource(output_filename);
1434 (void) RelinquishUniqueFileResource(reference_filename);
1436 if (exception->severity != UndefinedException)
1437 CatchException(exception);
1440 elapsed_time=GetElapsedTime(timer);
1441 user_time=GetUserTime(timer);
1442 (void) fprintf(stderr,"Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",
1443 iterations,1.0*iterations/elapsed_time,user_time,(long)
1444 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1445 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1446 timer=DestroyTimerInfo(timer);
1449 MagickCoreTerminus();
1450 return(fail == 0 ? 0 : 1);