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-2010 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 "wand/MagickWand.h"
49 #include "magick/string-private.h"
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 % V a l i d a t e C o m p a r e C o m m a n d %
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 % ValidateCompareCommand() validates the ImageMagick compare command line
64 % program and returns the number of validation tests that passed and failed.
66 % The format of the ValidateCompareCommand method is:
68 % size_t ValidateCompareCommand(ImageInfo *image_info,
69 % const char *reference_filename,const char *output_filename,
70 % size_t *fail,ExceptionInfo *exception)
72 % A description of each parameter follows:
74 % o image_info: the image info.
76 % o reference_filename: the reference image filename.
78 % o output_filename: the output image filename.
80 % o fail: return the number of validation tests that pass.
82 % o exception: return any errors or warnings in this structure.
85 static size_t ValidateCompareCommand(ImageInfo *image_info,
86 const char *reference_filename,const char *output_filename,
87 size_t *fail,ExceptionInfo *exception)
91 command[MaxTextExtent];
107 (void) fprintf(stdout,"validate compare command line program:\n");
108 for (i=0; compare_options[i] != (char *) NULL; i++)
110 CatchException(exception);
111 (void) fprintf(stdout," test %.20g: %s",(double) (test++),
113 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
114 compare_options[i],reference_filename,reference_filename,output_filename);
115 arguments=StringToArgv(command,&number_arguments);
116 if (arguments == (char **) NULL)
118 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
122 status=CompareImageCommand(image_info,number_arguments,arguments,
123 (char **) NULL,exception);
124 for (j=0; j < number_arguments; j++)
125 arguments[j]=DestroyString(arguments[j]);
126 arguments=(char **) RelinquishMagickMemory(arguments);
127 if (status != MagickFalse)
129 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
133 (void) fprintf(stdout,"... pass.\n");
135 (void) fprintf(stdout,
136 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
137 (double) (test-(*fail)),(double) *fail);
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 % V a l i d a t e C o m p o s i t e C o m m a n d %
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 % ValidateCompositeCommand() validates the ImageMagick composite command line
153 % program and returns the number of validation tests that passed and failed.
155 % The format of the ValidateCompositeCommand method is:
157 % size_t ValidateCompositeCommand(ImageInfo *image_info,
158 % const char *reference_filename,const char *output_filename,
159 % size_t *fail,ExceptionInfo *exception)
161 % A description of each parameter follows:
163 % o image_info: the image info.
165 % o reference_filename: the reference image filename.
167 % o output_filename: the output image filename.
169 % o fail: return the number of validation tests that pass.
171 % o exception: return any errors or warnings in this structure.
174 static size_t ValidateCompositeCommand(ImageInfo *image_info,
175 const char *reference_filename,const char *output_filename,
176 size_t *fail,ExceptionInfo *exception)
180 command[MaxTextExtent];
196 (void) fprintf(stdout,"validate composite command line program:\n");
197 for (i=0; composite_options[i] != (char *) NULL; i++)
199 CatchException(exception);
200 (void) fprintf(stdout," test %.20g: %s",(double) (test++),
201 composite_options[i]);
202 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
203 reference_filename,composite_options[i],reference_filename,
205 arguments=StringToArgv(command,&number_arguments);
206 if (arguments == (char **) NULL)
208 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
212 status=CompositeImageCommand(image_info,number_arguments,arguments,
213 (char **) NULL,exception);
214 for (j=0; j < number_arguments; j++)
215 arguments[j]=DestroyString(arguments[j]);
216 arguments=(char **) RelinquishMagickMemory(arguments);
217 if (status != MagickFalse)
219 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
223 (void) fprintf(stdout,"... pass.\n");
225 (void) fprintf(stdout,
226 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
227 (double) (test-(*fail)),(double) *fail);
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 % V a l i d a t e C o n v e r t C o m m a n d %
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 % ValidateConvertCommand() validates the ImageMagick convert command line
243 % program and returns the number of validation tests that passed and failed.
245 % The format of the ValidateConvertCommand method is:
247 % size_t ValidateConvertCommand(ImageInfo *image_info,
248 % const char *reference_filename,const char *output_filename,
249 % size_t *fail,ExceptionInfo *exception)
251 % A description of each parameter follows:
253 % o image_info: the image info.
255 % o reference_filename: the reference image filename.
257 % o output_filename: the output image filename.
259 % o fail: return the number of validation tests that pass.
261 % o exception: return any errors or warnings in this structure.
264 static size_t ValidateConvertCommand(ImageInfo *image_info,
265 const char *reference_filename,const char *output_filename,
266 size_t *fail,ExceptionInfo *exception)
270 command[MaxTextExtent];
286 (void) fprintf(stdout,"validate convert command line program:\n");
287 for (i=0; convert_options[i] != (char *) NULL; i++)
289 CatchException(exception);
290 (void) fprintf(stdout," test %.20g: %s",(double) test++,
292 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
293 reference_filename,convert_options[i],reference_filename,output_filename);
294 arguments=StringToArgv(command,&number_arguments);
295 if (arguments == (char **) NULL)
297 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
301 status=ConvertImageCommand(image_info,number_arguments,arguments,
302 (char **) NULL,exception);
303 for (j=0; j < number_arguments; j++)
304 arguments[j]=DestroyString(arguments[j]);
305 arguments=(char **) RelinquishMagickMemory(arguments);
306 if (status != MagickFalse)
308 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
312 (void) fprintf(stdout,"... pass.\n");
314 (void) fprintf(stdout,
315 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
316 (double) (test-(*fail)),(double) *fail);
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 % V a l i d a t e I d e n t i f y C o m m a n d %
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % ValidateIdentifyCommand() validates the ImageMagick identify command line
332 % program and returns the number of validation tests that passed and failed.
334 % The format of the ValidateIdentifyCommand method is:
336 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
337 % const char *reference_filename,const char *output_filename,
338 % size_t *fail,ExceptionInfo *exception)
340 % A description of each parameter follows:
342 % o image_info: the image info.
344 % o reference_filename: the reference image filename.
346 % o output_filename: the output image filename.
348 % o fail: return the number of validation tests that pass.
350 % o exception: return any errors or warnings in this structure.
353 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
354 const char *reference_filename,const char *output_filename,
355 size_t *fail,ExceptionInfo *exception)
359 command[MaxTextExtent];
374 (void) output_filename;
376 (void) fprintf(stdout,"validate identify command line program:\n");
377 for (i=0; identify_options[i] != (char *) NULL; i++)
379 CatchException(exception);
380 (void) fprintf(stdout," test %.20g: %s",(double) test++,
381 identify_options[i]);
382 (void) FormatMagickString(command,MaxTextExtent,"%s %s",
383 identify_options[i],reference_filename);
384 arguments=StringToArgv(command,&number_arguments);
385 if (arguments == (char **) NULL)
387 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
391 status=IdentifyImageCommand(image_info,number_arguments,arguments,
392 (char **) NULL,exception);
393 for (j=0; j < number_arguments; j++)
394 arguments[j]=DestroyString(arguments[j]);
395 arguments=(char **) RelinquishMagickMemory(arguments);
396 if (status != MagickFalse)
398 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
402 (void) fprintf(stdout,"... pass.\n");
404 (void) fprintf(stdout,
405 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
406 (double) (test-(*fail)),(double) *fail);
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 % 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 %
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
422 % memory and returns the number of validation tests that passed and failed.
424 % The format of the ValidateImageFormatsInMemory method is:
426 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
427 % const char *reference_filename,const char *output_filename,
428 % size_t *fail,ExceptionInfo *exception)
430 % A description of each parameter follows:
432 % o image_info: the image info.
434 % o reference_filename: the reference image filename.
436 % o output_filename: the output image filename.
438 % o fail: return the number of validation tests that pass.
440 % o exception: return any errors or warnings in this structure.
443 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
444 const char *reference_filename,const char *output_filename,
445 size_t *fail,ExceptionInfo *exception)
479 (void) fprintf(stdout,"validate image formats in memory:\n");
480 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
482 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
483 if ((magick_info == (const MagickInfo *) NULL) ||
484 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
485 (magick_info->encoder == (EncodeImageHandler *) NULL))
487 for (j=0; reference_types[j].type != UndefinedType; j++)
490 Generate reference image.
492 CatchException(exception);
493 (void) fprintf(stdout," test %.20g: %s/%s/%s/%.20g-bits",(double)
494 (test++),reference_formats[i].magick,MagickOptionToMnemonic(
495 MagickCompressOptions,reference_formats[i].compression),
496 MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
497 (double) reference_types[j].depth);
498 (void) CopyMagickString(image_info->filename,reference_filename,
500 reference_image=ReadImage(image_info,exception);
501 if (reference_image == (Image *) NULL)
503 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
508 Write reference image.
510 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",
511 (double) reference_image->columns,(double) reference_image->rows);
512 (void) CloneString(&image_info->size,size);
513 image_info->depth=reference_types[j].depth;
514 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
515 reference_formats[i].magick,output_filename);
516 status=SetImageType(reference_image,reference_types[j].type);
517 InheritException(exception,&reference_image->exception);
518 if (status == MagickFalse)
520 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
522 reference_image=DestroyImage(reference_image);
525 status=SetImageDepth(reference_image,reference_types[j].depth);
526 InheritException(exception,&reference_image->exception);
527 if (status == MagickFalse)
529 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
531 reference_image=DestroyImage(reference_image);
534 reference_image->compression=reference_formats[i].compression;
535 status=WriteImage(image_info,reference_image);
536 InheritException(exception,&reference_image->exception);
537 reference_image=DestroyImage(reference_image);
538 if (status == MagickFalse)
540 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
545 Read reference image.
547 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
548 reference_formats[i].magick,output_filename);
549 reference_image=ReadImage(image_info,exception);
550 if (reference_image == (Image *) NULL)
552 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
557 Write reference image.
559 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
560 reference_formats[i].magick,output_filename);
561 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
563 reference_image->depth=reference_types[j].depth;
564 reference_image->compression=reference_formats[i].compression;
566 blob=ImageToBlob(image_info,reference_image,&length,exception);
567 if (blob == (unsigned char *) NULL)
569 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
571 reference_image=DestroyImage(reference_image);
575 Read reconstruct image.
577 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
578 reference_formats[i].magick,output_filename);
579 reconstruct_image=BlobToImage(image_info,blob,length,exception);
580 blob=(unsigned char *) RelinquishMagickMemory(blob);
581 if (reconstruct_image == (Image *) NULL)
583 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
585 reference_image=DestroyImage(reference_image);
589 Compare reference to reconstruct image.
592 if (reference_formats[i].fuzz != 0.0)
593 fuzz=reference_formats[i].fuzz;
594 #if defined(MAGICKCORE_HDRI_SUPPORT)
597 if (reference_image->colorspace != RGBColorspace)
600 difference_image=CompareImageChannels(reference_image,reconstruct_image,
601 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
602 reconstruct_image=DestroyImage(reconstruct_image);
603 reference_image=DestroyImage(reference_image);
604 if (difference_image == (Image *) NULL)
606 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
610 difference_image=DestroyImage(difference_image);
611 if ((distortion/QuantumRange) > fuzz)
613 (void) fprintf(stdout,"... fail (with distortion %g).\n",
614 distortion/QuantumRange);
618 (void) fprintf(stdout,"... pass.\n");
621 (void) fprintf(stdout,
622 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
623 (double) (test-(*fail)),(double) *fail);
628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
632 % 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 %
636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
638 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
639 % and returns the number of validation tests that passed and failed.
641 % The format of the ValidateImageFormatsOnDisk method is:
643 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
644 % const char *reference_filename,const char *output_filename,
645 % size_t *fail,ExceptionInfo *exception)
647 % A description of each parameter follows:
649 % o image_info: the image info.
651 % o reference_filename: the reference image filename.
653 % o output_filename: the output image filename.
655 % o fail: return the number of validation tests that pass.
657 % o exception: return any errors or warnings in this structure.
660 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
661 const char *reference_filename,const char *output_filename,
662 size_t *fail,ExceptionInfo *exception)
690 (void) fprintf(stdout,"validate image formats on disk:\n");
691 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
693 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
694 if ((magick_info == (const MagickInfo *) NULL) ||
695 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
696 (magick_info->encoder == (EncodeImageHandler *) NULL))
698 for (j=0; reference_types[j].type != UndefinedType; j++)
701 Generate reference image.
703 CatchException(exception);
704 (void) fprintf(stdout," test %.20g: %s/%s/%s/%.20g-bits",(double)
705 (test++),reference_formats[i].magick,MagickOptionToMnemonic(
706 MagickCompressOptions,reference_formats[i].compression),
707 MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
708 (double) reference_types[j].depth);
709 (void) CopyMagickString(image_info->filename,reference_filename,
711 reference_image=ReadImage(image_info,exception);
712 if (reference_image == (Image *) NULL)
714 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
719 Write reference image.
721 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",
722 (double) reference_image->columns,(double) reference_image->rows);
723 (void) CloneString(&image_info->size,size);
724 image_info->depth=reference_types[j].depth;
725 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
726 reference_formats[i].magick,output_filename);
727 status=SetImageType(reference_image,reference_types[j].type);
728 InheritException(exception,&reference_image->exception);
729 if (status == MagickFalse)
731 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
733 reference_image=DestroyImage(reference_image);
736 status=SetImageDepth(reference_image,reference_types[j].depth);
737 InheritException(exception,&reference_image->exception);
738 if (status == MagickFalse)
740 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
742 reference_image=DestroyImage(reference_image);
745 reference_image->compression=reference_formats[i].compression;
746 status=WriteImage(image_info,reference_image);
747 InheritException(exception,&reference_image->exception);
748 reference_image=DestroyImage(reference_image);
749 if (status == MagickFalse)
751 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
756 Read reference image.
758 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
759 reference_formats[i].magick,output_filename);
760 reference_image=ReadImage(image_info,exception);
761 if (reference_image == (Image *) NULL)
763 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
768 Write reference image.
770 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
771 reference_formats[i].magick,output_filename);
772 reference_image->depth=reference_types[j].depth;
773 reference_image->compression=reference_formats[i].compression;
774 status=WriteImage(image_info,reference_image);
775 InheritException(exception,&reference_image->exception);
776 if (status == MagickFalse)
778 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
780 reference_image=DestroyImage(reference_image);
784 Read reconstruct image.
786 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
787 reference_formats[i].magick,output_filename);
788 reconstruct_image=ReadImage(image_info,exception);
789 if (reconstruct_image == (Image *) NULL)
791 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
793 reference_image=DestroyImage(reference_image);
797 Compare reference to reconstruct image.
800 if (reference_formats[i].fuzz != 0.0)
801 fuzz=reference_formats[i].fuzz;
802 #if defined(MAGICKCORE_HDRI_SUPPORT)
805 if (reference_image->colorspace != RGBColorspace)
808 difference_image=CompareImageChannels(reference_image,reconstruct_image,
809 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
810 reconstruct_image=DestroyImage(reconstruct_image);
811 reference_image=DestroyImage(reference_image);
812 if (difference_image == (Image *) NULL)
814 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
818 difference_image=DestroyImage(difference_image);
819 if ((distortion/QuantumRange) > fuzz)
821 (void) fprintf(stdout,"... fail (with distortion %g).\n",
822 distortion/QuantumRange);
826 (void) fprintf(stdout,"... pass.\n");
829 (void) fprintf(stdout,
830 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
831 (double) (test-(*fail)),(double) *fail);
836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
840 % 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 %
844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 % ValidateImportExportPixels() validates the pixel import and export methods.
847 % It returns the number of validation tests that passed and failed.
849 % The format of the ValidateImportExportPixels method is:
851 % size_t ValidateImportExportPixels(ImageInfo *image_info,
852 % const char *reference_filename,const char *output_filename,
853 % size_t *fail,ExceptionInfo *exception)
855 % A description of each parameter follows:
857 % o image_info: the image info.
859 % o reference_filename: the reference image filename.
861 % o output_filename: the output image filename.
863 % o fail: return the number of validation tests that pass.
865 % o exception: return any errors or warnings in this structure.
868 static size_t ValidateImportExportPixels(ImageInfo *image_info,
869 const char *reference_filename,const char *output_filename,
870 size_t *fail,ExceptionInfo *exception)
896 (void) output_filename;
898 (void) fprintf(stdout,"validate the import and export of image pixels:\n");
899 for (i=0; reference_map[i] != (char *) NULL; i++)
901 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
904 Generate reference image.
906 CatchException(exception);
907 (void) fprintf(stdout," test %.20g: %s/%s",(double) (test++),
908 reference_map[i],MagickOptionToMnemonic(MagickStorageOptions,
909 reference_storage[j].type));
910 (void) CopyMagickString(image_info->filename,reference_filename,
912 reference_image=ReadImage(image_info,exception);
913 if (reference_image == (Image *) NULL)
915 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
919 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
920 (void) TransformImageColorspace(reference_image,CMYKColorspace);
921 length=strlen(reference_map[i])*reference_image->columns*
922 reference_image->rows*reference_storage[j].quantum;
923 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
924 if (pixels == (unsigned char *) NULL)
926 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
928 reference_image=DestroyImage(reference_image);
931 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
932 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
933 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
935 if (status == MagickFalse)
937 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
939 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
940 reference_image=DestroyImage(reference_image);
943 (void) SetImageBackgroundColor(reference_image);
944 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
945 reference_image->rows,reference_map[i],reference_storage[j].type,
947 InheritException(exception,&reference_image->exception);
948 if (status == MagickFalse)
950 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
952 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
953 reference_image=DestroyImage(reference_image);
957 Read reconstruct image.
959 reconstruct_image=AcquireImage(image_info);
960 (void) SetImageExtent(reconstruct_image,reference_image->columns,
961 reference_image->rows);
962 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
963 (void) SetImageBackgroundColor(reconstruct_image);
964 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
965 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
967 InheritException(exception,&reconstruct_image->exception);
968 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
969 if (status == MagickFalse)
971 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
973 reference_image=DestroyImage(reference_image);
977 Compare reference to reconstruct image.
979 difference_image=CompareImageChannels(reference_image,reconstruct_image,
980 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
981 reconstruct_image=DestroyImage(reconstruct_image);
982 reference_image=DestroyImage(reference_image);
983 if (difference_image == (Image *) NULL)
985 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
989 difference_image=DestroyImage(difference_image);
990 if ((distortion/QuantumRange) > 0.0)
992 (void) fprintf(stdout,"... fail (with distortion %g).\n",
993 distortion/QuantumRange);
997 (void) fprintf(stdout,"... pass.\n");
1000 (void) fprintf(stdout,
1001 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1002 (double) (test-(*fail)),(double) *fail);
1007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1011 % V a l i d a t e M o n t a g e C o m m a n d %
1015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 % ValidateMontageCommand() validates the ImageMagick montage command line
1018 % program and returns the number of validation tests that passed and failed.
1020 % The format of the ValidateMontageCommand method is:
1022 % size_t ValidateMontageCommand(ImageInfo *image_info,
1023 % const char *reference_filename,const char *output_filename,
1024 % size_t *fail,ExceptionInfo *exception)
1026 % A description of each parameter follows:
1028 % o image_info: the image info.
1030 % o reference_filename: the reference image filename.
1032 % o output_filename: the output image filename.
1034 % o fail: return the number of validation tests that pass.
1036 % o exception: return any errors or warnings in this structure.
1039 static size_t ValidateMontageCommand(ImageInfo *image_info,
1040 const char *reference_filename,const char *output_filename,
1041 size_t *fail,ExceptionInfo *exception)
1045 command[MaxTextExtent];
1061 (void) fprintf(stdout,"validate montage command line program:\n");
1062 for (i=0; montage_options[i] != (char *) NULL; i++)
1064 CatchException(exception);
1065 (void) fprintf(stdout," test %.20g: %s",(double) (test++),
1066 montage_options[i]);
1067 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
1068 reference_filename,montage_options[i],reference_filename,
1070 arguments=StringToArgv(command,&number_arguments);
1071 if (arguments == (char **) NULL)
1073 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
1077 status=MontageImageCommand(image_info,number_arguments,arguments,
1078 (char **) NULL,exception);
1079 for (j=0; j < number_arguments; j++)
1080 arguments[j]=DestroyString(arguments[j]);
1081 arguments=(char **) RelinquishMagickMemory(arguments);
1082 if (status != MagickFalse)
1084 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
1088 (void) fprintf(stdout,"... pass.\n");
1090 (void) fprintf(stdout,
1091 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1092 (double) (test-(*fail)),(double) *fail);
1097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1101 % V a l i d a t e S t r e a m C o m m a n d %
1105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1107 % ValidateStreamCommand() validates the ImageMagick stream command line
1108 % program and returns the number of validation tests that passed and failed.
1110 % The format of the ValidateStreamCommand method is:
1112 % size_t ValidateStreamCommand(ImageInfo *image_info,
1113 % const char *reference_filename,const char *output_filename,
1114 % size_t *fail,ExceptionInfo *exception)
1116 % A description of each parameter follows:
1118 % o image_info: the image info.
1120 % o reference_filename: the reference image filename.
1122 % o output_filename: the output image filename.
1124 % o fail: return the number of validation tests that pass.
1126 % o exception: return any errors or warnings in this structure.
1129 static size_t ValidateStreamCommand(ImageInfo *image_info,
1130 const char *reference_filename,const char *output_filename,
1131 size_t *fail,ExceptionInfo *exception)
1135 command[MaxTextExtent];
1151 (void) fprintf(stdout,"validate stream command line program:\n");
1152 for (i=0; stream_options[i] != (char *) NULL; i++)
1154 CatchException(exception);
1155 (void) fprintf(stdout," test %.20g: %s",(double) (test++),
1157 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s",
1158 stream_options[i],reference_filename,output_filename);
1159 arguments=StringToArgv(command,&number_arguments);
1160 if (arguments == (char **) NULL)
1162 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
1166 status=StreamImageCommand(image_info,number_arguments,arguments,
1167 (char **) NULL,exception);
1168 for (j=0; j < number_arguments; j++)
1169 arguments[j]=DestroyString(arguments[j]);
1170 arguments=(char **) RelinquishMagickMemory(arguments);
1171 if (status != MagickFalse)
1173 (void) fprintf(stdout,"... fail @ %s/%s/%u.\n",GetMagickModule());
1177 (void) fprintf(stdout,"... pass.\n");
1179 (void) fprintf(stdout,
1180 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1181 (double) (test-(*fail)),(double) *fail);
1186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1199 static MagickBooleanType ValidateUsage(void)
1207 "-debug events display copious debugging information",
1208 "-help print program options",
1209 "-log format format of debugging information",
1210 "-validate type validation type",
1211 "-version print version information",
1216 "-regard-warnings pay attention to warning messages",
1217 "-verbose print detailed information about the image",
1221 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1222 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1223 (void) printf("Features: %s\n",GetMagickFeatures());
1224 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1225 (void) printf("\nValidate Settings:\n");
1226 for (p=settings; *p != (char *) NULL; p++)
1227 (void) printf(" %s\n",*p);
1228 (void) printf("\nMiscellaneous Options:\n");
1229 for (p=miscellaneous; *p != (char *) NULL; p++)
1230 (void) printf(" %s\n",*p);
1234 int main(int argc,char **argv)
1236 #define DestroyValidate() \
1238 image_info=DestroyImageInfo(image_info); \
1239 exception=DestroyExceptionInfo(exception); \
1241 #define ThrowValidateException(asperity,tag,option) \
1243 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1245 CatchException(exception); \
1246 DestroyValidate(); \
1247 return(MagickFalse); \
1251 output_filename[MaxTextExtent],
1252 reference_filename[MaxTextExtent],
1287 Validate the ImageMagick image processing suite.
1289 MagickCoreGenesis(*argv,MagickFalse);
1293 regard_warnings=MagickFalse;
1294 exception=AcquireExceptionInfo();
1295 image_info=AcquireImageInfo();
1296 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1297 for (i=1; i < (ssize_t) argc; i++)
1300 if (IsMagickOption(option) == MagickFalse)
1302 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1305 switch (*(option+1))
1309 if (LocaleCompare("bench",option+1) == 0)
1311 iterations=StringToUnsignedLong(argv[++i]);
1314 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1318 if (LocaleCompare("debug",option+1) == 0)
1320 (void) SetLogEventMask(argv[++i]);
1323 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1327 if (LocaleCompare("help",option+1) == 0)
1329 (void) ValidateUsage();
1332 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1336 if (LocaleCompare("log",option+1) == 0)
1339 (void) SetLogFormat(argv[i+1]);
1342 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1346 if (LocaleCompare("regard-warnings",option+1) == 0)
1348 regard_warnings=MagickTrue;
1351 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1355 if (LocaleCompare("validate",option+1) == 0)
1363 if (i == (ssize_t) argc)
1364 ThrowValidateException(OptionError,"MissingArgument",option);
1365 validate=ParseMagickOption(MagickValidateOptions,MagickFalse,
1368 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1370 type=(ValidateType) validate;
1373 if ((LocaleCompare("version",option+1) == 0) ||
1374 (LocaleCompare("-version",option+1) == 0))
1376 (void) fprintf(stdout,"Version: %s\n",
1377 GetMagickVersion((size_t *) NULL));
1378 (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright());
1379 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
1382 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1385 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1388 timer=(TimerInfo *) NULL;
1390 timer=AcquireTimerInfo();
1391 reference_image=ReadImage(image_info,exception);
1394 if (reference_image == (Image *) NULL)
1398 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1399 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1401 (void) AcquireUniqueFilename(reference_filename);
1402 (void) AcquireUniqueFilename(output_filename);
1403 (void) CopyMagickString(reference_image->filename,reference_filename,
1405 status=WriteImage(image_info,reference_image);
1406 InheritException(exception,&reference_image->exception);
1407 reference_image=DestroyImage(reference_image);
1408 if (status == MagickFalse)
1412 (void) fprintf(stdout,"Version: %s\n",
1413 GetMagickVersion((size_t *) NULL));
1414 (void) fprintf(stdout,"Copyright: %s\n\n",
1415 GetMagickCopyright());
1416 (void) fprintf(stdout,"ImageMagick Validation Suite (%s)\n\n",
1417 MagickOptionToMnemonic(MagickValidateOptions,(ssize_t) type));
1418 if ((type & CompareValidate) != 0)
1419 tests+=ValidateCompareCommand(image_info,reference_filename,
1420 output_filename,&fail,exception);
1421 if ((type & CompositeValidate) != 0)
1422 tests+=ValidateCompositeCommand(image_info,reference_filename,
1423 output_filename,&fail,exception);
1424 if ((type & ConvertValidate) != 0)
1425 tests+=ValidateConvertCommand(image_info,reference_filename,
1426 output_filename,&fail,exception);
1427 if ((type & FormatsInMemoryValidate) != 0)
1428 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1429 output_filename,&fail,exception);
1430 if ((type & FormatsOnDiskValidate) != 0)
1431 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1432 output_filename,&fail,exception);
1433 if ((type & IdentifyValidate) != 0)
1434 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1435 output_filename,&fail,exception);
1436 if ((type & ImportExportValidate) != 0)
1437 tests+=ValidateImportExportPixels(image_info,reference_filename,
1438 output_filename,&fail,exception);
1439 if ((type & MontageValidate) != 0)
1440 tests+=ValidateMontageCommand(image_info,reference_filename,
1441 output_filename,&fail,exception);
1442 if ((type & StreamValidate) != 0)
1443 tests+=ValidateStreamCommand(image_info,reference_filename,
1444 output_filename,&fail,exception);
1445 (void) fprintf(stdout,
1446 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
1447 (double) tests,(double) (tests-fail),(double) fail);
1449 (void) RelinquishUniqueFileResource(output_filename);
1450 (void) RelinquishUniqueFileResource(reference_filename);
1452 if (exception->severity != UndefinedException)
1453 CatchException(exception);
1456 elapsed_time=GetElapsedTime(timer);
1457 user_time=GetUserTime(timer);
1458 (void) fprintf(stderr,
1459 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
1460 iterations,1.0*iterations/elapsed_time,user_time,(long)
1461 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1462 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1463 timer=DestroyTimerInfo(timer);
1466 MagickCoreTerminus();
1467 return(fail == 0 ? 0 : 1);