2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 % V V AAA L IIIII DDDD AAA TTTTT EEEEE %
8 % V V A A L I D D A A T E %
9 % V V AAAAA L I D D AAAAA T EEE %
10 % V V A A L I D D A A T E %
11 % V A A LLLLL IIIII DDDD A A T EEEEE %
14 % ImageMagick Validation Suite %
21 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % see the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 #include "MagickWand/MagickWand.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/string-private.h"
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 % V a l i d a t e C o m p a r e C o m m a n d %
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % ValidateCompareCommand() validates the ImageMagick compare command line
65 % program and returns the number of validation tests that passed and failed.
67 % The format of the ValidateCompareCommand method is:
69 % size_t ValidateCompareCommand(ImageInfo *image_info,
70 % const char *reference_filename,const char *output_filename,
71 % size_t *fail,ExceptionInfo *exception)
73 % A description of each parameter follows:
75 % o image_info: the image info.
77 % o reference_filename: the reference image filename.
79 % o output_filename: the output image filename.
81 % o fail: return the number of validation tests that pass.
83 % o exception: return any errors or warnings in this structure.
86 static size_t ValidateCompareCommand(ImageInfo *image_info,
87 const char *reference_filename,const char *output_filename,
88 size_t *fail,ExceptionInfo *exception)
92 command[MaxTextExtent];
108 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
109 for (i=0; compare_options[i] != (char *) NULL; i++)
111 CatchException(exception);
112 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
114 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
115 compare_options[i],reference_filename,reference_filename,output_filename);
116 arguments=StringToArgv(command,&number_arguments);
117 if (arguments == (char **) NULL)
119 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
124 status=CompareImagesCommand(image_info,number_arguments,arguments,
125 (char **) NULL,exception);
126 for (j=0; j < number_arguments; j++)
127 arguments[j]=DestroyString(arguments[j]);
128 arguments=(char **) RelinquishMagickMemory(arguments);
129 if (status != MagickFalse)
131 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
136 (void) FormatLocaleFile(stdout,"... pass.\n");
138 (void) FormatLocaleFile(stdout,
139 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
140 (double) (test-(*fail)),(double) *fail);
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % V a l i d a t e C o m p o s i t e C o m m a n d %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % ValidateCompositeCommand() validates the ImageMagick composite command line
156 % program and returns the number of validation tests that passed and failed.
158 % The format of the ValidateCompositeCommand method is:
160 % size_t ValidateCompositeCommand(ImageInfo *image_info,
161 % const char *reference_filename,const char *output_filename,
162 % size_t *fail,ExceptionInfo *exception)
164 % A description of each parameter follows:
166 % o image_info: the image info.
168 % o reference_filename: the reference image filename.
170 % o output_filename: the output image filename.
172 % o fail: return the number of validation tests that pass.
174 % o exception: return any errors or warnings in this structure.
177 static size_t ValidateCompositeCommand(ImageInfo *image_info,
178 const char *reference_filename,const char *output_filename,
179 size_t *fail,ExceptionInfo *exception)
183 command[MaxTextExtent];
199 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
200 for (i=0; composite_options[i] != (char *) NULL; i++)
202 CatchException(exception);
203 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
204 composite_options[i]);
205 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
206 reference_filename,composite_options[i],reference_filename,
208 arguments=StringToArgv(command,&number_arguments);
209 if (arguments == (char **) NULL)
211 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
216 status=CompositeImageCommand(image_info,number_arguments,arguments,
217 (char **) NULL,exception);
218 for (j=0; j < number_arguments; j++)
219 arguments[j]=DestroyString(arguments[j]);
220 arguments=(char **) RelinquishMagickMemory(arguments);
221 if (status != MagickFalse)
223 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
228 (void) FormatLocaleFile(stdout,"... pass.\n");
230 (void) FormatLocaleFile(stdout,
231 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
232 (double) (test-(*fail)),(double) *fail);
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 % V a l i d a t e C o n v e r t C o m m a n d %
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % ValidateConvertCommand() validates the ImageMagick convert command line
248 % program and returns the number of validation tests that passed and failed.
250 % The format of the ValidateConvertCommand method is:
252 % size_t ValidateConvertCommand(ImageInfo *image_info,
253 % const char *reference_filename,const char *output_filename,
254 % size_t *fail,ExceptionInfo *exception)
256 % A description of each parameter follows:
258 % o image_info: the image info.
260 % o reference_filename: the reference image filename.
262 % o output_filename: the output image filename.
264 % o fail: return the number of validation tests that pass.
266 % o exception: return any errors or warnings in this structure.
269 static size_t ValidateConvertCommand(ImageInfo *image_info,
270 const char *reference_filename,const char *output_filename,
271 size_t *fail,ExceptionInfo *exception)
275 command[MaxTextExtent];
291 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
292 for (i=0; convert_options[i] != (char *) NULL; i++)
294 CatchException(exception);
295 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
297 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
298 reference_filename,convert_options[i],reference_filename,output_filename);
299 arguments=StringToArgv(command,&number_arguments);
300 if (arguments == (char **) NULL)
302 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
307 status=ConvertImageCommand(image_info,number_arguments,arguments,
308 (char **) NULL,exception);
309 for (j=0; j < number_arguments; j++)
310 arguments[j]=DestroyString(arguments[j]);
311 arguments=(char **) RelinquishMagickMemory(arguments);
312 if (status != MagickFalse)
314 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
319 (void) FormatLocaleFile(stdout,"... pass.\n");
321 (void) FormatLocaleFile(stdout,
322 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
323 (double) (test-(*fail)),(double) *fail);
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % V a l i d a t e I d e n t i f y C o m m a n d %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % ValidateIdentifyCommand() validates the ImageMagick identify command line
339 % program and returns the number of validation tests that passed and failed.
341 % The format of the ValidateIdentifyCommand method is:
343 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
344 % const char *reference_filename,const char *output_filename,
345 % size_t *fail,ExceptionInfo *exception)
347 % A description of each parameter follows:
349 % o image_info: the image info.
351 % o reference_filename: the reference image filename.
353 % o output_filename: the output image filename.
355 % o fail: return the number of validation tests that pass.
357 % o exception: return any errors or warnings in this structure.
360 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
361 const char *reference_filename,const char *output_filename,
362 size_t *fail,ExceptionInfo *exception)
366 command[MaxTextExtent];
381 (void) output_filename;
383 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
384 for (i=0; identify_options[i] != (char *) NULL; i++)
386 CatchException(exception);
387 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
388 identify_options[i]);
389 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
390 identify_options[i],reference_filename);
391 arguments=StringToArgv(command,&number_arguments);
392 if (arguments == (char **) NULL)
394 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
399 status=IdentifyImageCommand(image_info,number_arguments,arguments,
400 (char **) NULL,exception);
401 for (j=0; j < number_arguments; j++)
402 arguments[j]=DestroyString(arguments[j]);
403 arguments=(char **) RelinquishMagickMemory(arguments);
404 if (status != MagickFalse)
406 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
411 (void) FormatLocaleFile(stdout,"... pass.\n");
413 (void) FormatLocaleFile(stdout,
414 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
415 (double) (test-(*fail)),(double) *fail);
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 % V a l i d a t e I m a g e F o r m a t s I n M e m o r y %
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
431 % memory and returns the number of validation tests that passed and failed.
433 % The format of the ValidateImageFormatsInMemory method is:
435 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
436 % const char *reference_filename,const char *output_filename,
437 % size_t *fail,ExceptionInfo *exception)
439 % A description of each parameter follows:
441 % o image_info: the image info.
443 % o reference_filename: the reference image filename.
445 % o output_filename: the output image filename.
447 % o fail: return the number of validation tests that pass.
449 % o exception: return any errors or warnings in this structure.
452 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
453 const char *reference_filename,const char *output_filename,
454 size_t *fail,ExceptionInfo *exception)
488 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
489 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
491 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
492 if ((magick_info == (const MagickInfo *) NULL) ||
493 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
494 (magick_info->encoder == (EncodeImageHandler *) NULL))
496 for (j=0; reference_types[j].type != UndefinedType; j++)
499 Generate reference image.
501 CatchException(exception);
502 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
503 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
504 MagickCompressOptions,reference_formats[i].compression),
505 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
506 (double) reference_types[j].depth);
507 (void) CopyMagickString(image_info->filename,reference_filename,
509 reference_image=ReadImage(image_info,exception);
510 if (reference_image == (Image *) NULL)
512 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
518 Write reference image.
520 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
521 (double) reference_image->columns,(double) reference_image->rows);
522 (void) CloneString(&image_info->size,size);
523 image_info->depth=reference_types[j].depth;
524 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
525 reference_formats[i].magick,output_filename);
526 status=SetImageType(reference_image,reference_types[j].type,exception);
527 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,exception);
548 reference_image=DestroyImage(reference_image);
549 if (status == MagickFalse)
551 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
557 Read reference image.
559 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
560 reference_formats[i].magick,output_filename);
561 reference_image=ReadImage(image_info,exception);
562 if (reference_image == (Image *) NULL)
564 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
570 Write reference image.
572 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
573 reference_formats[i].magick,output_filename);
574 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
576 reference_image->depth=reference_types[j].depth;
577 reference_image->compression=reference_formats[i].compression;
579 blob=ImageToBlob(image_info,reference_image,&length,exception);
580 if (blob == (unsigned char *) NULL)
582 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
585 reference_image=DestroyImage(reference_image);
589 Read reconstruct image.
591 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
592 reference_formats[i].magick,output_filename);
593 reconstruct_image=BlobToImage(image_info,blob,length,exception);
594 blob=(unsigned char *) RelinquishMagickMemory(blob);
595 if (reconstruct_image == (Image *) NULL)
597 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
600 reference_image=DestroyImage(reference_image);
604 Compare reference to reconstruct image.
607 if (reference_formats[i].fuzz != 0.0)
608 fuzz=reference_formats[i].fuzz;
609 #if defined(MAGICKCORE_HDRI_SUPPORT)
612 if (IsRGBColorspace(reference_image->colorspace) == MagickFalse)
615 difference_image=CompareImages(reference_image,reconstruct_image,
616 MeanSquaredErrorMetric,&distortion,exception);
617 reconstruct_image=DestroyImage(reconstruct_image);
618 reference_image=DestroyImage(reference_image);
619 if (difference_image == (Image *) NULL)
621 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
626 difference_image=DestroyImage(difference_image);
627 if ((distortion/QuantumRange) > fuzz)
629 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
630 distortion/QuantumRange);
634 (void) FormatLocaleFile(stdout,"... pass.\n");
637 (void) FormatLocaleFile(stdout,
638 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
639 (double) (test-(*fail)),(double) *fail);
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 % V a l i d a t e I m a g e F o r m a t s O n D i s k %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
655 % and returns the number of validation tests that passed and failed.
657 % The format of the ValidateImageFormatsOnDisk method is:
659 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
660 % const char *reference_filename,const char *output_filename,
661 % size_t *fail,ExceptionInfo *exception)
663 % A description of each parameter follows:
665 % o image_info: the image info.
667 % o reference_filename: the reference image filename.
669 % o output_filename: the output image filename.
671 % o fail: return the number of validation tests that pass.
673 % o exception: return any errors or warnings in this structure.
676 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
677 const char *reference_filename,const char *output_filename,
678 size_t *fail,ExceptionInfo *exception)
706 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
707 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
709 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
710 if ((magick_info == (const MagickInfo *) NULL) ||
711 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
712 (magick_info->encoder == (EncodeImageHandler *) NULL))
714 for (j=0; reference_types[j].type != UndefinedType; j++)
717 Generate reference image.
719 CatchException(exception);
720 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
721 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
722 MagickCompressOptions,reference_formats[i].compression),
723 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
724 (double) reference_types[j].depth);
725 (void) CopyMagickString(image_info->filename,reference_filename,
727 reference_image=ReadImage(image_info,exception);
728 if (reference_image == (Image *) NULL)
730 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
736 Write reference image.
738 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
739 (double) reference_image->columns,(double) reference_image->rows);
740 (void) CloneString(&image_info->size,size);
741 image_info->depth=reference_types[j].depth;
742 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
743 reference_formats[i].magick,output_filename);
744 status=SetImageType(reference_image,reference_types[j].type,exception);
745 InheritException(exception,&reference_image->exception);
746 if (status == MagickFalse)
748 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
751 reference_image=DestroyImage(reference_image);
754 status=SetImageDepth(reference_image,reference_types[j].depth);
755 InheritException(exception,&reference_image->exception);
756 if (status == MagickFalse)
758 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
761 reference_image=DestroyImage(reference_image);
764 reference_image->compression=reference_formats[i].compression;
765 status=WriteImage(image_info,reference_image,exception);
766 reference_image=DestroyImage(reference_image);
767 if (status == MagickFalse)
769 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
775 Read reference image.
777 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
778 reference_formats[i].magick,output_filename);
779 reference_image=ReadImage(image_info,exception);
780 if (reference_image == (Image *) NULL)
782 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
788 Write reference image.
790 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
791 reference_formats[i].magick,output_filename);
792 reference_image->depth=reference_types[j].depth;
793 reference_image->compression=reference_formats[i].compression;
794 status=WriteImage(image_info,reference_image,exception);
795 if (status == MagickFalse)
797 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
800 reference_image=DestroyImage(reference_image);
804 Read reconstruct image.
806 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
807 reference_formats[i].magick,output_filename);
808 reconstruct_image=ReadImage(image_info,exception);
809 if (reconstruct_image == (Image *) NULL)
811 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
814 reference_image=DestroyImage(reference_image);
818 Compare reference to reconstruct image.
821 if (reference_formats[i].fuzz != 0.0)
822 fuzz=reference_formats[i].fuzz;
823 #if defined(MAGICKCORE_HDRI_SUPPORT)
826 if (IsRGBColorspace(reference_image->colorspace) == MagickFalse)
829 difference_image=CompareImages(reference_image,reconstruct_image,
830 MeanSquaredErrorMetric,&distortion,exception);
831 reconstruct_image=DestroyImage(reconstruct_image);
832 reference_image=DestroyImage(reference_image);
833 if (difference_image == (Image *) NULL)
835 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
840 difference_image=DestroyImage(difference_image);
841 if ((distortion/QuantumRange) > fuzz)
843 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
844 distortion/QuantumRange);
848 (void) FormatLocaleFile(stdout,"... pass.\n");
851 (void) FormatLocaleFile(stdout,
852 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
853 (double) (test-(*fail)),(double) *fail);
858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 % 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 %
866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
868 % ValidateImportExportPixels() validates the pixel import and export methods.
869 % It returns the number of validation tests that passed and failed.
871 % The format of the ValidateImportExportPixels method is:
873 % size_t ValidateImportExportPixels(ImageInfo *image_info,
874 % const char *reference_filename,const char *output_filename,
875 % size_t *fail,ExceptionInfo *exception)
877 % A description of each parameter follows:
879 % o image_info: the image info.
881 % o reference_filename: the reference image filename.
883 % o output_filename: the output image filename.
885 % o fail: return the number of validation tests that pass.
887 % o exception: return any errors or warnings in this structure.
890 static size_t ValidateImportExportPixels(ImageInfo *image_info,
891 const char *reference_filename,const char *output_filename,
892 size_t *fail,ExceptionInfo *exception)
918 (void) output_filename;
920 (void) FormatLocaleFile(stdout,
921 "validate the import and export of image pixels:\n");
922 for (i=0; reference_map[i] != (char *) NULL; i++)
924 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
927 Generate reference image.
929 CatchException(exception);
930 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
931 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
932 reference_storage[j].type));
933 (void) CopyMagickString(image_info->filename,reference_filename,
935 reference_image=ReadImage(image_info,exception);
936 if (reference_image == (Image *) NULL)
938 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
943 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
944 (void) TransformImageColorspace(reference_image,CMYKColorspace,
946 length=strlen(reference_map[i])*reference_image->columns*
947 reference_image->rows*reference_storage[j].quantum;
948 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
949 if (pixels == (unsigned char *) NULL)
951 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
954 reference_image=DestroyImage(reference_image);
957 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
958 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
959 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
961 if (status == MagickFalse)
963 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
966 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
967 reference_image=DestroyImage(reference_image);
970 (void) SetImageBackgroundColor(reference_image);
971 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
972 reference_image->rows,reference_map[i],reference_storage[j].type,
974 if (status == MagickFalse)
976 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
979 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
980 reference_image=DestroyImage(reference_image);
984 Read reconstruct image.
986 reconstruct_image=AcquireImage(image_info,exception);
987 (void) SetImageExtent(reconstruct_image,reference_image->columns,
988 reference_image->rows,exception);
989 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
991 (void) SetImageBackgroundColor(reconstruct_image);
992 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
993 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
995 InheritException(exception,&reconstruct_image->exception);
996 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
997 if (status == MagickFalse)
999 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1002 reference_image=DestroyImage(reference_image);
1006 Compare reference to reconstruct image.
1008 difference_image=CompareImages(reference_image,reconstruct_image,
1009 MeanSquaredErrorMetric,&distortion,exception);
1010 reconstruct_image=DestroyImage(reconstruct_image);
1011 reference_image=DestroyImage(reference_image);
1012 if (difference_image == (Image *) NULL)
1014 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1019 difference_image=DestroyImage(difference_image);
1020 if ((distortion/QuantumRange) > 0.0)
1022 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1023 distortion/QuantumRange);
1027 (void) FormatLocaleFile(stdout,"... pass.\n");
1030 (void) FormatLocaleFile(stdout,
1031 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1032 (double) (test-(*fail)),(double) *fail);
1037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 % V a l i d a t e M o n t a g e C o m m a n d %
1045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047 % ValidateMontageCommand() validates the ImageMagick montage command line
1048 % program and returns the number of validation tests that passed and failed.
1050 % The format of the ValidateMontageCommand method is:
1052 % size_t ValidateMontageCommand(ImageInfo *image_info,
1053 % const char *reference_filename,const char *output_filename,
1054 % size_t *fail,ExceptionInfo *exception)
1056 % A description of each parameter follows:
1058 % o image_info: the image info.
1060 % o reference_filename: the reference image filename.
1062 % o output_filename: the output image filename.
1064 % o fail: return the number of validation tests that pass.
1066 % o exception: return any errors or warnings in this structure.
1069 static size_t ValidateMontageCommand(ImageInfo *image_info,
1070 const char *reference_filename,const char *output_filename,
1071 size_t *fail,ExceptionInfo *exception)
1075 command[MaxTextExtent];
1091 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1092 for (i=0; montage_options[i] != (char *) NULL; i++)
1094 CatchException(exception);
1095 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1096 montage_options[i]);
1097 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1098 reference_filename,montage_options[i],reference_filename,
1100 arguments=StringToArgv(command,&number_arguments);
1101 if (arguments == (char **) NULL)
1103 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1108 status=MontageImageCommand(image_info,number_arguments,arguments,
1109 (char **) NULL,exception);
1110 for (j=0; j < number_arguments; j++)
1111 arguments[j]=DestroyString(arguments[j]);
1112 arguments=(char **) RelinquishMagickMemory(arguments);
1113 if (status != MagickFalse)
1115 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1120 (void) FormatLocaleFile(stdout,"... pass.\n");
1122 (void) FormatLocaleFile(stdout,
1123 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1124 (double) (test-(*fail)),(double) *fail);
1129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1133 % V a l i d a t e S t r e a m C o m m a n d %
1137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1139 % ValidateStreamCommand() validates the ImageMagick stream command line
1140 % program and returns the number of validation tests that passed and failed.
1142 % The format of the ValidateStreamCommand method is:
1144 % size_t ValidateStreamCommand(ImageInfo *image_info,
1145 % const char *reference_filename,const char *output_filename,
1146 % size_t *fail,ExceptionInfo *exception)
1148 % A description of each parameter follows:
1150 % o image_info: the image info.
1152 % o reference_filename: the reference image filename.
1154 % o output_filename: the output image filename.
1156 % o fail: return the number of validation tests that pass.
1158 % o exception: return any errors or warnings in this structure.
1161 static size_t ValidateStreamCommand(ImageInfo *image_info,
1162 const char *reference_filename,const char *output_filename,
1163 size_t *fail,ExceptionInfo *exception)
1167 command[MaxTextExtent];
1183 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1184 for (i=0; stream_options[i] != (char *) NULL; i++)
1186 CatchException(exception);
1187 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1189 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1190 stream_options[i],reference_filename,output_filename);
1191 arguments=StringToArgv(command,&number_arguments);
1192 if (arguments == (char **) NULL)
1194 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1199 status=StreamImageCommand(image_info,number_arguments,arguments,
1200 (char **) NULL,exception);
1201 for (j=0; j < number_arguments; j++)
1202 arguments[j]=DestroyString(arguments[j]);
1203 arguments=(char **) RelinquishMagickMemory(arguments);
1204 if (status != MagickFalse)
1206 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1211 (void) FormatLocaleFile(stdout,"... pass.\n");
1213 (void) FormatLocaleFile(stdout,
1214 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1215 (double) (test-(*fail)),(double) *fail);
1220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 static MagickBooleanType ValidateUsage(void)
1241 "-debug events display copious debugging information",
1242 "-help print program options",
1243 "-log format format of debugging information",
1244 "-validate type validation type",
1245 "-version print version information",
1250 "-regard-warnings pay attention to warning messages",
1251 "-verbose print detailed information about the image",
1255 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1256 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1257 (void) printf("Features: %s\n",GetMagickFeatures());
1258 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1259 (void) printf("\nValidate Settings:\n");
1260 for (p=settings; *p != (char *) NULL; p++)
1261 (void) printf(" %s\n",*p);
1262 (void) printf("\nMiscellaneous Options:\n");
1263 for (p=miscellaneous; *p != (char *) NULL; p++)
1264 (void) printf(" %s\n",*p);
1268 int main(int argc,char **argv)
1270 #define DestroyValidate() \
1272 image_info=DestroyImageInfo(image_info); \
1273 exception=DestroyExceptionInfo(exception); \
1275 #define ThrowValidateException(asperity,tag,option) \
1277 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1279 CatchException(exception); \
1280 DestroyValidate(); \
1281 return(MagickFalse); \
1285 output_filename[MaxTextExtent],
1286 reference_filename[MaxTextExtent],
1321 Validate the ImageMagick image processing suite.
1323 MagickCoreGenesis(*argv,MagickFalse);
1327 regard_warnings=MagickFalse;
1328 (void) regard_warnings;
1329 exception=AcquireExceptionInfo();
1330 image_info=AcquireImageInfo();
1331 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1332 for (i=1; i < (ssize_t) argc; i++)
1335 if (IsCommandOption(option) == MagickFalse)
1337 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1340 switch (*(option+1))
1344 if (LocaleCompare("bench",option+1) == 0)
1346 iterations=StringToUnsignedLong(argv[++i]);
1349 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1353 if (LocaleCompare("debug",option+1) == 0)
1355 (void) SetLogEventMask(argv[++i]);
1358 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1362 if (LocaleCompare("help",option+1) == 0)
1364 (void) ValidateUsage();
1367 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1371 if (LocaleCompare("log",option+1) == 0)
1374 (void) SetLogFormat(argv[i+1]);
1377 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1381 if (LocaleCompare("regard-warnings",option+1) == 0)
1383 regard_warnings=MagickTrue;
1386 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1390 if (LocaleCompare("validate",option+1) == 0)
1398 if (i == (ssize_t) argc)
1399 ThrowValidateException(OptionError,"MissingArgument",option);
1400 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1403 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1405 type=(ValidateType) validate;
1408 if ((LocaleCompare("version",option+1) == 0) ||
1409 (LocaleCompare("-version",option+1) == 0))
1411 (void) FormatLocaleFile(stdout,"Version: %s\n",
1412 GetMagickVersion((size_t *) NULL));
1413 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1414 GetMagickCopyright());
1415 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1416 GetMagickFeatures());
1419 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1422 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1425 timer=(TimerInfo *) NULL;
1427 timer=AcquireTimerInfo();
1428 reference_image=ReadImage(image_info,exception);
1431 if (reference_image == (Image *) NULL)
1435 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1436 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1438 (void) AcquireUniqueFilename(reference_filename);
1439 (void) AcquireUniqueFilename(output_filename);
1440 (void) CopyMagickString(reference_image->filename,reference_filename,
1442 status=WriteImage(image_info,reference_image,exception);
1443 reference_image=DestroyImage(reference_image);
1444 if (status == MagickFalse)
1448 (void) FormatLocaleFile(stdout,"Version: %s\n",
1449 GetMagickVersion((size_t *) NULL));
1450 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1451 GetMagickCopyright());
1452 (void) FormatLocaleFile(stdout,
1453 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1454 MagickValidateOptions,(ssize_t) type));
1455 if ((type & CompareValidate) != 0)
1456 tests+=ValidateCompareCommand(image_info,reference_filename,
1457 output_filename,&fail,exception);
1458 if ((type & CompositeValidate) != 0)
1459 tests+=ValidateCompositeCommand(image_info,reference_filename,
1460 output_filename,&fail,exception);
1461 if ((type & ConvertValidate) != 0)
1462 tests+=ValidateConvertCommand(image_info,reference_filename,
1463 output_filename,&fail,exception);
1464 if ((type & FormatsInMemoryValidate) != 0)
1465 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1466 output_filename,&fail,exception);
1467 if ((type & FormatsOnDiskValidate) != 0)
1468 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1469 output_filename,&fail,exception);
1470 if ((type & IdentifyValidate) != 0)
1471 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1472 output_filename,&fail,exception);
1473 if ((type & ImportExportValidate) != 0)
1474 tests+=ValidateImportExportPixels(image_info,reference_filename,
1475 output_filename,&fail,exception);
1476 if ((type & MontageValidate) != 0)
1477 tests+=ValidateMontageCommand(image_info,reference_filename,
1478 output_filename,&fail,exception);
1479 if ((type & StreamValidate) != 0)
1480 tests+=ValidateStreamCommand(image_info,reference_filename,
1481 output_filename,&fail,exception);
1482 (void) FormatLocaleFile(stdout,
1483 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1484 (double) tests,(double) (tests-fail),(double) fail);
1486 (void) RelinquishUniqueFileResource(output_filename);
1487 (void) RelinquishUniqueFileResource(reference_filename);
1489 if (exception->severity != UndefinedException)
1490 CatchException(exception);
1493 elapsed_time=GetElapsedTime(timer);
1494 user_time=GetUserTime(timer);
1495 (void) FormatLocaleFile(stderr,
1496 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1497 iterations,1.0*iterations/elapsed_time,user_time,(long)
1498 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1499 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1500 timer=DestroyTimerInfo(timer);
1503 MagickCoreTerminus();
1504 return(fail == 0 ? 0 : 1);