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"
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 < (ssize_t) 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 < (ssize_t) 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 < (ssize_t) 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 < (ssize_t) 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)
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,exception);
526 if (status == MagickFalse)
528 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
531 reference_image=DestroyImage(reference_image);
534 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
535 if (status == MagickFalse)
537 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
540 reference_image=DestroyImage(reference_image);
543 reference_image->compression=reference_formats[i].compression;
544 status=WriteImage(image_info,reference_image,exception);
545 reference_image=DestroyImage(reference_image);
546 if (status == MagickFalse)
548 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
554 Ping reference image.
556 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
557 reference_formats[i].magick,output_filename);
558 ping_image=PingImage(image_info,exception);
559 if (ping_image == (Image *) NULL)
561 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
566 ping_image=DestroyImage(ping_image);
568 Read reference image.
570 reference_image=ReadImage(image_info,exception);
571 if (reference_image == (Image *) NULL)
573 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
579 Write reference image.
581 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
582 reference_formats[i].magick,output_filename);
583 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
585 reference_image->depth=reference_types[j].depth;
586 reference_image->compression=reference_formats[i].compression;
588 blob=ImageToBlob(image_info,reference_image,&length,exception);
589 if (blob == (unsigned char *) NULL)
591 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
594 reference_image=DestroyImage(reference_image);
600 ping_image=PingBlob(image_info,blob,length,exception);
601 if (ping_image == (Image *) NULL)
603 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
606 blob=(unsigned char *) RelinquishMagickMemory(blob);
609 ping_image=DestroyImage(ping_image);
611 Read reconstruct image.
613 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
614 reference_formats[i].magick,output_filename);
615 reconstruct_image=BlobToImage(image_info,blob,length,exception);
616 blob=(unsigned char *) RelinquishMagickMemory(blob);
617 if (reconstruct_image == (Image *) NULL)
619 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
622 reference_image=DestroyImage(reference_image);
626 Compare reference to reconstruct image.
629 if (reference_formats[i].fuzz != 0.0)
630 fuzz=reference_formats[i].fuzz;
631 #if defined(MAGICKCORE_HDRI_SUPPORT)
634 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
637 difference_image=CompareImages(reference_image,reconstruct_image,
638 MeanSquaredErrorMetric,&distortion,exception);
639 reconstruct_image=DestroyImage(reconstruct_image);
640 reference_image=DestroyImage(reference_image);
641 if (difference_image == (Image *) NULL)
643 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
648 difference_image=DestroyImage(difference_image);
649 if ((distortion/QuantumRange) > fuzz)
651 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
652 distortion/QuantumRange);
656 (void) FormatLocaleFile(stdout,"... pass.\n");
659 (void) FormatLocaleFile(stdout,
660 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
661 (double) (test-(*fail)),(double) *fail);
666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 % 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 %
674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
677 % and returns the number of validation tests that passed and failed.
679 % The format of the ValidateImageFormatsOnDisk method is:
681 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
682 % const char *reference_filename,const char *output_filename,
683 % size_t *fail,ExceptionInfo *exception)
685 % A description of each parameter follows:
687 % o image_info: the image info.
689 % o reference_filename: the reference image filename.
691 % o output_filename: the output image filename.
693 % o fail: return the number of validation tests that pass.
695 % o exception: return any errors or warnings in this structure.
698 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
699 const char *reference_filename,const char *output_filename,
700 size_t *fail,ExceptionInfo *exception)
728 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
729 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
731 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
732 if ((magick_info == (const MagickInfo *) NULL) ||
733 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
734 (magick_info->encoder == (EncodeImageHandler *) NULL))
736 for (j=0; reference_types[j].type != UndefinedType; j++)
739 Generate reference image.
741 CatchException(exception);
742 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
743 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
744 MagickCompressOptions,reference_formats[i].compression),
745 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
746 (double) reference_types[j].depth);
747 (void) CopyMagickString(image_info->filename,reference_filename,
749 reference_image=ReadImage(image_info,exception);
750 if (reference_image == (Image *) NULL)
752 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
758 Write reference image.
760 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
761 (double) reference_image->columns,(double) reference_image->rows);
762 (void) CloneString(&image_info->size,size);
763 image_info->depth=reference_types[j].depth;
764 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
765 reference_formats[i].magick,output_filename);
766 status=SetImageType(reference_image,reference_types[j].type,exception);
767 if (status == MagickFalse)
769 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
772 reference_image=DestroyImage(reference_image);
775 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
776 if (status == MagickFalse)
778 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
781 reference_image=DestroyImage(reference_image);
784 reference_image->compression=reference_formats[i].compression;
785 status=WriteImage(image_info,reference_image,exception);
786 reference_image=DestroyImage(reference_image);
787 if (status == MagickFalse)
789 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
795 Read reference image.
797 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
798 reference_formats[i].magick,output_filename);
799 reference_image=ReadImage(image_info,exception);
800 if (reference_image == (Image *) NULL)
802 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
808 Write reference image.
810 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
811 reference_formats[i].magick,output_filename);
812 reference_image->depth=reference_types[j].depth;
813 reference_image->compression=reference_formats[i].compression;
814 status=WriteImage(image_info,reference_image,exception);
815 if (status == MagickFalse)
817 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
820 reference_image=DestroyImage(reference_image);
824 Read reconstruct image.
826 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
827 reference_formats[i].magick,output_filename);
828 reconstruct_image=ReadImage(image_info,exception);
829 if (reconstruct_image == (Image *) NULL)
831 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
834 reference_image=DestroyImage(reference_image);
838 Compare reference to reconstruct image.
841 if (reference_formats[i].fuzz != 0.0)
842 fuzz=reference_formats[i].fuzz;
843 #if defined(MAGICKCORE_HDRI_SUPPORT)
846 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
849 difference_image=CompareImages(reference_image,reconstruct_image,
850 MeanSquaredErrorMetric,&distortion,exception);
851 reconstruct_image=DestroyImage(reconstruct_image);
852 reference_image=DestroyImage(reference_image);
853 if (difference_image == (Image *) NULL)
855 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
860 difference_image=DestroyImage(difference_image);
861 if ((distortion/QuantumRange) > fuzz)
863 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
864 distortion/QuantumRange);
868 (void) FormatLocaleFile(stdout,"... pass.\n");
871 (void) FormatLocaleFile(stdout,
872 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
873 (double) (test-(*fail)),(double) *fail);
878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 % 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 %
886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888 % ValidateImportExportPixels() validates the pixel import and export methods.
889 % It returns the number of validation tests that passed and failed.
891 % The format of the ValidateImportExportPixels method is:
893 % size_t ValidateImportExportPixels(ImageInfo *image_info,
894 % const char *reference_filename,const char *output_filename,
895 % size_t *fail,ExceptionInfo *exception)
897 % A description of each parameter follows:
899 % o image_info: the image info.
901 % o reference_filename: the reference image filename.
903 % o output_filename: the output image filename.
905 % o fail: return the number of validation tests that pass.
907 % o exception: return any errors or warnings in this structure.
910 static size_t ValidateImportExportPixels(ImageInfo *image_info,
911 const char *reference_filename,const char *output_filename,
912 size_t *fail,ExceptionInfo *exception)
938 (void) output_filename;
940 (void) FormatLocaleFile(stdout,
941 "validate the import and export of image pixels:\n");
942 for (i=0; reference_map[i] != (char *) NULL; i++)
944 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
947 Generate reference image.
949 CatchException(exception);
950 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
951 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
952 reference_storage[j].type));
953 (void) CopyMagickString(image_info->filename,reference_filename,
955 reference_image=ReadImage(image_info,exception);
956 if (reference_image == (Image *) NULL)
958 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
963 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
964 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
965 length=strlen(reference_map[i])*reference_image->columns*
966 reference_image->rows*reference_storage[j].quantum;
967 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
968 if (pixels == (unsigned char *) NULL)
970 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
973 reference_image=DestroyImage(reference_image);
976 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
977 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
978 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
980 if (status == MagickFalse)
982 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
985 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
986 reference_image=DestroyImage(reference_image);
989 (void) SetImageBackgroundColor(reference_image,exception);
990 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
991 reference_image->rows,reference_map[i],reference_storage[j].type,
993 if (status == MagickFalse)
995 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
998 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
999 reference_image=DestroyImage(reference_image);
1003 Read reconstruct image.
1005 reconstruct_image=AcquireImage(image_info,exception);
1006 (void) SetImageExtent(reconstruct_image,reference_image->columns,
1007 reference_image->rows,exception);
1008 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
1010 (void) SetImageBackgroundColor(reconstruct_image,exception);
1011 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
1012 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
1014 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1015 if (status == MagickFalse)
1017 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1020 reference_image=DestroyImage(reference_image);
1024 Compare reference to reconstruct image.
1026 difference_image=CompareImages(reference_image,reconstruct_image,
1027 MeanSquaredErrorMetric,&distortion,exception);
1028 reconstruct_image=DestroyImage(reconstruct_image);
1029 reference_image=DestroyImage(reference_image);
1030 if (difference_image == (Image *) NULL)
1032 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1037 difference_image=DestroyImage(difference_image);
1038 if ((distortion/QuantumRange) > 0.0)
1040 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1041 distortion/QuantumRange);
1045 (void) FormatLocaleFile(stdout,"... pass.\n");
1048 (void) FormatLocaleFile(stdout,
1049 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1050 (double) (test-(*fail)),(double) *fail);
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 % V a l i d a t e M o n t a g e C o m m a n d %
1063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1065 % ValidateMontageCommand() validates the ImageMagick montage command line
1066 % program and returns the number of validation tests that passed and failed.
1068 % The format of the ValidateMontageCommand method is:
1070 % size_t ValidateMontageCommand(ImageInfo *image_info,
1071 % const char *reference_filename,const char *output_filename,
1072 % size_t *fail,ExceptionInfo *exception)
1074 % A description of each parameter follows:
1076 % o image_info: the image info.
1078 % o reference_filename: the reference image filename.
1080 % o output_filename: the output image filename.
1082 % o fail: return the number of validation tests that pass.
1084 % o exception: return any errors or warnings in this structure.
1087 static size_t ValidateMontageCommand(ImageInfo *image_info,
1088 const char *reference_filename,const char *output_filename,
1089 size_t *fail,ExceptionInfo *exception)
1093 command[MaxTextExtent];
1109 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1110 for (i=0; montage_options[i] != (char *) NULL; i++)
1112 CatchException(exception);
1113 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1114 montage_options[i]);
1115 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1116 reference_filename,montage_options[i],reference_filename,
1118 arguments=StringToArgv(command,&number_arguments);
1119 if (arguments == (char **) NULL)
1121 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1126 status=MontageImageCommand(image_info,number_arguments,arguments,
1127 (char **) NULL,exception);
1128 for (j=0; j < (ssize_t) number_arguments; j++)
1129 arguments[j]=DestroyString(arguments[j]);
1130 arguments=(char **) RelinquishMagickMemory(arguments);
1131 if (status != MagickFalse)
1133 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1138 (void) FormatLocaleFile(stdout,"... pass.\n");
1140 (void) FormatLocaleFile(stdout,
1141 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1142 (double) (test-(*fail)),(double) *fail);
1147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1151 % V a l i d a t e S t r e a m C o m m a n d %
1155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 % ValidateStreamCommand() validates the ImageMagick stream command line
1158 % program and returns the number of validation tests that passed and failed.
1160 % The format of the ValidateStreamCommand method is:
1162 % size_t ValidateStreamCommand(ImageInfo *image_info,
1163 % const char *reference_filename,const char *output_filename,
1164 % size_t *fail,ExceptionInfo *exception)
1166 % A description of each parameter follows:
1168 % o image_info: the image info.
1170 % o reference_filename: the reference image filename.
1172 % o output_filename: the output image filename.
1174 % o fail: return the number of validation tests that pass.
1176 % o exception: return any errors or warnings in this structure.
1179 static size_t ValidateStreamCommand(ImageInfo *image_info,
1180 const char *reference_filename,const char *output_filename,
1181 size_t *fail,ExceptionInfo *exception)
1185 command[MaxTextExtent];
1201 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1202 for (i=0; stream_options[i] != (char *) NULL; i++)
1204 CatchException(exception);
1205 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1207 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1208 stream_options[i],reference_filename,output_filename);
1209 arguments=StringToArgv(command,&number_arguments);
1210 if (arguments == (char **) NULL)
1212 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1217 status=StreamImageCommand(image_info,number_arguments,arguments,
1218 (char **) NULL,exception);
1219 for (j=0; j < (ssize_t) number_arguments; j++)
1220 arguments[j]=DestroyString(arguments[j]);
1221 arguments=(char **) RelinquishMagickMemory(arguments);
1222 if (status != MagickFalse)
1224 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1229 (void) FormatLocaleFile(stdout,"... pass.\n");
1231 (void) FormatLocaleFile(stdout,
1232 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1233 (double) (test-(*fail)),(double) *fail);
1238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1251 static MagickBooleanType ValidateUsage(void)
1259 "-debug events display copious debugging information",
1260 "-help print program options",
1261 "-log format format of debugging information",
1262 "-validate type validation type",
1263 "-version print version information",
1268 "-regard-warnings pay attention to warning messages",
1269 "-verbose print detailed information about the image",
1273 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1274 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1275 (void) printf("Features: %s\n",GetMagickFeatures());
1276 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1277 (void) printf("\nValidate Settings:\n");
1278 for (p=settings; *p != (char *) NULL; p++)
1279 (void) printf(" %s\n",*p);
1280 (void) printf("\nMiscellaneous Options:\n");
1281 for (p=miscellaneous; *p != (char *) NULL; p++)
1282 (void) printf(" %s\n",*p);
1286 int main(int argc,char **argv)
1288 #define DestroyValidate() \
1290 image_info=DestroyImageInfo(image_info); \
1291 exception=DestroyExceptionInfo(exception); \
1293 #define ThrowValidateException(asperity,tag,option) \
1295 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1297 CatchException(exception); \
1298 DestroyValidate(); \
1299 return(MagickFalse); \
1303 output_filename[MaxTextExtent],
1304 reference_filename[MaxTextExtent],
1339 Validate the ImageMagick image processing suite.
1341 MagickCoreGenesis(*argv,MagickFalse);
1345 regard_warnings=MagickFalse;
1346 (void) regard_warnings;
1347 exception=AcquireExceptionInfo();
1348 image_info=AcquireImageInfo();
1349 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1350 for (i=1; i < (ssize_t) argc; i++)
1353 if (IsCommandOption(option) == MagickFalse)
1355 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1358 switch (*(option+1))
1362 if (LocaleCompare("bench",option+1) == 0)
1364 iterations=StringToUnsignedLong(argv[++i]);
1367 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1371 if (LocaleCompare("debug",option+1) == 0)
1373 (void) SetLogEventMask(argv[++i]);
1376 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1380 if (LocaleCompare("help",option+1) == 0)
1382 (void) ValidateUsage();
1385 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1389 if (LocaleCompare("log",option+1) == 0)
1392 (void) SetLogFormat(argv[i+1]);
1395 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1399 if (LocaleCompare("regard-warnings",option+1) == 0)
1401 regard_warnings=MagickTrue;
1404 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1408 if (LocaleCompare("validate",option+1) == 0)
1416 if (i == (ssize_t) argc)
1417 ThrowValidateException(OptionError,"MissingArgument",option);
1418 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1421 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1423 type=(ValidateType) validate;
1426 if ((LocaleCompare("version",option+1) == 0) ||
1427 (LocaleCompare("-version",option+1) == 0))
1429 (void) FormatLocaleFile(stdout,"Version: %s\n",
1430 GetMagickVersion((size_t *) NULL));
1431 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1432 GetMagickCopyright());
1433 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1434 GetMagickFeatures());
1437 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1440 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1443 timer=(TimerInfo *) NULL;
1445 timer=AcquireTimerInfo();
1446 reference_image=ReadImage(image_info,exception);
1449 if (reference_image == (Image *) NULL)
1453 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1454 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1456 (void) AcquireUniqueFilename(reference_filename);
1457 (void) AcquireUniqueFilename(output_filename);
1458 (void) CopyMagickString(reference_image->filename,reference_filename,
1460 status=WriteImage(image_info,reference_image,exception);
1461 reference_image=DestroyImage(reference_image);
1462 if (status == MagickFalse)
1466 (void) FormatLocaleFile(stdout,"Version: %s\n",
1467 GetMagickVersion((size_t *) NULL));
1468 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1469 GetMagickCopyright());
1470 (void) FormatLocaleFile(stdout,
1471 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1472 MagickValidateOptions,(ssize_t) type));
1473 if ((type & CompareValidate) != 0)
1474 tests+=ValidateCompareCommand(image_info,reference_filename,
1475 output_filename,&fail,exception);
1476 if ((type & CompositeValidate) != 0)
1477 tests+=ValidateCompositeCommand(image_info,reference_filename,
1478 output_filename,&fail,exception);
1479 if ((type & ConvertValidate) != 0)
1480 tests+=ValidateConvertCommand(image_info,reference_filename,
1481 output_filename,&fail,exception);
1482 if ((type & FormatsInMemoryValidate) != 0)
1483 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1484 output_filename,&fail,exception);
1485 if ((type & FormatsOnDiskValidate) != 0)
1486 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1487 output_filename,&fail,exception);
1488 if ((type & IdentifyValidate) != 0)
1489 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1490 output_filename,&fail,exception);
1491 if ((type & ImportExportValidate) != 0)
1492 tests+=ValidateImportExportPixels(image_info,reference_filename,
1493 output_filename,&fail,exception);
1494 if ((type & MontageValidate) != 0)
1495 tests+=ValidateMontageCommand(image_info,reference_filename,
1496 output_filename,&fail,exception);
1497 if ((type & StreamValidate) != 0)
1498 tests+=ValidateStreamCommand(image_info,reference_filename,
1499 output_filename,&fail,exception);
1500 (void) FormatLocaleFile(stdout,
1501 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1502 (double) tests,(double) (tests-fail),(double) fail);
1504 (void) RelinquishUniqueFileResource(output_filename);
1505 (void) RelinquishUniqueFileResource(reference_filename);
1507 if (exception->severity != UndefinedException)
1508 CatchException(exception);
1511 elapsed_time=GetElapsedTime(timer);
1512 user_time=GetUserTime(timer);
1513 (void) FormatLocaleFile(stderr,
1514 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1515 iterations,1.0*iterations/elapsed_time,user_time,(long)
1516 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1517 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1518 timer=DestroyTimerInfo(timer);
1521 MagickCoreTerminus();
1522 return(fail == 0 ? 0 : 1);