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-2013 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 #include "MagickWand/MagickWand.h"
50 #include "MagickCore/colorspace-private.h"
51 #include "MagickCore/resource_.h"
52 #include "MagickCore/string-private.h"
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 % V a l i d a t e C o m p a r e C o m m a n d %
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 % ValidateCompareCommand() validates the ImageMagick compare command line
67 % program and returns the number of validation tests that passed and failed.
69 % The format of the ValidateCompareCommand method is:
71 % size_t ValidateCompareCommand(ImageInfo *image_info,
72 % const char *reference_filename,const char *output_filename,
73 % size_t *fail,ExceptionInfo *exception)
75 % A description of each parameter follows:
77 % o image_info: the image info.
79 % o reference_filename: the reference image filename.
81 % o output_filename: the output image filename.
83 % o fail: return the number of validation tests that pass.
85 % o exception: return any errors or warnings in this structure.
88 static size_t ValidateCompareCommand(ImageInfo *image_info,
89 const char *reference_filename,const char *output_filename,size_t *fail,
90 ExceptionInfo *exception)
94 command[MaxTextExtent];
110 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
111 for (i=0; compare_options[i] != (char *) NULL; i++)
113 CatchException(exception);
114 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
116 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
117 compare_options[i],reference_filename,reference_filename,output_filename);
118 arguments=StringToArgv(command,&number_arguments);
119 if (arguments == (char **) NULL)
121 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
126 status=CompareImagesCommand(image_info,number_arguments,arguments,
127 (char **) NULL,exception);
128 for (j=0; j < (ssize_t) number_arguments; j++)
129 arguments[j]=DestroyString(arguments[j]);
130 arguments=(char **) RelinquishMagickMemory(arguments);
131 if (status != MagickFalse)
133 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
138 (void) FormatLocaleFile(stdout,"... pass.\n");
140 (void) FormatLocaleFile(stdout,
141 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
142 (double) (test-(*fail)),(double) *fail);
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 % V a l i d a t e C o m p o s i t e C o m m a n d %
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 % ValidateCompositeCommand() validates the ImageMagick composite command line
158 % program and returns the number of validation tests that passed and failed.
160 % The format of the ValidateCompositeCommand method is:
162 % size_t ValidateCompositeCommand(ImageInfo *image_info,
163 % const char *reference_filename,const char *output_filename,
164 % size_t *fail,ExceptionInfo *exception)
166 % A description of each parameter follows:
168 % o image_info: the image info.
170 % o reference_filename: the reference image filename.
172 % o output_filename: the output image filename.
174 % o fail: return the number of validation tests that pass.
176 % o exception: return any errors or warnings in this structure.
179 static size_t ValidateCompositeCommand(ImageInfo *image_info,
180 const char *reference_filename,const char *output_filename,size_t *fail,
181 ExceptionInfo *exception)
185 command[MaxTextExtent];
201 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
202 for (i=0; composite_options[i] != (char *) NULL; i++)
204 CatchException(exception);
205 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
206 composite_options[i]);
207 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
208 reference_filename,composite_options[i],reference_filename,
210 arguments=StringToArgv(command,&number_arguments);
211 if (arguments == (char **) NULL)
213 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
218 status=CompositeImageCommand(image_info,number_arguments,arguments,
219 (char **) NULL,exception);
220 for (j=0; j < (ssize_t) number_arguments; j++)
221 arguments[j]=DestroyString(arguments[j]);
222 arguments=(char **) RelinquishMagickMemory(arguments);
223 if (status != MagickFalse)
225 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
230 (void) FormatLocaleFile(stdout,"... pass.\n");
232 (void) FormatLocaleFile(stdout,
233 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
234 (double) (test-(*fail)),(double) *fail);
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % V a l i d a t e C o n v e r t C o m m a n d %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 % ValidateConvertCommand() validates the ImageMagick convert command line
250 % program and returns the number of validation tests that passed and failed.
252 % The format of the ValidateConvertCommand method is:
254 % size_t ValidateConvertCommand(ImageInfo *image_info,
255 % const char *reference_filename,const char *output_filename,
256 % size_t *fail,ExceptionInfo *exception)
258 % A description of each parameter follows:
260 % o image_info: the image info.
262 % o reference_filename: the reference image filename.
264 % o output_filename: the output image filename.
266 % o fail: return the number of validation tests that pass.
268 % o exception: return any errors or warnings in this structure.
271 static size_t ValidateConvertCommand(ImageInfo *image_info,
272 const char *reference_filename,const char *output_filename,size_t *fail,
273 ExceptionInfo *exception)
277 command[MaxTextExtent];
293 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
294 for (i=0; convert_options[i] != (char *) NULL; i++)
296 CatchException(exception);
297 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
299 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
300 reference_filename,convert_options[i],reference_filename,output_filename);
301 arguments=StringToArgv(command,&number_arguments);
302 if (arguments == (char **) NULL)
304 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
309 status=ConvertImageCommand(image_info,number_arguments,arguments,
310 (char **) NULL,exception);
311 for (j=0; j < (ssize_t) number_arguments; j++)
312 arguments[j]=DestroyString(arguments[j]);
313 arguments=(char **) RelinquishMagickMemory(arguments);
314 if (status != MagickFalse)
316 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
321 (void) FormatLocaleFile(stdout,"... pass.\n");
323 (void) FormatLocaleFile(stdout,
324 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
325 (double) (test-(*fail)),(double) *fail);
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 % V a l i d a t e I d e n t i f y C o m m a n d %
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 % ValidateIdentifyCommand() validates the ImageMagick identify command line
341 % program and returns the number of validation tests that passed and failed.
343 % The format of the ValidateIdentifyCommand method is:
345 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
346 % const char *reference_filename,const char *output_filename,
347 % size_t *fail,ExceptionInfo *exception)
349 % A description of each parameter follows:
351 % o image_info: the image info.
353 % o reference_filename: the reference image filename.
355 % o output_filename: the output image filename.
357 % o fail: return the number of validation tests that pass.
359 % o exception: return any errors or warnings in this structure.
362 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
363 const char *reference_filename,const char *output_filename,size_t *fail,
364 ExceptionInfo *exception)
368 command[MaxTextExtent];
383 (void) output_filename;
385 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
386 for (i=0; identify_options[i] != (char *) NULL; i++)
388 CatchException(exception);
389 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
390 identify_options[i]);
391 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
392 identify_options[i],reference_filename);
393 arguments=StringToArgv(command,&number_arguments);
394 if (arguments == (char **) NULL)
396 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
401 status=IdentifyImageCommand(image_info,number_arguments,arguments,
402 (char **) NULL,exception);
403 for (j=0; j < (ssize_t) number_arguments; j++)
404 arguments[j]=DestroyString(arguments[j]);
405 arguments=(char **) RelinquishMagickMemory(arguments);
406 if (status != MagickFalse)
408 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
413 (void) FormatLocaleFile(stdout,"... pass.\n");
415 (void) FormatLocaleFile(stdout,
416 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
417 (double) (test-(*fail)),(double) *fail);
422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 % 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 %
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
433 % memory and returns the number of validation tests that passed and failed.
435 % The format of the ValidateImageFormatsInMemory method is:
437 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
438 % const char *reference_filename,const char *output_filename,
439 % size_t *fail,ExceptionInfo *exception)
441 % A description of each parameter follows:
443 % o image_info: the image info.
445 % o reference_filename: the reference image filename.
447 % o output_filename: the output image filename.
449 % o fail: return the number of validation tests that pass.
451 % o exception: return any errors or warnings in this structure.
456 Enable this to count remaining $TMPDIR/magick-* files. Note that the count
457 includes any files left over from other runs.
459 #undef MagickCountTempFiles
461 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
462 const char *reference_filename,const char *output_filename,size_t *fail,
463 ExceptionInfo *exception)
466 #ifdef MagickCountTempFiles
467 SystemCommand[MaxTextExtent],
500 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
502 #ifdef MagickCountTempFiles
503 (void)GetPathTemplate(path);
504 /* Remove file template except for the leading "/path/to/magick-" */
505 path[strlen(path)-17]='\0';
506 (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
509 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
511 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
512 if ((magick_info == (const MagickInfo *) NULL) ||
513 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
514 (magick_info->encoder == (EncodeImageHandler *) NULL))
516 for (j=0; reference_types[j].type != UndefinedType; j++)
519 Generate reference image.
521 CatchException(exception);
522 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
523 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
524 MagickCompressOptions,reference_formats[i].compression),
525 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
526 (double) reference_types[j].depth);
527 (void) CopyMagickString(image_info->filename,reference_filename,
529 reference_image=ReadImage(image_info,exception);
530 if (reference_image == (Image *) NULL)
532 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
538 Write reference image.
540 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
541 (double) reference_image->columns,(double) reference_image->rows);
542 (void) CloneString(&image_info->size,size);
543 image_info->depth=reference_types[j].depth;
544 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
545 reference_formats[i].magick,output_filename);
546 status=SetImageType(reference_image,reference_types[j].type,exception);
547 if (status == MagickFalse)
549 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
552 reference_image=DestroyImage(reference_image);
555 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
556 if (status == MagickFalse)
558 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
561 reference_image=DestroyImage(reference_image);
564 reference_image->compression=reference_formats[i].compression;
565 status=WriteImage(image_info,reference_image,exception);
566 reference_image=DestroyImage(reference_image);
567 if (status == MagickFalse)
569 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
575 Ping reference image.
577 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
578 reference_formats[i].magick,output_filename);
579 ping_image=PingImage(image_info,exception);
580 if (ping_image == (Image *) NULL)
582 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
587 ping_image=DestroyImage(ping_image);
589 Read reference image.
591 reference_image=ReadImage(image_info,exception);
592 if (reference_image == (Image *) NULL)
594 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
600 Write reference image.
602 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
603 reference_formats[i].magick,output_filename);
604 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
606 reference_image->depth=reference_types[j].depth;
607 reference_image->compression=reference_formats[i].compression;
609 blob=ImageToBlob(image_info,reference_image,&length,exception);
610 if (blob == (unsigned char *) NULL)
612 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
615 reference_image=DestroyImage(reference_image);
621 ping_image=PingBlob(image_info,blob,length,exception);
622 if (ping_image == (Image *) NULL)
624 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
627 blob=(unsigned char *) RelinquishMagickMemory(blob);
630 ping_image=DestroyImage(ping_image);
632 Read reconstruct image.
634 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
635 reference_formats[i].magick,output_filename);
636 reconstruct_image=BlobToImage(image_info,blob,length,exception);
637 blob=(unsigned char *) RelinquishMagickMemory(blob);
638 if (reconstruct_image == (Image *) NULL)
640 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
643 reference_image=DestroyImage(reference_image);
647 Compare reference to reconstruct image.
650 if (reference_formats[i].fuzz != 0.0)
651 fuzz=reference_formats[i].fuzz;
652 #if defined(MAGICKCORE_HDRI_SUPPORT)
655 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
658 difference_image=CompareImages(reference_image,reconstruct_image,
659 RootMeanSquaredErrorMetric,&distortion,exception);
660 reconstruct_image=DestroyImage(reconstruct_image);
661 reference_image=DestroyImage(reference_image);
662 if (difference_image == (Image *) NULL)
664 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
669 difference_image=DestroyImage(difference_image);
670 if ((QuantumScale*distortion) > fuzz)
672 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
673 QuantumScale*distortion);
677 #ifdef MagickCountTempFiles
678 (void) FormatLocaleFile(stdout,"... pass, ");
679 (void) fflush(stdout);
680 SystemCommand[0]='\0';
681 (void)strncat(SystemCommand,"echo `ls ",9);
682 (void)strncat(SystemCommand,path,MaxTextExtent-31);
683 (void)strncat(SystemCommand,"* | wc -w` tmp files.",20);
684 (void)system(SystemCommand);
685 (void) fflush(stdout);
687 (void) FormatLocaleFile(stdout,"... pass\n");
691 (void) FormatLocaleFile(stdout,
692 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
693 (double) (test-(*fail)),(double) *fail);
698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702 % 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 %
706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
709 % and returns the number of validation tests that passed and failed.
711 % The format of the ValidateImageFormatsOnDisk method is:
713 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
714 % const char *reference_filename,const char *output_filename,
715 % size_t *fail,ExceptionInfo *exception)
717 % A description of each parameter follows:
719 % o image_info: the image info.
721 % o reference_filename: the reference image filename.
723 % o output_filename: the output image filename.
725 % o fail: return the number of validation tests that pass.
727 % o exception: return any errors or warnings in this structure.
730 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
731 const char *reference_filename,const char *output_filename,size_t *fail,
732 ExceptionInfo *exception)
760 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
761 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
763 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
764 if ((magick_info == (const MagickInfo *) NULL) ||
765 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
766 (magick_info->encoder == (EncodeImageHandler *) NULL))
768 for (j=0; reference_types[j].type != UndefinedType; j++)
771 Generate reference image.
773 CatchException(exception);
774 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
775 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
776 MagickCompressOptions,reference_formats[i].compression),
777 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
778 (double) reference_types[j].depth);
779 (void) CopyMagickString(image_info->filename,reference_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(size,MaxTextExtent,"%.20gx%.20g",
793 (double) reference_image->columns,(double) reference_image->rows);
794 (void) CloneString(&image_info->size,size);
795 image_info->depth=reference_types[j].depth;
796 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
797 reference_formats[i].magick,output_filename);
798 status=SetImageType(reference_image,reference_types[j].type,exception);
799 if (status == MagickFalse)
801 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
804 reference_image=DestroyImage(reference_image);
807 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
808 if (status == MagickFalse)
810 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
813 reference_image=DestroyImage(reference_image);
816 reference_image->compression=reference_formats[i].compression;
817 status=WriteImage(image_info,reference_image,exception);
818 reference_image=DestroyImage(reference_image);
819 if (status == MagickFalse)
821 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
827 Read reference image.
829 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
830 reference_formats[i].magick,output_filename);
831 reference_image=ReadImage(image_info,exception);
832 if (reference_image == (Image *) NULL)
834 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
840 Write reference image.
842 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
843 reference_formats[i].magick,output_filename);
844 reference_image->depth=reference_types[j].depth;
845 reference_image->compression=reference_formats[i].compression;
846 status=WriteImage(image_info,reference_image,exception);
847 if (status == MagickFalse)
849 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
852 reference_image=DestroyImage(reference_image);
856 Read reconstruct image.
858 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
859 reference_formats[i].magick,output_filename);
860 reconstruct_image=ReadImage(image_info,exception);
861 if (reconstruct_image == (Image *) NULL)
863 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
866 reference_image=DestroyImage(reference_image);
870 Compare reference to reconstruct image.
873 if (reference_formats[i].fuzz != 0.0)
874 fuzz=reference_formats[i].fuzz;
875 #if defined(MAGICKCORE_HDRI_SUPPORT)
878 if (IssRGBColorspace(reference_image->colorspace) == MagickFalse)
881 difference_image=CompareImages(reference_image,reconstruct_image,
882 RootMeanSquaredErrorMetric,&distortion,exception);
883 reconstruct_image=DestroyImage(reconstruct_image);
884 reference_image=DestroyImage(reference_image);
885 if (difference_image == (Image *) NULL)
887 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
892 difference_image=DestroyImage(difference_image);
893 if ((QuantumScale*distortion) > fuzz)
895 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
896 QuantumScale*distortion);
900 (void) FormatLocaleFile(stdout,"... pass.\n");
903 (void) FormatLocaleFile(stdout,
904 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
905 (double) (test-(*fail)),(double) *fail);
910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
914 % 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 %
918 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920 % ValidateImportExportPixels() validates the pixel import and export methods.
921 % It returns the number of validation tests that passed and failed.
923 % The format of the ValidateImportExportPixels method is:
925 % size_t ValidateImportExportPixels(ImageInfo *image_info,
926 % const char *reference_filename,const char *output_filename,
927 % size_t *fail,ExceptionInfo *exception)
929 % A description of each parameter follows:
931 % o image_info: the image info.
933 % o reference_filename: the reference image filename.
935 % o output_filename: the output image filename.
937 % o fail: return the number of validation tests that pass.
939 % o exception: return any errors or warnings in this structure.
942 static size_t ValidateImportExportPixels(ImageInfo *image_info,
943 const char *reference_filename,const char *output_filename,size_t *fail,
944 ExceptionInfo *exception)
970 (void) output_filename;
972 (void) FormatLocaleFile(stdout,
973 "validate the import and export of image pixels:\n");
974 for (i=0; reference_map[i] != (char *) NULL; i++)
976 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
979 Generate reference image.
981 CatchException(exception);
982 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
983 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
984 reference_storage[j].type));
985 (void) CopyMagickString(image_info->filename,reference_filename,
987 reference_image=ReadImage(image_info,exception);
988 if (reference_image == (Image *) NULL)
990 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
995 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
996 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
997 length=strlen(reference_map[i])*reference_image->columns*
998 reference_image->rows*reference_storage[j].quantum;
999 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
1000 if (pixels == (unsigned char *) NULL)
1002 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1005 reference_image=DestroyImage(reference_image);
1008 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
1009 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
1010 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
1012 if (status == MagickFalse)
1014 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1017 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1018 reference_image=DestroyImage(reference_image);
1021 (void) SetImageBackgroundColor(reference_image,exception);
1022 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
1023 reference_image->rows,reference_map[i],reference_storage[j].type,
1025 if (status == MagickFalse)
1027 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1030 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1031 reference_image=DestroyImage(reference_image);
1035 Read reconstruct image.
1037 reconstruct_image=AcquireImage(image_info,exception);
1038 (void) SetImageExtent(reconstruct_image,reference_image->columns,
1039 reference_image->rows,exception);
1040 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
1042 (void) SetImageBackgroundColor(reconstruct_image,exception);
1043 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
1044 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
1046 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1047 if (status == MagickFalse)
1049 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1052 reference_image=DestroyImage(reference_image);
1056 Compare reference to reconstruct image.
1058 difference_image=CompareImages(reference_image,reconstruct_image,
1059 RootMeanSquaredErrorMetric,&distortion,exception);
1060 reconstruct_image=DestroyImage(reconstruct_image);
1061 reference_image=DestroyImage(reference_image);
1062 if (difference_image == (Image *) NULL)
1064 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1069 difference_image=DestroyImage(difference_image);
1070 if ((QuantumScale*distortion) > 0.0)
1072 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1073 QuantumScale*distortion);
1077 (void) FormatLocaleFile(stdout,"... pass.\n");
1080 (void) FormatLocaleFile(stdout,
1081 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1082 (double) (test-(*fail)),(double) *fail);
1087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091 % V a l i d a t e M o n t a g e C o m m a n d %
1095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097 % ValidateMontageCommand() validates the ImageMagick montage command line
1098 % program and returns the number of validation tests that passed and failed.
1100 % The format of the ValidateMontageCommand method is:
1102 % size_t ValidateMontageCommand(ImageInfo *image_info,
1103 % const char *reference_filename,const char *output_filename,
1104 % size_t *fail,ExceptionInfo *exception)
1106 % A description of each parameter follows:
1108 % o image_info: the image info.
1110 % o reference_filename: the reference image filename.
1112 % o output_filename: the output image filename.
1114 % o fail: return the number of validation tests that pass.
1116 % o exception: return any errors or warnings in this structure.
1119 static size_t ValidateMontageCommand(ImageInfo *image_info,
1120 const char *reference_filename,const char *output_filename,size_t *fail,
1121 ExceptionInfo *exception)
1125 command[MaxTextExtent];
1141 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
1142 for (i=0; montage_options[i] != (char *) NULL; i++)
1144 CatchException(exception);
1145 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1146 montage_options[i]);
1147 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1148 reference_filename,montage_options[i],reference_filename,
1150 arguments=StringToArgv(command,&number_arguments);
1151 if (arguments == (char **) NULL)
1153 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1158 status=MontageImageCommand(image_info,number_arguments,arguments,
1159 (char **) NULL,exception);
1160 for (j=0; j < (ssize_t) number_arguments; j++)
1161 arguments[j]=DestroyString(arguments[j]);
1162 arguments=(char **) RelinquishMagickMemory(arguments);
1163 if (status != MagickFalse)
1165 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1170 (void) FormatLocaleFile(stdout,"... pass.\n");
1172 (void) FormatLocaleFile(stdout,
1173 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1174 (double) (test-(*fail)),(double) *fail);
1179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1183 % V a l i d a t e S t r e a m C o m m a n d %
1187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189 % ValidateStreamCommand() validates the ImageMagick stream command line
1190 % program and returns the number of validation tests that passed and failed.
1192 % The format of the ValidateStreamCommand method is:
1194 % size_t ValidateStreamCommand(ImageInfo *image_info,
1195 % const char *reference_filename,const char *output_filename,
1196 % size_t *fail,ExceptionInfo *exception)
1198 % A description of each parameter follows:
1200 % o image_info: the image info.
1202 % o reference_filename: the reference image filename.
1204 % o output_filename: the output image filename.
1206 % o fail: return the number of validation tests that pass.
1208 % o exception: return any errors or warnings in this structure.
1211 static size_t ValidateStreamCommand(ImageInfo *image_info,
1212 const char *reference_filename,const char *output_filename,size_t *fail,
1213 ExceptionInfo *exception)
1217 command[MaxTextExtent];
1233 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
1234 for (i=0; stream_options[i] != (char *) NULL; i++)
1236 CatchException(exception);
1237 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1239 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
1240 stream_options[i],reference_filename,output_filename);
1241 arguments=StringToArgv(command,&number_arguments);
1242 if (arguments == (char **) NULL)
1244 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1249 status=StreamImageCommand(image_info,number_arguments,arguments,
1250 (char **) NULL,exception);
1251 for (j=0; j < (ssize_t) number_arguments; j++)
1252 arguments[j]=DestroyString(arguments[j]);
1253 arguments=(char **) RelinquishMagickMemory(arguments);
1254 if (status != MagickFalse)
1256 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1261 (void) FormatLocaleFile(stdout,"... pass.\n");
1263 (void) FormatLocaleFile(stdout,
1264 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1265 (double) (test-(*fail)),(double) *fail);
1270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 static MagickBooleanType ValidateUsage(void)
1291 "-debug events display copious debugging information",
1292 "-help print program options",
1293 "-log format format of debugging information",
1294 "-validate type validation type",
1295 "-version print version information",
1300 "-regard-warnings pay attention to warning messages",
1301 "-verbose print detailed information about the image",
1305 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1306 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1307 (void) printf("Features: %s\n",GetMagickFeatures());
1308 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1309 (void) printf("\nValidate Settings:\n");
1310 for (p=settings; *p != (char *) NULL; p++)
1311 (void) printf(" %s\n",*p);
1312 (void) printf("\nMiscellaneous Options:\n");
1313 for (p=miscellaneous; *p != (char *) NULL; p++)
1314 (void) printf(" %s\n",*p);
1318 int main(int argc,char **argv)
1320 #define DestroyValidate() \
1322 image_info=DestroyImageInfo(image_info); \
1323 exception=DestroyExceptionInfo(exception); \
1325 #define ThrowValidateException(asperity,tag,option) \
1327 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1329 CatchException(exception); \
1330 DestroyValidate(); \
1331 return(MagickFalse); \
1335 output_filename[MaxTextExtent],
1336 reference_filename[MaxTextExtent],
1375 Validate the ImageMagick image processing suite.
1377 MagickCoreGenesis(*argv,MagickTrue);
1378 (void) setlocale(LC_ALL,"");
1379 (void) setlocale(LC_NUMERIC,"C");
1383 regard_warnings=MagickFalse;
1384 (void) regard_warnings;
1385 exception=AcquireExceptionInfo();
1386 image_info=AcquireImageInfo();
1387 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1388 for (i=1; i < (ssize_t) argc; i++)
1391 if (IsCommandOption(option) == MagickFalse)
1393 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1396 switch (*(option+1))
1400 if (LocaleCompare("bench",option+1) == 0)
1402 iterations=StringToUnsignedLong(argv[++i]);
1405 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1409 if (LocaleCompare("debug",option+1) == 0)
1411 (void) SetLogEventMask(argv[++i]);
1414 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1418 if (LocaleCompare("help",option+1) == 0)
1420 (void) ValidateUsage();
1423 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1427 if (LocaleCompare("log",option+1) == 0)
1430 (void) SetLogFormat(argv[i+1]);
1433 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1437 if (LocaleCompare("regard-warnings",option+1) == 0)
1439 regard_warnings=MagickTrue;
1442 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1446 if (LocaleCompare("validate",option+1) == 0)
1454 if (i == (ssize_t) argc)
1455 ThrowValidateException(OptionError,"MissingArgument",option);
1456 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
1459 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1461 type=(ValidateType) validate;
1464 if ((LocaleCompare("version",option+1) == 0) ||
1465 (LocaleCompare("-version",option+1) == 0))
1467 (void) FormatLocaleFile(stdout,"Version: %s\n",
1468 GetMagickVersion((size_t *) NULL));
1469 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1470 GetMagickCopyright());
1471 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1472 GetMagickFeatures());
1475 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1478 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1481 timer=(TimerInfo *) NULL;
1483 timer=AcquireTimerInfo();
1484 reference_image=ReadImage(image_info,exception);
1487 if (reference_image == (Image *) NULL)
1491 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1492 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1494 (void) AcquireUniqueFilename(reference_filename);
1495 (void) AcquireUniqueFilename(output_filename);
1496 (void) CopyMagickString(reference_image->filename,reference_filename,
1498 status=WriteImage(image_info,reference_image,exception);
1499 reference_image=DestroyImage(reference_image);
1500 if (status == MagickFalse)
1504 (void) FormatLocaleFile(stdout,"Version: %s\n",
1505 GetMagickVersion((size_t *) NULL));
1506 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
1507 GetMagickCopyright());
1508 (void) FormatLocaleFile(stdout,
1509 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
1510 MagickValidateOptions,(ssize_t) type));
1511 if ((type & CompareValidate) != 0)
1512 tests+=ValidateCompareCommand(image_info,reference_filename,
1513 output_filename,&fail,exception);
1514 if ((type & CompositeValidate) != 0)
1515 tests+=ValidateCompositeCommand(image_info,reference_filename,
1516 output_filename,&fail,exception);
1517 if ((type & ConvertValidate) != 0)
1518 tests+=ValidateConvertCommand(image_info,reference_filename,
1519 output_filename,&fail,exception);
1520 if ((type & FormatsInMemoryValidate) != 0)
1522 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
1523 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1524 output_filename,&fail,exception);
1525 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
1526 memory_resource=SetMagickResourceLimit(MemoryResource,0);
1527 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1528 output_filename,&fail,exception);
1529 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
1530 map_resource=SetMagickResourceLimit(MapResource,0);
1531 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1532 output_filename,&fail,exception);
1533 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
1534 (void) SetMagickResourceLimit(MapResource,map_resource);
1536 if ((type & FormatsOnDiskValidate) != 0)
1538 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
1539 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1540 output_filename,&fail,exception);
1541 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
1542 memory_resource=SetMagickResourceLimit(MemoryResource,0);
1543 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1544 output_filename,&fail,exception);
1545 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
1546 map_resource=SetMagickResourceLimit(MapResource,0);
1547 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1548 output_filename,&fail,exception);
1549 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
1550 (void) SetMagickResourceLimit(MapResource,map_resource);
1552 if ((type & IdentifyValidate) != 0)
1553 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1554 output_filename,&fail,exception);
1555 if ((type & ImportExportValidate) != 0)
1556 tests+=ValidateImportExportPixels(image_info,reference_filename,
1557 output_filename,&fail,exception);
1558 if ((type & MontageValidate) != 0)
1559 tests+=ValidateMontageCommand(image_info,reference_filename,
1560 output_filename,&fail,exception);
1561 if ((type & StreamValidate) != 0)
1562 tests+=ValidateStreamCommand(image_info,reference_filename,
1563 output_filename,&fail,exception);
1564 (void) FormatLocaleFile(stdout,
1565 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1566 (double) tests,(double) (tests-fail),(double) fail);
1568 (void) RelinquishUniqueFileResource(output_filename);
1569 (void) RelinquishUniqueFileResource(reference_filename);
1571 if (exception->severity != UndefinedException)
1572 CatchException(exception);
1575 elapsed_time=GetElapsedTime(timer);
1576 user_time=GetUserTime(timer);
1577 (void) FormatLocaleFile(stderr,
1578 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1579 iterations,1.0*iterations/elapsed_time,user_time,(long)
1580 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1581 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1582 timer=DestroyTimerInfo(timer);
1585 MagickCoreTerminus();
1586 return(fail == 0 ? 0 : 1);