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"
58 #define CIEEpsilon (216.0/24389.0)
59 #define CIEK (24389.0/27.0)
63 #define ReferenceEpsilon (1.0e-0)
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 % V a l i d a t e C o l o r s p a c e s %
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % ValidateColorspaces() validates the ImageMagick colorspaces and returns the
77 % number of validation tests that passed and failed.
79 % The format of the ValidateColorspaces method is:
81 % size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
82 % ExceptionInfo *exception)
84 % A description of each parameter follows:
86 % o image_info: the image info.
88 % o fail: return the number of validation tests that pass.
90 % o exception: return any errors or warnings in this structure.
94 static void ConvertHSIToRGB(const double hue,const double saturation,
95 const double intensity,double *red,double *green,double *blue)
101 h-=360.0*floor(h/360.0);
104 *blue=intensity*(1.0-saturation);
105 *red=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
107 *green=3.0*intensity-*red-*blue;
113 *red=intensity*(1.0-saturation);
114 *green=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
116 *blue=3.0*intensity-*red-*green;
121 *green=intensity*(1.0-saturation);
122 *blue=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
124 *red=3.0*intensity-*green-*blue;
127 *green*=QuantumRange;
131 static inline double MagickMin(const double x,const double y)
138 static void ConvertRGBToHSI(const double red,const double green,
139 const double blue,double *hue,double *saturation,double *intensity)
145 *intensity=(QuantumScale*red+QuantumScale*green+QuantumScale*blue)/3.0;
146 if (*intensity <= 0.0)
152 *saturation=1.0-MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
153 QuantumScale*blue))/(*intensity);
154 alpha=0.5*(2.0*QuantumScale*red-QuantumScale*green-QuantumScale*blue);
155 beta=0.8660254037844385*(QuantumScale*green-QuantumScale*blue);
156 *hue=atan2(beta,alpha)*(180.0/MagickPI)/360.0;
161 MagickExport void ConvertHSLToRGB(const double hue,const double saturation,
162 const double lightness,double *red,double *green,double *blue)
171 if (lightness <= 0.5)
172 c=2.0*lightness*saturation;
174 c=(2.0-2.0*lightness)*saturation;
176 h-=360.0*floor(h/360.0);
178 x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
179 switch ((int) floor(h))
183 *red=QuantumRange*(min+c);
184 *green=QuantumRange*(min+x);
185 *blue=QuantumRange*min;
190 *red=QuantumRange*(min+x);
191 *green=QuantumRange*(min+c);
192 *blue=QuantumRange*min;
197 *red=QuantumRange*min;
198 *green=QuantumRange*(min+c);
199 *blue=QuantumRange*(min+x);
204 *red=QuantumRange*min;
205 *green=QuantumRange*(min+x);
206 *blue=QuantumRange*(min+c);
211 *red=QuantumRange*(min+x);
212 *green=QuantumRange*min;
213 *blue=QuantumRange*(min+c);
218 *red=QuantumRange*(min+c);
219 *green=QuantumRange*min;
220 *blue=QuantumRange*(min+x);
232 static inline double MagickMax(const double x,const double y)
239 MagickExport void ConvertRGBToHSL(const double red,const double green,
240 const double blue,double *hue,double *saturation,double *lightness)
247 max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
249 min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
252 *lightness=(max+min)/2.0;
259 if (max == (QuantumScale*red))
261 *hue=(QuantumScale*green-QuantumScale*blue)/c;
262 if ((QuantumScale*green) < (QuantumScale*blue))
266 if (max == (QuantumScale*green))
267 *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
269 *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
271 if (*lightness <= 0.5)
272 *saturation=c/(2.0*(*lightness));
274 *saturation=c/(2.0-2.0*(*lightness));
277 static void ConvertHSVToRGB(const double hue,const double saturation,
278 const double value,double *red,double *green,double *blue)
289 h-=360.0*floor(h/360.0);
291 x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
292 switch ((int) floor(h))
296 *red=QuantumRange*(min+c);
297 *green=QuantumRange*(min+x);
298 *blue=QuantumRange*min;
303 *red=QuantumRange*(min+x);
304 *green=QuantumRange*(min+c);
305 *blue=QuantumRange*min;
310 *red=QuantumRange*min;
311 *green=QuantumRange*(min+c);
312 *blue=QuantumRange*(min+x);
317 *red=QuantumRange*min;
318 *green=QuantumRange*(min+x);
319 *blue=QuantumRange*(min+c);
324 *red=QuantumRange*(min+x);
325 *green=QuantumRange*min;
326 *blue=QuantumRange*(min+c);
331 *red=QuantumRange*(min+c);
332 *green=QuantumRange*min;
333 *blue=QuantumRange*(min+x);
345 static inline void ConvertRGBToXYZ(const double red,const double green,
346 const double blue,double *X,double *Y,double *Z)
353 r=QuantumScale*DecodePixelGamma(red);
354 g=QuantumScale*DecodePixelGamma(green);
355 b=QuantumScale*DecodePixelGamma(blue);
356 *X=0.41239558896741421610*r+0.35758343076371481710*g+0.18049264738170157350*b;
357 *Y=0.21258623078559555160*r+0.71517030370341084990*g+0.07220049864333622685*b;
358 *Z=0.01929721549174694484*r+0.11918386458084853180*g+0.95049712513157976600*b;
361 static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
362 double *L,double *a,double *b)
369 if ((X/D65X) > CIEEpsilon)
370 x=pow(X/D65X,1.0/3.0);
372 x=(CIEK*X/D65X+16.0)/116.0;
373 if ((Y/D65Y) > CIEEpsilon)
374 y=pow(Y/D65Y,1.0/3.0);
376 y=(CIEK*Y/D65Y+16.0)/116.0;
377 if ((Z/D65Z) > CIEEpsilon)
378 z=pow(Z/D65Z,1.0/3.0);
380 z=(CIEK*Z/D65Z+16.0)/116.0;
381 *L=((116.0*y)-16.0)/100.0;
382 *a=(500.0*(x-y))/255.0+0.5;
383 *b=(200.0*(y-z))/255.0+0.5;
386 static void ConvertRGBToLab(const double red,const double green,
387 const double blue,double *L,double *a,double *b)
394 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
395 ConvertXYZToLab(X,Y,Z,L,a,b);
398 static inline void ConvertLabToXYZ(const double L,const double a,const double b,
399 double *X,double *Y,double *Z)
409 if ((x*x*x) > CIEEpsilon)
412 x=(116.0*x-16.0)/CIEK;
413 if ((y*y*y) > CIEEpsilon)
417 if ((z*z*z) > CIEEpsilon)
420 z=(116.0*z-16.0)/CIEK;
426 static inline void ConvertXYZToRGB(const double x,const double y,const double z,
427 double *red,double *green,double *blue)
434 r=3.2406*x-1.5372*y-0.4986*z;
435 g=(-0.9689*x+1.8758*y+0.0415*z);
436 b=0.0557*x-0.2040*y+1.0570*z;
437 *red=EncodePixelGamma(QuantumRange*r);
438 *green=EncodePixelGamma(QuantumRange*g);
439 *blue=EncodePixelGamma(QuantumRange*b);
442 static inline void ConvertLabToRGB(const double L,const double a,
443 const double b,double *red,double *green,double *blue)
450 ConvertLabToXYZ(L*100.0,255.0*(a-0.5),255.0*(b-0.5),&X,&Y,&Z);
451 ConvertXYZToRGB(X,Y,Z,red,green,blue);
454 static void ConvertRGBToYPbPr(const double red,const double green,
455 const double blue,double *Y,double *Pb,double *Pr)
457 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
458 *Pb=QuantumScale*((-0.1687367)*red-0.331264*green+0.5*blue)+0.5;
459 *Pr=QuantumScale*(0.5*red-0.418688*green-0.081312*blue)+0.5;
462 static void ConvertRGBToYCbCr(const double red,const double green,
463 const double blue,double *Y,double *Cb,double *Cr)
465 ConvertRGBToYPbPr(red,green,blue,Y,Cb,Cr);
468 static void ConvertYPbPrToRGB(const double Y,const double Pb,const double Pr,
469 double *red,double *green,double *blue)
471 *red=QuantumRange*(0.99999999999914679361*Y-1.2188941887145875e-06*(Pb-0.5)+
472 1.4019995886561440468*(Pr-0.5));
473 *green=QuantumRange*(0.99999975910502514331*Y-0.34413567816504303521*(Pb-0.5)-
474 0.71413649331646789076*(Pr-0.5));
475 *blue=QuantumRange*(1.00000124040004623180*Y+1.77200006607230409200*(Pb-0.5)+
476 2.1453384174593273e-06*(Pr-0.5));
479 static void ConvertYCbCrToRGB(const double Y,const double Cb,
480 const double Cr,double *red,double *green,double *blue)
482 ConvertYPbPrToRGB(Y,Cb,Cr,red,green,blue);
485 static inline void ConvertLCHabToXYZ(const double luma,const double chroma,
486 const double hue,double *X,double *Y,double *Z)
488 ConvertLabToXYZ(luma,chroma*cos(hue*MagickPI/180.0),chroma*
489 sin(hue*MagickPI/180.0),X,Y,Z);
492 static void ConvertLCHabToRGB(const double luma,const double chroma,
493 const double hue,double *red,double *green,double *blue)
500 ConvertLCHabToXYZ(luma*100.0,255.0*(chroma-0.5),255.0*(hue-0.5),&X,&Y,&Z);
501 ConvertXYZToRGB(X,Y,Z,red,green,blue);
504 static void ConvertRGBToHSV(const double red,const double green,
505 const double blue,double *hue,double *saturation,double *value)
512 max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
514 min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
524 if (max == (QuantumScale*red))
526 *hue=(QuantumScale*green-QuantumScale*blue)/c;
527 if ((QuantumScale*green) < (QuantumScale*blue))
531 if (max == (QuantumScale*green))
532 *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
534 *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
539 static inline void ConvertXYZToLCHab(const double X,const double Y,
540 const double Z,double *luma,double *chroma,double *hue)
546 ConvertXYZToLab(X,Y,Z,luma,&a,&b);
547 *chroma=hypot(255.0*(a-0.5),255.0*(b-0.5));
548 *hue=180.0*atan2(255.0*(b-0.5),255.0*(a-0.5))/MagickPI;
549 *chroma=(*chroma)/255.0+0.5;
550 *hue=(*hue)/255.0+0.5;
555 static void ConvertRGBToLCHab(const double red,const double green,
556 const double blue,double *luma,double *chroma,double *hue)
563 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
564 ConvertXYZToLCHab(X,Y,Z,luma,chroma,hue);
567 static inline void ConvertLMSToXYZ(const double L,const double M,const double S,
568 double *X,double *Y,double *Z)
570 *X=1.096123820835514*L-0.278869000218287*M+0.182745179382773*S;
571 *Y=0.454369041975359*L+0.473533154307412*M+0.072097803717229*S;
572 *Z=(-0.009627608738429)*L-0.005698031216113*M+1.015325639954543*S;
575 static inline void ConvertLMSToRGB(const double L,const double M,
576 const double S,double *red,double *green,double *blue)
583 ConvertLMSToXYZ(L,M,S,&X,&Y,&Z);
584 ConvertXYZToRGB(X,Y,Z,red,green,blue);
587 static inline void ConvertXYZToLMS(const double x,const double y,
588 const double z,double *L,double *M,double *S)
590 *L=0.7328*x+0.4296*y-0.1624*z;
591 *M=(-0.7036*x+1.6975*y+0.0061*z);
592 *S=0.0030*x+0.0136*y+0.9834*z;
595 static void ConvertRGBToLMS(const double red,const double green,
596 const double blue,double *L,double *M,double *S)
603 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
604 ConvertXYZToLMS(X,Y,Z,L,M,S);
607 static inline double PerceptibleReciprocal(const double x)
613 Return 1/x where x is perceptible (not unlimited or infinitesimal).
615 sign=x < 0.0 ? -1.0 : 1.0;
616 if ((sign*x) >= MagickEpsilon)
618 return(sign/MagickEpsilon);
621 static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
622 double *L,double *u,double *v)
627 if ((Y/D65Y) > CIEEpsilon)
628 *L=(double) (116.0*pow(Y/D65Y,1.0/3.0)-16.0);
631 alpha=PerceptibleReciprocal(X+15.0*Y+3.0*Z);
632 *u=13.0*(*L)*((4.0*alpha*X)-(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z)));
633 *v=13.0*(*L)*((9.0*alpha*Y)-(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z)));
639 static void ConvertRGBToLuv(const double red,const double green,
640 const double blue,double *L,double *u,double *v)
647 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
648 ConvertXYZToLuv(X,Y,Z,L,u,v);
651 static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
652 double *X,double *Y,double *Z)
654 if (L > (CIEK*CIEEpsilon))
655 *Y=(double) pow((L+16.0)/116.0,3.0);
658 *X=((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
659 5.0*(*Y))/((((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/
661 *Z=(*X*(((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
665 static inline void ConvertLuvToRGB(const double L,const double u,
666 const double v,double *red,double *green,double *blue)
673 ConvertLuvToXYZ(100.0*L,354.0*u-134.0,262.0*v-140.0,&X,&Y,&Z);
674 ConvertXYZToRGB(X,Y,Z,red,green,blue);
677 static void ConvertRGBToYDbDr(const double red,const double green,
678 const double blue,double *Y,double *Db,double *Dr)
680 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
681 *Db=QuantumScale*(-0.450*red-0.883*green+1.333*blue)+0.5;
682 *Dr=QuantumScale*(-1.333*red+1.116*green+0.217*blue)+0.5;
685 static void ConvertYDbDrToRGB(const double Y,const double Db,const double Dr,
686 double *red,double *green,double *blue)
688 *red=QuantumRange*(Y+9.2303716147657e-05*(Db-0.5)-0.52591263066186533*
690 *green=QuantumRange*(Y-0.12913289889050927*(Db-0.5)+0.26789932820759876*
692 *blue=QuantumRange*(Y+0.66467905997895482*(Db-0.5)-7.9202543533108e-05*
696 static void ConvertRGBToYIQ(const double red,const double green,
697 const double blue,double *Y,double *I,double *Q)
699 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
700 *I=QuantumScale*(0.595716*red-0.274453*green-0.321263*blue)+0.5;
701 *Q=QuantumScale*(0.211456*red-0.522591*green+0.311135*blue)+0.5;
704 static void ConvertYIQToRGB(const double Y,const double I,const double Q,
705 double *red,double *green,double *blue)
707 *red=QuantumRange*(Y+0.9562957197589482261*(I-0.5)+0.6210244164652610754*
709 *green=QuantumRange*(Y-0.2721220993185104464*(I-0.5)-0.6473805968256950427*
711 *blue=QuantumRange*(Y-1.1069890167364901945*(I-0.5)+1.7046149983646481374*
715 static void ConvertRGBToYUV(const double red,const double green,
716 const double blue,double *Y,double *U,double *V)
718 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
719 *U=QuantumScale*((-0.147)*red-0.289*green+0.436*blue)+0.5;
720 *V=QuantumScale*(0.615*red-0.515*green-0.100*blue)+0.5;
723 static void ConvertYUVToRGB(const double Y,const double U,const double V,
724 double *red,double *green,double *blue)
726 *red=QuantumRange*(Y-3.945707070708279e-05*(U-0.5)+1.1398279671717170825*
728 *green=QuantumRange*(Y-0.3946101641414141437*(U-0.5)-0.5805003156565656797*
730 *blue=QuantumRange*(Y+2.0319996843434342537*(U-0.5)-4.813762626262513e-04*
734 static MagickBooleanType ValidateHSIToRGB()
741 (void) FormatLocaleFile(stdout," HSIToRGB");
742 ConvertHSIToRGB(111.244375/360.0,0.295985,0.658734,&r,&g,&b);
743 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
744 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
745 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
750 static MagickBooleanType ValidateRGBToHSI()
757 (void) FormatLocaleFile(stdout," RGBToHSI");
758 ConvertRGBToHSI(0.545877*QuantumRange,0.966567*QuantumRange,
759 0.463759*QuantumRange,&h,&s,&i);
760 if ((fabs(h-111.244374/360.0) >= ReferenceEpsilon) ||
761 (fabs(s-0.295985) >= ReferenceEpsilon) ||
762 (fabs(i-0.658734) >= ReferenceEpsilon))
767 static MagickBooleanType ValidateHSLToRGB()
774 (void) FormatLocaleFile(stdout," HSLToRGB");
775 ConvertHSLToRGB(110.200859/360.0,0.882623,0.715163,&r,&g,&b);
776 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
777 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
778 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
783 static MagickBooleanType ValidateRGBToHSL()
790 (void) FormatLocaleFile(stdout," RGBToHSL");
791 ConvertRGBToHSL(0.545877*QuantumRange,0.966567*QuantumRange,
792 0.463759*QuantumRange,&h,&s,&l);
793 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
794 (fabs(s-0.882623) >= ReferenceEpsilon) ||
795 (fabs(l-0.715163) >= ReferenceEpsilon))
800 static MagickBooleanType ValidateHSVToRGB()
807 (void) FormatLocaleFile(stdout," HSVToRGB");
808 ConvertHSVToRGB(110.200859/360.0,0.520200,0.966567,&r,&g,&b);
809 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
810 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
811 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
816 static MagickBooleanType ValidateRGBToHSV()
823 (void) FormatLocaleFile(stdout," RGBToHSV");
824 ConvertRGBToHSV(0.545877*QuantumRange,0.966567*QuantumRange,
825 0.463759*QuantumRange,&h,&s,&v);
826 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
827 (fabs(s-0.520200) >= ReferenceEpsilon) ||
828 (fabs(v-0.966567) >= ReferenceEpsilon))
833 static MagickBooleanType ValidateRGBToJPEGYCbCr()
840 (void) FormatLocaleFile(stdout," RGBToJPEGYCbCr");
841 ConvertRGBToYCbCr(0.545877*QuantumRange,0.966567*QuantumRange,
842 0.463759*QuantumRange,&Y,&Cb,&Cr);
843 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
844 (fabs(Cb-0.319581) >= ReferenceEpsilon) ||
845 (fabs(Cr-0.330539) >= ReferenceEpsilon))
850 static MagickBooleanType ValidateJPEGYCbCrToRGB()
857 (void) FormatLocaleFile(stdout," JPEGYCbCrToRGB");
858 ConvertYCbCrToRGB(0.783460,0.319581,0.330539,&r,&g,&b);
859 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
860 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
861 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
866 static MagickBooleanType ValidateLabToRGB()
873 (void) FormatLocaleFile(stdout," LabToRGB");
874 ConvertLabToRGB(88.456154/100.0,-54.671483/255+0.5,51.662818/255.0+0.5,
876 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
877 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
878 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
883 static MagickBooleanType ValidateRGBToLab()
890 (void) FormatLocaleFile(stdout," RGBToLab");
891 ConvertRGBToLab(0.545877*QuantumRange,0.966567*QuantumRange,
892 0.463759*QuantumRange,&L,&a,&b);
893 if ((fabs(L-(88.456154/100.0)) >= ReferenceEpsilon) ||
894 (fabs(a-(-54.671483/255.0+0.5)) >= ReferenceEpsilon) ||
895 (fabs(b-(51.662818/255.0+0.5)) >= ReferenceEpsilon))
900 static MagickBooleanType ValidateLchToRGB()
907 (void) FormatLocaleFile(stdout," LchToRGB");
908 ConvertLCHabToRGB(88.456154/100.0,75.219797/255.0+0.5,136.620717/255.0+0.5,
910 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
911 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
912 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
917 static MagickBooleanType ValidateRGBToLch()
924 (void) FormatLocaleFile(stdout," RGBToLch");
925 ConvertRGBToLCHab(0.545877*QuantumRange,0.966567*QuantumRange,
926 0.463759*QuantumRange,&L,&c,&h);
927 if ((fabs(L-88.456154/100.0) >= ReferenceEpsilon) ||
928 (fabs(c-(75.219797/255.0+0.5)) >= ReferenceEpsilon) ||
929 (fabs(h-(136.620717/255.0+0.5)) >= ReferenceEpsilon))
934 static MagickBooleanType ValidateRGBToLMS()
941 (void) FormatLocaleFile(stdout," RGBToLMS");
942 ConvertRGBToLMS(0.545877*QuantumRange,0.966567*QuantumRange,
943 0.463759*QuantumRange,&L,&M,&S);
944 if ((fabs(L-0.611749) >= ReferenceEpsilon) ||
945 (fabs(M-0.910088) >= ReferenceEpsilon) ||
946 (fabs(S-0.294880) >= ReferenceEpsilon))
951 static MagickBooleanType ValidateLMSToRGB()
958 (void) FormatLocaleFile(stdout," LMSToRGB");
959 ConvertLMSToRGB(0.611749,0.910088,0.294880,&r,&g,&b);
960 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
961 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
962 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
967 static MagickBooleanType ValidateRGBToLuv()
974 (void) FormatLocaleFile(stdout," RGBToLuv");
975 ConvertRGBToLuv(0.545877*QuantumRange,0.966567*QuantumRange,
976 0.463759*QuantumRange,&l,&u,&v);
977 if ((fabs(l-88.456154/262.0) >= ReferenceEpsilon) ||
978 (fabs(u-(-51.330414+134.0)/354.0) >= ReferenceEpsilon) ||
979 (fabs(v-(76.405526+140.0)/262.0) >= ReferenceEpsilon))
984 static MagickBooleanType ValidateLuvToRGB()
991 (void) FormatLocaleFile(stdout," LuvToRGB");
992 ConvertLuvToRGB(88.456154/100.0,(-51.330414+134.0)/354.0,
993 (76.405526+140.0)/262.0,&r,&g,&b);
994 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
995 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
996 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1001 static MagickBooleanType ValidateRGBToXYZ()
1008 (void) FormatLocaleFile(stdout," RGBToXYZ");
1009 ConvertRGBToXYZ(0.545877*QuantumRange,0.966567*QuantumRange,
1010 0.463759*QuantumRange,&x,&y,&z);
1011 if ((fabs(x-0.470646) >= ReferenceEpsilon) ||
1012 (fabs(y-0.730178) >= ReferenceEpsilon) ||
1013 (fabs(z-0.288324) >= ReferenceEpsilon))
1014 return(MagickFalse);
1018 static MagickBooleanType ValidateXYZToRGB()
1025 (void) FormatLocaleFile(stdout," XYZToRGB");
1026 ConvertXYZToRGB(0.470646,0.730178,0.288324,&r,&g,&b);
1027 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1028 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1029 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1030 return(MagickFalse);
1034 static MagickBooleanType ValidateYDbDrToRGB()
1041 (void) FormatLocaleFile(stdout," YDbDrToRGB");
1042 ConvertYDbDrToRGB(0.783460,-0.480932+0.5,0.451670+0.5,&r,&g,&b);
1043 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1044 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1045 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1046 return(MagickFalse);
1050 static MagickBooleanType ValidateRGBToYDbDr()
1057 (void) FormatLocaleFile(stdout," RGBToYDbDr");
1058 ConvertRGBToYDbDr(0.545877*QuantumRange,0.966567*QuantumRange,
1059 0.463759*QuantumRange,&Y,&Db,&Dr);
1060 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
1061 (fabs(Db-(-0.480932)) >= ReferenceEpsilon) ||
1062 (fabs(Dr-0.451670) >= ReferenceEpsilon))
1063 return(MagickFalse);
1067 static MagickBooleanType ValidateRGBToYIQ()
1074 (void) FormatLocaleFile(stdout," RGBToYIQ");
1075 ConvertRGBToYIQ(0.545877*QuantumRange,0.966567*QuantumRange,
1076 0.463759*QuantumRange,&y,&i,&q);
1077 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
1078 (fabs(i-(-0.089078)) >= ReferenceEpsilon) ||
1079 (fabs(q-(-0.245399)) >= ReferenceEpsilon))
1080 return(MagickFalse);
1084 static MagickBooleanType ValidateYIQToRGB()
1091 (void) FormatLocaleFile(stdout," YIQToRGB");
1092 ConvertYIQToRGB(0.783460,-0.089078+0.5,-0.245399+0.5,&r,&g,&b);
1093 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1094 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1095 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1096 return(MagickFalse);
1100 static MagickBooleanType ValidateRGBToYPbPr()
1107 (void) FormatLocaleFile(stdout," RGBToYPbPr");
1108 ConvertRGBToYPbPr(0.545877*QuantumRange,0.966567*QuantumRange,
1109 0.463759*QuantumRange,&y,&Pb,&Pr);
1110 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
1111 (fabs(Pb-(-0.180419)) >= ReferenceEpsilon) ||
1112 (fabs(Pr-(-0.169461)) >= ReferenceEpsilon))
1113 return(MagickFalse);
1117 static MagickBooleanType ValidateYPbPrToRGB()
1124 (void) FormatLocaleFile(stdout," YPbPrToRGB");
1125 ConvertYPbPrToRGB(0.783460,-0.180419+0.5,-0.169461+0.5,&r,&g,&b);
1126 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1127 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1128 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1129 return(MagickFalse);
1133 static MagickBooleanType ValidateRGBToYUV()
1140 (void) FormatLocaleFile(stdout," RGBToYUV");
1141 ConvertRGBToYUV(0.545877*QuantumRange,0.966567*QuantumRange,
1142 0.463759*QuantumRange,&Y,&U,&V);
1143 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
1144 (fabs(U-(-0.157383)) >= ReferenceEpsilon) ||
1145 (fabs(V-(-0.208443)) >= ReferenceEpsilon))
1146 return(MagickFalse);
1150 static MagickBooleanType ValidateYUVToRGB()
1157 (void) FormatLocaleFile(stdout," YUVToRGB");
1158 ConvertYUVToRGB(0.783460,-0.157383+0.5,-0.208443+0.5,&r,&g,&b);
1159 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1160 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1161 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1162 return(MagickFalse);
1166 static size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
1167 ExceptionInfo *exception)
1176 Reference: https://code.google.com/p/chroma.
1179 Observer = 2° (1931)
1181 XYZ 0.470645, 0.730177, 0.288323
1182 sRGB 0.545877, 0.966567, 0.463759
1183 CAT02 LMS 0.611749, 0.910088, 0.294880
1184 Y'DbDr 0.783460, -0.480932, 0.451670
1185 Y'IQ 0.783460, -0.089078, -0.245399
1186 Y'PbPr 0.783460, -0.180419, -0.169461
1187 Y'UV 0.783460, -0.157383, -0.208443
1188 JPEG-Y'CbCr 0.783460, 0.319581, 0.330539
1189 L*u*v* 88.456154, -51.330414, 76.405526
1190 L*a*b* 88.456154, -54.671483, 51.662818
1191 L*C*H* 88.456154, 75.219797, 136.620717
1192 HSV 110.200859, 0.520200, 0.966567
1193 HSL 110.200859, 0.882623, 0.715163
1194 HSI 111.244375, 0.295985, 0.658734
1195 Y'CbCr 187.577791, 87.586330, 90.040886
1197 (void) FormatLocaleFile(stdout,"validate colorspaces:\n");
1198 for (test=0; test < 26; test++)
1200 CatchException(exception);
1201 (void) FormatLocaleFile(stdout," test %.20g: ",(double) test);
1204 case 0: status=ValidateHSIToRGB(); break;
1205 case 1: status=ValidateRGBToHSI(); break;
1206 case 2: status=ValidateHSLToRGB(); break;
1207 case 3: status=ValidateRGBToHSL(); break;
1208 case 4: status=ValidateHSVToRGB(); break;
1209 case 5: status=ValidateRGBToHSV(); break;
1210 case 6: status=ValidateJPEGYCbCrToRGB(); break;
1211 case 7: status=ValidateRGBToJPEGYCbCr(); break;
1212 case 8: status=ValidateLabToRGB(); break;
1213 case 9: status=ValidateRGBToLab(); break;
1214 case 10: status=ValidateLchToRGB(); break;
1215 case 11: status=ValidateRGBToLch(); break;
1216 case 12: status=ValidateLMSToRGB(); break;
1217 case 13: status=ValidateRGBToLMS(); break;
1218 case 14: status=ValidateLuvToRGB(); break;
1219 case 15: status=ValidateRGBToLuv(); break;
1220 case 16: status=ValidateXYZToRGB(); break;
1221 case 17: status=ValidateRGBToXYZ(); break;
1222 case 18: status=ValidateYDbDrToRGB(); break;
1223 case 19: status=ValidateRGBToYDbDr(); break;
1224 case 20: status=ValidateYIQToRGB(); break;
1225 case 21: status=ValidateRGBToYIQ(); break;
1226 case 22: status=ValidateYPbPrToRGB(); break;
1227 case 23: status=ValidateRGBToYPbPr(); break;
1228 case 24: status=ValidateYUVToRGB(); break;
1229 case 25: status=ValidateRGBToYUV(); break;
1230 default: status=MagickFalse;
1232 if (status == MagickFalse)
1234 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1239 (void) FormatLocaleFile(stdout,"... pass.\n");
1241 (void) FormatLocaleFile(stdout,
1242 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1243 (double) (test-(*fail)),(double) *fail);
1248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1252 % V a l i d a t e C o m p a r e C o m m a n d %
1256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1258 % ValidateCompareCommand() validates the ImageMagick compare command line
1259 % program and returns the number of validation tests that passed and failed.
1261 % The format of the ValidateCompareCommand method is:
1263 % size_t ValidateCompareCommand(ImageInfo *image_info,
1264 % const char *reference_filename,const char *output_filename,
1265 % size_t *fail,ExceptionInfo *exception)
1267 % A description of each parameter follows:
1269 % o image_info: the image info.
1271 % o reference_filename: the reference image filename.
1273 % o output_filename: the output image filename.
1275 % o fail: return the number of validation tests that pass.
1277 % o exception: return any errors or warnings in this structure.
1280 static size_t ValidateCompareCommand(ImageInfo *image_info,
1281 const char *reference_filename,const char *output_filename,size_t *fail,
1282 ExceptionInfo *exception)
1286 command[MaxTextExtent];
1302 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
1303 for (i=0; compare_options[i] != (char *) NULL; i++)
1305 CatchException(exception);
1306 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1307 compare_options[i]);
1308 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1309 compare_options[i],reference_filename,reference_filename,output_filename);
1310 arguments=StringToArgv(command,&number_arguments);
1311 if (arguments == (char **) NULL)
1313 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1318 status=CompareImagesCommand(image_info,number_arguments,arguments,
1319 (char **) NULL,exception);
1320 for (j=0; j < (ssize_t) number_arguments; j++)
1321 arguments[j]=DestroyString(arguments[j]);
1322 arguments=(char **) RelinquishMagickMemory(arguments);
1323 if (status != MagickFalse)
1325 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1330 (void) FormatLocaleFile(stdout,"... pass.\n");
1332 (void) FormatLocaleFile(stdout,
1333 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1334 (double) (test-(*fail)),(double) *fail);
1339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1343 % V a l i d a t e C o m p o s i t e C o m m a n d %
1347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1349 % ValidateCompositeCommand() validates the ImageMagick composite command line
1350 % program and returns the number of validation tests that passed and failed.
1352 % The format of the ValidateCompositeCommand method is:
1354 % size_t ValidateCompositeCommand(ImageInfo *image_info,
1355 % const char *reference_filename,const char *output_filename,
1356 % size_t *fail,ExceptionInfo *exception)
1358 % A description of each parameter follows:
1360 % o image_info: the image info.
1362 % o reference_filename: the reference image filename.
1364 % o output_filename: the output image filename.
1366 % o fail: return the number of validation tests that pass.
1368 % o exception: return any errors or warnings in this structure.
1371 static size_t ValidateCompositeCommand(ImageInfo *image_info,
1372 const char *reference_filename,const char *output_filename,size_t *fail,
1373 ExceptionInfo *exception)
1377 command[MaxTextExtent];
1393 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
1394 for (i=0; composite_options[i] != (char *) NULL; i++)
1396 CatchException(exception);
1397 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1398 composite_options[i]);
1399 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1400 reference_filename,composite_options[i],reference_filename,
1402 arguments=StringToArgv(command,&number_arguments);
1403 if (arguments == (char **) NULL)
1405 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1410 status=CompositeImageCommand(image_info,number_arguments,arguments,
1411 (char **) NULL,exception);
1412 for (j=0; j < (ssize_t) number_arguments; j++)
1413 arguments[j]=DestroyString(arguments[j]);
1414 arguments=(char **) RelinquishMagickMemory(arguments);
1415 if (status != MagickFalse)
1417 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1422 (void) FormatLocaleFile(stdout,"... pass.\n");
1424 (void) FormatLocaleFile(stdout,
1425 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1426 (double) (test-(*fail)),(double) *fail);
1431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1435 % V a l i d a t e C o n v e r t C o m m a n d %
1439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1441 % ValidateConvertCommand() validates the ImageMagick convert command line
1442 % program and returns the number of validation tests that passed and failed.
1444 % The format of the ValidateConvertCommand method is:
1446 % size_t ValidateConvertCommand(ImageInfo *image_info,
1447 % const char *reference_filename,const char *output_filename,
1448 % size_t *fail,ExceptionInfo *exception)
1450 % A description of each parameter follows:
1452 % o image_info: the image info.
1454 % o reference_filename: the reference image filename.
1456 % o output_filename: the output image filename.
1458 % o fail: return the number of validation tests that pass.
1460 % o exception: return any errors or warnings in this structure.
1463 static size_t ValidateConvertCommand(ImageInfo *image_info,
1464 const char *reference_filename,const char *output_filename,size_t *fail,
1465 ExceptionInfo *exception)
1469 command[MaxTextExtent];
1485 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
1486 for (i=0; convert_options[i] != (char *) NULL; i++)
1488 CatchException(exception);
1489 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1490 convert_options[i]);
1491 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1492 reference_filename,convert_options[i],reference_filename,output_filename);
1493 arguments=StringToArgv(command,&number_arguments);
1494 if (arguments == (char **) NULL)
1496 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1501 status=ConvertImageCommand(image_info,number_arguments,arguments,
1502 (char **) NULL,exception);
1503 for (j=0; j < (ssize_t) number_arguments; j++)
1504 arguments[j]=DestroyString(arguments[j]);
1505 arguments=(char **) RelinquishMagickMemory(arguments);
1506 if (status != MagickFalse)
1508 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1513 (void) FormatLocaleFile(stdout,"... pass.\n");
1515 (void) FormatLocaleFile(stdout,
1516 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1517 (double) (test-(*fail)),(double) *fail);
1522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 % V a l i d a t e I d e n t i f y C o m m a n d %
1530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1532 % ValidateIdentifyCommand() validates the ImageMagick identify command line
1533 % program and returns the number of validation tests that passed and failed.
1535 % The format of the ValidateIdentifyCommand method is:
1537 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
1538 % const char *reference_filename,const char *output_filename,
1539 % size_t *fail,ExceptionInfo *exception)
1541 % A description of each parameter follows:
1543 % o image_info: the image info.
1545 % o reference_filename: the reference image filename.
1547 % o output_filename: the output image filename.
1549 % o fail: return the number of validation tests that pass.
1551 % o exception: return any errors or warnings in this structure.
1554 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
1555 const char *reference_filename,const char *output_filename,size_t *fail,
1556 ExceptionInfo *exception)
1560 command[MaxTextExtent];
1575 (void) output_filename;
1577 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
1578 for (i=0; identify_options[i] != (char *) NULL; i++)
1580 CatchException(exception);
1581 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1582 identify_options[i]);
1583 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
1584 identify_options[i],reference_filename);
1585 arguments=StringToArgv(command,&number_arguments);
1586 if (arguments == (char **) NULL)
1588 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1593 status=IdentifyImageCommand(image_info,number_arguments,arguments,
1594 (char **) NULL,exception);
1595 for (j=0; j < (ssize_t) number_arguments; j++)
1596 arguments[j]=DestroyString(arguments[j]);
1597 arguments=(char **) RelinquishMagickMemory(arguments);
1598 if (status != MagickFalse)
1600 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1605 (void) FormatLocaleFile(stdout,"... pass.\n");
1607 (void) FormatLocaleFile(stdout,
1608 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1609 (double) (test-(*fail)),(double) *fail);
1614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1618 % 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 %
1622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1624 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
1625 % memory and returns the number of validation tests that passed and failed.
1627 % The format of the ValidateImageFormatsInMemory method is:
1629 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1630 % const char *reference_filename,const char *output_filename,
1631 % size_t *fail,ExceptionInfo *exception)
1633 % A description of each parameter follows:
1635 % o image_info: the image info.
1637 % o reference_filename: the reference image filename.
1639 % o output_filename: the output image filename.
1641 % o fail: return the number of validation tests that pass.
1643 % o exception: return any errors or warnings in this structure.
1648 Enable this to count remaining $TMPDIR/magick-* files. Note that the count
1649 includes any files left over from other runs.
1651 #undef MagickCountTempFiles
1653 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1654 const char *reference_filename,const char *output_filename,size_t *fail,
1655 ExceptionInfo *exception)
1658 #ifdef MagickCountTempFiles
1659 path[MaxTextExtent],
1660 SystemCommand[MaxTextExtent],
1662 size[MaxTextExtent];
1692 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
1694 #ifdef MagickCountTempFiles
1695 (void)GetPathTemplate(path);
1696 /* Remove file template except for the leading "/path/to/magick-" */
1697 path[strlen(path)-17]='\0';
1698 (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
1701 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1703 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1704 if ((magick_info == (const MagickInfo *) NULL) ||
1705 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1706 (magick_info->encoder == (EncodeImageHandler *) NULL))
1708 for (j=0; reference_types[j].type != UndefinedType; j++)
1711 Generate reference image.
1713 CatchException(exception);
1714 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1715 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1716 MagickCompressOptions,reference_formats[i].compression),
1717 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1718 (double) reference_types[j].depth);
1719 (void) CopyMagickString(image_info->filename,reference_filename,
1721 reference_image=ReadImage(image_info,exception);
1722 if (reference_image == (Image *) NULL)
1724 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1730 Write reference image.
1732 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
1733 (double) reference_image->columns,(double) reference_image->rows);
1734 (void) CloneString(&image_info->size,size);
1735 image_info->depth=reference_types[j].depth;
1736 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1737 reference_formats[i].magick,output_filename);
1738 status=SetImageType(reference_image,reference_types[j].type,exception);
1739 if (status == MagickFalse)
1741 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1744 reference_image=DestroyImage(reference_image);
1747 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1748 if (status == MagickFalse)
1750 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1753 reference_image=DestroyImage(reference_image);
1756 reference_image->compression=reference_formats[i].compression;
1757 status=WriteImage(image_info,reference_image,exception);
1758 reference_image=DestroyImage(reference_image);
1759 if (status == MagickFalse)
1761 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1767 Ping reference image.
1769 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1770 reference_formats[i].magick,output_filename);
1771 ping_image=PingImage(image_info,exception);
1772 if (ping_image == (Image *) NULL)
1774 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1779 ping_image=DestroyImage(ping_image);
1781 Read reference image.
1783 reference_image=ReadImage(image_info,exception);
1784 if (reference_image == (Image *) NULL)
1786 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1792 Write reference image.
1794 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1795 reference_formats[i].magick,output_filename);
1796 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
1798 reference_image->depth=reference_types[j].depth;
1799 reference_image->compression=reference_formats[i].compression;
1801 blob=ImageToBlob(image_info,reference_image,&length,exception);
1802 if (blob == (unsigned char *) NULL)
1804 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1807 reference_image=DestroyImage(reference_image);
1811 Ping reference blob.
1813 ping_image=PingBlob(image_info,blob,length,exception);
1814 if (ping_image == (Image *) NULL)
1816 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1819 blob=(unsigned char *) RelinquishMagickMemory(blob);
1822 ping_image=DestroyImage(ping_image);
1824 Read reconstruct image.
1826 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1827 reference_formats[i].magick,output_filename);
1828 reconstruct_image=BlobToImage(image_info,blob,length,exception);
1829 blob=(unsigned char *) RelinquishMagickMemory(blob);
1830 if (reconstruct_image == (Image *) NULL)
1832 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1835 reference_image=DestroyImage(reference_image);
1839 Compare reference to reconstruct image.
1841 fuzz=0.003; /* grayscale */
1842 if (reference_formats[i].fuzz != 0.0)
1843 fuzz=reference_formats[i].fuzz;
1844 difference_image=CompareImages(reference_image,reconstruct_image,
1845 RootMeanSquaredErrorMetric,&distortion,exception);
1846 reconstruct_image=DestroyImage(reconstruct_image);
1847 reference_image=DestroyImage(reference_image);
1848 if (difference_image == (Image *) NULL)
1850 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1855 difference_image=DestroyImage(difference_image);
1856 if ((QuantumScale*distortion) > fuzz)
1858 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1859 QuantumScale*distortion);
1863 #ifdef MagickCountTempFiles
1864 (void) FormatLocaleFile(stdout,"... pass, ");
1865 (void) fflush(stdout);
1866 SystemCommand[0]='\0';
1867 (void) strncat(SystemCommand,"echo `ls ",9);
1868 (void) strncat(SystemCommand,path,MaxTextExtent-31);
1869 (void) strncat(SystemCommand,"* | wc -w` tmp files.",20);
1870 (void) system(SystemCommand);
1871 (void) fflush(stdout);
1873 (void) FormatLocaleFile(stdout,"... pass\n");
1877 (void) FormatLocaleFile(stdout,
1878 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1879 (double) (test-(*fail)),(double) *fail);
1884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1888 % 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 %
1892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1894 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
1895 % and returns the number of validation tests that passed and failed.
1897 % The format of the ValidateImageFormatsOnDisk method is:
1899 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1900 % const char *reference_filename,const char *output_filename,
1901 % size_t *fail,ExceptionInfo *exception)
1903 % A description of each parameter follows:
1905 % o image_info: the image info.
1907 % o reference_filename: the reference image filename.
1909 % o output_filename: the output image filename.
1911 % o fail: return the number of validation tests that pass.
1913 % o exception: return any errors or warnings in this structure.
1916 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1917 const char *reference_filename,const char *output_filename,size_t *fail,
1918 ExceptionInfo *exception)
1921 size[MaxTextExtent];
1946 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
1947 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1949 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1950 if ((magick_info == (const MagickInfo *) NULL) ||
1951 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1952 (magick_info->encoder == (EncodeImageHandler *) NULL))
1954 for (j=0; reference_types[j].type != UndefinedType; j++)
1957 Generate reference image.
1959 CatchException(exception);
1960 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1961 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1962 MagickCompressOptions,reference_formats[i].compression),
1963 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1964 (double) reference_types[j].depth);
1965 (void) CopyMagickString(image_info->filename,reference_filename,
1967 reference_image=ReadImage(image_info,exception);
1968 if (reference_image == (Image *) NULL)
1970 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1976 Write reference image.
1978 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
1979 (double) reference_image->columns,(double) reference_image->rows);
1980 (void) CloneString(&image_info->size,size);
1981 image_info->depth=reference_types[j].depth;
1982 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1983 reference_formats[i].magick,output_filename);
1984 status=SetImageType(reference_image,reference_types[j].type,exception);
1985 if (status == MagickFalse)
1987 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1990 reference_image=DestroyImage(reference_image);
1993 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1994 if (status == MagickFalse)
1996 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1999 reference_image=DestroyImage(reference_image);
2002 reference_image->compression=reference_formats[i].compression;
2003 status=WriteImage(image_info,reference_image,exception);
2004 reference_image=DestroyImage(reference_image);
2005 if (status == MagickFalse)
2007 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2013 Read reference image.
2015 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
2016 reference_formats[i].magick,output_filename);
2017 reference_image=ReadImage(image_info,exception);
2018 if (reference_image == (Image *) NULL)
2020 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2026 Write reference image.
2028 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
2029 reference_formats[i].magick,output_filename);
2030 reference_image->depth=reference_types[j].depth;
2031 reference_image->compression=reference_formats[i].compression;
2032 status=WriteImage(image_info,reference_image,exception);
2033 if (status == MagickFalse)
2035 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2038 reference_image=DestroyImage(reference_image);
2042 Read reconstruct image.
2044 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
2045 reference_formats[i].magick,output_filename);
2046 reconstruct_image=ReadImage(image_info,exception);
2047 if (reconstruct_image == (Image *) NULL)
2049 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2052 reference_image=DestroyImage(reference_image);
2056 Compare reference to reconstruct image.
2058 fuzz=0.003; /* grayscale */
2059 if (reference_formats[i].fuzz != 0.0)
2060 fuzz=reference_formats[i].fuzz;
2061 difference_image=CompareImages(reference_image,reconstruct_image,
2062 RootMeanSquaredErrorMetric,&distortion,exception);
2063 reconstruct_image=DestroyImage(reconstruct_image);
2064 reference_image=DestroyImage(reference_image);
2065 if (difference_image == (Image *) NULL)
2067 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2072 difference_image=DestroyImage(difference_image);
2073 if ((QuantumScale*distortion) > fuzz)
2075 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2076 QuantumScale*distortion);
2080 (void) FormatLocaleFile(stdout,"... pass.\n");
2083 (void) FormatLocaleFile(stdout,
2084 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2085 (double) (test-(*fail)),(double) *fail);
2090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2094 % 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 %
2098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2100 % ValidateImportExportPixels() validates the pixel import and export methods.
2101 % It returns the number of validation tests that passed and failed.
2103 % The format of the ValidateImportExportPixels method is:
2105 % size_t ValidateImportExportPixels(ImageInfo *image_info,
2106 % const char *reference_filename,const char *output_filename,
2107 % size_t *fail,ExceptionInfo *exception)
2109 % A description of each parameter follows:
2111 % o image_info: the image info.
2113 % o reference_filename: the reference image filename.
2115 % o output_filename: the output image filename.
2117 % o fail: return the number of validation tests that pass.
2119 % o exception: return any errors or warnings in this structure.
2122 static size_t ValidateImportExportPixels(ImageInfo *image_info,
2123 const char *reference_filename,const char *output_filename,size_t *fail,
2124 ExceptionInfo *exception)
2150 (void) output_filename;
2152 (void) FormatLocaleFile(stdout,
2153 "validate the import and export of image pixels:\n");
2154 for (i=0; reference_map[i] != (char *) NULL; i++)
2156 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
2159 Generate reference image.
2161 CatchException(exception);
2162 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
2163 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
2164 reference_storage[j].type));
2165 (void) CopyMagickString(image_info->filename,reference_filename,
2167 reference_image=ReadImage(image_info,exception);
2168 if (reference_image == (Image *) NULL)
2170 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2175 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
2176 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
2177 length=strlen(reference_map[i])*reference_image->columns*
2178 reference_image->rows*reference_storage[j].quantum;
2179 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
2180 if (pixels == (unsigned char *) NULL)
2182 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2185 reference_image=DestroyImage(reference_image);
2188 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
2189 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
2190 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
2192 if (status == MagickFalse)
2194 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2197 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2198 reference_image=DestroyImage(reference_image);
2201 (void) SetImageBackgroundColor(reference_image,exception);
2202 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
2203 reference_image->rows,reference_map[i],reference_storage[j].type,
2205 if (status == MagickFalse)
2207 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2210 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2211 reference_image=DestroyImage(reference_image);
2215 Read reconstruct image.
2217 reconstruct_image=AcquireImage(image_info,exception);
2218 (void) SetImageExtent(reconstruct_image,reference_image->columns,
2219 reference_image->rows,exception);
2220 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
2222 (void) SetImageBackgroundColor(reconstruct_image,exception);
2223 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
2224 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
2226 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2227 if (status == MagickFalse)
2229 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2232 reference_image=DestroyImage(reference_image);
2236 Compare reference to reconstruct image.
2238 difference_image=CompareImages(reference_image,reconstruct_image,
2239 RootMeanSquaredErrorMetric,&distortion,exception);
2240 reconstruct_image=DestroyImage(reconstruct_image);
2241 reference_image=DestroyImage(reference_image);
2242 if (difference_image == (Image *) NULL)
2244 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2249 difference_image=DestroyImage(difference_image);
2250 if ((QuantumScale*distortion) > 0.0)
2252 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2253 QuantumScale*distortion);
2257 (void) FormatLocaleFile(stdout,"... pass.\n");
2260 (void) FormatLocaleFile(stdout,
2261 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2262 (double) (test-(*fail)),(double) *fail);
2267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2271 % V a l i d a t e M o n t a g e C o m m a n d %
2275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2277 % ValidateMontageCommand() validates the ImageMagick montage command line
2278 % program and returns the number of validation tests that passed and failed.
2280 % The format of the ValidateMontageCommand method is:
2282 % size_t ValidateMontageCommand(ImageInfo *image_info,
2283 % const char *reference_filename,const char *output_filename,
2284 % size_t *fail,ExceptionInfo *exception)
2286 % A description of each parameter follows:
2288 % o image_info: the image info.
2290 % o reference_filename: the reference image filename.
2292 % o output_filename: the output image filename.
2294 % o fail: return the number of validation tests that pass.
2296 % o exception: return any errors or warnings in this structure.
2299 static size_t ValidateMontageCommand(ImageInfo *image_info,
2300 const char *reference_filename,const char *output_filename,size_t *fail,
2301 ExceptionInfo *exception)
2305 command[MaxTextExtent];
2321 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
2322 for (i=0; montage_options[i] != (char *) NULL; i++)
2324 CatchException(exception);
2325 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2326 montage_options[i]);
2327 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
2328 reference_filename,montage_options[i],reference_filename,
2330 arguments=StringToArgv(command,&number_arguments);
2331 if (arguments == (char **) NULL)
2333 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2338 status=MontageImageCommand(image_info,number_arguments,arguments,
2339 (char **) NULL,exception);
2340 for (j=0; j < (ssize_t) number_arguments; j++)
2341 arguments[j]=DestroyString(arguments[j]);
2342 arguments=(char **) RelinquishMagickMemory(arguments);
2343 if (status != MagickFalse)
2345 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2350 (void) FormatLocaleFile(stdout,"... pass.\n");
2352 (void) FormatLocaleFile(stdout,
2353 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2354 (double) (test-(*fail)),(double) *fail);
2359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2363 % V a l i d a t e S t r e a m C o m m a n d %
2367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2369 % ValidateStreamCommand() validates the ImageMagick stream command line
2370 % program and returns the number of validation tests that passed and failed.
2372 % The format of the ValidateStreamCommand method is:
2374 % size_t ValidateStreamCommand(ImageInfo *image_info,
2375 % const char *reference_filename,const char *output_filename,
2376 % size_t *fail,ExceptionInfo *exception)
2378 % A description of each parameter follows:
2380 % o image_info: the image info.
2382 % o reference_filename: the reference image filename.
2384 % o output_filename: the output image filename.
2386 % o fail: return the number of validation tests that pass.
2388 % o exception: return any errors or warnings in this structure.
2391 static size_t ValidateStreamCommand(ImageInfo *image_info,
2392 const char *reference_filename,const char *output_filename,size_t *fail,
2393 ExceptionInfo *exception)
2397 command[MaxTextExtent];
2413 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
2414 for (i=0; stream_options[i] != (char *) NULL; i++)
2416 CatchException(exception);
2417 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2419 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
2420 stream_options[i],reference_filename,output_filename);
2421 arguments=StringToArgv(command,&number_arguments);
2422 if (arguments == (char **) NULL)
2424 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2429 status=StreamImageCommand(image_info,number_arguments,arguments,
2430 (char **) NULL,exception);
2431 for (j=0; j < (ssize_t) number_arguments; j++)
2432 arguments[j]=DestroyString(arguments[j]);
2433 arguments=(char **) RelinquishMagickMemory(arguments);
2434 if (status != MagickFalse)
2436 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2441 (void) FormatLocaleFile(stdout,"... pass.\n");
2443 (void) FormatLocaleFile(stdout,
2444 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2445 (double) (test-(*fail)),(double) *fail);
2450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2463 static MagickBooleanType ValidateUsage(void)
2471 "-debug events display copious debugging information",
2472 "-help print program options",
2473 "-log format format of debugging information",
2474 "-validate type validation type",
2475 "-version print version information",
2480 "-regard-warnings pay attention to warning messages",
2481 "-verbose print detailed information about the image",
2485 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
2486 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
2487 (void) printf("Features: %s\n",GetMagickFeatures());
2488 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
2489 (void) printf("\nValidate Settings:\n");
2490 for (p=settings; *p != (char *) NULL; p++)
2491 (void) printf(" %s\n",*p);
2492 (void) printf("\nMiscellaneous Options:\n");
2493 for (p=miscellaneous; *p != (char *) NULL; p++)
2494 (void) printf(" %s\n",*p);
2498 int main(int argc,char **argv)
2500 #define DestroyValidate() \
2502 image_info=DestroyImageInfo(image_info); \
2503 exception=DestroyExceptionInfo(exception); \
2505 #define ThrowValidateException(asperity,tag,option) \
2507 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
2509 CatchException(exception); \
2510 DestroyValidate(); \
2511 return(MagickFalse); \
2515 output_filename[MaxTextExtent],
2516 reference_filename[MaxTextExtent],
2555 Validate the ImageMagick image processing suite.
2557 MagickCoreGenesis(*argv,MagickTrue);
2558 (void) setlocale(LC_ALL,"");
2559 (void) setlocale(LC_NUMERIC,"C");
2563 regard_warnings=MagickFalse;
2564 (void) regard_warnings;
2565 exception=AcquireExceptionInfo();
2566 image_info=AcquireImageInfo();
2567 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
2568 for (i=1; i < (ssize_t) argc; i++)
2571 if (IsCommandOption(option) == MagickFalse)
2573 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
2576 switch (*(option+1))
2580 if (LocaleCompare("bench",option+1) == 0)
2582 iterations=StringToUnsignedLong(argv[++i]);
2585 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2589 if (LocaleCompare("debug",option+1) == 0)
2591 (void) SetLogEventMask(argv[++i]);
2594 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2598 if (LocaleCompare("help",option+1) == 0)
2600 (void) ValidateUsage();
2603 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2607 if (LocaleCompare("log",option+1) == 0)
2610 (void) SetLogFormat(argv[i+1]);
2613 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2617 if (LocaleCompare("regard-warnings",option+1) == 0)
2619 regard_warnings=MagickTrue;
2622 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2626 if (LocaleCompare("validate",option+1) == 0)
2634 if (i == (ssize_t) argc)
2635 ThrowValidateException(OptionError,"MissingArgument",option);
2636 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
2639 ThrowValidateException(OptionError,"UnrecognizedValidateType",
2641 type=(ValidateType) validate;
2644 if ((LocaleCompare("version",option+1) == 0) ||
2645 (LocaleCompare("-version",option+1) == 0))
2647 (void) FormatLocaleFile(stdout,"Version: %s\n",
2648 GetMagickVersion((size_t *) NULL));
2649 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2650 GetMagickCopyright());
2651 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
2652 GetMagickFeatures());
2655 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2658 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2661 timer=(TimerInfo *) NULL;
2663 timer=AcquireTimerInfo();
2664 reference_image=ReadImage(image_info,exception);
2667 if (reference_image == (Image *) NULL)
2671 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
2672 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
2674 (void) AcquireUniqueFilename(reference_filename);
2675 (void) AcquireUniqueFilename(output_filename);
2676 (void) CopyMagickString(reference_image->filename,reference_filename,
2678 status=WriteImage(image_info,reference_image,exception);
2679 reference_image=DestroyImage(reference_image);
2680 if (status == MagickFalse)
2684 (void) FormatLocaleFile(stdout,"Version: %s\n",
2685 GetMagickVersion((size_t *) NULL));
2686 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2687 GetMagickCopyright());
2688 (void) FormatLocaleFile(stdout,
2689 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
2690 MagickValidateOptions,(ssize_t) type));
2691 if ((type & ColorspaceValidate) != 0)
2692 tests+=ValidateColorspaces(image_info,&fail,exception);
2693 if ((type & CompareValidate) != 0)
2694 tests+=ValidateCompareCommand(image_info,reference_filename,
2695 output_filename,&fail,exception);
2696 if ((type & CompositeValidate) != 0)
2697 tests+=ValidateCompositeCommand(image_info,reference_filename,
2698 output_filename,&fail,exception);
2699 if ((type & ConvertValidate) != 0)
2700 tests+=ValidateConvertCommand(image_info,reference_filename,
2701 output_filename,&fail,exception);
2702 if ((type & FormatsInMemoryValidate) != 0)
2704 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2705 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2706 output_filename,&fail,exception);
2707 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2708 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2709 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2710 output_filename,&fail,exception);
2711 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2712 map_resource=SetMagickResourceLimit(MapResource,0);
2713 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2714 output_filename,&fail,exception);
2715 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2716 (void) SetMagickResourceLimit(MapResource,map_resource);
2718 if ((type & FormatsOnDiskValidate) != 0)
2720 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2721 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2722 output_filename,&fail,exception);
2723 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2724 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2725 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2726 output_filename,&fail,exception);
2727 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2728 map_resource=SetMagickResourceLimit(MapResource,0);
2729 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2730 output_filename,&fail,exception);
2731 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2732 (void) SetMagickResourceLimit(MapResource,map_resource);
2734 if ((type & IdentifyValidate) != 0)
2735 tests+=ValidateIdentifyCommand(image_info,reference_filename,
2736 output_filename,&fail,exception);
2737 if ((type & ImportExportValidate) != 0)
2738 tests+=ValidateImportExportPixels(image_info,reference_filename,
2739 output_filename,&fail,exception);
2740 if ((type & MontageValidate) != 0)
2741 tests+=ValidateMontageCommand(image_info,reference_filename,
2742 output_filename,&fail,exception);
2743 if ((type & StreamValidate) != 0)
2744 tests+=ValidateStreamCommand(image_info,reference_filename,
2745 output_filename,&fail,exception);
2746 (void) FormatLocaleFile(stdout,
2747 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
2748 (double) tests,(double) (tests-fail),(double) fail);
2750 (void) RelinquishUniqueFileResource(output_filename);
2751 (void) RelinquishUniqueFileResource(reference_filename);
2753 if (exception->severity != UndefinedException)
2754 CatchException(exception);
2757 elapsed_time=GetElapsedTime(timer);
2758 user_time=GetUserTime(timer);
2759 (void) FormatLocaleFile(stderr,
2760 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
2761 iterations,1.0*iterations/elapsed_time,user_time,(long)
2762 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
2763 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
2764 timer=DestroyTimerInfo(timer);
2767 MagickCoreTerminus();
2768 return(fail == 0 ? 0 : 1);