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);
945 length=strlen(reference_map[i])*reference_image->columns*
946 reference_image->rows*reference_storage[j].quantum;
947 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
948 if (pixels == (unsigned char *) NULL)
950 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
953 reference_image=DestroyImage(reference_image);
956 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
957 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
958 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
960 if (status == MagickFalse)
962 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
965 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
966 reference_image=DestroyImage(reference_image);
969 (void) SetImageBackgroundColor(reference_image);
970 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
971 reference_image->rows,reference_map[i],reference_storage[j].type,
973 if (status == MagickFalse)
975 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
978 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
979 reference_image=DestroyImage(reference_image);
983 Read reconstruct image.
985 reconstruct_image=AcquireImage(image_info,exception);
986 (void) SetImageExtent(reconstruct_image,reference_image->columns,
987 reference_image->rows,exception);
988 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
990 (void) SetImageBackgroundColor(reconstruct_image);
991 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
992 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
994 InheritException(exception,&reconstruct_image->exception);
995 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
996 if (status == MagickFalse)
998 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1001 reference_image=DestroyImage(reference_image);
1005 Compare reference to reconstruct image.
1007 difference_image=CompareImages(reference_image,reconstruct_image,
1008 MeanSquaredErrorMetric,&distortion,exception);
1009 reconstruct_image=DestroyImage(reconstruct_image);
1010 reference_image=DestroyImage(reference_image);
1011 if (difference_image == (Image *) NULL)
1013 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1018 difference_image=DestroyImage(difference_image);
1019 if ((distortion/QuantumRange) > 0.0)
1021 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1022 distortion/QuantumRange);
1026 (void) FormatLocaleFile(stdout,"... pass.\n");
1029 (void) FormatLocaleFile(stdout,
1030 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1031 (double) (test-(*fail)),(double) *fail);
1036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040 % V a l i d a t e M o n t a g e C o m m a n d %
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1046 % ValidateMontageCommand() validates the ImageMagick montage command line
1047 % program and returns the number of validation tests that passed and failed.
1049 % The format of the ValidateMontageCommand method is:
1051 % size_t ValidateMontageCommand(ImageInfo *image_info,
1052 % const char *reference_filename,const char *output_filename,
1053 % size_t *fail,ExceptionInfo *exception)
1055 % A description of each parameter follows:
1057 % o image_info: the image info.
1059 % o reference_filename: the reference image filename.
1061 % o output_filename: the output image filename.
1063 % o fail: return the number of validation tests that pass.
1065 % o exception: return any errors or warnings in this structure.
1068 static size_t ValidateMontageCommand(ImageInfo *image_info,
1069 const char *reference_filename,const char *output_filename,
1070 size_t *fail,ExceptionInfo *exception)
1074 command[MaxTextExtent];
1090 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1091 for (i=0; montage_options[i] != (char *) NULL; i++)
1093 CatchException(exception);
1094 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1095 montage_options[i]);
1096 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1097 reference_filename,montage_options[i],reference_filename,
1099 arguments=StringToArgv(command,&number_arguments);
1100 if (arguments == (char **) NULL)
1102 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1107 status=MontageImageCommand(image_info,number_arguments,arguments,
1108 (char **) NULL,exception);
1109 for (j=0; j < number_arguments; j++)
1110 arguments[j]=DestroyString(arguments[j]);
1111 arguments=(char **) RelinquishMagickMemory(arguments);
1112 if (status != MagickFalse)
1114 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1119 (void) FormatLocaleFile(stdout,"... pass.\n");
1121 (void) FormatLocaleFile(stdout,
1122 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1123 (double) (test-(*fail)),(double) *fail);
1128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1132 % V a l i d a t e S t r e a m C o m m a n d %
1136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1138 % ValidateStreamCommand() validates the ImageMagick stream command line
1139 % program and returns the number of validation tests that passed and failed.
1141 % The format of the ValidateStreamCommand method is:
1143 % size_t ValidateStreamCommand(ImageInfo *image_info,
1144 % const char *reference_filename,const char *output_filename,
1145 % size_t *fail,ExceptionInfo *exception)
1147 % A description of each parameter follows:
1149 % o image_info: the image info.
1151 % o reference_filename: the reference image filename.
1153 % o output_filename: the output image filename.
1155 % o fail: return the number of validation tests that pass.
1157 % o exception: return any errors or warnings in this structure.
1160 static size_t ValidateStreamCommand(ImageInfo *image_info,
1161 const char *reference_filename,const char *output_filename,
1162 size_t *fail,ExceptionInfo *exception)
1166 command[MaxTextExtent];
1182 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1183 for (i=0; stream_options[i] != (char *) NULL; i++)
1185 CatchException(exception);
1186 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1188 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1189 stream_options[i],reference_filename,output_filename);
1190 arguments=StringToArgv(command,&number_arguments);
1191 if (arguments == (char **) NULL)
1193 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1198 status=StreamImageCommand(image_info,number_arguments,arguments,
1199 (char **) NULL,exception);
1200 for (j=0; j < number_arguments; j++)
1201 arguments[j]=DestroyString(arguments[j]);
1202 arguments=(char **) RelinquishMagickMemory(arguments);
1203 if (status != MagickFalse)
1205 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1210 (void) FormatLocaleFile(stdout,"... pass.\n");
1212 (void) FormatLocaleFile(stdout,
1213 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1214 (double) (test-(*fail)),(double) *fail);
1219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1232 static MagickBooleanType ValidateUsage(void)
1240 "-debug events display copious debugging information",
1241 "-help print program options",
1242 "-log format format of debugging information",
1243 "-validate type validation type",
1244 "-version print version information",
1249 "-regard-warnings pay attention to warning messages",
1250 "-verbose print detailed information about the image",
1254 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1255 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1256 (void) printf("Features: %s\n",GetMagickFeatures());
1257 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1258 (void) printf("\nValidate Settings:\n");
1259 for (p=settings; *p != (char *) NULL; p++)
1260 (void) printf(" %s\n",*p);
1261 (void) printf("\nMiscellaneous Options:\n");
1262 for (p=miscellaneous; *p != (char *) NULL; p++)
1263 (void) printf(" %s\n",*p);
1267 int main(int argc,char **argv)
1269 #define DestroyValidate() \
1271 image_info=DestroyImageInfo(image_info); \
1272 exception=DestroyExceptionInfo(exception); \
1274 #define ThrowValidateException(asperity,tag,option) \
1276 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1278 CatchException(exception); \
1279 DestroyValidate(); \
1280 return(MagickFalse); \
1284 output_filename[MaxTextExtent],
1285 reference_filename[MaxTextExtent],
1320 Validate the ImageMagick image processing suite.
1322 MagickCoreGenesis(*argv,MagickFalse);
1326 regard_warnings=MagickFalse;
1327 (void) regard_warnings;
1328 exception=AcquireExceptionInfo();
1329 image_info=AcquireImageInfo();
1330 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1331 for (i=1; i < (ssize_t) argc; i++)
1334 if (IsCommandOption(option) == MagickFalse)
1336 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1339 switch (*(option+1))
1343 if (LocaleCompare("bench",option+1) == 0)
1345 iterations=StringToUnsignedLong(argv[++i]);
1348 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1352 if (LocaleCompare("debug",option+1) == 0)
1354 (void) SetLogEventMask(argv[++i]);
1357 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1361 if (LocaleCompare("help",option+1) == 0)
1363 (void) ValidateUsage();
1366 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1370 if (LocaleCompare("log",option+1) == 0)
1373 (void) SetLogFormat(argv[i+1]);
1376 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1380 if (LocaleCompare("regard-warnings",option+1) == 0)
1382 regard_warnings=MagickTrue;
1385 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1389 if (LocaleCompare("validate",option+1) == 0)
1397 if (i == (ssize_t) argc)
1398 ThrowValidateException(OptionError,"MissingArgument",option);
1399 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1402 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1404 type=(ValidateType) validate;
1407 if ((LocaleCompare("version",option+1) == 0) ||
1408 (LocaleCompare("-version",option+1) == 0))
1410 (void) FormatLocaleFile(stdout,"Version: %s\n",
1411 GetMagickVersion((size_t *) NULL));
1412 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1413 GetMagickCopyright());
1414 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1415 GetMagickFeatures());
1418 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1421 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1424 timer=(TimerInfo *) NULL;
1426 timer=AcquireTimerInfo();
1427 reference_image=ReadImage(image_info,exception);
1430 if (reference_image == (Image *) NULL)
1434 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1435 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1437 (void) AcquireUniqueFilename(reference_filename);
1438 (void) AcquireUniqueFilename(output_filename);
1439 (void) CopyMagickString(reference_image->filename,reference_filename,
1441 status=WriteImage(image_info,reference_image,exception);
1442 reference_image=DestroyImage(reference_image);
1443 if (status == MagickFalse)
1447 (void) FormatLocaleFile(stdout,"Version: %s\n",
1448 GetMagickVersion((size_t *) NULL));
1449 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1450 GetMagickCopyright());
1451 (void) FormatLocaleFile(stdout,
1452 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1453 MagickValidateOptions,(ssize_t) type));
1454 if ((type & CompareValidate) != 0)
1455 tests+=ValidateCompareCommand(image_info,reference_filename,
1456 output_filename,&fail,exception);
1457 if ((type & CompositeValidate) != 0)
1458 tests+=ValidateCompositeCommand(image_info,reference_filename,
1459 output_filename,&fail,exception);
1460 if ((type & ConvertValidate) != 0)
1461 tests+=ValidateConvertCommand(image_info,reference_filename,
1462 output_filename,&fail,exception);
1463 if ((type & FormatsInMemoryValidate) != 0)
1464 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1465 output_filename,&fail,exception);
1466 if ((type & FormatsOnDiskValidate) != 0)
1467 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1468 output_filename,&fail,exception);
1469 if ((type & IdentifyValidate) != 0)
1470 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1471 output_filename,&fail,exception);
1472 if ((type & ImportExportValidate) != 0)
1473 tests+=ValidateImportExportPixels(image_info,reference_filename,
1474 output_filename,&fail,exception);
1475 if ((type & MontageValidate) != 0)
1476 tests+=ValidateMontageCommand(image_info,reference_filename,
1477 output_filename,&fail,exception);
1478 if ((type & StreamValidate) != 0)
1479 tests+=ValidateStreamCommand(image_info,reference_filename,
1480 output_filename,&fail,exception);
1481 (void) FormatLocaleFile(stdout,
1482 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1483 (double) tests,(double) (tests-fail),(double) fail);
1485 (void) RelinquishUniqueFileResource(output_filename);
1486 (void) RelinquishUniqueFileResource(reference_filename);
1488 if (exception->severity != UndefinedException)
1489 CatchException(exception);
1492 elapsed_time=GetElapsedTime(timer);
1493 user_time=GetUserTime(timer);
1494 (void) FormatLocaleFile(stderr,
1495 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1496 iterations,1.0*iterations/elapsed_time,user_time,(long)
1497 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1498 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1499 timer=DestroyTimerInfo(timer);
1502 MagickCoreTerminus();
1503 return(fail == 0 ? 0 : 1);