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/string-private.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 % size_t ValidateCompareCommand(ImageInfo *image_info,
69 % const char *reference_filename,const char *output_filename,
70 % size_t *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 size_t ValidateCompareCommand(ImageInfo *image_info,
86 const char *reference_filename,const char *output_filename,
87 size_t *fail,ExceptionInfo *exception)
91 command[MaxTextExtent];
107 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
108 for (i=0; compare_options[i] != (char *) NULL; i++)
110 CatchException(exception);
111 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
113 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
114 compare_options[i],reference_filename,reference_filename,output_filename);
115 arguments=StringToArgv(command,&number_arguments);
116 if (arguments == (char **) NULL)
118 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
123 status=CompareImagesCommand(image_info,number_arguments,arguments,
124 (char **) NULL,exception);
125 for (j=0; j < number_arguments; j++)
126 arguments[j]=DestroyString(arguments[j]);
127 arguments=(char **) RelinquishMagickMemory(arguments);
128 if (status != MagickFalse)
130 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
135 (void) FormatLocaleFile(stdout,"... pass.\n");
137 (void) FormatLocaleFile(stdout,
138 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
139 (double) (test-(*fail)),(double) *fail);
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % V a l i d a t e C o m p o s i t e C o m m a n d %
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 % ValidateCompositeCommand() validates the ImageMagick composite command line
155 % program and returns the number of validation tests that passed and failed.
157 % The format of the ValidateCompositeCommand method is:
159 % size_t ValidateCompositeCommand(ImageInfo *image_info,
160 % const char *reference_filename,const char *output_filename,
161 % size_t *fail,ExceptionInfo *exception)
163 % A description of each parameter follows:
165 % o image_info: the image info.
167 % o reference_filename: the reference image filename.
169 % o output_filename: the output image filename.
171 % o fail: return the number of validation tests that pass.
173 % o exception: return any errors or warnings in this structure.
176 static size_t ValidateCompositeCommand(ImageInfo *image_info,
177 const char *reference_filename,const char *output_filename,
178 size_t *fail,ExceptionInfo *exception)
182 command[MaxTextExtent];
198 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
199 for (i=0; composite_options[i] != (char *) NULL; i++)
201 CatchException(exception);
202 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
203 composite_options[i]);
204 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
205 reference_filename,composite_options[i],reference_filename,
207 arguments=StringToArgv(command,&number_arguments);
208 if (arguments == (char **) NULL)
210 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
215 status=CompositeImageCommand(image_info,number_arguments,arguments,
216 (char **) NULL,exception);
217 for (j=0; j < number_arguments; j++)
218 arguments[j]=DestroyString(arguments[j]);
219 arguments=(char **) RelinquishMagickMemory(arguments);
220 if (status != MagickFalse)
222 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
227 (void) FormatLocaleFile(stdout,"... pass.\n");
229 (void) FormatLocaleFile(stdout,
230 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
231 (double) (test-(*fail)),(double) *fail);
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % V a l i d a t e C o n v e r t C o m m a n d %
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % ValidateConvertCommand() validates the ImageMagick convert command line
247 % program and returns the number of validation tests that passed and failed.
249 % The format of the ValidateConvertCommand method is:
251 % size_t ValidateConvertCommand(ImageInfo *image_info,
252 % const char *reference_filename,const char *output_filename,
253 % size_t *fail,ExceptionInfo *exception)
255 % A description of each parameter follows:
257 % o image_info: the image info.
259 % o reference_filename: the reference image filename.
261 % o output_filename: the output image filename.
263 % o fail: return the number of validation tests that pass.
265 % o exception: return any errors or warnings in this structure.
268 static size_t ValidateConvertCommand(ImageInfo *image_info,
269 const char *reference_filename,const char *output_filename,
270 size_t *fail,ExceptionInfo *exception)
274 command[MaxTextExtent];
290 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
291 for (i=0; convert_options[i] != (char *) NULL; i++)
293 CatchException(exception);
294 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
296 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
297 reference_filename,convert_options[i],reference_filename,output_filename);
298 arguments=StringToArgv(command,&number_arguments);
299 if (arguments == (char **) NULL)
301 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
306 status=ConvertImageCommand(image_info,number_arguments,arguments,
307 (char **) NULL,exception);
308 for (j=0; j < number_arguments; j++)
309 arguments[j]=DestroyString(arguments[j]);
310 arguments=(char **) RelinquishMagickMemory(arguments);
311 if (status != MagickFalse)
313 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
318 (void) FormatLocaleFile(stdout,"... pass.\n");
320 (void) FormatLocaleFile(stdout,
321 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
322 (double) (test-(*fail)),(double) *fail);
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % V a l i d a t e I d e n t i f y C o m m a n d %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % ValidateIdentifyCommand() validates the ImageMagick identify command line
338 % program and returns the number of validation tests that passed and failed.
340 % The format of the ValidateIdentifyCommand method is:
342 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
343 % const char *reference_filename,const char *output_filename,
344 % size_t *fail,ExceptionInfo *exception)
346 % A description of each parameter follows:
348 % o image_info: the image info.
350 % o reference_filename: the reference image filename.
352 % o output_filename: the output image filename.
354 % o fail: return the number of validation tests that pass.
356 % o exception: return any errors or warnings in this structure.
359 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
360 const char *reference_filename,const char *output_filename,
361 size_t *fail,ExceptionInfo *exception)
365 command[MaxTextExtent];
380 (void) output_filename;
382 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
383 for (i=0; identify_options[i] != (char *) NULL; i++)
385 CatchException(exception);
386 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
387 identify_options[i]);
388 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
389 identify_options[i],reference_filename);
390 arguments=StringToArgv(command,&number_arguments);
391 if (arguments == (char **) NULL)
393 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
398 status=IdentifyImageCommand(image_info,number_arguments,arguments,
399 (char **) NULL,exception);
400 for (j=0; j < number_arguments; j++)
401 arguments[j]=DestroyString(arguments[j]);
402 arguments=(char **) RelinquishMagickMemory(arguments);
403 if (status != MagickFalse)
405 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
410 (void) FormatLocaleFile(stdout,"... pass.\n");
412 (void) FormatLocaleFile(stdout,
413 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
414 (double) (test-(*fail)),(double) *fail);
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 % 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 %
427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
430 % memory and returns the number of validation tests that passed and failed.
432 % The format of the ValidateImageFormatsInMemory method is:
434 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
435 % const char *reference_filename,const char *output_filename,
436 % size_t *fail,ExceptionInfo *exception)
438 % A description of each parameter follows:
440 % o image_info: the image info.
442 % o reference_filename: the reference image filename.
444 % o output_filename: the output image filename.
446 % o fail: return the number of validation tests that pass.
448 % o exception: return any errors or warnings in this structure.
451 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
452 const char *reference_filename,const char *output_filename,
453 size_t *fail,ExceptionInfo *exception)
487 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
488 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
490 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
491 if ((magick_info == (const MagickInfo *) NULL) ||
492 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
493 (magick_info->encoder == (EncodeImageHandler *) NULL))
495 for (j=0; reference_types[j].type != UndefinedType; j++)
498 Generate reference image.
500 CatchException(exception);
501 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
502 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
503 MagickCompressOptions,reference_formats[i].compression),
504 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
505 (double) reference_types[j].depth);
506 (void) CopyMagickString(image_info->filename,reference_filename,
508 reference_image=ReadImage(image_info,exception);
509 if (reference_image == (Image *) NULL)
511 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
517 Write reference image.
519 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
520 (double) reference_image->columns,(double) reference_image->rows);
521 (void) CloneString(&image_info->size,size);
522 image_info->depth=reference_types[j].depth;
523 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
524 reference_formats[i].magick,output_filename);
525 status=SetImageType(reference_image,reference_types[j].type);
526 InheritException(exception,&reference_image->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);
536 InheritException(exception,&reference_image->exception);
537 if (status == MagickFalse)
539 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
542 reference_image=DestroyImage(reference_image);
545 reference_image->compression=reference_formats[i].compression;
546 status=WriteImage(image_info,reference_image);
547 InheritException(exception,&reference_image->exception);
548 reference_image=DestroyImage(reference_image);
549 if (status == MagickFalse)
551 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
557 Read reference image.
559 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
560 reference_formats[i].magick,output_filename);
561 reference_image=ReadImage(image_info,exception);
562 if (reference_image == (Image *) NULL)
564 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
570 Write reference image.
572 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
573 reference_formats[i].magick,output_filename);
574 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
576 reference_image->depth=reference_types[j].depth;
577 reference_image->compression=reference_formats[i].compression;
579 blob=ImageToBlob(image_info,reference_image,&length,exception);
580 if (blob == (unsigned char *) NULL)
582 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
585 reference_image=DestroyImage(reference_image);
589 Read reconstruct image.
591 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
592 reference_formats[i].magick,output_filename);
593 reconstruct_image=BlobToImage(image_info,blob,length,exception);
594 blob=(unsigned char *) RelinquishMagickMemory(blob);
595 if (reconstruct_image == (Image *) NULL)
597 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
600 reference_image=DestroyImage(reference_image);
604 Compare reference to reconstruct image.
607 if (reference_formats[i].fuzz != 0.0)
608 fuzz=reference_formats[i].fuzz;
609 #if defined(MAGICKCORE_HDRI_SUPPORT)
612 if (reference_image->colorspace != RGBColorspace)
615 difference_image=CompareImages(reference_image,reconstruct_image,
616 CompositeChannels,MeanSquaredErrorMetric,&distortion,exception);
617 reconstruct_image=DestroyImage(reconstruct_image);
618 reference_image=DestroyImage(reference_image);
619 if (difference_image == (Image *) NULL)
621 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
626 difference_image=DestroyImage(difference_image);
627 if ((distortion/QuantumRange) > fuzz)
629 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
630 distortion/QuantumRange);
634 (void) FormatLocaleFile(stdout,"... pass.\n");
637 (void) FormatLocaleFile(stdout,
638 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
639 (double) (test-(*fail)),(double) *fail);
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 % 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 %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
655 % and returns the number of validation tests that passed and failed.
657 % The format of the ValidateImageFormatsOnDisk method is:
659 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
660 % const char *reference_filename,const char *output_filename,
661 % size_t *fail,ExceptionInfo *exception)
663 % A description of each parameter follows:
665 % o image_info: the image info.
667 % o reference_filename: the reference image filename.
669 % o output_filename: the output image filename.
671 % o fail: return the number of validation tests that pass.
673 % o exception: return any errors or warnings in this structure.
676 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
677 const char *reference_filename,const char *output_filename,
678 size_t *fail,ExceptionInfo *exception)
706 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
707 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
709 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
710 if ((magick_info == (const MagickInfo *) NULL) ||
711 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
712 (magick_info->encoder == (EncodeImageHandler *) NULL))
714 for (j=0; reference_types[j].type != UndefinedType; j++)
717 Generate reference image.
719 CatchException(exception);
720 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
721 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
722 MagickCompressOptions,reference_formats[i].compression),
723 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
724 (double) reference_types[j].depth);
725 (void) CopyMagickString(image_info->filename,reference_filename,
727 reference_image=ReadImage(image_info,exception);
728 if (reference_image == (Image *) NULL)
730 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
736 Write reference image.
738 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
739 (double) reference_image->columns,(double) reference_image->rows);
740 (void) CloneString(&image_info->size,size);
741 image_info->depth=reference_types[j].depth;
742 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
743 reference_formats[i].magick,output_filename);
744 status=SetImageType(reference_image,reference_types[j].type);
745 InheritException(exception,&reference_image->exception);
746 if (status == MagickFalse)
748 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
751 reference_image=DestroyImage(reference_image);
754 status=SetImageDepth(reference_image,reference_types[j].depth);
755 InheritException(exception,&reference_image->exception);
756 if (status == MagickFalse)
758 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
761 reference_image=DestroyImage(reference_image);
764 reference_image->compression=reference_formats[i].compression;
765 status=WriteImage(image_info,reference_image);
766 InheritException(exception,&reference_image->exception);
767 reference_image=DestroyImage(reference_image);
768 if (status == MagickFalse)
770 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
776 Read reference image.
778 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
779 reference_formats[i].magick,output_filename);
780 reference_image=ReadImage(image_info,exception);
781 if (reference_image == (Image *) NULL)
783 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
789 Write reference image.
791 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
792 reference_formats[i].magick,output_filename);
793 reference_image->depth=reference_types[j].depth;
794 reference_image->compression=reference_formats[i].compression;
795 status=WriteImage(image_info,reference_image);
796 InheritException(exception,&reference_image->exception);
797 if (status == MagickFalse)
799 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
802 reference_image=DestroyImage(reference_image);
806 Read reconstruct image.
808 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
809 reference_formats[i].magick,output_filename);
810 reconstruct_image=ReadImage(image_info,exception);
811 if (reconstruct_image == (Image *) NULL)
813 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
816 reference_image=DestroyImage(reference_image);
820 Compare reference to reconstruct image.
823 if (reference_formats[i].fuzz != 0.0)
824 fuzz=reference_formats[i].fuzz;
825 #if defined(MAGICKCORE_HDRI_SUPPORT)
828 if (reference_image->colorspace != RGBColorspace)
831 difference_image=CompareImages(reference_image,reconstruct_image,
832 CompositeChannels,MeanSquaredErrorMetric,&distortion,exception);
833 reconstruct_image=DestroyImage(reconstruct_image);
834 reference_image=DestroyImage(reference_image);
835 if (difference_image == (Image *) NULL)
837 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
842 difference_image=DestroyImage(difference_image);
843 if ((distortion/QuantumRange) > fuzz)
845 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
846 distortion/QuantumRange);
850 (void) FormatLocaleFile(stdout,"... pass.\n");
853 (void) FormatLocaleFile(stdout,
854 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
855 (double) (test-(*fail)),(double) *fail);
860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
864 % 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 %
868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
870 % ValidateImportExportPixels() validates the pixel import and export methods.
871 % It returns the number of validation tests that passed and failed.
873 % The format of the ValidateImportExportPixels method is:
875 % size_t ValidateImportExportPixels(ImageInfo *image_info,
876 % const char *reference_filename,const char *output_filename,
877 % size_t *fail,ExceptionInfo *exception)
879 % A description of each parameter follows:
881 % o image_info: the image info.
883 % o reference_filename: the reference image filename.
885 % o output_filename: the output image filename.
887 % o fail: return the number of validation tests that pass.
889 % o exception: return any errors or warnings in this structure.
892 static size_t ValidateImportExportPixels(ImageInfo *image_info,
893 const char *reference_filename,const char *output_filename,
894 size_t *fail,ExceptionInfo *exception)
920 (void) output_filename;
922 (void) FormatLocaleFile(stdout,
923 "validate the import and export of image pixels:\n");
924 for (i=0; reference_map[i] != (char *) NULL; i++)
926 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
929 Generate reference image.
931 CatchException(exception);
932 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
933 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
934 reference_storage[j].type));
935 (void) CopyMagickString(image_info->filename,reference_filename,
937 reference_image=ReadImage(image_info,exception);
938 if (reference_image == (Image *) NULL)
940 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
945 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
946 (void) TransformImageColorspace(reference_image,CMYKColorspace);
947 length=strlen(reference_map[i])*reference_image->columns*
948 reference_image->rows*reference_storage[j].quantum;
949 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
950 if (pixels == (unsigned char *) NULL)
952 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
955 reference_image=DestroyImage(reference_image);
958 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
959 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
960 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
962 if (status == MagickFalse)
964 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
967 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
968 reference_image=DestroyImage(reference_image);
971 (void) SetImageBackgroundColor(reference_image);
972 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
973 reference_image->rows,reference_map[i],reference_storage[j].type,
975 InheritException(exception,&reference_image->exception);
976 if (status == MagickFalse)
978 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
981 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
982 reference_image=DestroyImage(reference_image);
986 Read reconstruct image.
988 reconstruct_image=AcquireImage(image_info);
989 (void) SetImageExtent(reconstruct_image,reference_image->columns,
990 reference_image->rows);
991 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
992 (void) SetImageBackgroundColor(reconstruct_image);
993 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
994 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
996 InheritException(exception,&reconstruct_image->exception);
997 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
998 if (status == MagickFalse)
1000 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1003 reference_image=DestroyImage(reference_image);
1007 Compare reference to reconstruct image.
1009 difference_image=CompareImages(reference_image,reconstruct_image,
1010 CompositeChannels,MeanSquaredErrorMetric,&distortion,exception);
1011 reconstruct_image=DestroyImage(reconstruct_image);
1012 reference_image=DestroyImage(reference_image);
1013 if (difference_image == (Image *) NULL)
1015 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1020 difference_image=DestroyImage(difference_image);
1021 if ((distortion/QuantumRange) > 0.0)
1023 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1024 distortion/QuantumRange);
1028 (void) FormatLocaleFile(stdout,"... pass.\n");
1031 (void) FormatLocaleFile(stdout,
1032 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1033 (double) (test-(*fail)),(double) *fail);
1038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 % V a l i d a t e M o n t a g e C o m m a n d %
1046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 % ValidateMontageCommand() validates the ImageMagick montage command line
1049 % program and returns the number of validation tests that passed and failed.
1051 % The format of the ValidateMontageCommand method is:
1053 % size_t ValidateMontageCommand(ImageInfo *image_info,
1054 % const char *reference_filename,const char *output_filename,
1055 % size_t *fail,ExceptionInfo *exception)
1057 % A description of each parameter follows:
1059 % o image_info: the image info.
1061 % o reference_filename: the reference image filename.
1063 % o output_filename: the output image filename.
1065 % o fail: return the number of validation tests that pass.
1067 % o exception: return any errors or warnings in this structure.
1070 static size_t ValidateMontageCommand(ImageInfo *image_info,
1071 const char *reference_filename,const char *output_filename,
1072 size_t *fail,ExceptionInfo *exception)
1076 command[MaxTextExtent];
1092 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1093 for (i=0; montage_options[i] != (char *) NULL; i++)
1095 CatchException(exception);
1096 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1097 montage_options[i]);
1098 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1099 reference_filename,montage_options[i],reference_filename,
1101 arguments=StringToArgv(command,&number_arguments);
1102 if (arguments == (char **) NULL)
1104 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1109 status=MontageImageCommand(image_info,number_arguments,arguments,
1110 (char **) NULL,exception);
1111 for (j=0; j < number_arguments; j++)
1112 arguments[j]=DestroyString(arguments[j]);
1113 arguments=(char **) RelinquishMagickMemory(arguments);
1114 if (status != MagickFalse)
1116 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1121 (void) FormatLocaleFile(stdout,"... pass.\n");
1123 (void) FormatLocaleFile(stdout,
1124 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1125 (double) (test-(*fail)),(double) *fail);
1130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1134 % V a l i d a t e S t r e a m C o m m a n d %
1138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1140 % ValidateStreamCommand() validates the ImageMagick stream command line
1141 % program and returns the number of validation tests that passed and failed.
1143 % The format of the ValidateStreamCommand method is:
1145 % size_t ValidateStreamCommand(ImageInfo *image_info,
1146 % const char *reference_filename,const char *output_filename,
1147 % size_t *fail,ExceptionInfo *exception)
1149 % A description of each parameter follows:
1151 % o image_info: the image info.
1153 % o reference_filename: the reference image filename.
1155 % o output_filename: the output image filename.
1157 % o fail: return the number of validation tests that pass.
1159 % o exception: return any errors or warnings in this structure.
1162 static size_t ValidateStreamCommand(ImageInfo *image_info,
1163 const char *reference_filename,const char *output_filename,
1164 size_t *fail,ExceptionInfo *exception)
1168 command[MaxTextExtent];
1184 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1185 for (i=0; stream_options[i] != (char *) NULL; i++)
1187 CatchException(exception);
1188 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1190 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1191 stream_options[i],reference_filename,output_filename);
1192 arguments=StringToArgv(command,&number_arguments);
1193 if (arguments == (char **) NULL)
1195 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1200 status=StreamImageCommand(image_info,number_arguments,arguments,
1201 (char **) NULL,exception);
1202 for (j=0; j < number_arguments; j++)
1203 arguments[j]=DestroyString(arguments[j]);
1204 arguments=(char **) RelinquishMagickMemory(arguments);
1205 if (status != MagickFalse)
1207 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1212 (void) FormatLocaleFile(stdout,"... pass.\n");
1214 (void) FormatLocaleFile(stdout,
1215 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1216 (double) (test-(*fail)),(double) *fail);
1221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234 static MagickBooleanType ValidateUsage(void)
1242 "-debug events display copious debugging information",
1243 "-help print program options",
1244 "-log format format of debugging information",
1245 "-validate type validation type",
1246 "-version print version information",
1251 "-regard-warnings pay attention to warning messages",
1252 "-verbose print detailed information about the image",
1256 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1257 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1258 (void) printf("Features: %s\n",GetMagickFeatures());
1259 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1260 (void) printf("\nValidate Settings:\n");
1261 for (p=settings; *p != (char *) NULL; p++)
1262 (void) printf(" %s\n",*p);
1263 (void) printf("\nMiscellaneous Options:\n");
1264 for (p=miscellaneous; *p != (char *) NULL; p++)
1265 (void) printf(" %s\n",*p);
1269 int main(int argc,char **argv)
1271 #define DestroyValidate() \
1273 image_info=DestroyImageInfo(image_info); \
1274 exception=DestroyExceptionInfo(exception); \
1276 #define ThrowValidateException(asperity,tag,option) \
1278 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1280 CatchException(exception); \
1281 DestroyValidate(); \
1282 return(MagickFalse); \
1286 output_filename[MaxTextExtent],
1287 reference_filename[MaxTextExtent],
1322 Validate the ImageMagick image processing suite.
1324 MagickCoreGenesis(*argv,MagickFalse);
1328 regard_warnings=MagickFalse;
1329 (void) regard_warnings;
1330 exception=AcquireExceptionInfo();
1331 image_info=AcquireImageInfo();
1332 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1333 for (i=1; i < (ssize_t) argc; i++)
1336 if (IsCommandOption(option) == MagickFalse)
1338 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1341 switch (*(option+1))
1345 if (LocaleCompare("bench",option+1) == 0)
1347 iterations=StringToUnsignedLong(argv[++i]);
1350 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1354 if (LocaleCompare("debug",option+1) == 0)
1356 (void) SetLogEventMask(argv[++i]);
1359 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1363 if (LocaleCompare("help",option+1) == 0)
1365 (void) ValidateUsage();
1368 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1372 if (LocaleCompare("log",option+1) == 0)
1375 (void) SetLogFormat(argv[i+1]);
1378 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1382 if (LocaleCompare("regard-warnings",option+1) == 0)
1384 regard_warnings=MagickTrue;
1387 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1391 if (LocaleCompare("validate",option+1) == 0)
1399 if (i == (ssize_t) argc)
1400 ThrowValidateException(OptionError,"MissingArgument",option);
1401 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1404 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1406 type=(ValidateType) validate;
1409 if ((LocaleCompare("version",option+1) == 0) ||
1410 (LocaleCompare("-version",option+1) == 0))
1412 (void) FormatLocaleFile(stdout,"Version: %s\n",
1413 GetMagickVersion((size_t *) NULL));
1414 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1415 GetMagickCopyright());
1416 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1417 GetMagickFeatures());
1420 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1423 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1426 timer=(TimerInfo *) NULL;
1428 timer=AcquireTimerInfo();
1429 reference_image=ReadImage(image_info,exception);
1432 if (reference_image == (Image *) NULL)
1436 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1437 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1439 (void) AcquireUniqueFilename(reference_filename);
1440 (void) AcquireUniqueFilename(output_filename);
1441 (void) CopyMagickString(reference_image->filename,reference_filename,
1443 status=WriteImage(image_info,reference_image);
1444 InheritException(exception,&reference_image->exception);
1445 reference_image=DestroyImage(reference_image);
1446 if (status == MagickFalse)
1450 (void) FormatLocaleFile(stdout,"Version: %s\n",
1451 GetMagickVersion((size_t *) NULL));
1452 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1453 GetMagickCopyright());
1454 (void) FormatLocaleFile(stdout,
1455 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1456 MagickValidateOptions,(ssize_t) type));
1457 if ((type & CompareValidate) != 0)
1458 tests+=ValidateCompareCommand(image_info,reference_filename,
1459 output_filename,&fail,exception);
1460 if ((type & CompositeValidate) != 0)
1461 tests+=ValidateCompositeCommand(image_info,reference_filename,
1462 output_filename,&fail,exception);
1463 if ((type & ConvertValidate) != 0)
1464 tests+=ValidateConvertCommand(image_info,reference_filename,
1465 output_filename,&fail,exception);
1466 if ((type & FormatsInMemoryValidate) != 0)
1467 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1468 output_filename,&fail,exception);
1469 if ((type & FormatsOnDiskValidate) != 0)
1470 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1471 output_filename,&fail,exception);
1472 if ((type & IdentifyValidate) != 0)
1473 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1474 output_filename,&fail,exception);
1475 if ((type & ImportExportValidate) != 0)
1476 tests+=ValidateImportExportPixels(image_info,reference_filename,
1477 output_filename,&fail,exception);
1478 if ((type & MontageValidate) != 0)
1479 tests+=ValidateMontageCommand(image_info,reference_filename,
1480 output_filename,&fail,exception);
1481 if ((type & StreamValidate) != 0)
1482 tests+=ValidateStreamCommand(image_info,reference_filename,
1483 output_filename,&fail,exception);
1484 (void) FormatLocaleFile(stdout,
1485 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1486 (double) tests,(double) (tests-fail),(double) fail);
1488 (void) RelinquishUniqueFileResource(output_filename);
1489 (void) RelinquishUniqueFileResource(reference_filename);
1491 if (exception->severity != UndefinedException)
1492 CatchException(exception);
1495 elapsed_time=GetElapsedTime(timer);
1496 user_time=GetUserTime(timer);
1497 (void) FormatLocaleFile(stderr,
1498 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1499 iterations,1.0*iterations/elapsed_time,user_time,(long)
1500 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1501 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1502 timer=DestroyTimerInfo(timer);
1505 MagickCoreTerminus();
1506 return(fail == 0 ? 0 : 1);