2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 % V V AAA L IIIII DDDD AAA TTTTT EEEEE %
8 % V V A A L I D D A A T E %
9 % V V AAAAA L I D D AAAAA T EEE %
10 % V V A A L I D D A A T E %
11 % V A A LLLLL IIIII DDDD A A T EEEEE %
14 % ImageMagick Validation Suite %
21 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % see the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 #include "MagickWand/MagickWand.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/string-private.h"
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 % V a l i d a t e C o m p a r e C o m m a n d %
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % ValidateCompareCommand() validates the ImageMagick compare command line
65 % program and returns the number of validation tests that passed and failed.
67 % The format of the ValidateCompareCommand method is:
69 % size_t ValidateCompareCommand(ImageInfo *image_info,
70 % const char *reference_filename,const char *output_filename,
71 % size_t *fail,ExceptionInfo *exception)
73 % A description of each parameter follows:
75 % o image_info: the image info.
77 % o reference_filename: the reference image filename.
79 % o output_filename: the output image filename.
81 % o fail: return the number of validation tests that pass.
83 % o exception: return any errors or warnings in this structure.
86 static size_t ValidateCompareCommand(ImageInfo *image_info,
87 const char *reference_filename,const char *output_filename,
88 size_t *fail,ExceptionInfo *exception)
92 command[MaxTextExtent];
108 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
109 for (i=0; compare_options[i] != (char *) NULL; i++)
111 CatchException(exception);
112 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
114 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
115 compare_options[i],reference_filename,reference_filename,output_filename);
116 arguments=StringToArgv(command,&number_arguments);
117 if (arguments == (char **) NULL)
119 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
124 status=CompareImagesCommand(image_info,number_arguments,arguments,
125 (char **) NULL,exception);
126 for (j=0; j < number_arguments; j++)
127 arguments[j]=DestroyString(arguments[j]);
128 arguments=(char **) RelinquishMagickMemory(arguments);
129 if (status != MagickFalse)
131 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
136 (void) FormatLocaleFile(stdout,"... pass.\n");
138 (void) FormatLocaleFile(stdout,
139 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
140 (double) (test-(*fail)),(double) *fail);
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % V a l i d a t e C o m p o s i t e C o m m a n d %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % ValidateCompositeCommand() validates the ImageMagick composite command line
156 % program and returns the number of validation tests that passed and failed.
158 % The format of the ValidateCompositeCommand method is:
160 % size_t ValidateCompositeCommand(ImageInfo *image_info,
161 % const char *reference_filename,const char *output_filename,
162 % size_t *fail,ExceptionInfo *exception)
164 % A description of each parameter follows:
166 % o image_info: the image info.
168 % o reference_filename: the reference image filename.
170 % o output_filename: the output image filename.
172 % o fail: return the number of validation tests that pass.
174 % o exception: return any errors or warnings in this structure.
177 static size_t ValidateCompositeCommand(ImageInfo *image_info,
178 const char *reference_filename,const char *output_filename,
179 size_t *fail,ExceptionInfo *exception)
183 command[MaxTextExtent];
199 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
200 for (i=0; composite_options[i] != (char *) NULL; i++)
202 CatchException(exception);
203 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
204 composite_options[i]);
205 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
206 reference_filename,composite_options[i],reference_filename,
208 arguments=StringToArgv(command,&number_arguments);
209 if (arguments == (char **) NULL)
211 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
216 status=CompositeImageCommand(image_info,number_arguments,arguments,
217 (char **) NULL,exception);
218 for (j=0; j < number_arguments; j++)
219 arguments[j]=DestroyString(arguments[j]);
220 arguments=(char **) RelinquishMagickMemory(arguments);
221 if (status != MagickFalse)
223 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
228 (void) FormatLocaleFile(stdout,"... pass.\n");
230 (void) FormatLocaleFile(stdout,
231 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
232 (double) (test-(*fail)),(double) *fail);
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 % V a l i d a t e C o n v e r t C o m m a n d %
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % ValidateConvertCommand() validates the ImageMagick convert command line
248 % program and returns the number of validation tests that passed and failed.
250 % The format of the ValidateConvertCommand method is:
252 % size_t ValidateConvertCommand(ImageInfo *image_info,
253 % const char *reference_filename,const char *output_filename,
254 % size_t *fail,ExceptionInfo *exception)
256 % A description of each parameter follows:
258 % o image_info: the image info.
260 % o reference_filename: the reference image filename.
262 % o output_filename: the output image filename.
264 % o fail: return the number of validation tests that pass.
266 % o exception: return any errors or warnings in this structure.
269 static size_t ValidateConvertCommand(ImageInfo *image_info,
270 const char *reference_filename,const char *output_filename,
271 size_t *fail,ExceptionInfo *exception)
275 command[MaxTextExtent];
291 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
292 for (i=0; convert_options[i] != (char *) NULL; i++)
294 CatchException(exception);
295 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
297 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
298 reference_filename,convert_options[i],reference_filename,output_filename);
299 arguments=StringToArgv(command,&number_arguments);
300 if (arguments == (char **) NULL)
302 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
307 status=ConvertImageCommand(image_info,number_arguments,arguments,
308 (char **) NULL,exception);
309 for (j=0; j < number_arguments; j++)
310 arguments[j]=DestroyString(arguments[j]);
311 arguments=(char **) RelinquishMagickMemory(arguments);
312 if (status != MagickFalse)
314 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
319 (void) FormatLocaleFile(stdout,"... pass.\n");
321 (void) FormatLocaleFile(stdout,
322 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
323 (double) (test-(*fail)),(double) *fail);
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % V a l i d a t e I d e n t i f y C o m m a n d %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % ValidateIdentifyCommand() validates the ImageMagick identify command line
339 % program and returns the number of validation tests that passed and failed.
341 % The format of the ValidateIdentifyCommand method is:
343 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
344 % const char *reference_filename,const char *output_filename,
345 % size_t *fail,ExceptionInfo *exception)
347 % A description of each parameter follows:
349 % o image_info: the image info.
351 % o reference_filename: the reference image filename.
353 % o output_filename: the output image filename.
355 % o fail: return the number of validation tests that pass.
357 % o exception: return any errors or warnings in this structure.
360 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
361 const char *reference_filename,const char *output_filename,
362 size_t *fail,ExceptionInfo *exception)
366 command[MaxTextExtent];
381 (void) output_filename;
383 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
384 for (i=0; identify_options[i] != (char *) NULL; i++)
386 CatchException(exception);
387 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
388 identify_options[i]);
389 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
390 identify_options[i],reference_filename);
391 arguments=StringToArgv(command,&number_arguments);
392 if (arguments == (char **) NULL)
394 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
399 status=IdentifyImageCommand(image_info,number_arguments,arguments,
400 (char **) NULL,exception);
401 for (j=0; j < number_arguments; j++)
402 arguments[j]=DestroyString(arguments[j]);
403 arguments=(char **) RelinquishMagickMemory(arguments);
404 if (status != MagickFalse)
406 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
411 (void) FormatLocaleFile(stdout,"... pass.\n");
413 (void) FormatLocaleFile(stdout,
414 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
415 (double) (test-(*fail)),(double) *fail);
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 % V a l i d a t e I m a g e F o r m a t s I n M e m o r y %
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
431 % memory and returns the number of validation tests that passed and failed.
433 % The format of the ValidateImageFormatsInMemory method is:
435 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
436 % const char *reference_filename,const char *output_filename,
437 % size_t *fail,ExceptionInfo *exception)
439 % A description of each parameter follows:
441 % o image_info: the image info.
443 % o reference_filename: the reference image filename.
445 % o output_filename: the output image filename.
447 % o fail: return the number of validation tests that pass.
449 % o exception: return any errors or warnings in this structure.
452 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
453 const char *reference_filename,const char *output_filename,
454 size_t *fail,ExceptionInfo *exception)
488 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
489 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
491 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
492 if ((magick_info == (const MagickInfo *) NULL) ||
493 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
494 (magick_info->encoder == (EncodeImageHandler *) NULL))
496 for (j=0; reference_types[j].type != UndefinedType; j++)
499 Generate reference image.
501 CatchException(exception);
502 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
503 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
504 MagickCompressOptions,reference_formats[i].compression),
505 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
506 (double) reference_types[j].depth);
507 (void) CopyMagickString(image_info->filename,reference_filename,
509 reference_image=ReadImage(image_info,exception);
510 if (reference_image == (Image *) NULL)
512 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
518 Write reference image.
520 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
521 (double) reference_image->columns,(double) reference_image->rows);
522 (void) CloneString(&image_info->size,size);
523 image_info->depth=reference_types[j].depth;
524 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
525 reference_formats[i].magick,output_filename);
526 status=SetImageType(reference_image,reference_types[j].type);
527 InheritException(exception,&reference_image->exception);
528 if (status == MagickFalse)
530 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
533 reference_image=DestroyImage(reference_image);
536 status=SetImageDepth(reference_image,reference_types[j].depth);
537 InheritException(exception,&reference_image->exception);
538 if (status == MagickFalse)
540 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
543 reference_image=DestroyImage(reference_image);
546 reference_image->compression=reference_formats[i].compression;
547 status=WriteImage(image_info,reference_image);
548 InheritException(exception,&reference_image->exception);
549 reference_image=DestroyImage(reference_image);
550 if (status == MagickFalse)
552 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
558 Read reference image.
560 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
561 reference_formats[i].magick,output_filename);
562 reference_image=ReadImage(image_info,exception);
563 if (reference_image == (Image *) NULL)
565 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
571 Write reference image.
573 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
574 reference_formats[i].magick,output_filename);
575 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
577 reference_image->depth=reference_types[j].depth;
578 reference_image->compression=reference_formats[i].compression;
580 blob=ImageToBlob(image_info,reference_image,&length,exception);
581 if (blob == (unsigned char *) NULL)
583 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
586 reference_image=DestroyImage(reference_image);
590 Read reconstruct image.
592 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
593 reference_formats[i].magick,output_filename);
594 reconstruct_image=BlobToImage(image_info,blob,length,exception);
595 blob=(unsigned char *) RelinquishMagickMemory(blob);
596 if (reconstruct_image == (Image *) NULL)
598 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
601 reference_image=DestroyImage(reference_image);
605 Compare reference to reconstruct image.
608 if (reference_formats[i].fuzz != 0.0)
609 fuzz=reference_formats[i].fuzz;
610 #if defined(MAGICKCORE_HDRI_SUPPORT)
613 if (IsRGBColorspace(reference_image->colorspace) == MagickFalse)
616 difference_image=CompareImages(reference_image,reconstruct_image,
617 MeanSquaredErrorMetric,&distortion,exception);
618 reconstruct_image=DestroyImage(reconstruct_image);
619 reference_image=DestroyImage(reference_image);
620 if (difference_image == (Image *) NULL)
622 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
627 difference_image=DestroyImage(difference_image);
628 if ((distortion/QuantumRange) > fuzz)
630 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
631 distortion/QuantumRange);
635 (void) FormatLocaleFile(stdout,"... pass.\n");
638 (void) FormatLocaleFile(stdout,
639 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
640 (double) (test-(*fail)),(double) *fail);
645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649 % 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 %
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
656 % and returns the number of validation tests that passed and failed.
658 % The format of the ValidateImageFormatsOnDisk method is:
660 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
661 % const char *reference_filename,const char *output_filename,
662 % size_t *fail,ExceptionInfo *exception)
664 % A description of each parameter follows:
666 % o image_info: the image info.
668 % o reference_filename: the reference image filename.
670 % o output_filename: the output image filename.
672 % o fail: return the number of validation tests that pass.
674 % o exception: return any errors or warnings in this structure.
677 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
678 const char *reference_filename,const char *output_filename,
679 size_t *fail,ExceptionInfo *exception)
707 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
708 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
710 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
711 if ((magick_info == (const MagickInfo *) NULL) ||
712 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
713 (magick_info->encoder == (EncodeImageHandler *) NULL))
715 for (j=0; reference_types[j].type != UndefinedType; j++)
718 Generate reference image.
720 CatchException(exception);
721 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
722 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
723 MagickCompressOptions,reference_formats[i].compression),
724 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
725 (double) reference_types[j].depth);
726 (void) CopyMagickString(image_info->filename,reference_filename,
728 reference_image=ReadImage(image_info,exception);
729 if (reference_image == (Image *) NULL)
731 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
737 Write reference image.
739 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
740 (double) reference_image->columns,(double) reference_image->rows);
741 (void) CloneString(&image_info->size,size);
742 image_info->depth=reference_types[j].depth;
743 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
744 reference_formats[i].magick,output_filename);
745 status=SetImageType(reference_image,reference_types[j].type);
746 InheritException(exception,&reference_image->exception);
747 if (status == MagickFalse)
749 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
752 reference_image=DestroyImage(reference_image);
755 status=SetImageDepth(reference_image,reference_types[j].depth);
756 InheritException(exception,&reference_image->exception);
757 if (status == MagickFalse)
759 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
762 reference_image=DestroyImage(reference_image);
765 reference_image->compression=reference_formats[i].compression;
766 status=WriteImage(image_info,reference_image);
767 InheritException(exception,&reference_image->exception);
768 reference_image=DestroyImage(reference_image);
769 if (status == MagickFalse)
771 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
777 Read reference image.
779 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
780 reference_formats[i].magick,output_filename);
781 reference_image=ReadImage(image_info,exception);
782 if (reference_image == (Image *) NULL)
784 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
790 Write reference image.
792 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
793 reference_formats[i].magick,output_filename);
794 reference_image->depth=reference_types[j].depth;
795 reference_image->compression=reference_formats[i].compression;
796 status=WriteImage(image_info,reference_image);
797 InheritException(exception,&reference_image->exception);
798 if (status == MagickFalse)
800 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
803 reference_image=DestroyImage(reference_image);
807 Read reconstruct image.
809 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
810 reference_formats[i].magick,output_filename);
811 reconstruct_image=ReadImage(image_info,exception);
812 if (reconstruct_image == (Image *) NULL)
814 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
817 reference_image=DestroyImage(reference_image);
821 Compare reference to reconstruct image.
824 if (reference_formats[i].fuzz != 0.0)
825 fuzz=reference_formats[i].fuzz;
826 #if defined(MAGICKCORE_HDRI_SUPPORT)
829 if (IsRGBColorspace(reference_image->colorspace) == MagickFalse)
832 difference_image=CompareImages(reference_image,reconstruct_image,
833 MeanSquaredErrorMetric,&distortion,exception);
834 reconstruct_image=DestroyImage(reconstruct_image);
835 reference_image=DestroyImage(reference_image);
836 if (difference_image == (Image *) NULL)
838 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
843 difference_image=DestroyImage(difference_image);
844 if ((distortion/QuantumRange) > fuzz)
846 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
847 distortion/QuantumRange);
851 (void) FormatLocaleFile(stdout,"... pass.\n");
854 (void) FormatLocaleFile(stdout,
855 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
856 (double) (test-(*fail)),(double) *fail);
861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
865 % 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 %
869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
871 % ValidateImportExportPixels() validates the pixel import and export methods.
872 % It returns the number of validation tests that passed and failed.
874 % The format of the ValidateImportExportPixels method is:
876 % size_t ValidateImportExportPixels(ImageInfo *image_info,
877 % const char *reference_filename,const char *output_filename,
878 % size_t *fail,ExceptionInfo *exception)
880 % A description of each parameter follows:
882 % o image_info: the image info.
884 % o reference_filename: the reference image filename.
886 % o output_filename: the output image filename.
888 % o fail: return the number of validation tests that pass.
890 % o exception: return any errors or warnings in this structure.
893 static size_t ValidateImportExportPixels(ImageInfo *image_info,
894 const char *reference_filename,const char *output_filename,
895 size_t *fail,ExceptionInfo *exception)
921 (void) output_filename;
923 (void) FormatLocaleFile(stdout,
924 "validate the import and export of image pixels:\n");
925 for (i=0; reference_map[i] != (char *) NULL; i++)
927 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
930 Generate reference image.
932 CatchException(exception);
933 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
934 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
935 reference_storage[j].type));
936 (void) CopyMagickString(image_info->filename,reference_filename,
938 reference_image=ReadImage(image_info,exception);
939 if (reference_image == (Image *) NULL)
941 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
946 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
947 (void) TransformImageColorspace(reference_image,CMYKColorspace);
948 length=strlen(reference_map[i])*reference_image->columns*
949 reference_image->rows*reference_storage[j].quantum;
950 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
951 if (pixels == (unsigned char *) NULL)
953 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
956 reference_image=DestroyImage(reference_image);
959 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
960 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
961 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
963 if (status == MagickFalse)
965 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
968 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
969 reference_image=DestroyImage(reference_image);
972 (void) SetImageBackgroundColor(reference_image);
973 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
974 reference_image->rows,reference_map[i],reference_storage[j].type,
976 InheritException(exception,&reference_image->exception);
977 if (status == MagickFalse)
979 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
982 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
983 reference_image=DestroyImage(reference_image);
987 Read reconstruct image.
989 reconstruct_image=AcquireImage(image_info);
990 (void) SetImageExtent(reconstruct_image,reference_image->columns,
991 reference_image->rows);
992 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
993 (void) SetImageBackgroundColor(reconstruct_image);
994 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
995 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
997 InheritException(exception,&reconstruct_image->exception);
998 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
999 if (status == MagickFalse)
1001 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1004 reference_image=DestroyImage(reference_image);
1008 Compare reference to reconstruct image.
1010 difference_image=CompareImages(reference_image,reconstruct_image,
1011 MeanSquaredErrorMetric,&distortion,exception);
1012 reconstruct_image=DestroyImage(reconstruct_image);
1013 reference_image=DestroyImage(reference_image);
1014 if (difference_image == (Image *) NULL)
1016 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1021 difference_image=DestroyImage(difference_image);
1022 if ((distortion/QuantumRange) > 0.0)
1024 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1025 distortion/QuantumRange);
1029 (void) FormatLocaleFile(stdout,"... pass.\n");
1032 (void) FormatLocaleFile(stdout,
1033 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1034 (double) (test-(*fail)),(double) *fail);
1039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043 % V a l i d a t e M o n t a g e C o m m a n d %
1047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049 % ValidateMontageCommand() validates the ImageMagick montage command line
1050 % program and returns the number of validation tests that passed and failed.
1052 % The format of the ValidateMontageCommand method is:
1054 % size_t ValidateMontageCommand(ImageInfo *image_info,
1055 % const char *reference_filename,const char *output_filename,
1056 % size_t *fail,ExceptionInfo *exception)
1058 % A description of each parameter follows:
1060 % o image_info: the image info.
1062 % o reference_filename: the reference image filename.
1064 % o output_filename: the output image filename.
1066 % o fail: return the number of validation tests that pass.
1068 % o exception: return any errors or warnings in this structure.
1071 static size_t ValidateMontageCommand(ImageInfo *image_info,
1072 const char *reference_filename,const char *output_filename,
1073 size_t *fail,ExceptionInfo *exception)
1077 command[MaxTextExtent];
1093 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1094 for (i=0; montage_options[i] != (char *) NULL; i++)
1096 CatchException(exception);
1097 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1098 montage_options[i]);
1099 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1100 reference_filename,montage_options[i],reference_filename,
1102 arguments=StringToArgv(command,&number_arguments);
1103 if (arguments == (char **) NULL)
1105 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1110 status=MontageImageCommand(image_info,number_arguments,arguments,
1111 (char **) NULL,exception);
1112 for (j=0; j < number_arguments; j++)
1113 arguments[j]=DestroyString(arguments[j]);
1114 arguments=(char **) RelinquishMagickMemory(arguments);
1115 if (status != MagickFalse)
1117 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1122 (void) FormatLocaleFile(stdout,"... pass.\n");
1124 (void) FormatLocaleFile(stdout,
1125 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1126 (double) (test-(*fail)),(double) *fail);
1131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1135 % V a l i d a t e S t r e a m C o m m a n d %
1139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141 % ValidateStreamCommand() validates the ImageMagick stream command line
1142 % program and returns the number of validation tests that passed and failed.
1144 % The format of the ValidateStreamCommand method is:
1146 % size_t ValidateStreamCommand(ImageInfo *image_info,
1147 % const char *reference_filename,const char *output_filename,
1148 % size_t *fail,ExceptionInfo *exception)
1150 % A description of each parameter follows:
1152 % o image_info: the image info.
1154 % o reference_filename: the reference image filename.
1156 % o output_filename: the output image filename.
1158 % o fail: return the number of validation tests that pass.
1160 % o exception: return any errors or warnings in this structure.
1163 static size_t ValidateStreamCommand(ImageInfo *image_info,
1164 const char *reference_filename,const char *output_filename,
1165 size_t *fail,ExceptionInfo *exception)
1169 command[MaxTextExtent];
1185 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1186 for (i=0; stream_options[i] != (char *) NULL; i++)
1188 CatchException(exception);
1189 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1191 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1192 stream_options[i],reference_filename,output_filename);
1193 arguments=StringToArgv(command,&number_arguments);
1194 if (arguments == (char **) NULL)
1196 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1201 status=StreamImageCommand(image_info,number_arguments,arguments,
1202 (char **) NULL,exception);
1203 for (j=0; j < number_arguments; j++)
1204 arguments[j]=DestroyString(arguments[j]);
1205 arguments=(char **) RelinquishMagickMemory(arguments);
1206 if (status != MagickFalse)
1208 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1213 (void) FormatLocaleFile(stdout,"... pass.\n");
1215 (void) FormatLocaleFile(stdout,
1216 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1217 (double) (test-(*fail)),(double) *fail);
1222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1235 static MagickBooleanType ValidateUsage(void)
1243 "-debug events display copious debugging information",
1244 "-help print program options",
1245 "-log format format of debugging information",
1246 "-validate type validation type",
1247 "-version print version information",
1252 "-regard-warnings pay attention to warning messages",
1253 "-verbose print detailed information about the image",
1257 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1258 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1259 (void) printf("Features: %s\n",GetMagickFeatures());
1260 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1261 (void) printf("\nValidate Settings:\n");
1262 for (p=settings; *p != (char *) NULL; p++)
1263 (void) printf(" %s\n",*p);
1264 (void) printf("\nMiscellaneous Options:\n");
1265 for (p=miscellaneous; *p != (char *) NULL; p++)
1266 (void) printf(" %s\n",*p);
1270 int main(int argc,char **argv)
1272 #define DestroyValidate() \
1274 image_info=DestroyImageInfo(image_info); \
1275 exception=DestroyExceptionInfo(exception); \
1277 #define ThrowValidateException(asperity,tag,option) \
1279 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1281 CatchException(exception); \
1282 DestroyValidate(); \
1283 return(MagickFalse); \
1287 output_filename[MaxTextExtent],
1288 reference_filename[MaxTextExtent],
1323 Validate the ImageMagick image processing suite.
1325 MagickCoreGenesis(*argv,MagickFalse);
1329 regard_warnings=MagickFalse;
1330 (void) regard_warnings;
1331 exception=AcquireExceptionInfo();
1332 image_info=AcquireImageInfo();
1333 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1334 for (i=1; i < (ssize_t) argc; i++)
1337 if (IsCommandOption(option) == MagickFalse)
1339 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1342 switch (*(option+1))
1346 if (LocaleCompare("bench",option+1) == 0)
1348 iterations=StringToUnsignedLong(argv[++i]);
1351 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1355 if (LocaleCompare("debug",option+1) == 0)
1357 (void) SetLogEventMask(argv[++i]);
1360 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1364 if (LocaleCompare("help",option+1) == 0)
1366 (void) ValidateUsage();
1369 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1373 if (LocaleCompare("log",option+1) == 0)
1376 (void) SetLogFormat(argv[i+1]);
1379 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1383 if (LocaleCompare("regard-warnings",option+1) == 0)
1385 regard_warnings=MagickTrue;
1388 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1392 if (LocaleCompare("validate",option+1) == 0)
1400 if (i == (ssize_t) argc)
1401 ThrowValidateException(OptionError,"MissingArgument",option);
1402 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1405 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1407 type=(ValidateType) validate;
1410 if ((LocaleCompare("version",option+1) == 0) ||
1411 (LocaleCompare("-version",option+1) == 0))
1413 (void) FormatLocaleFile(stdout,"Version: %s\n",
1414 GetMagickVersion((size_t *) NULL));
1415 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1416 GetMagickCopyright());
1417 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1418 GetMagickFeatures());
1421 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1424 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1427 timer=(TimerInfo *) NULL;
1429 timer=AcquireTimerInfo();
1430 reference_image=ReadImage(image_info,exception);
1433 if (reference_image == (Image *) NULL)
1437 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1438 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1440 (void) AcquireUniqueFilename(reference_filename);
1441 (void) AcquireUniqueFilename(output_filename);
1442 (void) CopyMagickString(reference_image->filename,reference_filename,
1444 status=WriteImage(image_info,reference_image);
1445 InheritException(exception,&reference_image->exception);
1446 reference_image=DestroyImage(reference_image);
1447 if (status == MagickFalse)
1451 (void) FormatLocaleFile(stdout,"Version: %s\n",
1452 GetMagickVersion((size_t *) NULL));
1453 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1454 GetMagickCopyright());
1455 (void) FormatLocaleFile(stdout,
1456 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1457 MagickValidateOptions,(ssize_t) type));
1458 if ((type & CompareValidate) != 0)
1459 tests+=ValidateCompareCommand(image_info,reference_filename,
1460 output_filename,&fail,exception);
1461 if ((type & CompositeValidate) != 0)
1462 tests+=ValidateCompositeCommand(image_info,reference_filename,
1463 output_filename,&fail,exception);
1464 if ((type & ConvertValidate) != 0)
1465 tests+=ValidateConvertCommand(image_info,reference_filename,
1466 output_filename,&fail,exception);
1467 if ((type & FormatsInMemoryValidate) != 0)
1468 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1469 output_filename,&fail,exception);
1470 if ((type & FormatsOnDiskValidate) != 0)
1471 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1472 output_filename,&fail,exception);
1473 if ((type & IdentifyValidate) != 0)
1474 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1475 output_filename,&fail,exception);
1476 if ((type & ImportExportValidate) != 0)
1477 tests+=ValidateImportExportPixels(image_info,reference_filename,
1478 output_filename,&fail,exception);
1479 if ((type & MontageValidate) != 0)
1480 tests+=ValidateMontageCommand(image_info,reference_filename,
1481 output_filename,&fail,exception);
1482 if ((type & StreamValidate) != 0)
1483 tests+=ValidateStreamCommand(image_info,reference_filename,
1484 output_filename,&fail,exception);
1485 (void) FormatLocaleFile(stdout,
1486 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1487 (double) tests,(double) (tests-fail),(double) fail);
1489 (void) RelinquishUniqueFileResource(output_filename);
1490 (void) RelinquishUniqueFileResource(reference_filename);
1492 if (exception->severity != UndefinedException)
1493 CatchException(exception);
1496 elapsed_time=GetElapsedTime(timer);
1497 user_time=GetUserTime(timer);
1498 (void) FormatLocaleFile(stderr,
1499 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1500 iterations,1.0*iterations/elapsed_time,user_time,(long)
1501 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1502 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1503 timer=DestroyTimerInfo(timer);
1506 MagickCoreTerminus();
1507 return(fail == 0 ? 0 : 1);