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 %lu: %s",(unsigned long) 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/%lu.\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/%lu.\n",GetMagickModule());
133 (void) fprintf(stdout,"... pass.\n");
135 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
136 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % V a l i d a t e C o m p o s i t e C o m m a n d %
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 % ValidateCompositeCommand() validates the ImageMagick composite command line
152 % program and returns the number of validation tests that passed and failed.
154 % The format of the ValidateCompositeCommand method is:
156 % size_t ValidateCompositeCommand(ImageInfo *image_info,
157 % const char *reference_filename,const char *output_filename,
158 % size_t *fail,ExceptionInfo *exception)
160 % A description of each parameter follows:
162 % o image_info: the image info.
164 % o reference_filename: the reference image filename.
166 % o output_filename: the output image filename.
168 % o fail: return the number of validation tests that pass.
170 % o exception: return any errors or warnings in this structure.
173 static size_t ValidateCompositeCommand(ImageInfo *image_info,
174 const char *reference_filename,const char *output_filename,
175 size_t *fail,ExceptionInfo *exception)
179 command[MaxTextExtent];
195 (void) fprintf(stdout,"validate composite command line program:\n");
196 for (i=0; composite_options[i] != (char *) NULL; i++)
198 CatchException(exception);
199 (void) fprintf(stdout," test %lu: %s",(unsigned long) test++,
200 composite_options[i]);
201 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
202 reference_filename,composite_options[i],reference_filename,
204 arguments=StringToArgv(command,&number_arguments);
205 if (arguments == (char **) NULL)
207 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
211 status=CompositeImageCommand(image_info,number_arguments,arguments,
212 (char **) NULL,exception);
213 for (j=0; j < number_arguments; j++)
214 arguments[j]=DestroyString(arguments[j]);
215 arguments=(char **) RelinquishMagickMemory(arguments);
216 if (status != MagickFalse)
218 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
222 (void) fprintf(stdout,"... pass.\n");
224 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
225 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % V a l i d a t e C o n v e r t C o m m a n d %
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % ValidateConvertCommand() validates the ImageMagick convert command line
241 % program and returns the number of validation tests that passed and failed.
243 % The format of the ValidateConvertCommand method is:
245 % size_t ValidateConvertCommand(ImageInfo *image_info,
246 % const char *reference_filename,const char *output_filename,
247 % size_t *fail,ExceptionInfo *exception)
249 % A description of each parameter follows:
251 % o image_info: the image info.
253 % o reference_filename: the reference image filename.
255 % o output_filename: the output image filename.
257 % o fail: return the number of validation tests that pass.
259 % o exception: return any errors or warnings in this structure.
262 static size_t ValidateConvertCommand(ImageInfo *image_info,
263 const char *reference_filename,const char *output_filename,
264 size_t *fail,ExceptionInfo *exception)
268 command[MaxTextExtent];
284 (void) fprintf(stdout,"validate convert command line program:\n");
285 for (i=0; convert_options[i] != (char *) NULL; i++)
287 CatchException(exception);
288 (void) fprintf(stdout," test %lu: %s",(unsigned long) test++,
290 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
291 reference_filename,convert_options[i],reference_filename,output_filename);
292 arguments=StringToArgv(command,&number_arguments);
293 if (arguments == (char **) NULL)
295 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
299 status=ConvertImageCommand(image_info,number_arguments,arguments,
300 (char **) NULL,exception);
301 for (j=0; j < number_arguments; j++)
302 arguments[j]=DestroyString(arguments[j]);
303 arguments=(char **) RelinquishMagickMemory(arguments);
304 if (status != MagickFalse)
306 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
310 (void) fprintf(stdout,"... pass.\n");
312 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
313 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 % V a l i d a t e I d e n t i f y C o m m a n d %
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 % ValidateIdentifyCommand() validates the ImageMagick identify command line
329 % program and returns the number of validation tests that passed and failed.
331 % The format of the ValidateIdentifyCommand method is:
333 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
334 % const char *reference_filename,const char *output_filename,
335 % size_t *fail,ExceptionInfo *exception)
337 % A description of each parameter follows:
339 % o image_info: the image info.
341 % o reference_filename: the reference image filename.
343 % o output_filename: the output image filename.
345 % o fail: return the number of validation tests that pass.
347 % o exception: return any errors or warnings in this structure.
350 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
351 const char *reference_filename,const char *output_filename,
352 size_t *fail,ExceptionInfo *exception)
356 command[MaxTextExtent];
371 (void) output_filename;
373 (void) fprintf(stdout,"validate identify command line program:\n");
374 for (i=0; identify_options[i] != (char *) NULL; i++)
376 CatchException(exception);
377 (void) fprintf(stdout," test %lu: %s",(unsigned long) test++,
378 identify_options[i]);
379 (void) FormatMagickString(command,MaxTextExtent,"%s %s",
380 identify_options[i],reference_filename);
381 arguments=StringToArgv(command,&number_arguments);
382 if (arguments == (char **) NULL)
384 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
388 status=IdentifyImageCommand(image_info,number_arguments,arguments,
389 (char **) NULL,exception);
390 for (j=0; j < number_arguments; j++)
391 arguments[j]=DestroyString(arguments[j]);
392 arguments=(char **) RelinquishMagickMemory(arguments);
393 if (status != MagickFalse)
395 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
399 (void) fprintf(stdout,"... pass.\n");
401 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
402 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 % 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 %
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
418 % memory and returns the number of validation tests that passed and failed.
420 % The format of the ValidateImageFormatsInMemory method is:
422 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
423 % const char *reference_filename,const char *output_filename,
424 % size_t *fail,ExceptionInfo *exception)
426 % A description of each parameter follows:
428 % o image_info: the image info.
430 % o reference_filename: the reference image filename.
432 % o output_filename: the output image filename.
434 % o fail: return the number of validation tests that pass.
436 % o exception: return any errors or warnings in this structure.
439 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
440 const char *reference_filename,const char *output_filename,
441 size_t *fail,ExceptionInfo *exception)
475 (void) fprintf(stdout,"validate image formats in memory:\n");
476 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
478 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
479 if ((magick_info == (const MagickInfo *) NULL) ||
480 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
481 (magick_info->encoder == (EncodeImageHandler *) NULL))
483 for (j=0; reference_types[j].type != UndefinedType; j++)
486 Generate reference image.
488 CatchException(exception);
489 (void) fprintf(stdout," test %lu: %s/%s/%s/%lu-bits",(unsigned long)
490 test++,reference_formats[i].magick,MagickOptionToMnemonic(
491 MagickCompressOptions,reference_formats[i].compression),
492 MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
493 (unsigned long) reference_types[j].depth);
494 (void) CopyMagickString(image_info->filename,reference_filename,
496 reference_image=ReadImage(image_info,exception);
497 if (reference_image == (Image *) NULL)
499 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
504 Write reference image.
506 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",
507 (unsigned long) reference_image->columns,(unsigned long)
508 reference_image->rows);
509 (void) CloneString(&image_info->size,size);
510 image_info->depth=reference_types[j].depth;
511 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
512 reference_formats[i].magick,output_filename);
513 status=SetImageType(reference_image,reference_types[j].type);
514 InheritException(exception,&reference_image->exception);
515 if (status == MagickFalse)
517 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
519 reference_image=DestroyImage(reference_image);
522 status=SetImageDepth(reference_image,reference_types[j].depth);
523 InheritException(exception,&reference_image->exception);
524 if (status == MagickFalse)
526 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
528 reference_image=DestroyImage(reference_image);
531 reference_image->compression=reference_formats[i].compression;
532 status=WriteImage(image_info,reference_image);
533 InheritException(exception,&reference_image->exception);
534 reference_image=DestroyImage(reference_image);
535 if (status == MagickFalse)
537 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
542 Read reference image.
544 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
545 reference_formats[i].magick,output_filename);
546 reference_image=ReadImage(image_info,exception);
547 if (reference_image == (Image *) NULL)
549 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
554 Write reference image.
556 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
557 reference_formats[i].magick,output_filename);
558 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
560 reference_image->depth=reference_types[j].depth;
561 reference_image->compression=reference_formats[i].compression;
563 blob=ImageToBlob(image_info,reference_image,&length,exception);
564 if (blob == (unsigned char *) NULL)
566 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
568 reference_image=DestroyImage(reference_image);
572 Read reconstruct image.
574 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
575 reference_formats[i].magick,output_filename);
576 reconstruct_image=BlobToImage(image_info,blob,length,exception);
577 blob=(unsigned char *) RelinquishMagickMemory(blob);
578 if (reconstruct_image == (Image *) NULL)
580 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
582 reference_image=DestroyImage(reference_image);
586 Compare reference to reconstruct image.
589 if (reference_formats[i].fuzz != 0.0)
590 fuzz=reference_formats[i].fuzz;
591 #if defined(MAGICKCORE_HDRI_SUPPORT)
594 if (reference_image->colorspace != RGBColorspace)
597 difference_image=CompareImageChannels(reference_image,reconstruct_image,
598 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
599 reconstruct_image=DestroyImage(reconstruct_image);
600 reference_image=DestroyImage(reference_image);
601 if (difference_image == (Image *) NULL)
603 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
607 difference_image=DestroyImage(difference_image);
608 if ((distortion/QuantumRange) > fuzz)
610 (void) fprintf(stdout,"... fail (with distortion %g).\n",
611 distortion/QuantumRange);
615 (void) fprintf(stdout,"... pass.\n");
618 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
619 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % 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 %
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
635 % and returns the number of validation tests that passed and failed.
637 % The format of the ValidateImageFormatsOnDisk method is:
639 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
640 % const char *reference_filename,const char *output_filename,
641 % size_t *fail,ExceptionInfo *exception)
643 % A description of each parameter follows:
645 % o image_info: the image info.
647 % o reference_filename: the reference image filename.
649 % o output_filename: the output image filename.
651 % o fail: return the number of validation tests that pass.
653 % o exception: return any errors or warnings in this structure.
656 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
657 const char *reference_filename,const char *output_filename,
658 size_t *fail,ExceptionInfo *exception)
686 (void) fprintf(stdout,"validate image formats on disk:\n");
687 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
689 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
690 if ((magick_info == (const MagickInfo *) NULL) ||
691 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
692 (magick_info->encoder == (EncodeImageHandler *) NULL))
694 for (j=0; reference_types[j].type != UndefinedType; j++)
697 Generate reference image.
699 CatchException(exception);
700 (void) fprintf(stdout," test %lu: %s/%s/%s/%lu-bits",(unsigned long)
701 test++,reference_formats[i].magick,MagickOptionToMnemonic(
702 MagickCompressOptions,reference_formats[i].compression),
703 MagickOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
704 (unsigned long) reference_types[j].depth);
705 (void) CopyMagickString(image_info->filename,reference_filename,
707 reference_image=ReadImage(image_info,exception);
708 if (reference_image == (Image *) NULL)
710 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
715 Write reference image.
717 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",
718 (unsigned long) reference_image->columns,(unsigned long)
719 reference_image->rows);
720 (void) CloneString(&image_info->size,size);
721 image_info->depth=reference_types[j].depth;
722 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
723 reference_formats[i].magick,output_filename);
724 status=SetImageType(reference_image,reference_types[j].type);
725 InheritException(exception,&reference_image->exception);
726 if (status == MagickFalse)
728 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
730 reference_image=DestroyImage(reference_image);
733 status=SetImageDepth(reference_image,reference_types[j].depth);
734 InheritException(exception,&reference_image->exception);
735 if (status == MagickFalse)
737 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
739 reference_image=DestroyImage(reference_image);
742 reference_image->compression=reference_formats[i].compression;
743 status=WriteImage(image_info,reference_image);
744 InheritException(exception,&reference_image->exception);
745 reference_image=DestroyImage(reference_image);
746 if (status == MagickFalse)
748 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
753 Read reference image.
755 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
756 reference_formats[i].magick,output_filename);
757 reference_image=ReadImage(image_info,exception);
758 if (reference_image == (Image *) NULL)
760 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
765 Write reference image.
767 (void) FormatMagickString(reference_image->filename,MaxTextExtent,"%s:%s",
768 reference_formats[i].magick,output_filename);
769 reference_image->depth=reference_types[j].depth;
770 reference_image->compression=reference_formats[i].compression;
771 status=WriteImage(image_info,reference_image);
772 InheritException(exception,&reference_image->exception);
773 if (status == MagickFalse)
775 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
777 reference_image=DestroyImage(reference_image);
781 Read reconstruct image.
783 (void) FormatMagickString(image_info->filename,MaxTextExtent,"%s:%s",
784 reference_formats[i].magick,output_filename);
785 reconstruct_image=ReadImage(image_info,exception);
786 if (reconstruct_image == (Image *) NULL)
788 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
790 reference_image=DestroyImage(reference_image);
794 Compare reference to reconstruct image.
797 if (reference_formats[i].fuzz != 0.0)
798 fuzz=reference_formats[i].fuzz;
799 #if defined(MAGICKCORE_HDRI_SUPPORT)
802 if (reference_image->colorspace != RGBColorspace)
805 difference_image=CompareImageChannels(reference_image,reconstruct_image,
806 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
807 reconstruct_image=DestroyImage(reconstruct_image);
808 reference_image=DestroyImage(reference_image);
809 if (difference_image == (Image *) NULL)
811 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
815 difference_image=DestroyImage(difference_image);
816 if ((distortion/QuantumRange) > fuzz)
818 (void) fprintf(stdout,"... fail (with distortion %g).\n",
819 distortion/QuantumRange);
823 (void) fprintf(stdout,"... pass.\n");
826 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
827 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
836 % 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 %
840 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
842 % ValidateImportExportPixels() validates the pixel import and export methods.
843 % It returns the number of validation tests that passed and failed.
845 % The format of the ValidateImportExportPixels method is:
847 % size_t ValidateImportExportPixels(ImageInfo *image_info,
848 % const char *reference_filename,const char *output_filename,
849 % size_t *fail,ExceptionInfo *exception)
851 % A description of each parameter follows:
853 % o image_info: the image info.
855 % o reference_filename: the reference image filename.
857 % o output_filename: the output image filename.
859 % o fail: return the number of validation tests that pass.
861 % o exception: return any errors or warnings in this structure.
864 static size_t ValidateImportExportPixels(ImageInfo *image_info,
865 const char *reference_filename,const char *output_filename,
866 size_t *fail,ExceptionInfo *exception)
892 (void) output_filename;
894 (void) fprintf(stdout,"validate the import and export of image pixels:\n");
895 for (i=0; reference_map[i] != (char *) NULL; i++)
897 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
900 Generate reference image.
902 CatchException(exception);
903 (void) fprintf(stdout," test %lu: %s/%s",(unsigned long) test++,
904 reference_map[i],MagickOptionToMnemonic(MagickStorageOptions,
905 reference_storage[j].type));
906 (void) CopyMagickString(image_info->filename,reference_filename,
908 reference_image=ReadImage(image_info,exception);
909 if (reference_image == (Image *) NULL)
911 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
915 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
916 (void) TransformImageColorspace(reference_image,CMYKColorspace);
917 length=strlen(reference_map[i])*reference_image->columns*
918 reference_image->rows*reference_storage[j].quantum;
919 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
920 if (pixels == (unsigned char *) NULL)
922 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
924 reference_image=DestroyImage(reference_image);
927 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
928 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
929 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
931 if (status == MagickFalse)
933 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
935 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
936 reference_image=DestroyImage(reference_image);
939 (void) SetImageBackgroundColor(reference_image);
940 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
941 reference_image->rows,reference_map[i],reference_storage[j].type,
943 InheritException(exception,&reference_image->exception);
944 if (status == MagickFalse)
946 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
948 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
949 reference_image=DestroyImage(reference_image);
953 Read reconstruct image.
955 reconstruct_image=AcquireImage(image_info);
956 (void) SetImageExtent(reconstruct_image,reference_image->columns,
957 reference_image->rows);
958 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
959 (void) SetImageBackgroundColor(reconstruct_image);
960 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
961 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
963 InheritException(exception,&reconstruct_image->exception);
964 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
965 if (status == MagickFalse)
967 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
969 reference_image=DestroyImage(reference_image);
973 Compare reference to reconstruct image.
975 difference_image=CompareImageChannels(reference_image,reconstruct_image,
976 AllChannels,MeanSquaredErrorMetric,&distortion,exception);
977 reconstruct_image=DestroyImage(reconstruct_image);
978 reference_image=DestroyImage(reference_image);
979 if (difference_image == (Image *) NULL)
981 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
985 difference_image=DestroyImage(difference_image);
986 if ((distortion/QuantumRange) > 0.0)
988 (void) fprintf(stdout,"... fail (with distortion %g).\n",
989 distortion/QuantumRange);
993 (void) fprintf(stdout,"... pass.\n");
996 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
997 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
1002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 % V a l i d a t e M o n t a g e C o m m a n d %
1010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1012 % ValidateMontageCommand() validates the ImageMagick montage command line
1013 % program and returns the number of validation tests that passed and failed.
1015 % The format of the ValidateMontageCommand method is:
1017 % size_t ValidateMontageCommand(ImageInfo *image_info,
1018 % const char *reference_filename,const char *output_filename,
1019 % size_t *fail,ExceptionInfo *exception)
1021 % A description of each parameter follows:
1023 % o image_info: the image info.
1025 % o reference_filename: the reference image filename.
1027 % o output_filename: the output image filename.
1029 % o fail: return the number of validation tests that pass.
1031 % o exception: return any errors or warnings in this structure.
1034 static size_t ValidateMontageCommand(ImageInfo *image_info,
1035 const char *reference_filename,const char *output_filename,
1036 size_t *fail,ExceptionInfo *exception)
1040 command[MaxTextExtent];
1056 (void) fprintf(stdout,"validate montage command line program:\n");
1057 for (i=0; montage_options[i] != (char *) NULL; i++)
1059 CatchException(exception);
1060 (void) fprintf(stdout," test %lu: %s",(unsigned long) test++,
1061 montage_options[i]);
1062 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s %s",
1063 reference_filename,montage_options[i],reference_filename,
1065 arguments=StringToArgv(command,&number_arguments);
1066 if (arguments == (char **) NULL)
1068 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1072 status=MontageImageCommand(image_info,number_arguments,arguments,
1073 (char **) NULL,exception);
1074 for (j=0; j < number_arguments; j++)
1075 arguments[j]=DestroyString(arguments[j]);
1076 arguments=(char **) RelinquishMagickMemory(arguments);
1077 if (status != MagickFalse)
1079 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1083 (void) fprintf(stdout,"... pass.\n");
1085 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
1086 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
1091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1095 % V a l i d a t e S t r e a m C o m m a n d %
1099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1101 % ValidateStreamCommand() validates the ImageMagick stream command line
1102 % program and returns the number of validation tests that passed and failed.
1104 % The format of the ValidateStreamCommand method is:
1106 % size_t ValidateStreamCommand(ImageInfo *image_info,
1107 % const char *reference_filename,const char *output_filename,
1108 % size_t *fail,ExceptionInfo *exception)
1110 % A description of each parameter follows:
1112 % o image_info: the image info.
1114 % o reference_filename: the reference image filename.
1116 % o output_filename: the output image filename.
1118 % o fail: return the number of validation tests that pass.
1120 % o exception: return any errors or warnings in this structure.
1123 static size_t ValidateStreamCommand(ImageInfo *image_info,
1124 const char *reference_filename,const char *output_filename,
1125 size_t *fail,ExceptionInfo *exception)
1129 command[MaxTextExtent];
1145 (void) fprintf(stdout,"validate stream command line program:\n");
1146 for (i=0; stream_options[i] != (char *) NULL; i++)
1148 CatchException(exception);
1149 (void) fprintf(stdout," test %lu: %s",(unsigned long) test++,
1151 (void) FormatMagickString(command,MaxTextExtent,"%s %s %s",
1152 stream_options[i],reference_filename,output_filename);
1153 arguments=StringToArgv(command,&number_arguments);
1154 if (arguments == (char **) NULL)
1156 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1160 status=StreamImageCommand(image_info,number_arguments,arguments,
1161 (char **) NULL,exception);
1162 for (j=0; j < number_arguments; j++)
1163 arguments[j]=DestroyString(arguments[j]);
1164 arguments=(char **) RelinquishMagickMemory(arguments);
1165 if (status != MagickFalse)
1167 (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
1171 (void) fprintf(stdout,"... pass.\n");
1173 (void) fprintf(stdout," summary: %lu subtests; %lu passed; %lu failed.\n",
1174 (unsigned long) test,(unsigned long) (test-(*fail)),(unsigned long) *fail);
1179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1192 static MagickBooleanType ValidateUsage(void)
1200 "-debug events display copious debugging information",
1201 "-help print program options",
1202 "-log format format of debugging information",
1203 "-validate type validation type",
1204 "-version print version information",
1209 "-regard-warnings pay attention to warning messages",
1210 "-verbose print detailed information about the image",
1214 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
1215 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
1216 (void) printf("Features: %s\n",GetMagickFeatures());
1217 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
1218 (void) printf("\nValidate Settings:\n");
1219 for (p=settings; *p != (char *) NULL; p++)
1220 (void) printf(" %s\n",*p);
1221 (void) printf("\nMiscellaneous Options:\n");
1222 for (p=miscellaneous; *p != (char *) NULL; p++)
1223 (void) printf(" %s\n",*p);
1227 int main(int argc,char **argv)
1229 #define DestroyValidate() \
1231 image_info=DestroyImageInfo(image_info); \
1232 exception=DestroyExceptionInfo(exception); \
1234 #define ThrowValidateException(asperity,tag,option) \
1236 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
1238 CatchException(exception); \
1239 DestroyValidate(); \
1240 return(MagickFalse); \
1244 output_filename[MaxTextExtent],
1245 reference_filename[MaxTextExtent],
1280 Validate the ImageMagick image processing suite.
1282 MagickCoreGenesis(*argv,MagickFalse);
1286 regard_warnings=MagickFalse;
1287 exception=AcquireExceptionInfo();
1288 image_info=AcquireImageInfo();
1289 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
1290 for (i=1; i < (ssize_t) argc; i++)
1293 if (IsMagickOption(option) == MagickFalse)
1295 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
1298 switch (*(option+1))
1302 if (LocaleCompare("bench",option+1) == 0)
1304 iterations=StringToUnsignedLong(argv[++i]);
1307 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1311 if (LocaleCompare("debug",option+1) == 0)
1313 (void) SetLogEventMask(argv[++i]);
1316 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1320 if (LocaleCompare("help",option+1) == 0)
1322 (void) ValidateUsage();
1325 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1329 if (LocaleCompare("log",option+1) == 0)
1332 (void) SetLogFormat(argv[i+1]);
1335 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1339 if (LocaleCompare("regard-warnings",option+1) == 0)
1341 regard_warnings=MagickTrue;
1344 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1348 if (LocaleCompare("validate",option+1) == 0)
1356 if (i == (ssize_t) argc)
1357 ThrowValidateException(OptionError,"MissingArgument",option);
1358 validate=ParseMagickOption(MagickValidateOptions,MagickFalse,
1361 ThrowValidateException(OptionError,"UnrecognizedValidateType",
1363 type=(ValidateType) validate;
1366 if ((LocaleCompare("version",option+1) == 0) ||
1367 (LocaleCompare("-version",option+1) == 0))
1369 (void) fprintf(stdout,"Version: %s\n",
1370 GetMagickVersion((size_t *) NULL));
1371 (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright());
1372 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
1375 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1378 ThrowValidateException(OptionError,"UnrecognizedOption",option)
1381 timer=(TimerInfo *) NULL;
1383 timer=AcquireTimerInfo();
1384 reference_image=ReadImage(image_info,exception);
1387 if (reference_image == (Image *) NULL)
1391 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
1392 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
1394 (void) AcquireUniqueFilename(reference_filename);
1395 (void) AcquireUniqueFilename(output_filename);
1396 (void) CopyMagickString(reference_image->filename,reference_filename,
1398 status=WriteImage(image_info,reference_image);
1399 InheritException(exception,&reference_image->exception);
1400 reference_image=DestroyImage(reference_image);
1401 if (status == MagickFalse)
1405 (void) fprintf(stdout,"Version: %s\n",
1406 GetMagickVersion((size_t *) NULL));
1407 (void) fprintf(stdout,"Copyright: %s\n\n",
1408 GetMagickCopyright());
1409 (void) fprintf(stdout,"ImageMagick Validation Suite (%s)\n\n",
1410 MagickOptionToMnemonic(MagickValidateOptions,(ssize_t) type));
1411 if ((type & CompareValidate) != 0)
1412 tests+=ValidateCompareCommand(image_info,reference_filename,
1413 output_filename,&fail,exception);
1414 if ((type & CompositeValidate) != 0)
1415 tests+=ValidateCompositeCommand(image_info,reference_filename,
1416 output_filename,&fail,exception);
1417 if ((type & ConvertValidate) != 0)
1418 tests+=ValidateConvertCommand(image_info,reference_filename,
1419 output_filename,&fail,exception);
1420 if ((type & FormatsInMemoryValidate) != 0)
1421 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
1422 output_filename,&fail,exception);
1423 if ((type & FormatsOnDiskValidate) != 0)
1424 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
1425 output_filename,&fail,exception);
1426 if ((type & IdentifyValidate) != 0)
1427 tests+=ValidateIdentifyCommand(image_info,reference_filename,
1428 output_filename,&fail,exception);
1429 if ((type & ImportExportValidate) != 0)
1430 tests+=ValidateImportExportPixels(image_info,reference_filename,
1431 output_filename,&fail,exception);
1432 if ((type & MontageValidate) != 0)
1433 tests+=ValidateMontageCommand(image_info,reference_filename,
1434 output_filename,&fail,exception);
1435 if ((type & StreamValidate) != 0)
1436 tests+=ValidateStreamCommand(image_info,reference_filename,
1437 output_filename,&fail,exception);
1438 (void) fprintf(stdout,"validation suite: %lu tests; %lu passed; "
1439 "%lu failed.\n",(unsigned long) tests,(unsigned long) (tests-fail),
1440 (unsigned long) fail);
1442 (void) RelinquishUniqueFileResource(output_filename);
1443 (void) RelinquishUniqueFileResource(reference_filename);
1445 if (exception->severity != UndefinedException)
1446 CatchException(exception);
1449 elapsed_time=GetElapsedTime(timer);
1450 user_time=GetUserTime(timer);
1451 (void) fprintf(stderr,
1452 "Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",(unsigned long)
1453 iterations,1.0*iterations/elapsed_time,user_time,(long)
1454 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
1455 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
1456 timer=DestroyTimerInfo(timer);
1459 MagickCoreTerminus();
1460 return(fail == 0 ? 0 : 1);