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-2012 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"
56 #define DistortionEpsilon ((MagickRealType) 1.0e-5)
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 % V a l i d a t e C o m p a r e C o m m a n d %
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 % ValidateCompareCommand() validates the ImageMagick compare command line
70 % program and returns the number of validation tests that passed and failed.
72 % The format of the ValidateCompareCommand method is:
74 % size_t ValidateCompareCommand(ImageInfo *image_info,
75 % const char *reference_filename,const char *output_filename,
76 % size_t *fail,ExceptionInfo *exception)
78 % A description of each parameter follows:
80 % o image_info: the image info.
82 % o reference_filename: the reference image filename.
84 % o output_filename: the output image filename.
86 % o fail: return the number of validation tests that pass.
88 % o exception: return any errors or warnings in this structure.
91 static size_t ValidateCompareCommand(ImageInfo *image_info,
92 const char *reference_filename,const char *output_filename,
93 size_t *fail,ExceptionInfo *exception)
97 command[MaxTextExtent];
113 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
114 for (i=0; compare_options[i] != (char *) NULL; i++)
116 CatchException(exception);
117 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
119 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
120 compare_options[i],reference_filename,reference_filename,output_filename);
121 arguments=StringToArgv(command,&number_arguments);
122 if (arguments == (char **) NULL)
124 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
129 status=CompareImagesCommand(image_info,number_arguments,arguments,
130 (char **) NULL,exception);
131 for (j=0; j < (ssize_t) number_arguments; j++)
132 arguments[j]=DestroyString(arguments[j]);
133 arguments=(char **) RelinquishMagickMemory(arguments);
134 if (status != MagickFalse)
136 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
141 (void) FormatLocaleFile(stdout,"... pass.\n");
143 (void) FormatLocaleFile(stdout,
144 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
145 (double) (test-(*fail)),(double) *fail);
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 % V a l i d a t e C o m p o s i t e C o m m a n d %
158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 % ValidateCompositeCommand() validates the ImageMagick composite command line
161 % program and returns the number of validation tests that passed and failed.
163 % The format of the ValidateCompositeCommand method is:
165 % size_t ValidateCompositeCommand(ImageInfo *image_info,
166 % const char *reference_filename,const char *output_filename,
167 % size_t *fail,ExceptionInfo *exception)
169 % A description of each parameter follows:
171 % o image_info: the image info.
173 % o reference_filename: the reference image filename.
175 % o output_filename: the output image filename.
177 % o fail: return the number of validation tests that pass.
179 % o exception: return any errors or warnings in this structure.
182 static size_t ValidateCompositeCommand(ImageInfo *image_info,
183 const char *reference_filename,const char *output_filename,
184 size_t *fail,ExceptionInfo *exception)
188 command[MaxTextExtent];
204 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
205 for (i=0; composite_options[i] != (char *) NULL; i++)
207 CatchException(exception);
208 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
209 composite_options[i]);
210 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
211 reference_filename,composite_options[i],reference_filename,
213 arguments=StringToArgv(command,&number_arguments);
214 if (arguments == (char **) NULL)
216 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
221 status=CompositeImageCommand(image_info,number_arguments,arguments,
222 (char **) NULL,exception);
223 for (j=0; j < (ssize_t) number_arguments; j++)
224 arguments[j]=DestroyString(arguments[j]);
225 arguments=(char **) RelinquishMagickMemory(arguments);
226 if (status != MagickFalse)
228 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
233 (void) FormatLocaleFile(stdout,"... pass.\n");
235 (void) FormatLocaleFile(stdout,
236 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
237 (double) (test-(*fail)),(double) *fail);
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % V a l i d a t e C o n v e r t C o m m a n d %
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % ValidateConvertCommand() validates the ImageMagick convert command line
253 % program and returns the number of validation tests that passed and failed.
255 % The format of the ValidateConvertCommand method is:
257 % size_t ValidateConvertCommand(ImageInfo *image_info,
258 % const char *reference_filename,const char *output_filename,
259 % size_t *fail,ExceptionInfo *exception)
261 % A description of each parameter follows:
263 % o image_info: the image info.
265 % o reference_filename: the reference image filename.
267 % o output_filename: the output image filename.
269 % o fail: return the number of validation tests that pass.
271 % o exception: return any errors or warnings in this structure.
274 static size_t ValidateConvertCommand(ImageInfo *image_info,
275 const char *reference_filename,const char *output_filename,
276 size_t *fail,ExceptionInfo *exception)
280 command[MaxTextExtent];
296 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
297 for (i=0; convert_options[i] != (char *) NULL; i++)
299 CatchException(exception);
300 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
302 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
303 reference_filename,convert_options[i],reference_filename,output_filename);
304 arguments=StringToArgv(command,&number_arguments);
305 if (arguments == (char **) NULL)
307 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
312 status=ConvertImageCommand(image_info,number_arguments,arguments,
313 (char **) NULL,exception);
314 for (j=0; j < (ssize_t) number_arguments; j++)
315 arguments[j]=DestroyString(arguments[j]);
316 arguments=(char **) RelinquishMagickMemory(arguments);
317 if (status != MagickFalse)
319 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
324 (void) FormatLocaleFile(stdout,"... pass.\n");
326 (void) FormatLocaleFile(stdout,
327 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
328 (double) (test-(*fail)),(double) *fail);
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % V a l i d a t e I d e n t i f y C o m m a n d %
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 % ValidateIdentifyCommand() validates the ImageMagick identify command line
344 % program and returns the number of validation tests that passed and failed.
346 % The format of the ValidateIdentifyCommand method is:
348 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
349 % const char *reference_filename,const char *output_filename,
350 % size_t *fail,ExceptionInfo *exception)
352 % A description of each parameter follows:
354 % o image_info: the image info.
356 % o reference_filename: the reference image filename.
358 % o output_filename: the output image filename.
360 % o fail: return the number of validation tests that pass.
362 % o exception: return any errors or warnings in this structure.
365 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
366 const char *reference_filename,const char *output_filename,
367 size_t *fail,ExceptionInfo *exception)
371 command[MaxTextExtent];
386 (void) output_filename;
388 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
389 for (i=0; identify_options[i] != (char *) NULL; i++)
391 CatchException(exception);
392 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
393 identify_options[i]);
394 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
395 identify_options[i],reference_filename);
396 arguments=StringToArgv(command,&number_arguments);
397 if (arguments == (char **) NULL)
399 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
404 status=IdentifyImageCommand(image_info,number_arguments,arguments,
405 (char **) NULL,exception);
406 for (j=0; j < (ssize_t) number_arguments; j++)
407 arguments[j]=DestroyString(arguments[j]);
408 arguments=(char **) RelinquishMagickMemory(arguments);
409 if (status != MagickFalse)
411 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
416 (void) FormatLocaleFile(stdout,"... pass.\n");
418 (void) FormatLocaleFile(stdout,
419 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
420 (double) (test-(*fail)),(double) *fail);
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % 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 %
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
436 % memory and returns the number of validation tests that passed and failed.
438 % The format of the ValidateImageFormatsInMemory method is:
440 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
441 % const char *reference_filename,const char *output_filename,
442 % size_t *fail,ExceptionInfo *exception)
444 % A description of each parameter follows:
446 % o image_info: the image info.
448 % o reference_filename: the reference image filename.
450 % o output_filename: the output image filename.
452 % o fail: return the number of validation tests that pass.
454 % o exception: return any errors or warnings in this structure.
457 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
458 const char *reference_filename,const char *output_filename,
459 size_t *fail,ExceptionInfo *exception)
492 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
493 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
495 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
496 if ((magick_info == (const MagickInfo *) NULL) ||
497 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
498 (magick_info->encoder == (EncodeImageHandler *) NULL))
500 for (j=0; reference_types[j].type != UndefinedType; j++)
503 Generate reference image.
505 CatchException(exception);
506 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
507 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
508 MagickCompressOptions,reference_formats[i].compression),
509 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
510 (double) reference_types[j].depth);
511 (void) CopyMagickString(image_info->filename,reference_filename,
513 reference_image=ReadImage(image_info,exception);
514 if (reference_image == (Image *) NULL)
516 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
522 Write reference image.
524 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
525 (double) reference_image->columns,(double) reference_image->rows);
526 (void) CloneString(&image_info->size,size);
527 image_info->depth=reference_types[j].depth;
528 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
529 reference_formats[i].magick,output_filename);
530 status=SetImageType(reference_image,reference_types[j].type,exception);
531 if (status == MagickFalse)
533 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
536 reference_image=DestroyImage(reference_image);
539 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
540 if (status == MagickFalse)
542 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
545 reference_image=DestroyImage(reference_image);
548 reference_image->compression=reference_formats[i].compression;
549 status=WriteImage(image_info,reference_image,exception);
550 reference_image=DestroyImage(reference_image);
551 if (status == MagickFalse)
553 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
559 Ping reference image.
561 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
562 reference_formats[i].magick,output_filename);
563 ping_image=PingImage(image_info,exception);
564 if (ping_image == (Image *) NULL)
566 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
571 ping_image=DestroyImage(ping_image);
573 Read reference image.
575 reference_image=ReadImage(image_info,exception);
576 if (reference_image == (Image *) NULL)
578 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
584 Write reference image.
586 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
587 reference_formats[i].magick,output_filename);
588 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
590 reference_image->depth=reference_types[j].depth;
591 reference_image->compression=reference_formats[i].compression;
593 blob=ImageToBlob(image_info,reference_image,&length,exception);
594 if (blob == (unsigned char *) NULL)
596 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
599 reference_image=DestroyImage(reference_image);
605 ping_image=PingBlob(image_info,blob,length,exception);
606 if (ping_image == (Image *) NULL)
608 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
611 blob=(unsigned char *) RelinquishMagickMemory(blob);
614 ping_image=DestroyImage(ping_image);
616 Read reconstruct image.
618 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
619 reference_formats[i].magick,output_filename);
620 reconstruct_image=BlobToImage(image_info,blob,length,exception);
621 blob=(unsigned char *) RelinquishMagickMemory(blob);
622 if (reconstruct_image == (Image *) NULL)
624 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
627 reference_image=DestroyImage(reference_image);
631 Compare reference to reconstruct image.
634 if (reference_formats[i].fuzz != 0.0)
635 fuzz=reference_formats[i].fuzz;
636 #if defined(MAGICKCORE_HDRI_SUPPORT)
639 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
641 fuzz+=DistortionEpsilon;
642 difference_image=CompareImages(reference_image,reconstruct_image,
643 MeanSquaredErrorMetric,&distortion,exception);
644 reconstruct_image=DestroyImage(reconstruct_image);
645 reference_image=DestroyImage(reference_image);
646 if (difference_image == (Image *) NULL)
648 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
653 difference_image=DestroyImage(difference_image);
654 if ((QuantumScale*distortion) > fuzz)
656 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
657 QuantumScale*distortion);
661 (void) FormatLocaleFile(stdout,"... pass.\n");
664 (void) FormatLocaleFile(stdout,
665 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
666 (double) (test-(*fail)),(double) *fail);
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 % 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 %
679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
682 % and returns the number of validation tests that passed and failed.
684 % The format of the ValidateImageFormatsOnDisk method is:
686 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
687 % const char *reference_filename,const char *output_filename,
688 % size_t *fail,ExceptionInfo *exception)
690 % A description of each parameter follows:
692 % o image_info: the image info.
694 % o reference_filename: the reference image filename.
696 % o output_filename: the output image filename.
698 % o fail: return the number of validation tests that pass.
700 % o exception: return any errors or warnings in this structure.
703 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
704 const char *reference_filename,const char *output_filename,
705 size_t *fail,ExceptionInfo *exception)
733 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
734 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
736 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
737 if ((magick_info == (const MagickInfo *) NULL) ||
738 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
739 (magick_info->encoder == (EncodeImageHandler *) NULL))
741 for (j=0; reference_types[j].type != UndefinedType; j++)
744 Generate reference image.
746 CatchException(exception);
747 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
748 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
749 MagickCompressOptions,reference_formats[i].compression),
750 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
751 (double) reference_types[j].depth);
752 (void) CopyMagickString(image_info->filename,reference_filename,
754 reference_image=ReadImage(image_info,exception);
755 if (reference_image == (Image *) NULL)
757 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
763 Write reference image.
765 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
766 (double) reference_image->columns,(double) reference_image->rows);
767 (void) CloneString(&image_info->size,size);
768 image_info->depth=reference_types[j].depth;
769 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
770 reference_formats[i].magick,output_filename);
771 status=SetImageType(reference_image,reference_types[j].type,exception);
772 if (status == MagickFalse)
774 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
777 reference_image=DestroyImage(reference_image);
780 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
781 if (status == MagickFalse)
783 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
786 reference_image=DestroyImage(reference_image);
789 reference_image->compression=reference_formats[i].compression;
790 status=WriteImage(image_info,reference_image,exception);
791 reference_image=DestroyImage(reference_image);
792 if (status == MagickFalse)
794 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
800 Read reference image.
802 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
803 reference_formats[i].magick,output_filename);
804 reference_image=ReadImage(image_info,exception);
805 if (reference_image == (Image *) NULL)
807 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
813 Write reference image.
815 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
816 reference_formats[i].magick,output_filename);
817 reference_image->depth=reference_types[j].depth;
818 reference_image->compression=reference_formats[i].compression;
819 status=WriteImage(image_info,reference_image,exception);
820 if (status == MagickFalse)
822 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
825 reference_image=DestroyImage(reference_image);
829 Read reconstruct image.
831 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
832 reference_formats[i].magick,output_filename);
833 reconstruct_image=ReadImage(image_info,exception);
834 if (reconstruct_image == (Image *) NULL)
836 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
839 reference_image=DestroyImage(reference_image);
843 Compare reference to reconstruct image.
846 if (reference_formats[i].fuzz != 0.0)
847 fuzz=reference_formats[i].fuzz;
848 #if defined(MAGICKCORE_HDRI_SUPPORT)
851 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
853 fuzz+=DistortionEpsilon;
854 difference_image=CompareImages(reference_image,reconstruct_image,
855 MeanSquaredErrorMetric,&distortion,exception);
856 reconstruct_image=DestroyImage(reconstruct_image);
857 reference_image=DestroyImage(reference_image);
858 if (difference_image == (Image *) NULL)
860 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
865 difference_image=DestroyImage(difference_image);
866 if ((QuantumScale*distortion) > fuzz)
868 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
869 QuantumScale*distortion);
873 (void) FormatLocaleFile(stdout,"... pass.\n");
876 (void) FormatLocaleFile(stdout,
877 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
878 (double) (test-(*fail)),(double) *fail);
883 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887 % 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 %
891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
893 % ValidateImportExportPixels() validates the pixel import and export methods.
894 % It returns the number of validation tests that passed and failed.
896 % The format of the ValidateImportExportPixels method is:
898 % size_t ValidateImportExportPixels(ImageInfo *image_info,
899 % const char *reference_filename,const char *output_filename,
900 % size_t *fail,ExceptionInfo *exception)
902 % A description of each parameter follows:
904 % o image_info: the image info.
906 % o reference_filename: the reference image filename.
908 % o output_filename: the output image filename.
910 % o fail: return the number of validation tests that pass.
912 % o exception: return any errors or warnings in this structure.
915 static size_t ValidateImportExportPixels(ImageInfo *image_info,
916 const char *reference_filename,const char *output_filename,
917 size_t *fail,ExceptionInfo *exception)
943 (void) output_filename;
945 (void) FormatLocaleFile(stdout,
946 "validate the import and export of image pixels:\n");
947 for (i=0; reference_map[i] != (char *) NULL; i++)
949 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
952 Generate reference image.
954 CatchException(exception);
955 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
956 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
957 reference_storage[j].type));
958 (void) CopyMagickString(image_info->filename,reference_filename,
960 reference_image=ReadImage(image_info,exception);
961 if (reference_image == (Image *) NULL)
963 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
968 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
969 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
970 length=strlen(reference_map[i])*reference_image->columns*
971 reference_image->rows*reference_storage[j].quantum;
972 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
973 if (pixels == (unsigned char *) NULL)
975 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
978 reference_image=DestroyImage(reference_image);
981 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
982 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
983 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
985 if (status == MagickFalse)
987 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
990 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
991 reference_image=DestroyImage(reference_image);
994 (void) SetImageBackgroundColor(reference_image,exception);
995 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
996 reference_image->rows,reference_map[i],reference_storage[j].type,
998 if (status == MagickFalse)
1000 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1003 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1004 reference_image=DestroyImage(reference_image);
1008 Read reconstruct image.
1010 reconstruct_image=AcquireImage(image_info,exception);
1011 (void) SetImageExtent(reconstruct_image,reference_image->columns,
1012 reference_image->rows,exception);
1013 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
1015 (void) SetImageBackgroundColor(reconstruct_image,exception);
1016 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
1017 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
1019 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1020 if (status == MagickFalse)
1022 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1025 reference_image=DestroyImage(reference_image);
1029 Compare reference to reconstruct image.
1031 difference_image=CompareImages(reference_image,reconstruct_image,
1032 MeanSquaredErrorMetric,&distortion,exception);
1033 reconstruct_image=DestroyImage(reconstruct_image);
1034 reference_image=DestroyImage(reference_image);
1035 if (difference_image == (Image *) NULL)
1037 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1042 difference_image=DestroyImage(difference_image);
1043 if ((QuantumScale*distortion) > 0.0)
1045 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1046 QuantumScale*distortion);
1050 (void) FormatLocaleFile(stdout,"... pass.\n");
1053 (void) FormatLocaleFile(stdout,
1054 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1055 (double) (test-(*fail)),(double) *fail);
1060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 % V a l i d a t e M o n t a g e C o m m a n d %
1068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1070 % ValidateMontageCommand() validates the ImageMagick montage command line
1071 % program and returns the number of validation tests that passed and failed.
1073 % The format of the ValidateMontageCommand method is:
1075 % size_t ValidateMontageCommand(ImageInfo *image_info,
1076 % const char *reference_filename,const char *output_filename,
1077 % size_t *fail,ExceptionInfo *exception)
1079 % A description of each parameter follows:
1081 % o image_info: the image info.
1083 % o reference_filename: the reference image filename.
1085 % o output_filename: the output image filename.
1087 % o fail: return the number of validation tests that pass.
1089 % o exception: return any errors or warnings in this structure.
1092 static size_t ValidateMontageCommand(ImageInfo *image_info,
1093 const char *reference_filename,const char *output_filename,
1094 size_t *fail,ExceptionInfo *exception)
1098 command[MaxTextExtent];
1114 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1115 for (i=0; montage_options[i] != (char *) NULL; i++)
1117 CatchException(exception);
1118 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1119 montage_options[i]);
1120 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1121 reference_filename,montage_options[i],reference_filename,
1123 arguments=StringToArgv(command,&number_arguments);
1124 if (arguments == (char **) NULL)
1126 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1131 status=MontageImageCommand(image_info,number_arguments,arguments,
1132 (char **) NULL,exception);
1133 for (j=0; j < (ssize_t) number_arguments; j++)
1134 arguments[j]=DestroyString(arguments[j]);
1135 arguments=(char **) RelinquishMagickMemory(arguments);
1136 if (status != MagickFalse)
1138 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1143 (void) FormatLocaleFile(stdout,"... pass.\n");
1145 (void) FormatLocaleFile(stdout,
1146 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1147 (double) (test-(*fail)),(double) *fail);
1152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1156 % V a l i d a t e S t r e a m C o m m a n d %
1160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162 % ValidateStreamCommand() validates the ImageMagick stream command line
1163 % program and returns the number of validation tests that passed and failed.
1165 % The format of the ValidateStreamCommand method is:
1167 % size_t ValidateStreamCommand(ImageInfo *image_info,
1168 % const char *reference_filename,const char *output_filename,
1169 % size_t *fail,ExceptionInfo *exception)
1171 % A description of each parameter follows:
1173 % o image_info: the image info.
1175 % o reference_filename: the reference image filename.
1177 % o output_filename: the output image filename.
1179 % o fail: return the number of validation tests that pass.
1181 % o exception: return any errors or warnings in this structure.
1184 static size_t ValidateStreamCommand(ImageInfo *image_info,
1185 const char *reference_filename,const char *output_filename,
1186 size_t *fail,ExceptionInfo *exception)
1190 command[MaxTextExtent];
1206 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1207 for (i=0; stream_options[i] != (char *) NULL; i++)
1209 CatchException(exception);
1210 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1212 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1213 stream_options[i],reference_filename,output_filename);
1214 arguments=StringToArgv(command,&number_arguments);
1215 if (arguments == (char **) NULL)
1217 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1222 status=StreamImageCommand(image_info,number_arguments,arguments,
1223 (char **) NULL,exception);
1224 for (j=0; j < (ssize_t) number_arguments; j++)
1225 arguments[j]=DestroyString(arguments[j]);
1226 arguments=(char **) RelinquishMagickMemory(arguments);
1227 if (status != MagickFalse)
1229 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1234 (void) FormatLocaleFile(stdout,"... pass.\n");
1236 (void) FormatLocaleFile(stdout,
1237 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1238 (double) (test-(*fail)),(double) *fail);
1243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1256 static MagickBooleanType ValidateUsage(void)
1264 "-debug events display copious debugging information",
1265 "-help print program options",
1266 "-log format format of debugging information",
1267 "-validate type validation type",
1268 "-version print version information",
1273 "-regard-warnings pay attention to warning messages",
1274 "-verbose print detailed information about the image",
1278 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1279 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1280 (void) printf("Features: %s\n",GetMagickFeatures());
1281 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1282 (void) printf("\nValidate Settings:\n");
1283 for (p=settings; *p != (char *) NULL; p++)
1284 (void) printf(" %s\n",*p);
1285 (void) printf("\nMiscellaneous Options:\n");
1286 for (p=miscellaneous; *p != (char *) NULL; p++)
1287 (void) printf(" %s\n",*p);
1291 int main(int argc,char **argv)
1293 #define DestroyValidate() \
1295 image_info=DestroyImageInfo(image_info); \
1296 exception=DestroyExceptionInfo(exception); \
1298 #define ThrowValidateException(asperity,tag,option) \
1300 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1302 CatchException(exception); \
1303 DestroyValidate(); \
1304 return(MagickFalse); \
1308 output_filename[MaxTextExtent],
1309 reference_filename[MaxTextExtent],
1344 Validate the ImageMagick image processing suite.
1346 MagickCoreGenesis(*argv,MagickFalse);
1350 regard_warnings=MagickFalse;
1351 (void) regard_warnings;
1352 exception=AcquireExceptionInfo();
1353 image_info=AcquireImageInfo();
1354 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1355 for (i=1; i < (ssize_t) argc; i++)
1358 if (IsCommandOption(option) == MagickFalse)
1360 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1363 switch (*(option+1))
1367 if (LocaleCompare("bench",option+1) == 0)
1369 iterations=StringToUnsignedLong(argv[++i]);
1372 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1376 if (LocaleCompare("debug",option+1) == 0)
1378 (void) SetLogEventMask(argv[++i]);
1381 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1385 if (LocaleCompare("help",option+1) == 0)
1387 (void) ValidateUsage();
1390 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1394 if (LocaleCompare("log",option+1) == 0)
1397 (void) SetLogFormat(argv[i+1]);
1400 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1404 if (LocaleCompare("regard-warnings",option+1) == 0)
1406 regard_warnings=MagickTrue;
1409 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1413 if (LocaleCompare("validate",option+1) == 0)
1421 if (i == (ssize_t) argc)
1422 ThrowValidateException(OptionError,"MissingArgument",option);
1423 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1426 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1428 type=(ValidateType) validate;
1431 if ((LocaleCompare("version",option+1) == 0) ||
1432 (LocaleCompare("-version",option+1) == 0))
1434 (void) FormatLocaleFile(stdout,"Version: %s\n",
1435 GetMagickVersion((size_t *) NULL));
1436 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1437 GetMagickCopyright());
1438 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1439 GetMagickFeatures());
1442 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1445 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1448 timer=(TimerInfo *) NULL;
1450 timer=AcquireTimerInfo();
1451 reference_image=ReadImage(image_info,exception);
1454 if (reference_image == (Image *) NULL)
1458 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1459 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1461 (void) AcquireUniqueFilename(reference_filename);
1462 (void) AcquireUniqueFilename(output_filename);
1463 (void) CopyMagickString(reference_image->filename,reference_filename,
1465 status=WriteImage(image_info,reference_image,exception);
1466 reference_image=DestroyImage(reference_image);
1467 if (status == MagickFalse)
1471 (void) FormatLocaleFile(stdout,"Version: %s\n",
1472 GetMagickVersion((size_t *) NULL));
1473 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1474 GetMagickCopyright());
1475 (void) FormatLocaleFile(stdout,
1476 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1477 MagickValidateOptions,(ssize_t) type));
1478 if ((type & CompareValidate) != 0)
1479 tests+=ValidateCompareCommand(image_info,reference_filename,
1480 output_filename,&fail,exception);
1481 if ((type & CompositeValidate) != 0)
1482 tests+=ValidateCompositeCommand(image_info,reference_filename,
1483 output_filename,&fail,exception);
1484 if ((type & ConvertValidate) != 0)
1485 tests+=ValidateConvertCommand(image_info,reference_filename,
1486 output_filename,&fail,exception);
1487 if ((type & FormatsInMemoryValidate) != 0)
1488 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1489 output_filename,&fail,exception);
1490 if ((type & FormatsOnDiskValidate) != 0)
1491 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1492 output_filename,&fail,exception);
1493 if ((type & IdentifyValidate) != 0)
1494 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1495 output_filename,&fail,exception);
1496 if ((type & ImportExportValidate) != 0)
1497 tests+=ValidateImportExportPixels(image_info,reference_filename,
1498 output_filename,&fail,exception);
1499 if ((type & MontageValidate) != 0)
1500 tests+=ValidateMontageCommand(image_info,reference_filename,
1501 output_filename,&fail,exception);
1502 if ((type & StreamValidate) != 0)
1503 tests+=ValidateStreamCommand(image_info,reference_filename,
1504 output_filename,&fail,exception);
1505 (void) FormatLocaleFile(stdout,
1506 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1507 (double) tests,(double) (tests-fail),(double) fail);
1509 (void) RelinquishUniqueFileResource(output_filename);
1510 (void) RelinquishUniqueFileResource(reference_filename);
1512 if (exception->severity != UndefinedException)
1513 CatchException(exception);
1516 elapsed_time=GetElapsedTime(timer);
1517 user_time=GetUserTime(timer);
1518 (void) FormatLocaleFile(stderr,
1519 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1520 iterations,1.0*iterations/elapsed_time,user_time,(long)
1521 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1522 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1523 timer=DestroyTimerInfo(timer);
1526 MagickCoreTerminus();
1527 return(fail == 0 ? 0 : 1);