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-2014 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 (QuantumRange*1.0e-2)
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),360.0*hue,&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))/255.0+0.5;
548 *hue=180.0*atan2(255.0*(b-0.5),255.0*(a-0.5))/MagickPI/360.0;
553 static void ConvertRGBToLCHab(const double red,const double green,
554 const double blue,double *luma,double *chroma,double *hue)
561 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
562 ConvertXYZToLCHab(X,Y,Z,luma,chroma,hue);
565 static inline void ConvertLMSToXYZ(const double L,const double M,const double S,
566 double *X,double *Y,double *Z)
568 *X=1.096123820835514*L-0.278869000218287*M+0.182745179382773*S;
569 *Y=0.454369041975359*L+0.473533154307412*M+0.072097803717229*S;
570 *Z=(-0.009627608738429)*L-0.005698031216113*M+1.015325639954543*S;
573 static inline void ConvertLMSToRGB(const double L,const double M,
574 const double S,double *red,double *green,double *blue)
581 ConvertLMSToXYZ(L,M,S,&X,&Y,&Z);
582 ConvertXYZToRGB(X,Y,Z,red,green,blue);
585 static inline void ConvertXYZToLMS(const double x,const double y,
586 const double z,double *L,double *M,double *S)
588 *L=0.7328*x+0.4296*y-0.1624*z;
589 *M=(-0.7036*x+1.6975*y+0.0061*z);
590 *S=0.0030*x+0.0136*y+0.9834*z;
593 static void ConvertRGBToLMS(const double red,const double green,
594 const double blue,double *L,double *M,double *S)
601 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
602 ConvertXYZToLMS(X,Y,Z,L,M,S);
605 static inline double PerceptibleReciprocal(const double x)
611 Return 1/x where x is perceptible (not unlimited or infinitesimal).
613 sign=x < 0.0 ? -1.0 : 1.0;
614 if ((sign*x) >= MagickEpsilon)
616 return(sign/MagickEpsilon);
619 static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
620 double *L,double *u,double *v)
625 if ((Y/D65Y) > CIEEpsilon)
626 *L=(double) (116.0*pow(Y/D65Y,1.0/3.0)-16.0);
629 alpha=PerceptibleReciprocal(X+15.0*Y+3.0*Z);
630 *u=13.0*(*L)*((4.0*alpha*X)-(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z)));
631 *v=13.0*(*L)*((9.0*alpha*Y)-(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z)));
637 static void ConvertRGBToLuv(const double red,const double green,
638 const double blue,double *L,double *u,double *v)
645 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
646 ConvertXYZToLuv(X,Y,Z,L,u,v);
649 static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
650 double *X,double *Y,double *Z)
652 if (L > (CIEK*CIEEpsilon))
653 *Y=(double) pow((L+16.0)/116.0,3.0);
656 *X=((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
657 5.0*(*Y))/((((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/
659 *Z=(*X*(((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
663 static inline void ConvertLuvToRGB(const double L,const double u,
664 const double v,double *red,double *green,double *blue)
671 ConvertLuvToXYZ(100.0*L,354.0*u-134.0,262.0*v-140.0,&X,&Y,&Z);
672 ConvertXYZToRGB(X,Y,Z,red,green,blue);
675 static void ConvertRGBToYDbDr(const double red,const double green,
676 const double blue,double *Y,double *Db,double *Dr)
678 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
679 *Db=QuantumScale*(-0.450*red-0.883*green+1.333*blue)+0.5;
680 *Dr=QuantumScale*(-1.333*red+1.116*green+0.217*blue)+0.5;
683 static void ConvertYDbDrToRGB(const double Y,const double Db,const double Dr,
684 double *red,double *green,double *blue)
686 *red=QuantumRange*(Y+9.2303716147657e-05*(Db-0.5)-0.52591263066186533*
688 *green=QuantumRange*(Y-0.12913289889050927*(Db-0.5)+0.26789932820759876*
690 *blue=QuantumRange*(Y+0.66467905997895482*(Db-0.5)-7.9202543533108e-05*
694 static void ConvertRGBToYIQ(const double red,const double green,
695 const double blue,double *Y,double *I,double *Q)
697 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
698 *I=QuantumScale*(0.595716*red-0.274453*green-0.321263*blue)+0.5;
699 *Q=QuantumScale*(0.211456*red-0.522591*green+0.311135*blue)+0.5;
702 static void ConvertYIQToRGB(const double Y,const double I,const double Q,
703 double *red,double *green,double *blue)
705 *red=QuantumRange*(Y+0.9562957197589482261*(I-0.5)+0.6210244164652610754*
707 *green=QuantumRange*(Y-0.2721220993185104464*(I-0.5)-0.6473805968256950427*
709 *blue=QuantumRange*(Y-1.1069890167364901945*(I-0.5)+1.7046149983646481374*
713 static void ConvertRGBToYUV(const double red,const double green,
714 const double blue,double *Y,double *U,double *V)
716 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
717 *U=QuantumScale*((-0.147)*red-0.289*green+0.436*blue)+0.5;
718 *V=QuantumScale*(0.615*red-0.515*green-0.100*blue)+0.5;
721 static void ConvertYUVToRGB(const double Y,const double U,const double V,
722 double *red,double *green,double *blue)
724 *red=QuantumRange*(Y-3.945707070708279e-05*(U-0.5)+1.1398279671717170825*
726 *green=QuantumRange*(Y-0.3946101641414141437*(U-0.5)-0.5805003156565656797*
728 *blue=QuantumRange*(Y+2.0319996843434342537*(U-0.5)-4.813762626262513e-04*
732 static MagickBooleanType ValidateHSIToRGB()
739 (void) FormatLocaleFile(stdout," HSIToRGB");
740 ConvertHSIToRGB(111.244375/360.0,0.295985,0.658734,&r,&g,&b);
741 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
742 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
743 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
748 static MagickBooleanType ValidateRGBToHSI()
755 (void) FormatLocaleFile(stdout," RGBToHSI");
756 ConvertRGBToHSI(0.545877*QuantumRange,0.966567*QuantumRange,
757 0.463759*QuantumRange,&h,&s,&i);
758 if ((fabs(h-111.244374/360.0) >= ReferenceEpsilon) ||
759 (fabs(s-0.295985) >= ReferenceEpsilon) ||
760 (fabs(i-0.658734) >= ReferenceEpsilon))
765 static MagickBooleanType ValidateHSLToRGB()
772 (void) FormatLocaleFile(stdout," HSLToRGB");
773 ConvertHSLToRGB(110.200859/360.0,0.882623,0.715163,&r,&g,&b);
774 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
775 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
776 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
781 static MagickBooleanType ValidateRGBToHSL()
788 (void) FormatLocaleFile(stdout," RGBToHSL");
789 ConvertRGBToHSL(0.545877*QuantumRange,0.966567*QuantumRange,
790 0.463759*QuantumRange,&h,&s,&l);
791 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
792 (fabs(s-0.882623) >= ReferenceEpsilon) ||
793 (fabs(l-0.715163) >= ReferenceEpsilon))
798 static MagickBooleanType ValidateHSVToRGB()
805 (void) FormatLocaleFile(stdout," HSVToRGB");
806 ConvertHSVToRGB(110.200859/360.0,0.520200,0.966567,&r,&g,&b);
807 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
808 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
809 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
814 static MagickBooleanType ValidateRGBToHSV()
821 (void) FormatLocaleFile(stdout," RGBToHSV");
822 ConvertRGBToHSV(0.545877*QuantumRange,0.966567*QuantumRange,
823 0.463759*QuantumRange,&h,&s,&v);
824 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
825 (fabs(s-0.520200) >= ReferenceEpsilon) ||
826 (fabs(v-0.966567) >= ReferenceEpsilon))
831 static MagickBooleanType ValidateRGBToJPEGYCbCr()
838 (void) FormatLocaleFile(stdout," RGBToJPEGYCbCr");
839 ConvertRGBToYCbCr(0.545877*QuantumRange,0.966567*QuantumRange,
840 0.463759*QuantumRange,&Y,&Cb,&Cr);
841 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
842 (fabs(Cb-0.319581) >= ReferenceEpsilon) ||
843 (fabs(Cr-0.330539) >= ReferenceEpsilon))
848 static MagickBooleanType ValidateJPEGYCbCrToRGB()
855 (void) FormatLocaleFile(stdout," JPEGYCbCrToRGB");
856 ConvertYCbCrToRGB(0.783460,0.319581,0.330539,&r,&g,&b);
857 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
858 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
859 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
864 static MagickBooleanType ValidateLabToRGB()
871 (void) FormatLocaleFile(stdout," LabToRGB");
872 ConvertLabToRGB(88.456154/100.0,-54.671483/255+0.5,51.662818/255.0+0.5,
874 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
875 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
876 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
881 static MagickBooleanType ValidateRGBToLab()
888 (void) FormatLocaleFile(stdout," RGBToLab");
889 ConvertRGBToLab(0.545877*QuantumRange,0.966567*QuantumRange,
890 0.463759*QuantumRange,&L,&a,&b);
891 if ((fabs(L-(88.456154/100.0)) >= ReferenceEpsilon) ||
892 (fabs(a-(-54.671483/255.0+0.5)) >= ReferenceEpsilon) ||
893 (fabs(b-(51.662818/255.0+0.5)) >= ReferenceEpsilon))
898 static MagickBooleanType ValidateLchToRGB()
905 (void) FormatLocaleFile(stdout," LchToRGB");
906 ConvertLCHabToRGB(88.456154/100.0,75.219797/255.0+0.5,136.620717/360.0,
908 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
909 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
910 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
915 static MagickBooleanType ValidateRGBToLch()
922 (void) FormatLocaleFile(stdout," RGBToLch");
923 ConvertRGBToLCHab(0.545877*QuantumRange,0.966567*QuantumRange,
924 0.463759*QuantumRange,&L,&c,&h);
925 if ((fabs(L-88.456154/100.0) >= ReferenceEpsilon) ||
926 (fabs(c-(75.219797/255.0+0.5)) >= ReferenceEpsilon) ||
927 (fabs(h-(136.620717/255.0+0.5)) >= ReferenceEpsilon))
932 static MagickBooleanType ValidateRGBToLMS()
939 (void) FormatLocaleFile(stdout," RGBToLMS");
940 ConvertRGBToLMS(0.545877*QuantumRange,0.966567*QuantumRange,
941 0.463759*QuantumRange,&L,&M,&S);
942 if ((fabs(L-0.611749) >= ReferenceEpsilon) ||
943 (fabs(M-0.910088) >= ReferenceEpsilon) ||
944 (fabs(S-0.294880) >= ReferenceEpsilon))
949 static MagickBooleanType ValidateLMSToRGB()
956 (void) FormatLocaleFile(stdout," LMSToRGB");
957 ConvertLMSToRGB(0.611749,0.910088,0.294880,&r,&g,&b);
958 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
959 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
960 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
965 static MagickBooleanType ValidateRGBToLuv()
972 (void) FormatLocaleFile(stdout," RGBToLuv");
973 ConvertRGBToLuv(0.545877*QuantumRange,0.966567*QuantumRange,
974 0.463759*QuantumRange,&l,&u,&v);
975 if ((fabs(l-88.456154/262.0) >= ReferenceEpsilon) ||
976 (fabs(u-(-51.330414+134.0)/354.0) >= ReferenceEpsilon) ||
977 (fabs(v-(76.405526+140.0)/262.0) >= ReferenceEpsilon))
982 static MagickBooleanType ValidateLuvToRGB()
989 (void) FormatLocaleFile(stdout," LuvToRGB");
990 ConvertLuvToRGB(88.456154/100.0,(-51.330414+134.0)/354.0,
991 (76.405526+140.0)/262.0,&r,&g,&b);
992 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
993 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
994 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
999 static MagickBooleanType ValidateRGBToXYZ()
1006 (void) FormatLocaleFile(stdout," RGBToXYZ");
1007 ConvertRGBToXYZ(0.545877*QuantumRange,0.966567*QuantumRange,
1008 0.463759*QuantumRange,&x,&y,&z);
1009 if ((fabs(x-0.470646) >= ReferenceEpsilon) ||
1010 (fabs(y-0.730178) >= ReferenceEpsilon) ||
1011 (fabs(z-0.288324) >= ReferenceEpsilon))
1012 return(MagickFalse);
1016 static MagickBooleanType ValidateXYZToRGB()
1023 (void) FormatLocaleFile(stdout," XYZToRGB");
1024 ConvertXYZToRGB(0.470646,0.730178,0.288324,&r,&g,&b);
1025 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1026 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1027 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1028 return(MagickFalse);
1032 static MagickBooleanType ValidateYDbDrToRGB()
1039 (void) FormatLocaleFile(stdout," YDbDrToRGB");
1040 ConvertYDbDrToRGB(0.783460,-0.480932+0.5,0.451670+0.5,&r,&g,&b);
1041 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1042 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1043 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1044 return(MagickFalse);
1048 static MagickBooleanType ValidateRGBToYDbDr()
1055 (void) FormatLocaleFile(stdout," RGBToYDbDr");
1056 ConvertRGBToYDbDr(0.545877*QuantumRange,0.966567*QuantumRange,
1057 0.463759*QuantumRange,&Y,&Db,&Dr);
1058 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
1059 (fabs(Db-(-0.480932)) >= ReferenceEpsilon) ||
1060 (fabs(Dr-0.451670) >= ReferenceEpsilon))
1061 return(MagickFalse);
1065 static MagickBooleanType ValidateRGBToYIQ()
1072 (void) FormatLocaleFile(stdout," RGBToYIQ");
1073 ConvertRGBToYIQ(0.545877*QuantumRange,0.966567*QuantumRange,
1074 0.463759*QuantumRange,&y,&i,&q);
1075 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
1076 (fabs(i-(-0.089078)) >= ReferenceEpsilon) ||
1077 (fabs(q-(-0.245399)) >= ReferenceEpsilon))
1078 return(MagickFalse);
1082 static MagickBooleanType ValidateYIQToRGB()
1089 (void) FormatLocaleFile(stdout," YIQToRGB");
1090 ConvertYIQToRGB(0.783460,-0.089078+0.5,-0.245399+0.5,&r,&g,&b);
1091 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1092 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1093 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1094 return(MagickFalse);
1098 static MagickBooleanType ValidateRGBToYPbPr()
1105 (void) FormatLocaleFile(stdout," RGBToYPbPr");
1106 ConvertRGBToYPbPr(0.545877*QuantumRange,0.966567*QuantumRange,
1107 0.463759*QuantumRange,&y,&Pb,&Pr);
1108 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
1109 (fabs(Pb-(-0.180419)) >= ReferenceEpsilon) ||
1110 (fabs(Pr-(-0.169461)) >= ReferenceEpsilon))
1111 return(MagickFalse);
1115 static MagickBooleanType ValidateYPbPrToRGB()
1122 (void) FormatLocaleFile(stdout," YPbPrToRGB");
1123 ConvertYPbPrToRGB(0.783460,-0.180419+0.5,-0.169461+0.5,&r,&g,&b);
1124 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1125 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1126 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1127 return(MagickFalse);
1131 static MagickBooleanType ValidateRGBToYUV()
1138 (void) FormatLocaleFile(stdout," RGBToYUV");
1139 ConvertRGBToYUV(0.545877*QuantumRange,0.966567*QuantumRange,
1140 0.463759*QuantumRange,&Y,&U,&V);
1141 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
1142 (fabs(U-(-0.157383)) >= ReferenceEpsilon) ||
1143 (fabs(V-(-0.208443)) >= ReferenceEpsilon))
1144 return(MagickFalse);
1148 static MagickBooleanType ValidateYUVToRGB()
1155 (void) FormatLocaleFile(stdout," YUVToRGB");
1156 ConvertYUVToRGB(0.783460,-0.157383+0.5,-0.208443+0.5,&r,&g,&b);
1157 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1158 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1159 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1160 return(MagickFalse);
1164 static size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
1165 ExceptionInfo *exception)
1174 Reference: https://code.google.com/p/chroma.
1177 Observer = 2° (1931)
1179 XYZ 0.470645, 0.730177, 0.288323
1180 sRGB 0.545877, 0.966567, 0.463759
1181 CAT02 LMS 0.611749, 0.910088, 0.294880
1182 Y'DbDr 0.783460, -0.480932, 0.451670
1183 Y'IQ 0.783460, -0.089078, -0.245399
1184 Y'PbPr 0.783460, -0.180419, -0.169461
1185 Y'UV 0.783460, -0.157383, -0.208443
1186 JPEG-Y'CbCr 0.783460, 0.319581, 0.330539
1187 L*u*v* 88.456154, -51.330414, 76.405526
1188 L*a*b* 88.456154, -54.671483, 51.662818
1189 L*C*H* 88.456154, 75.219797, 136.620717
1190 HSV 110.200859, 0.520200, 0.966567
1191 HSL 110.200859, 0.882623, 0.715163
1192 HSI 111.244375, 0.295985, 0.658734
1193 Y'CbCr 187.577791, 87.586330, 90.040886
1195 (void) FormatLocaleFile(stdout,"validate colorspaces:\n");
1196 for (test=0; test < 26; test++)
1198 CatchException(exception);
1199 (void) FormatLocaleFile(stdout," test %.20g: ",(double) test);
1202 case 0: status=ValidateHSIToRGB(); break;
1203 case 1: status=ValidateRGBToHSI(); break;
1204 case 2: status=ValidateHSLToRGB(); break;
1205 case 3: status=ValidateRGBToHSL(); break;
1206 case 4: status=ValidateHSVToRGB(); break;
1207 case 5: status=ValidateRGBToHSV(); break;
1208 case 6: status=ValidateJPEGYCbCrToRGB(); break;
1209 case 7: status=ValidateRGBToJPEGYCbCr(); break;
1210 case 8: status=ValidateLabToRGB(); break;
1211 case 9: status=ValidateRGBToLab(); break;
1212 case 10: status=ValidateLchToRGB(); break;
1213 case 11: status=ValidateRGBToLch(); break;
1214 case 12: status=ValidateLMSToRGB(); break;
1215 case 13: status=ValidateRGBToLMS(); break;
1216 case 14: status=ValidateLuvToRGB(); break;
1217 case 15: status=ValidateRGBToLuv(); break;
1218 case 16: status=ValidateXYZToRGB(); break;
1219 case 17: status=ValidateRGBToXYZ(); break;
1220 case 18: status=ValidateYDbDrToRGB(); break;
1221 case 19: status=ValidateRGBToYDbDr(); break;
1222 case 20: status=ValidateYIQToRGB(); break;
1223 case 21: status=ValidateRGBToYIQ(); break;
1224 case 22: status=ValidateYPbPrToRGB(); break;
1225 case 23: status=ValidateRGBToYPbPr(); break;
1226 case 24: status=ValidateYUVToRGB(); break;
1227 case 25: status=ValidateRGBToYUV(); break;
1228 default: status=MagickFalse;
1230 if (status == MagickFalse)
1232 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1237 (void) FormatLocaleFile(stdout,"... pass.\n");
1239 (void) FormatLocaleFile(stdout,
1240 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1241 (double) (test-(*fail)),(double) *fail);
1246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1250 % V a l i d a t e C o m p a r e C o m m a n d %
1254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1256 % ValidateCompareCommand() validates the ImageMagick compare command line
1257 % program and returns the number of validation tests that passed and failed.
1259 % The format of the ValidateCompareCommand method is:
1261 % size_t ValidateCompareCommand(ImageInfo *image_info,
1262 % const char *reference_filename,const char *output_filename,
1263 % size_t *fail,ExceptionInfo *exception)
1265 % A description of each parameter follows:
1267 % o image_info: the image info.
1269 % o reference_filename: the reference image filename.
1271 % o output_filename: the output image filename.
1273 % o fail: return the number of validation tests that pass.
1275 % o exception: return any errors or warnings in this structure.
1278 static size_t ValidateCompareCommand(ImageInfo *image_info,
1279 const char *reference_filename,const char *output_filename,size_t *fail,
1280 ExceptionInfo *exception)
1284 command[MaxTextExtent];
1300 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
1301 for (i=0; compare_options[i] != (char *) NULL; i++)
1303 CatchException(exception);
1304 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1305 compare_options[i]);
1306 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1307 compare_options[i],reference_filename,reference_filename,output_filename);
1308 arguments=StringToArgv(command,&number_arguments);
1309 if (arguments == (char **) NULL)
1311 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1316 status=CompareImagesCommand(image_info,number_arguments,arguments,
1317 (char **) NULL,exception);
1318 for (j=0; j < (ssize_t) number_arguments; j++)
1319 arguments[j]=DestroyString(arguments[j]);
1320 arguments=(char **) RelinquishMagickMemory(arguments);
1321 if (status != MagickFalse)
1323 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1328 (void) FormatLocaleFile(stdout,"... pass.\n");
1330 (void) FormatLocaleFile(stdout,
1331 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1332 (double) (test-(*fail)),(double) *fail);
1337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1341 % V a l i d a t e C o m p o s i t e C o m m a n d %
1345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1347 % ValidateCompositeCommand() validates the ImageMagick composite command line
1348 % program and returns the number of validation tests that passed and failed.
1350 % The format of the ValidateCompositeCommand method is:
1352 % size_t ValidateCompositeCommand(ImageInfo *image_info,
1353 % const char *reference_filename,const char *output_filename,
1354 % size_t *fail,ExceptionInfo *exception)
1356 % A description of each parameter follows:
1358 % o image_info: the image info.
1360 % o reference_filename: the reference image filename.
1362 % o output_filename: the output image filename.
1364 % o fail: return the number of validation tests that pass.
1366 % o exception: return any errors or warnings in this structure.
1369 static size_t ValidateCompositeCommand(ImageInfo *image_info,
1370 const char *reference_filename,const char *output_filename,size_t *fail,
1371 ExceptionInfo *exception)
1375 command[MaxTextExtent];
1391 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
1392 for (i=0; composite_options[i] != (char *) NULL; i++)
1394 CatchException(exception);
1395 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1396 composite_options[i]);
1397 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1398 reference_filename,composite_options[i],reference_filename,
1400 arguments=StringToArgv(command,&number_arguments);
1401 if (arguments == (char **) NULL)
1403 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1408 status=CompositeImageCommand(image_info,number_arguments,arguments,
1409 (char **) NULL,exception);
1410 for (j=0; j < (ssize_t) number_arguments; j++)
1411 arguments[j]=DestroyString(arguments[j]);
1412 arguments=(char **) RelinquishMagickMemory(arguments);
1413 if (status != MagickFalse)
1415 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1420 (void) FormatLocaleFile(stdout,"... pass.\n");
1422 (void) FormatLocaleFile(stdout,
1423 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1424 (double) (test-(*fail)),(double) *fail);
1429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1433 % V a l i d a t e C o n v e r t C o m m a n d %
1437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1439 % ValidateConvertCommand() validates the ImageMagick convert command line
1440 % program and returns the number of validation tests that passed and failed.
1442 % The format of the ValidateConvertCommand method is:
1444 % size_t ValidateConvertCommand(ImageInfo *image_info,
1445 % const char *reference_filename,const char *output_filename,
1446 % size_t *fail,ExceptionInfo *exception)
1448 % A description of each parameter follows:
1450 % o image_info: the image info.
1452 % o reference_filename: the reference image filename.
1454 % o output_filename: the output image filename.
1456 % o fail: return the number of validation tests that pass.
1458 % o exception: return any errors or warnings in this structure.
1461 static size_t ValidateConvertCommand(ImageInfo *image_info,
1462 const char *reference_filename,const char *output_filename,size_t *fail,
1463 ExceptionInfo *exception)
1467 command[MaxTextExtent];
1483 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
1484 for (i=0; convert_options[i] != (char *) NULL; i++)
1486 CatchException(exception);
1487 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1488 convert_options[i]);
1489 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1490 reference_filename,convert_options[i],reference_filename,output_filename);
1491 arguments=StringToArgv(command,&number_arguments);
1492 if (arguments == (char **) NULL)
1494 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1499 status=ConvertImageCommand(image_info,number_arguments,arguments,
1500 (char **) NULL,exception);
1501 for (j=0; j < (ssize_t) number_arguments; j++)
1502 arguments[j]=DestroyString(arguments[j]);
1503 arguments=(char **) RelinquishMagickMemory(arguments);
1504 if (status != MagickFalse)
1506 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1511 (void) FormatLocaleFile(stdout,"... pass.\n");
1513 (void) FormatLocaleFile(stdout,
1514 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1515 (double) (test-(*fail)),(double) *fail);
1520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1524 % V a l i d a t e I d e n t i f y C o m m a n d %
1528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1530 % ValidateIdentifyCommand() validates the ImageMagick identify command line
1531 % program and returns the number of validation tests that passed and failed.
1533 % The format of the ValidateIdentifyCommand method is:
1535 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
1536 % const char *reference_filename,const char *output_filename,
1537 % size_t *fail,ExceptionInfo *exception)
1539 % A description of each parameter follows:
1541 % o image_info: the image info.
1543 % o reference_filename: the reference image filename.
1545 % o output_filename: the output image filename.
1547 % o fail: return the number of validation tests that pass.
1549 % o exception: return any errors or warnings in this structure.
1552 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
1553 const char *reference_filename,const char *output_filename,size_t *fail,
1554 ExceptionInfo *exception)
1558 command[MaxTextExtent];
1573 (void) output_filename;
1575 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
1576 for (i=0; identify_options[i] != (char *) NULL; i++)
1578 CatchException(exception);
1579 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1580 identify_options[i]);
1581 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
1582 identify_options[i],reference_filename);
1583 arguments=StringToArgv(command,&number_arguments);
1584 if (arguments == (char **) NULL)
1586 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1591 status=IdentifyImageCommand(image_info,number_arguments,arguments,
1592 (char **) NULL,exception);
1593 for (j=0; j < (ssize_t) number_arguments; j++)
1594 arguments[j]=DestroyString(arguments[j]);
1595 arguments=(char **) RelinquishMagickMemory(arguments);
1596 if (status != MagickFalse)
1598 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1603 (void) FormatLocaleFile(stdout,"... pass.\n");
1605 (void) FormatLocaleFile(stdout,
1606 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1607 (double) (test-(*fail)),(double) *fail);
1612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1616 % 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 %
1620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1622 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
1623 % memory and returns the number of validation tests that passed and failed.
1625 % The format of the ValidateImageFormatsInMemory method is:
1627 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1628 % const char *reference_filename,const char *output_filename,
1629 % size_t *fail,ExceptionInfo *exception)
1631 % A description of each parameter follows:
1633 % o image_info: the image info.
1635 % o reference_filename: the reference image filename.
1637 % o output_filename: the output image filename.
1639 % o fail: return the number of validation tests that pass.
1641 % o exception: return any errors or warnings in this structure.
1646 Enable this to count remaining $TMPDIR/magick-* files. Note that the count
1647 includes any files left over from other runs.
1649 #undef MagickCountTempFiles
1651 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1652 const char *reference_filename,const char *output_filename,size_t *fail,
1653 ExceptionInfo *exception)
1656 #ifdef MagickCountTempFiles
1657 path[MaxTextExtent],
1658 SystemCommand[MaxTextExtent],
1660 size[MaxTextExtent];
1690 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
1692 #ifdef MagickCountTempFiles
1693 (void)GetPathTemplate(path);
1694 /* Remove file template except for the leading "/path/to/magick-" */
1695 path[strlen(path)-17]='\0';
1696 (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
1699 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1701 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1702 if ((magick_info == (const MagickInfo *) NULL) ||
1703 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1704 (magick_info->encoder == (EncodeImageHandler *) NULL))
1706 for (j=0; reference_types[j].type != UndefinedType; j++)
1709 Generate reference image.
1711 CatchException(exception);
1712 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1713 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1714 MagickCompressOptions,reference_formats[i].compression),
1715 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1716 (double) reference_types[j].depth);
1717 (void) CopyMagickString(image_info->filename,reference_filename,
1719 reference_image=ReadImage(image_info,exception);
1720 if (reference_image == (Image *) NULL)
1722 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1728 Write reference image.
1730 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
1731 (double) reference_image->columns,(double) reference_image->rows);
1732 (void) CloneString(&image_info->size,size);
1733 image_info->depth=reference_types[j].depth;
1734 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1735 reference_formats[i].magick,output_filename);
1736 status=SetImageType(reference_image,reference_types[j].type,exception);
1737 if (status == MagickFalse)
1739 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1742 reference_image=DestroyImage(reference_image);
1745 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1746 if (status == MagickFalse)
1748 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1751 reference_image=DestroyImage(reference_image);
1754 reference_image->compression=reference_formats[i].compression;
1755 status=WriteImage(image_info,reference_image,exception);
1756 reference_image=DestroyImage(reference_image);
1757 if (status == MagickFalse)
1759 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1765 Ping reference image.
1767 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1768 reference_formats[i].magick,output_filename);
1769 ping_image=PingImage(image_info,exception);
1770 if (ping_image == (Image *) NULL)
1772 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1777 ping_image=DestroyImage(ping_image);
1779 Read reference image.
1781 reference_image=ReadImage(image_info,exception);
1782 if (reference_image == (Image *) NULL)
1784 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1790 Write reference image.
1792 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1793 reference_formats[i].magick,output_filename);
1794 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
1796 reference_image->depth=reference_types[j].depth;
1797 reference_image->compression=reference_formats[i].compression;
1799 blob=ImageToBlob(image_info,reference_image,&length,exception);
1800 if (blob == (unsigned char *) NULL)
1802 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1805 reference_image=DestroyImage(reference_image);
1809 Ping reference blob.
1811 ping_image=PingBlob(image_info,blob,length,exception);
1812 if (ping_image == (Image *) NULL)
1814 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1817 blob=(unsigned char *) RelinquishMagickMemory(blob);
1820 ping_image=DestroyImage(ping_image);
1822 Read reconstruct image.
1824 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1825 reference_formats[i].magick,output_filename);
1826 reconstruct_image=BlobToImage(image_info,blob,length,exception);
1827 blob=(unsigned char *) RelinquishMagickMemory(blob);
1828 if (reconstruct_image == (Image *) NULL)
1830 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1833 reference_image=DestroyImage(reference_image);
1837 Compare reference to reconstruct image.
1839 fuzz=0.003; /* grayscale */
1840 if (reference_formats[i].fuzz != 0.0)
1841 fuzz=reference_formats[i].fuzz;
1842 difference_image=CompareImages(reference_image,reconstruct_image,
1843 RootMeanSquaredErrorMetric,&distortion,exception);
1844 reconstruct_image=DestroyImage(reconstruct_image);
1845 reference_image=DestroyImage(reference_image);
1846 if (difference_image == (Image *) NULL)
1848 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1853 difference_image=DestroyImage(difference_image);
1854 if ((QuantumScale*distortion) > fuzz)
1856 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1857 QuantumScale*distortion);
1861 #ifdef MagickCountTempFiles
1862 (void) FormatLocaleFile(stdout,"... pass, ");
1863 (void) fflush(stdout);
1864 SystemCommand[0]='\0';
1865 (void) strncat(SystemCommand,"echo `ls ",9);
1866 (void) strncat(SystemCommand,path,MaxTextExtent-31);
1867 (void) strncat(SystemCommand,"* | wc -w` tmp files.",20);
1868 (void) system(SystemCommand);
1869 (void) fflush(stdout);
1871 (void) FormatLocaleFile(stdout,"... pass\n");
1875 (void) FormatLocaleFile(stdout,
1876 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1877 (double) (test-(*fail)),(double) *fail);
1882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1886 % 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 %
1890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1892 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
1893 % and returns the number of validation tests that passed and failed.
1895 % The format of the ValidateImageFormatsOnDisk method is:
1897 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1898 % const char *reference_filename,const char *output_filename,
1899 % size_t *fail,ExceptionInfo *exception)
1901 % A description of each parameter follows:
1903 % o image_info: the image info.
1905 % o reference_filename: the reference image filename.
1907 % o output_filename: the output image filename.
1909 % o fail: return the number of validation tests that pass.
1911 % o exception: return any errors or warnings in this structure.
1914 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1915 const char *reference_filename,const char *output_filename,size_t *fail,
1916 ExceptionInfo *exception)
1919 size[MaxTextExtent];
1944 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
1945 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1947 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1948 if ((magick_info == (const MagickInfo *) NULL) ||
1949 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1950 (magick_info->encoder == (EncodeImageHandler *) NULL))
1952 for (j=0; reference_types[j].type != UndefinedType; j++)
1955 Generate reference image.
1957 CatchException(exception);
1958 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1959 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1960 MagickCompressOptions,reference_formats[i].compression),
1961 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1962 (double) reference_types[j].depth);
1963 (void) CopyMagickString(image_info->filename,reference_filename,
1965 reference_image=ReadImage(image_info,exception);
1966 if (reference_image == (Image *) NULL)
1968 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1974 Write reference image.
1976 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
1977 (double) reference_image->columns,(double) reference_image->rows);
1978 (void) CloneString(&image_info->size,size);
1979 image_info->depth=reference_types[j].depth;
1980 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1981 reference_formats[i].magick,output_filename);
1982 status=SetImageType(reference_image,reference_types[j].type,exception);
1983 if (status == MagickFalse)
1985 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1988 reference_image=DestroyImage(reference_image);
1991 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1992 if (status == MagickFalse)
1994 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1997 reference_image=DestroyImage(reference_image);
2000 reference_image->compression=reference_formats[i].compression;
2001 status=WriteImage(image_info,reference_image,exception);
2002 reference_image=DestroyImage(reference_image);
2003 if (status == MagickFalse)
2005 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2011 Read reference image.
2013 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
2014 reference_formats[i].magick,output_filename);
2015 reference_image=ReadImage(image_info,exception);
2016 if (reference_image == (Image *) NULL)
2018 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2024 Write reference image.
2026 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
2027 reference_formats[i].magick,output_filename);
2028 reference_image->depth=reference_types[j].depth;
2029 reference_image->compression=reference_formats[i].compression;
2030 status=WriteImage(image_info,reference_image,exception);
2031 if (status == MagickFalse)
2033 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2036 reference_image=DestroyImage(reference_image);
2040 Read reconstruct image.
2042 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
2043 reference_formats[i].magick,output_filename);
2044 reconstruct_image=ReadImage(image_info,exception);
2045 if (reconstruct_image == (Image *) NULL)
2047 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2050 reference_image=DestroyImage(reference_image);
2054 Compare reference to reconstruct image.
2056 fuzz=0.003; /* grayscale */
2057 if (reference_formats[i].fuzz != 0.0)
2058 fuzz=reference_formats[i].fuzz;
2059 difference_image=CompareImages(reference_image,reconstruct_image,
2060 RootMeanSquaredErrorMetric,&distortion,exception);
2061 reconstruct_image=DestroyImage(reconstruct_image);
2062 reference_image=DestroyImage(reference_image);
2063 if (difference_image == (Image *) NULL)
2065 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2070 difference_image=DestroyImage(difference_image);
2071 if ((QuantumScale*distortion) > fuzz)
2073 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2074 QuantumScale*distortion);
2078 (void) FormatLocaleFile(stdout,"... pass.\n");
2081 (void) FormatLocaleFile(stdout,
2082 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2083 (double) (test-(*fail)),(double) *fail);
2088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2092 % 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 %
2096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2098 % ValidateImportExportPixels() validates the pixel import and export methods.
2099 % It returns the number of validation tests that passed and failed.
2101 % The format of the ValidateImportExportPixels method is:
2103 % size_t ValidateImportExportPixels(ImageInfo *image_info,
2104 % const char *reference_filename,const char *output_filename,
2105 % size_t *fail,ExceptionInfo *exception)
2107 % A description of each parameter follows:
2109 % o image_info: the image info.
2111 % o reference_filename: the reference image filename.
2113 % o output_filename: the output image filename.
2115 % o fail: return the number of validation tests that pass.
2117 % o exception: return any errors or warnings in this structure.
2120 static size_t ValidateImportExportPixels(ImageInfo *image_info,
2121 const char *reference_filename,const char *output_filename,size_t *fail,
2122 ExceptionInfo *exception)
2148 (void) output_filename;
2150 (void) FormatLocaleFile(stdout,
2151 "validate the import and export of image pixels:\n");
2152 for (i=0; reference_map[i] != (char *) NULL; i++)
2154 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
2157 Generate reference image.
2159 CatchException(exception);
2160 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
2161 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
2162 reference_storage[j].type));
2163 (void) CopyMagickString(image_info->filename,reference_filename,
2165 reference_image=ReadImage(image_info,exception);
2166 if (reference_image == (Image *) NULL)
2168 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2173 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
2174 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
2175 length=strlen(reference_map[i])*reference_image->columns*
2176 reference_image->rows*reference_storage[j].quantum;
2177 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
2178 if (pixels == (unsigned char *) NULL)
2180 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2183 reference_image=DestroyImage(reference_image);
2186 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
2187 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
2188 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
2190 if (status == MagickFalse)
2192 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2195 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2196 reference_image=DestroyImage(reference_image);
2199 (void) SetImageBackgroundColor(reference_image,exception);
2200 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
2201 reference_image->rows,reference_map[i],reference_storage[j].type,
2203 if (status == MagickFalse)
2205 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2208 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2209 reference_image=DestroyImage(reference_image);
2213 Read reconstruct image.
2215 reconstruct_image=AcquireImage(image_info,exception);
2216 (void) SetImageExtent(reconstruct_image,reference_image->columns,
2217 reference_image->rows,exception);
2218 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
2220 (void) SetImageBackgroundColor(reconstruct_image,exception);
2221 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
2222 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
2224 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2225 if (status == MagickFalse)
2227 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2230 reference_image=DestroyImage(reference_image);
2234 Compare reference to reconstruct image.
2236 difference_image=CompareImages(reference_image,reconstruct_image,
2237 RootMeanSquaredErrorMetric,&distortion,exception);
2238 reconstruct_image=DestroyImage(reconstruct_image);
2239 reference_image=DestroyImage(reference_image);
2240 if (difference_image == (Image *) NULL)
2242 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2247 difference_image=DestroyImage(difference_image);
2248 if ((QuantumScale*distortion) > 0.0)
2250 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2251 QuantumScale*distortion);
2255 (void) FormatLocaleFile(stdout,"... pass.\n");
2258 (void) FormatLocaleFile(stdout,
2259 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2260 (double) (test-(*fail)),(double) *fail);
2265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2269 % V a l i d a t e M o n t a g e C o m m a n d %
2273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2275 % ValidateMontageCommand() validates the ImageMagick montage command line
2276 % program and returns the number of validation tests that passed and failed.
2278 % The format of the ValidateMontageCommand method is:
2280 % size_t ValidateMontageCommand(ImageInfo *image_info,
2281 % const char *reference_filename,const char *output_filename,
2282 % size_t *fail,ExceptionInfo *exception)
2284 % A description of each parameter follows:
2286 % o image_info: the image info.
2288 % o reference_filename: the reference image filename.
2290 % o output_filename: the output image filename.
2292 % o fail: return the number of validation tests that pass.
2294 % o exception: return any errors or warnings in this structure.
2297 static size_t ValidateMontageCommand(ImageInfo *image_info,
2298 const char *reference_filename,const char *output_filename,size_t *fail,
2299 ExceptionInfo *exception)
2303 command[MaxTextExtent];
2319 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
2320 for (i=0; montage_options[i] != (char *) NULL; i++)
2322 CatchException(exception);
2323 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2324 montage_options[i]);
2325 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
2326 reference_filename,montage_options[i],reference_filename,
2328 arguments=StringToArgv(command,&number_arguments);
2329 if (arguments == (char **) NULL)
2331 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2336 status=MontageImageCommand(image_info,number_arguments,arguments,
2337 (char **) NULL,exception);
2338 for (j=0; j < (ssize_t) number_arguments; j++)
2339 arguments[j]=DestroyString(arguments[j]);
2340 arguments=(char **) RelinquishMagickMemory(arguments);
2341 if (status != MagickFalse)
2343 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2348 (void) FormatLocaleFile(stdout,"... pass.\n");
2350 (void) FormatLocaleFile(stdout,
2351 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2352 (double) (test-(*fail)),(double) *fail);
2357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2361 % V a l i d a t e S t r e a m C o m m a n d %
2365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2367 % ValidateStreamCommand() validates the ImageMagick stream command line
2368 % program and returns the number of validation tests that passed and failed.
2370 % The format of the ValidateStreamCommand method is:
2372 % size_t ValidateStreamCommand(ImageInfo *image_info,
2373 % const char *reference_filename,const char *output_filename,
2374 % size_t *fail,ExceptionInfo *exception)
2376 % A description of each parameter follows:
2378 % o image_info: the image info.
2380 % o reference_filename: the reference image filename.
2382 % o output_filename: the output image filename.
2384 % o fail: return the number of validation tests that pass.
2386 % o exception: return any errors or warnings in this structure.
2389 static size_t ValidateStreamCommand(ImageInfo *image_info,
2390 const char *reference_filename,const char *output_filename,size_t *fail,
2391 ExceptionInfo *exception)
2395 command[MaxTextExtent];
2411 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
2412 for (i=0; stream_options[i] != (char *) NULL; i++)
2414 CatchException(exception);
2415 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2417 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
2418 stream_options[i],reference_filename,output_filename);
2419 arguments=StringToArgv(command,&number_arguments);
2420 if (arguments == (char **) NULL)
2422 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2427 status=StreamImageCommand(image_info,number_arguments,arguments,
2428 (char **) NULL,exception);
2429 for (j=0; j < (ssize_t) number_arguments; j++)
2430 arguments[j]=DestroyString(arguments[j]);
2431 arguments=(char **) RelinquishMagickMemory(arguments);
2432 if (status != MagickFalse)
2434 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2439 (void) FormatLocaleFile(stdout,"... pass.\n");
2441 (void) FormatLocaleFile(stdout,
2442 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2443 (double) (test-(*fail)),(double) *fail);
2448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2461 static MagickBooleanType ValidateUsage(void)
2469 "-debug events display copious debugging information",
2470 "-help print program options",
2471 "-log format format of debugging information",
2472 "-validate type validation type",
2473 "-version print version information",
2478 "-regard-warnings pay attention to warning messages",
2479 "-verbose print detailed information about the image",
2483 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
2484 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
2485 (void) printf("Features: %s\n",GetMagickFeatures());
2486 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
2487 (void) printf("\nValidate Settings:\n");
2488 for (p=settings; *p != (char *) NULL; p++)
2489 (void) printf(" %s\n",*p);
2490 (void) printf("\nMiscellaneous Options:\n");
2491 for (p=miscellaneous; *p != (char *) NULL; p++)
2492 (void) printf(" %s\n",*p);
2496 int main(int argc,char **argv)
2498 #define DestroyValidate() \
2500 image_info=DestroyImageInfo(image_info); \
2501 exception=DestroyExceptionInfo(exception); \
2503 #define ThrowValidateException(asperity,tag,option) \
2505 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
2507 CatchException(exception); \
2508 DestroyValidate(); \
2509 return(MagickFalse); \
2513 output_filename[MaxTextExtent],
2514 reference_filename[MaxTextExtent],
2553 Validate the ImageMagick image processing suite.
2555 MagickCoreGenesis(*argv,MagickTrue);
2556 (void) setlocale(LC_ALL,"");
2557 (void) setlocale(LC_NUMERIC,"C");
2561 regard_warnings=MagickFalse;
2562 (void) regard_warnings;
2563 exception=AcquireExceptionInfo();
2564 image_info=AcquireImageInfo();
2565 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
2566 for (i=1; i < (ssize_t) argc; i++)
2569 if (IsCommandOption(option) == MagickFalse)
2571 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
2574 switch (*(option+1))
2578 if (LocaleCompare("bench",option+1) == 0)
2580 iterations=StringToUnsignedLong(argv[++i]);
2583 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2587 if (LocaleCompare("debug",option+1) == 0)
2589 (void) SetLogEventMask(argv[++i]);
2592 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2596 if (LocaleCompare("help",option+1) == 0)
2598 (void) ValidateUsage();
2601 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2605 if (LocaleCompare("log",option+1) == 0)
2608 (void) SetLogFormat(argv[i+1]);
2611 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2615 if (LocaleCompare("regard-warnings",option+1) == 0)
2617 regard_warnings=MagickTrue;
2620 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2624 if (LocaleCompare("validate",option+1) == 0)
2632 if (i == (ssize_t) argc)
2633 ThrowValidateException(OptionError,"MissingArgument",option);
2634 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
2637 ThrowValidateException(OptionError,"UnrecognizedValidateType",
2639 type=(ValidateType) validate;
2642 if ((LocaleCompare("version",option+1) == 0) ||
2643 (LocaleCompare("-version",option+1) == 0))
2645 (void) FormatLocaleFile(stdout,"Version: %s\n",
2646 GetMagickVersion((size_t *) NULL));
2647 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2648 GetMagickCopyright());
2649 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
2650 GetMagickFeatures());
2653 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2656 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2659 timer=(TimerInfo *) NULL;
2661 timer=AcquireTimerInfo();
2662 reference_image=ReadImage(image_info,exception);
2665 if (reference_image == (Image *) NULL)
2669 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
2670 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
2672 (void) AcquireUniqueFilename(reference_filename);
2673 (void) AcquireUniqueFilename(output_filename);
2674 (void) CopyMagickString(reference_image->filename,reference_filename,
2676 status=WriteImage(image_info,reference_image,exception);
2677 reference_image=DestroyImage(reference_image);
2678 if (status == MagickFalse)
2682 (void) FormatLocaleFile(stdout,"Version: %s\n",
2683 GetMagickVersion((size_t *) NULL));
2684 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2685 GetMagickCopyright());
2686 (void) FormatLocaleFile(stdout,
2687 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
2688 MagickValidateOptions,(ssize_t) type));
2689 if ((type & ColorspaceValidate) != 0)
2690 tests+=ValidateColorspaces(image_info,&fail,exception);
2691 if ((type & CompareValidate) != 0)
2692 tests+=ValidateCompareCommand(image_info,reference_filename,
2693 output_filename,&fail,exception);
2694 if ((type & CompositeValidate) != 0)
2695 tests+=ValidateCompositeCommand(image_info,reference_filename,
2696 output_filename,&fail,exception);
2697 if ((type & ConvertValidate) != 0)
2698 tests+=ValidateConvertCommand(image_info,reference_filename,
2699 output_filename,&fail,exception);
2700 if ((type & FormatsDiskValidate) != 0)
2702 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2703 map_resource=SetMagickResourceLimit(MapResource,0);
2704 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2705 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2706 output_filename,&fail,exception);
2707 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2708 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2709 output_filename,&fail,exception);
2710 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2711 (void) SetMagickResourceLimit(MapResource,map_resource);
2713 if ((type & FormatsMapValidate) != 0)
2715 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2716 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2717 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2718 output_filename,&fail,exception);
2719 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2720 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2721 output_filename,&fail,exception);
2722 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2724 if ((type & FormatsMemoryValidate) != 0)
2726 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2727 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2728 output_filename,&fail,exception);
2729 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2730 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2731 output_filename,&fail,exception);
2733 if ((type & IdentifyValidate) != 0)
2734 tests+=ValidateIdentifyCommand(image_info,reference_filename,
2735 output_filename,&fail,exception);
2736 if ((type & ImportExportValidate) != 0)
2737 tests+=ValidateImportExportPixels(image_info,reference_filename,
2738 output_filename,&fail,exception);
2739 if ((type & MontageValidate) != 0)
2740 tests+=ValidateMontageCommand(image_info,reference_filename,
2741 output_filename,&fail,exception);
2742 if ((type & StreamValidate) != 0)
2743 tests+=ValidateStreamCommand(image_info,reference_filename,
2744 output_filename,&fail,exception);
2745 (void) FormatLocaleFile(stdout,
2746 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
2747 (double) tests,(double) (tests-fail),(double) fail);
2749 (void) RelinquishUniqueFileResource(output_filename);
2750 (void) RelinquishUniqueFileResource(reference_filename);
2752 if (exception->severity != UndefinedException)
2753 CatchException(exception);
2756 elapsed_time=GetElapsedTime(timer);
2757 user_time=GetUserTime(timer);
2758 (void) FormatLocaleFile(stderr,
2759 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
2760 iterations,1.0*iterations/elapsed_time,user_time,(long)
2761 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
2762 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
2763 timer=DestroyTimerInfo(timer);
2766 MagickCoreTerminus();
2767 return(fail == 0 ? 0 : 1);