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-2011 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 "MagickWand/MagickWand.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/string-private.h"
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 % V a l i d a t e C o m p a r e C o m m a n d %
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % ValidateCompareCommand() validates the ImageMagick compare command line
65 % program and returns the number of validation tests that passed and failed.
67 % The format of the ValidateCompareCommand method is:
69 % size_t ValidateCompareCommand(ImageInfo *image_info,
70 % const char *reference_filename,const char *output_filename,
71 % size_t *fail,ExceptionInfo *exception)
73 % A description of each parameter follows:
75 % o image_info: the image info.
77 % o reference_filename: the reference image filename.
79 % o output_filename: the output image filename.
81 % o fail: return the number of validation tests that pass.
83 % o exception: return any errors or warnings in this structure.
86 static size_t ValidateCompareCommand(ImageInfo *image_info,
87 const char *reference_filename,const char *output_filename,
88 size_t *fail,ExceptionInfo *exception)
92 command[MaxTextExtent];
108 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
109 for (i=0; compare_options[i] != (char *) NULL; i++)
111 CatchException(exception);
112 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
114 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
115 compare_options[i],reference_filename,reference_filename,output_filename);
116 arguments=StringToArgv(command,&number_arguments);
117 if (arguments == (char **) NULL)
119 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
124 status=CompareImagesCommand(image_info,number_arguments,arguments,
125 (char **) NULL,exception);
126 for (j=0; j < number_arguments; j++)
127 arguments[j]=DestroyString(arguments[j]);
128 arguments=(char **) RelinquishMagickMemory(arguments);
129 if (status != MagickFalse)
131 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
136 (void) FormatLocaleFile(stdout,"... pass.\n");
138 (void) FormatLocaleFile(stdout,
139 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
140 (double) (test-(*fail)),(double) *fail);
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % V a l i d a t e C o m p o s i t e C o m m a n d %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % ValidateCompositeCommand() validates the ImageMagick composite command line
156 % program and returns the number of validation tests that passed and failed.
158 % The format of the ValidateCompositeCommand method is:
160 % size_t ValidateCompositeCommand(ImageInfo *image_info,
161 % const char *reference_filename,const char *output_filename,
162 % size_t *fail,ExceptionInfo *exception)
164 % A description of each parameter follows:
166 % o image_info: the image info.
168 % o reference_filename: the reference image filename.
170 % o output_filename: the output image filename.
172 % o fail: return the number of validation tests that pass.
174 % o exception: return any errors or warnings in this structure.
177 static size_t ValidateCompositeCommand(ImageInfo *image_info,
178 const char *reference_filename,const char *output_filename,
179 size_t *fail,ExceptionInfo *exception)
183 command[MaxTextExtent];
199 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
200 for (i=0; composite_options[i] != (char *) NULL; i++)
202 CatchException(exception);
203 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
204 composite_options[i]);
205 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
206 reference_filename,composite_options[i],reference_filename,
208 arguments=StringToArgv(command,&number_arguments);
209 if (arguments == (char **) NULL)
211 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
216 status=CompositeImageCommand(image_info,number_arguments,arguments,
217 (char **) NULL,exception);
218 for (j=0; j < number_arguments; j++)
219 arguments[j]=DestroyString(arguments[j]);
220 arguments=(char **) RelinquishMagickMemory(arguments);
221 if (status != MagickFalse)
223 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
228 (void) FormatLocaleFile(stdout,"... pass.\n");
230 (void) FormatLocaleFile(stdout,
231 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
232 (double) (test-(*fail)),(double) *fail);
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 % V a l i d a t e C o n v e r t C o m m a n d %
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % ValidateConvertCommand() validates the ImageMagick convert command line
248 % program and returns the number of validation tests that passed and failed.
250 % The format of the ValidateConvertCommand method is:
252 % size_t ValidateConvertCommand(ImageInfo *image_info,
253 % const char *reference_filename,const char *output_filename,
254 % size_t *fail,ExceptionInfo *exception)
256 % A description of each parameter follows:
258 % o image_info: the image info.
260 % o reference_filename: the reference image filename.
262 % o output_filename: the output image filename.
264 % o fail: return the number of validation tests that pass.
266 % o exception: return any errors or warnings in this structure.
269 static size_t ValidateConvertCommand(ImageInfo *image_info,
270 const char *reference_filename,const char *output_filename,
271 size_t *fail,ExceptionInfo *exception)
275 command[MaxTextExtent];
291 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
292 for (i=0; convert_options[i] != (char *) NULL; i++)
294 CatchException(exception);
295 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
297 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
298 reference_filename,convert_options[i],reference_filename,output_filename);
299 arguments=StringToArgv(command,&number_arguments);
300 if (arguments == (char **) NULL)
302 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
307 status=ConvertImageCommand(image_info,number_arguments,arguments,
308 (char **) NULL,exception);
309 for (j=0; j < number_arguments; j++)
310 arguments[j]=DestroyString(arguments[j]);
311 arguments=(char **) RelinquishMagickMemory(arguments);
312 if (status != MagickFalse)
314 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
319 (void) FormatLocaleFile(stdout,"... pass.\n");
321 (void) FormatLocaleFile(stdout,
322 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
323 (double) (test-(*fail)),(double) *fail);
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % V a l i d a t e I d e n t i f y C o m m a n d %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % ValidateIdentifyCommand() validates the ImageMagick identify command line
339 % program and returns the number of validation tests that passed and failed.
341 % The format of the ValidateIdentifyCommand method is:
343 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
344 % const char *reference_filename,const char *output_filename,
345 % size_t *fail,ExceptionInfo *exception)
347 % A description of each parameter follows:
349 % o image_info: the image info.
351 % o reference_filename: the reference image filename.
353 % o output_filename: the output image filename.
355 % o fail: return the number of validation tests that pass.
357 % o exception: return any errors or warnings in this structure.
360 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
361 const char *reference_filename,const char *output_filename,
362 size_t *fail,ExceptionInfo *exception)
366 command[MaxTextExtent];
381 (void) output_filename;
383 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
384 for (i=0; identify_options[i] != (char *) NULL; i++)
386 CatchException(exception);
387 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
388 identify_options[i]);
389 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
390 identify_options[i],reference_filename);
391 arguments=StringToArgv(command,&number_arguments);
392 if (arguments == (char **) NULL)
394 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
399 status=IdentifyImageCommand(image_info,number_arguments,arguments,
400 (char **) NULL,exception);
401 for (j=0; j < number_arguments; j++)
402 arguments[j]=DestroyString(arguments[j]);
403 arguments=(char **) RelinquishMagickMemory(arguments);
404 if (status != MagickFalse)
406 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
411 (void) FormatLocaleFile(stdout,"... pass.\n");
413 (void) FormatLocaleFile(stdout,
414 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
415 (double) (test-(*fail)),(double) *fail);
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 % V a l i d a t e I m a g e F o r m a t s I n M e m o r y %
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
431 % memory and returns the number of validation tests that passed and failed.
433 % The format of the ValidateImageFormatsInMemory method is:
435 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
436 % const char *reference_filename,const char *output_filename,
437 % size_t *fail,ExceptionInfo *exception)
439 % A description of each parameter follows:
441 % o image_info: the image info.
443 % o reference_filename: the reference image filename.
445 % o output_filename: the output image filename.
447 % o fail: return the number of validation tests that pass.
449 % o exception: return any errors or warnings in this structure.
452 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
453 const char *reference_filename,const char *output_filename,
454 size_t *fail,ExceptionInfo *exception)
488 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
489 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
491 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
492 if ((magick_info == (const MagickInfo *) NULL) ||
493 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
494 (magick_info->encoder == (EncodeImageHandler *) NULL))
496 for (j=0; reference_types[j].type != UndefinedType; j++)
499 Generate reference image.
501 CatchException(exception);
502 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
503 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
504 MagickCompressOptions,reference_formats[i].compression),
505 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
506 (double) reference_types[j].depth);
507 (void) CopyMagickString(image_info->filename,reference_filename,
509 reference_image=ReadImage(image_info,exception);
510 if (reference_image == (Image *) NULL)
512 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
518 Write reference image.
520 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
521 (double) reference_image->columns,(double) reference_image->rows);
522 (void) CloneString(&image_info->size,size);
523 image_info->depth=reference_types[j].depth;
524 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
525 reference_formats[i].magick,output_filename);
526 status=SetImageType(reference_image,reference_types[j].type,exception);
527 if (status == MagickFalse)
529 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
532 reference_image=DestroyImage(reference_image);
535 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
536 if (status == MagickFalse)
538 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
541 reference_image=DestroyImage(reference_image);
544 reference_image->compression=reference_formats[i].compression;
545 status=WriteImage(image_info,reference_image,exception);
546 reference_image=DestroyImage(reference_image);
547 if (status == MagickFalse)
549 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
555 Read reference image.
557 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
558 reference_formats[i].magick,output_filename);
559 reference_image=ReadImage(image_info,exception);
560 if (reference_image == (Image *) NULL)
562 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
568 Write reference image.
570 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
571 reference_formats[i].magick,output_filename);
572 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
574 reference_image->depth=reference_types[j].depth;
575 reference_image->compression=reference_formats[i].compression;
577 blob=ImageToBlob(image_info,reference_image,&length,exception);
578 if (blob == (unsigned char *) NULL)
580 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
583 reference_image=DestroyImage(reference_image);
587 Read reconstruct image.
589 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
590 reference_formats[i].magick,output_filename);
591 reconstruct_image=BlobToImage(image_info,blob,length,exception);
592 blob=(unsigned char *) RelinquishMagickMemory(blob);
593 if (reconstruct_image == (Image *) NULL)
595 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
598 reference_image=DestroyImage(reference_image);
602 Compare reference to reconstruct image.
605 if (reference_formats[i].fuzz != 0.0)
606 fuzz=reference_formats[i].fuzz;
607 #if defined(MAGICKCORE_HDRI_SUPPORT)
610 if (IsRGBColorspace(reference_image->colorspace) == MagickFalse)
613 difference_image=CompareImages(reference_image,reconstruct_image,
614 MeanSquaredErrorMetric,&distortion,exception);
615 reconstruct_image=DestroyImage(reconstruct_image);
616 reference_image=DestroyImage(reference_image);
617 if (difference_image == (Image *) NULL)
619 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
624 difference_image=DestroyImage(difference_image);
625 if ((distortion/QuantumRange) > fuzz)
627 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
628 distortion/QuantumRange);
632 (void) FormatLocaleFile(stdout,"... pass.\n");
635 (void) FormatLocaleFile(stdout,
636 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
637 (double) (test-(*fail)),(double) *fail);
642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 % 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 %
650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
653 % and returns the number of validation tests that passed and failed.
655 % The format of the ValidateImageFormatsOnDisk method is:
657 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
658 % const char *reference_filename,const char *output_filename,
659 % size_t *fail,ExceptionInfo *exception)
661 % A description of each parameter follows:
663 % o image_info: the image info.
665 % o reference_filename: the reference image filename.
667 % o output_filename: the output image filename.
669 % o fail: return the number of validation tests that pass.
671 % o exception: return any errors or warnings in this structure.
674 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
675 const char *reference_filename,const char *output_filename,
676 size_t *fail,ExceptionInfo *exception)
704 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
705 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
707 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
708 if ((magick_info == (const MagickInfo *) NULL) ||
709 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
710 (magick_info->encoder == (EncodeImageHandler *) NULL))
712 for (j=0; reference_types[j].type != UndefinedType; j++)
715 Generate reference image.
717 CatchException(exception);
718 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
719 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
720 MagickCompressOptions,reference_formats[i].compression),
721 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
722 (double) reference_types[j].depth);
723 (void) CopyMagickString(image_info->filename,reference_filename,
725 reference_image=ReadImage(image_info,exception);
726 if (reference_image == (Image *) NULL)
728 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
734 Write reference image.
736 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
737 (double) reference_image->columns,(double) reference_image->rows);
738 (void) CloneString(&image_info->size,size);
739 image_info->depth=reference_types[j].depth;
740 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
741 reference_formats[i].magick,output_filename);
742 status=SetImageType(reference_image,reference_types[j].type,exception);
743 if (status == MagickFalse)
745 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
748 reference_image=DestroyImage(reference_image);
751 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
752 if (status == MagickFalse)
754 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
757 reference_image=DestroyImage(reference_image);
760 reference_image->compression=reference_formats[i].compression;
761 status=WriteImage(image_info,reference_image,exception);
762 reference_image=DestroyImage(reference_image);
763 if (status == MagickFalse)
765 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
771 Read reference image.
773 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
774 reference_formats[i].magick,output_filename);
775 reference_image=ReadImage(image_info,exception);
776 if (reference_image == (Image *) NULL)
778 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
784 Write reference image.
786 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
787 reference_formats[i].magick,output_filename);
788 reference_image->depth=reference_types[j].depth;
789 reference_image->compression=reference_formats[i].compression;
790 status=WriteImage(image_info,reference_image,exception);
791 if (status == MagickFalse)
793 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
796 reference_image=DestroyImage(reference_image);
800 Read reconstruct image.
802 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
803 reference_formats[i].magick,output_filename);
804 reconstruct_image=ReadImage(image_info,exception);
805 if (reconstruct_image == (Image *) NULL)
807 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
810 reference_image=DestroyImage(reference_image);
814 Compare reference to reconstruct image.
817 if (reference_formats[i].fuzz != 0.0)
818 fuzz=reference_formats[i].fuzz;
819 #if defined(MAGICKCORE_HDRI_SUPPORT)
822 if (IsRGBColorspace(reference_image->colorspace) == MagickFalse)
825 difference_image=CompareImages(reference_image,reconstruct_image,
826 MeanSquaredErrorMetric,&distortion,exception);
827 reconstruct_image=DestroyImage(reconstruct_image);
828 reference_image=DestroyImage(reference_image);
829 if (difference_image == (Image *) NULL)
831 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
836 difference_image=DestroyImage(difference_image);
837 if ((distortion/QuantumRange) > fuzz)
839 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
840 distortion/QuantumRange);
844 (void) FormatLocaleFile(stdout,"... pass.\n");
847 (void) FormatLocaleFile(stdout,
848 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
849 (double) (test-(*fail)),(double) *fail);
854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
858 % 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 %
862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
864 % ValidateImportExportPixels() validates the pixel import and export methods.
865 % It returns the number of validation tests that passed and failed.
867 % The format of the ValidateImportExportPixels method is:
869 % size_t ValidateImportExportPixels(ImageInfo *image_info,
870 % const char *reference_filename,const char *output_filename,
871 % size_t *fail,ExceptionInfo *exception)
873 % A description of each parameter follows:
875 % o image_info: the image info.
877 % o reference_filename: the reference image filename.
879 % o output_filename: the output image filename.
881 % o fail: return the number of validation tests that pass.
883 % o exception: return any errors or warnings in this structure.
886 static size_t ValidateImportExportPixels(ImageInfo *image_info,
887 const char *reference_filename,const char *output_filename,
888 size_t *fail,ExceptionInfo *exception)
914 (void) output_filename;
916 (void) FormatLocaleFile(stdout,
917 "validate the import and export of image pixels:\n");
918 for (i=0; reference_map[i] != (char *) NULL; i++)
920 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
923 Generate reference image.
925 CatchException(exception);
926 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
927 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
928 reference_storage[j].type));
929 (void) CopyMagickString(image_info->filename,reference_filename,
931 reference_image=ReadImage(image_info,exception);
932 if (reference_image == (Image *) NULL)
934 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
939 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
940 (void) TransformImageColorspace(reference_image,CMYKColorspace,
942 length=strlen(reference_map[i])*reference_image->columns*
943 reference_image->rows*reference_storage[j].quantum;
944 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
945 if (pixels == (unsigned char *) NULL)
947 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
950 reference_image=DestroyImage(reference_image);
953 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
954 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
955 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
957 if (status == MagickFalse)
959 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
962 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
963 reference_image=DestroyImage(reference_image);
966 (void) SetImageBackgroundColor(reference_image,exception);
967 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
968 reference_image->rows,reference_map[i],reference_storage[j].type,
970 if (status == MagickFalse)
972 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
975 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
976 reference_image=DestroyImage(reference_image);
980 Read reconstruct image.
982 reconstruct_image=AcquireImage(image_info,exception);
983 (void) SetImageExtent(reconstruct_image,reference_image->columns,
984 reference_image->rows,exception);
985 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
987 (void) SetImageBackgroundColor(reconstruct_image,exception);
988 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
989 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
991 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
992 if (status == MagickFalse)
994 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
997 reference_image=DestroyImage(reference_image);
1001 Compare reference to reconstruct image.
1003 difference_image=CompareImages(reference_image,reconstruct_image,
1004 MeanSquaredErrorMetric,&distortion,exception);
1005 reconstruct_image=DestroyImage(reconstruct_image);
1006 reference_image=DestroyImage(reference_image);
1007 if (difference_image == (Image *) NULL)
1009 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1014 difference_image=DestroyImage(difference_image);
1015 if ((distortion/QuantumRange) > 0.0)
1017 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1018 distortion/QuantumRange);
1022 (void) FormatLocaleFile(stdout,"... pass.\n");
1025 (void) FormatLocaleFile(stdout,
1026 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1027 (double) (test-(*fail)),(double) *fail);
1032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1036 % V a l i d a t e M o n t a g e C o m m a n d %
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 % ValidateMontageCommand() validates the ImageMagick montage command line
1043 % program and returns the number of validation tests that passed and failed.
1045 % The format of the ValidateMontageCommand method is:
1047 % size_t ValidateMontageCommand(ImageInfo *image_info,
1048 % const char *reference_filename,const char *output_filename,
1049 % size_t *fail,ExceptionInfo *exception)
1051 % A description of each parameter follows:
1053 % o image_info: the image info.
1055 % o reference_filename: the reference image filename.
1057 % o output_filename: the output image filename.
1059 % o fail: return the number of validation tests that pass.
1061 % o exception: return any errors or warnings in this structure.
1064 static size_t ValidateMontageCommand(ImageInfo *image_info,
1065 const char *reference_filename,const char *output_filename,
1066 size_t *fail,ExceptionInfo *exception)
1070 command[MaxTextExtent];
1086 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1087 for (i=0; montage_options[i] != (char *) NULL; i++)
1089 CatchException(exception);
1090 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1091 montage_options[i]);
1092 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1093 reference_filename,montage_options[i],reference_filename,
1095 arguments=StringToArgv(command,&number_arguments);
1096 if (arguments == (char **) NULL)
1098 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1103 status=MontageImageCommand(image_info,number_arguments,arguments,
1104 (char **) NULL,exception);
1105 for (j=0; j < number_arguments; j++)
1106 arguments[j]=DestroyString(arguments[j]);
1107 arguments=(char **) RelinquishMagickMemory(arguments);
1108 if (status != MagickFalse)
1110 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1115 (void) FormatLocaleFile(stdout,"... pass.\n");
1117 (void) FormatLocaleFile(stdout,
1118 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1119 (double) (test-(*fail)),(double) *fail);
1124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1128 % V a l i d a t e S t r e a m C o m m a n d %
1132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1134 % ValidateStreamCommand() validates the ImageMagick stream command line
1135 % program and returns the number of validation tests that passed and failed.
1137 % The format of the ValidateStreamCommand method is:
1139 % size_t ValidateStreamCommand(ImageInfo *image_info,
1140 % const char *reference_filename,const char *output_filename,
1141 % size_t *fail,ExceptionInfo *exception)
1143 % A description of each parameter follows:
1145 % o image_info: the image info.
1147 % o reference_filename: the reference image filename.
1149 % o output_filename: the output image filename.
1151 % o fail: return the number of validation tests that pass.
1153 % o exception: return any errors or warnings in this structure.
1156 static size_t ValidateStreamCommand(ImageInfo *image_info,
1157 const char *reference_filename,const char *output_filename,
1158 size_t *fail,ExceptionInfo *exception)
1162 command[MaxTextExtent];
1178 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1179 for (i=0; stream_options[i] != (char *) NULL; i++)
1181 CatchException(exception);
1182 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1184 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1185 stream_options[i],reference_filename,output_filename);
1186 arguments=StringToArgv(command,&number_arguments);
1187 if (arguments == (char **) NULL)
1189 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1194 status=StreamImageCommand(image_info,number_arguments,arguments,
1195 (char **) NULL,exception);
1196 for (j=0; j < number_arguments; j++)
1197 arguments[j]=DestroyString(arguments[j]);
1198 arguments=(char **) RelinquishMagickMemory(arguments);
1199 if (status != MagickFalse)
1201 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1206 (void) FormatLocaleFile(stdout,"... pass.\n");
1208 (void) FormatLocaleFile(stdout,
1209 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1210 (double) (test-(*fail)),(double) *fail);
1215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228 static MagickBooleanType ValidateUsage(void)
1236 "-debug events display copious debugging information",
1237 "-help print program options",
1238 "-log format format of debugging information",
1239 "-validate type validation type",
1240 "-version print version information",
1245 "-regard-warnings pay attention to warning messages",
1246 "-verbose print detailed information about the image",
1250 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1251 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1252 (void) printf("Features: %s\n",GetMagickFeatures());
1253 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1254 (void) printf("\nValidate Settings:\n");
1255 for (p=settings; *p != (char *) NULL; p++)
1256 (void) printf(" %s\n",*p);
1257 (void) printf("\nMiscellaneous Options:\n");
1258 for (p=miscellaneous; *p != (char *) NULL; p++)
1259 (void) printf(" %s\n",*p);
1263 int main(int argc,char **argv)
1265 #define DestroyValidate() \
1267 image_info=DestroyImageInfo(image_info); \
1268 exception=DestroyExceptionInfo(exception); \
1270 #define ThrowValidateException(asperity,tag,option) \
1272 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1274 CatchException(exception); \
1275 DestroyValidate(); \
1276 return(MagickFalse); \
1280 output_filename[MaxTextExtent],
1281 reference_filename[MaxTextExtent],
1316 Validate the ImageMagick image processing suite.
1318 MagickCoreGenesis(*argv,MagickFalse);
1322 regard_warnings=MagickFalse;
1323 (void) regard_warnings;
1324 exception=AcquireExceptionInfo();
1325 image_info=AcquireImageInfo();
1326 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1327 for (i=1; i < (ssize_t) argc; i++)
1330 if (IsCommandOption(option) == MagickFalse)
1332 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1335 switch (*(option+1))
1339 if (LocaleCompare("bench",option+1) == 0)
1341 iterations=StringToUnsignedLong(argv[++i]);
1344 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1348 if (LocaleCompare("debug",option+1) == 0)
1350 (void) SetLogEventMask(argv[++i]);
1353 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1357 if (LocaleCompare("help",option+1) == 0)
1359 (void) ValidateUsage();
1362 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1366 if (LocaleCompare("log",option+1) == 0)
1369 (void) SetLogFormat(argv[i+1]);
1372 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1376 if (LocaleCompare("regard-warnings",option+1) == 0)
1378 regard_warnings=MagickTrue;
1381 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1385 if (LocaleCompare("validate",option+1) == 0)
1393 if (i == (ssize_t) argc)
1394 ThrowValidateException(OptionError,"MissingArgument",option);
1395 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1398 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1400 type=(ValidateType) validate;
1403 if ((LocaleCompare("version",option+1) == 0) ||
1404 (LocaleCompare("-version",option+1) == 0))
1406 (void) FormatLocaleFile(stdout,"Version: %s\n",
1407 GetMagickVersion((size_t *) NULL));
1408 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1409 GetMagickCopyright());
1410 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1411 GetMagickFeatures());
1414 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1417 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1420 timer=(TimerInfo *) NULL;
1422 timer=AcquireTimerInfo();
1423 reference_image=ReadImage(image_info,exception);
1426 if (reference_image == (Image *) NULL)
1430 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1431 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1433 (void) AcquireUniqueFilename(reference_filename);
1434 (void) AcquireUniqueFilename(output_filename);
1435 (void) CopyMagickString(reference_image->filename,reference_filename,
1437 status=WriteImage(image_info,reference_image,exception);
1438 reference_image=DestroyImage(reference_image);
1439 if (status == MagickFalse)
1443 (void) FormatLocaleFile(stdout,"Version: %s\n",
1444 GetMagickVersion((size_t *) NULL));
1445 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1446 GetMagickCopyright());
1447 (void) FormatLocaleFile(stdout,
1448 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1449 MagickValidateOptions,(ssize_t) type));
1450 if ((type & CompareValidate) != 0)
1451 tests+=ValidateCompareCommand(image_info,reference_filename,
1452 output_filename,&fail,exception);
1453 if ((type & CompositeValidate) != 0)
1454 tests+=ValidateCompositeCommand(image_info,reference_filename,
1455 output_filename,&fail,exception);
1456 if ((type & ConvertValidate) != 0)
1457 tests+=ValidateConvertCommand(image_info,reference_filename,
1458 output_filename,&fail,exception);
1459 if ((type & FormatsInMemoryValidate) != 0)
1460 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1461 output_filename,&fail,exception);
1462 if ((type & FormatsOnDiskValidate) != 0)
1463 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1464 output_filename,&fail,exception);
1465 if ((type & IdentifyValidate) != 0)
1466 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1467 output_filename,&fail,exception);
1468 if ((type & ImportExportValidate) != 0)
1469 tests+=ValidateImportExportPixels(image_info,reference_filename,
1470 output_filename,&fail,exception);
1471 if ((type & MontageValidate) != 0)
1472 tests+=ValidateMontageCommand(image_info,reference_filename,
1473 output_filename,&fail,exception);
1474 if ((type & StreamValidate) != 0)
1475 tests+=ValidateStreamCommand(image_info,reference_filename,
1476 output_filename,&fail,exception);
1477 (void) FormatLocaleFile(stdout,
1478 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1479 (double) tests,(double) (tests-fail),(double) fail);
1481 (void) RelinquishUniqueFileResource(output_filename);
1482 (void) RelinquishUniqueFileResource(reference_filename);
1484 if (exception->severity != UndefinedException)
1485 CatchException(exception);
1488 elapsed_time=GetElapsedTime(timer);
1489 user_time=GetUserTime(timer);
1490 (void) FormatLocaleFile(stderr,
1491 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1492 iterations,1.0*iterations/elapsed_time,user_time,(long)
1493 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1494 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1495 timer=DestroyTimerInfo(timer);
1498 MagickCoreTerminus();
1499 return(fail == 0 ? 0 : 1);