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-2017 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 % https://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/gem.h"
52 #include "MagickCore/resource_.h"
53 #include "MagickCore/string-private.h"
59 #define CIEEpsilon (216.0/24389.0)
60 #define CIEK (24389.0/27.0)
64 #define ReferenceEpsilon (QuantumRange*1.0e-2)
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % V a l i d a t e C o l o r s p a c e s %
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % ValidateColorspaces() validates the ImageMagick colorspaces and returns the
78 % number of validation tests that passed and failed.
80 % The format of the ValidateColorspaces method is:
82 % size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
83 % ExceptionInfo *exception)
85 % A description of each parameter follows:
87 % o image_info: the image info.
89 % o fail: return the number of validation tests that pass.
91 % o exception: return any errors or warnings in this structure.
95 static void ConvertHSIToRGB(const double hue,const double saturation,
96 const double intensity,double *red,double *green,double *blue)
102 h-=360.0*floor(h/360.0);
105 *blue=intensity*(1.0-saturation);
106 *red=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
108 *green=3.0*intensity-*red-*blue;
114 *red=intensity*(1.0-saturation);
115 *green=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
117 *blue=3.0*intensity-*red-*green;
122 *green=intensity*(1.0-saturation);
123 *blue=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
125 *red=3.0*intensity-*green-*blue;
128 *green*=QuantumRange;
132 static void ConvertRGBToHSI(const double red,const double green,
133 const double blue,double *hue,double *saturation,double *intensity)
139 *intensity=(QuantumScale*red+QuantumScale*green+QuantumScale*blue)/3.0;
140 if (*intensity <= 0.0)
146 *saturation=1.0-MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
147 QuantumScale*blue))/(*intensity);
148 alpha=0.5*(2.0*QuantumScale*red-QuantumScale*green-QuantumScale*blue);
149 beta=0.8660254037844385*(QuantumScale*green-QuantumScale*blue);
150 *hue=atan2(beta,alpha)*(180.0/MagickPI)/360.0;
155 static void ConvertHSVToRGB(const double hue,const double saturation,
156 const double value,double *red,double *green,double *blue)
167 h-=360.0*floor(h/360.0);
169 x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
170 switch ((int) floor(h))
174 *red=QuantumRange*(min+c);
175 *green=QuantumRange*(min+x);
176 *blue=QuantumRange*min;
181 *red=QuantumRange*(min+x);
182 *green=QuantumRange*(min+c);
183 *blue=QuantumRange*min;
188 *red=QuantumRange*min;
189 *green=QuantumRange*(min+c);
190 *blue=QuantumRange*(min+x);
195 *red=QuantumRange*min;
196 *green=QuantumRange*(min+x);
197 *blue=QuantumRange*(min+c);
202 *red=QuantumRange*(min+x);
203 *green=QuantumRange*min;
204 *blue=QuantumRange*(min+c);
209 *red=QuantumRange*(min+c);
210 *green=QuantumRange*min;
211 *blue=QuantumRange*(min+x);
223 static inline void ConvertRGBToXYZ(const double red,const double green,
224 const double blue,double *X,double *Y,double *Z)
231 r=QuantumScale*DecodePixelGamma(red);
232 g=QuantumScale*DecodePixelGamma(green);
233 b=QuantumScale*DecodePixelGamma(blue);
234 *X=0.41239558896741421610*r+0.35758343076371481710*g+0.18049264738170157350*b;
235 *Y=0.21258623078559555160*r+0.71517030370341084990*g+0.07220049864333622685*b;
236 *Z=0.01929721549174694484*r+0.11918386458084853180*g+0.95049712513157976600*b;
239 static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
240 double *L,double *a,double *b)
247 if ((X/D65X) > CIEEpsilon)
248 x=pow(X/D65X,1.0/3.0);
250 x=(CIEK*X/D65X+16.0)/116.0;
251 if ((Y/D65Y) > CIEEpsilon)
252 y=pow(Y/D65Y,1.0/3.0);
254 y=(CIEK*Y/D65Y+16.0)/116.0;
255 if ((Z/D65Z) > CIEEpsilon)
256 z=pow(Z/D65Z,1.0/3.0);
258 z=(CIEK*Z/D65Z+16.0)/116.0;
259 *L=((116.0*y)-16.0)/100.0;
260 *a=(500.0*(x-y))/255.0+0.5;
261 *b=(200.0*(y-z))/255.0+0.5;
264 static void ConvertRGBToLab(const double red,const double green,
265 const double blue,double *L,double *a,double *b)
272 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
273 ConvertXYZToLab(X,Y,Z,L,a,b);
276 static inline void ConvertLabToXYZ(const double L,const double a,const double b,
277 double *X,double *Y,double *Z)
287 if ((x*x*x) > CIEEpsilon)
290 x=(116.0*x-16.0)/CIEK;
291 if ((y*y*y) > CIEEpsilon)
295 if ((z*z*z) > CIEEpsilon)
298 z=(116.0*z-16.0)/CIEK;
304 static inline void ConvertXYZToRGB(const double x,const double y,const double z,
305 double *red,double *green,double *blue)
312 r=3.2406*x-1.5372*y-0.4986*z;
313 g=(-0.9689*x+1.8758*y+0.0415*z);
314 b=0.0557*x-0.2040*y+1.0570*z;
315 *red=EncodePixelGamma(QuantumRange*r);
316 *green=EncodePixelGamma(QuantumRange*g);
317 *blue=EncodePixelGamma(QuantumRange*b);
320 static inline void ConvertLabToRGB(const double L,const double a,
321 const double b,double *red,double *green,double *blue)
328 ConvertLabToXYZ(L*100.0,255.0*(a-0.5),255.0*(b-0.5),&X,&Y,&Z);
329 ConvertXYZToRGB(X,Y,Z,red,green,blue);
332 static void ConvertRGBToYPbPr(const double red,const double green,
333 const double blue,double *Y,double *Pb,double *Pr)
335 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
336 *Pb=QuantumScale*((-0.1687367)*red-0.331264*green+0.5*blue)+0.5;
337 *Pr=QuantumScale*(0.5*red-0.418688*green-0.081312*blue)+0.5;
340 static void ConvertRGBToYCbCr(const double red,const double green,
341 const double blue,double *Y,double *Cb,double *Cr)
343 ConvertRGBToYPbPr(red,green,blue,Y,Cb,Cr);
346 static void ConvertYPbPrToRGB(const double Y,const double Pb,const double Pr,
347 double *red,double *green,double *blue)
349 *red=QuantumRange*(0.99999999999914679361*Y-1.2188941887145875e-06*(Pb-0.5)+
350 1.4019995886561440468*(Pr-0.5));
351 *green=QuantumRange*(0.99999975910502514331*Y-0.34413567816504303521*(Pb-0.5)-
352 0.71413649331646789076*(Pr-0.5));
353 *blue=QuantumRange*(1.00000124040004623180*Y+1.77200006607230409200*(Pb-0.5)+
354 2.1453384174593273e-06*(Pr-0.5));
357 static void ConvertYCbCrToRGB(const double Y,const double Cb,
358 const double Cr,double *red,double *green,double *blue)
360 ConvertYPbPrToRGB(Y,Cb,Cr,red,green,blue);
363 static inline void ConvertLCHabToXYZ(const double luma,const double chroma,
364 const double hue,double *X,double *Y,double *Z)
366 ConvertLabToXYZ(luma,chroma*cos(hue*MagickPI/180.0),chroma*
367 sin(hue*MagickPI/180.0),X,Y,Z);
370 static void ConvertLCHabToRGB(const double luma,const double chroma,
371 const double hue,double *red,double *green,double *blue)
378 ConvertLCHabToXYZ(luma*100.0,255.0*(chroma-0.5),360.0*hue,&X,&Y,&Z);
379 ConvertXYZToRGB(X,Y,Z,red,green,blue);
382 static void ConvertRGBToHSV(const double red,const double green,
383 const double blue,double *hue,double *saturation,double *value)
390 max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
392 min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
402 if (max == (QuantumScale*red))
404 *hue=(QuantumScale*green-QuantumScale*blue)/c;
405 if ((QuantumScale*green) < (QuantumScale*blue))
409 if (max == (QuantumScale*green))
410 *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
412 *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
417 static inline void ConvertXYZToLCHab(const double X,const double Y,
418 const double Z,double *luma,double *chroma,double *hue)
424 ConvertXYZToLab(X,Y,Z,luma,&a,&b);
425 *chroma=hypot(255.0*(a-0.5),255.0*(b-0.5))/255.0+0.5;
426 *hue=180.0*atan2(255.0*(b-0.5),255.0*(a-0.5))/MagickPI/360.0;
431 static void ConvertRGBToLCHab(const double red,const double green,
432 const double blue,double *luma,double *chroma,double *hue)
439 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
440 ConvertXYZToLCHab(X,Y,Z,luma,chroma,hue);
443 static inline void ConvertLMSToXYZ(const double L,const double M,const double S,
444 double *X,double *Y,double *Z)
446 *X=1.096123820835514*L-0.278869000218287*M+0.182745179382773*S;
447 *Y=0.454369041975359*L+0.473533154307412*M+0.072097803717229*S;
448 *Z=(-0.009627608738429)*L-0.005698031216113*M+1.015325639954543*S;
451 static inline void ConvertLMSToRGB(const double L,const double M,
452 const double S,double *red,double *green,double *blue)
459 ConvertLMSToXYZ(L,M,S,&X,&Y,&Z);
460 ConvertXYZToRGB(X,Y,Z,red,green,blue);
463 static inline void ConvertXYZToLMS(const double x,const double y,
464 const double z,double *L,double *M,double *S)
466 *L=0.7328*x+0.4296*y-0.1624*z;
467 *M=(-0.7036*x+1.6975*y+0.0061*z);
468 *S=0.0030*x+0.0136*y+0.9834*z;
471 static void ConvertRGBToLMS(const double red,const double green,
472 const double blue,double *L,double *M,double *S)
479 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
480 ConvertXYZToLMS(X,Y,Z,L,M,S);
483 static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
484 double *L,double *u,double *v)
489 if ((Y/D65Y) > CIEEpsilon)
490 *L=(double) (116.0*pow(Y/D65Y,1.0/3.0)-16.0);
493 alpha=PerceptibleReciprocal(X+15.0*Y+3.0*Z);
494 *u=13.0*(*L)*((4.0*alpha*X)-(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z)));
495 *v=13.0*(*L)*((9.0*alpha*Y)-(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z)));
501 static void ConvertRGBToLuv(const double red,const double green,
502 const double blue,double *L,double *u,double *v)
509 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
510 ConvertXYZToLuv(X,Y,Z,L,u,v);
513 static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
514 double *X,double *Y,double *Z)
516 if (L > (CIEK*CIEEpsilon))
517 *Y=(double) pow((L+16.0)/116.0,3.0);
520 *X=((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
521 5.0*(*Y))/((((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/
523 *Z=(*X*(((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
527 static inline void ConvertLuvToRGB(const double L,const double u,
528 const double v,double *red,double *green,double *blue)
535 ConvertLuvToXYZ(100.0*L,354.0*u-134.0,262.0*v-140.0,&X,&Y,&Z);
536 ConvertXYZToRGB(X,Y,Z,red,green,blue);
539 static void ConvertRGBToYDbDr(const double red,const double green,
540 const double blue,double *Y,double *Db,double *Dr)
542 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
543 *Db=QuantumScale*(-0.450*red-0.883*green+1.333*blue)+0.5;
544 *Dr=QuantumScale*(-1.333*red+1.116*green+0.217*blue)+0.5;
547 static void ConvertYDbDrToRGB(const double Y,const double Db,const double Dr,
548 double *red,double *green,double *blue)
550 *red=QuantumRange*(Y+9.2303716147657e-05*(Db-0.5)-0.52591263066186533*
552 *green=QuantumRange*(Y-0.12913289889050927*(Db-0.5)+0.26789932820759876*
554 *blue=QuantumRange*(Y+0.66467905997895482*(Db-0.5)-7.9202543533108e-05*
558 static void ConvertRGBToYIQ(const double red,const double green,
559 const double blue,double *Y,double *I,double *Q)
561 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
562 *I=QuantumScale*(0.595716*red-0.274453*green-0.321263*blue)+0.5;
563 *Q=QuantumScale*(0.211456*red-0.522591*green+0.311135*blue)+0.5;
566 static void ConvertYIQToRGB(const double Y,const double I,const double Q,
567 double *red,double *green,double *blue)
569 *red=QuantumRange*(Y+0.9562957197589482261*(I-0.5)+0.6210244164652610754*
571 *green=QuantumRange*(Y-0.2721220993185104464*(I-0.5)-0.6473805968256950427*
573 *blue=QuantumRange*(Y-1.1069890167364901945*(I-0.5)+1.7046149983646481374*
577 static void ConvertRGBToYUV(const double red,const double green,
578 const double blue,double *Y,double *U,double *V)
580 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
581 *U=QuantumScale*((-0.147)*red-0.289*green+0.436*blue)+0.5;
582 *V=QuantumScale*(0.615*red-0.515*green-0.100*blue)+0.5;
585 static void ConvertYUVToRGB(const double Y,const double U,const double V,
586 double *red,double *green,double *blue)
588 *red=QuantumRange*(Y-3.945707070708279e-05*(U-0.5)+1.1398279671717170825*
590 *green=QuantumRange*(Y-0.3946101641414141437*(U-0.5)-0.5805003156565656797*
592 *blue=QuantumRange*(Y+2.0319996843434342537*(U-0.5)-4.813762626262513e-04*
596 static MagickBooleanType ValidateHSIToRGB()
603 (void) FormatLocaleFile(stdout," HSIToRGB");
604 ConvertHSIToRGB(111.244375/360.0,0.295985,0.658734,&r,&g,&b);
605 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
606 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
607 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
612 static MagickBooleanType ValidateRGBToHSI()
619 (void) FormatLocaleFile(stdout," RGBToHSI");
620 ConvertRGBToHSI(0.545877*QuantumRange,0.966567*QuantumRange,
621 0.463759*QuantumRange,&h,&s,&i);
622 if ((fabs(h-111.244374/360.0) >= ReferenceEpsilon) ||
623 (fabs(s-0.295985) >= ReferenceEpsilon) ||
624 (fabs(i-0.658734) >= ReferenceEpsilon))
629 static MagickBooleanType ValidateHSLToRGB()
636 (void) FormatLocaleFile(stdout," HSLToRGB");
637 ConvertHSLToRGB(110.200859/360.0,0.882623,0.715163,&r,&g,&b);
638 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
639 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
640 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
645 static MagickBooleanType ValidateRGBToHSL()
652 (void) FormatLocaleFile(stdout," RGBToHSL");
653 ConvertRGBToHSL(0.545877*QuantumRange,0.966567*QuantumRange,
654 0.463759*QuantumRange,&h,&s,&l);
655 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
656 (fabs(s-0.882623) >= ReferenceEpsilon) ||
657 (fabs(l-0.715163) >= ReferenceEpsilon))
662 static MagickBooleanType ValidateHSVToRGB()
669 (void) FormatLocaleFile(stdout," HSVToRGB");
670 ConvertHSVToRGB(110.200859/360.0,0.520200,0.966567,&r,&g,&b);
671 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
672 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
673 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
678 static MagickBooleanType ValidateRGBToHSV()
685 (void) FormatLocaleFile(stdout," RGBToHSV");
686 ConvertRGBToHSV(0.545877*QuantumRange,0.966567*QuantumRange,
687 0.463759*QuantumRange,&h,&s,&v);
688 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
689 (fabs(s-0.520200) >= ReferenceEpsilon) ||
690 (fabs(v-0.966567) >= ReferenceEpsilon))
695 static MagickBooleanType ValidateRGBToJPEGYCbCr()
702 (void) FormatLocaleFile(stdout," RGBToJPEGYCbCr");
703 ConvertRGBToYCbCr(0.545877*QuantumRange,0.966567*QuantumRange,
704 0.463759*QuantumRange,&Y,&Cb,&Cr);
705 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
706 (fabs(Cb-0.319581) >= ReferenceEpsilon) ||
707 (fabs(Cr-0.330539) >= ReferenceEpsilon))
712 static MagickBooleanType ValidateJPEGYCbCrToRGB()
719 (void) FormatLocaleFile(stdout," JPEGYCbCrToRGB");
720 ConvertYCbCrToRGB(0.783460,0.319581,0.330539,&r,&g,&b);
721 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
722 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
723 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
728 static MagickBooleanType ValidateLabToRGB()
735 (void) FormatLocaleFile(stdout," LabToRGB");
736 ConvertLabToRGB(88.456154/100.0,-54.671483/255+0.5,51.662818/255.0+0.5,
738 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
739 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
740 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
745 static MagickBooleanType ValidateRGBToLab()
752 (void) FormatLocaleFile(stdout," RGBToLab");
753 ConvertRGBToLab(0.545877*QuantumRange,0.966567*QuantumRange,
754 0.463759*QuantumRange,&L,&a,&b);
755 if ((fabs(L-(88.456154/100.0)) >= ReferenceEpsilon) ||
756 (fabs(a-(-54.671483/255.0+0.5)) >= ReferenceEpsilon) ||
757 (fabs(b-(51.662818/255.0+0.5)) >= ReferenceEpsilon))
762 static MagickBooleanType ValidateLchToRGB()
769 (void) FormatLocaleFile(stdout," LchToRGB");
770 ConvertLCHabToRGB(88.456154/100.0,75.219797/255.0+0.5,136.620717/360.0,
772 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
773 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
774 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
779 static MagickBooleanType ValidateRGBToLch()
786 (void) FormatLocaleFile(stdout," RGBToLch");
787 ConvertRGBToLCHab(0.545877*QuantumRange,0.966567*QuantumRange,
788 0.463759*QuantumRange,&L,&c,&h);
789 if ((fabs(L-88.456154/100.0) >= ReferenceEpsilon) ||
790 (fabs(c-(75.219797/255.0+0.5)) >= ReferenceEpsilon) ||
791 (fabs(h-(136.620717/255.0+0.5)) >= ReferenceEpsilon))
796 static MagickBooleanType ValidateRGBToLMS()
803 (void) FormatLocaleFile(stdout," RGBToLMS");
804 ConvertRGBToLMS(0.545877*QuantumRange,0.966567*QuantumRange,
805 0.463759*QuantumRange,&L,&M,&S);
806 if ((fabs(L-0.611749) >= ReferenceEpsilon) ||
807 (fabs(M-0.910088) >= ReferenceEpsilon) ||
808 (fabs(S-0.294880) >= ReferenceEpsilon))
813 static MagickBooleanType ValidateLMSToRGB()
820 (void) FormatLocaleFile(stdout," LMSToRGB");
821 ConvertLMSToRGB(0.611749,0.910088,0.294880,&r,&g,&b);
822 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
823 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
824 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
829 static MagickBooleanType ValidateRGBToLuv()
836 (void) FormatLocaleFile(stdout," RGBToLuv");
837 ConvertRGBToLuv(0.545877*QuantumRange,0.966567*QuantumRange,
838 0.463759*QuantumRange,&l,&u,&v);
839 if ((fabs(l-88.456154/262.0) >= ReferenceEpsilon) ||
840 (fabs(u-(-51.330414+134.0)/354.0) >= ReferenceEpsilon) ||
841 (fabs(v-(76.405526+140.0)/262.0) >= ReferenceEpsilon))
846 static MagickBooleanType ValidateLuvToRGB()
853 (void) FormatLocaleFile(stdout," LuvToRGB");
854 ConvertLuvToRGB(88.456154/100.0,(-51.330414+134.0)/354.0,
855 (76.405526+140.0)/262.0,&r,&g,&b);
856 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
857 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
858 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
863 static MagickBooleanType ValidateRGBToXYZ()
870 (void) FormatLocaleFile(stdout," RGBToXYZ");
871 ConvertRGBToXYZ(0.545877*QuantumRange,0.966567*QuantumRange,
872 0.463759*QuantumRange,&x,&y,&z);
873 if ((fabs(x-0.470646) >= ReferenceEpsilon) ||
874 (fabs(y-0.730178) >= ReferenceEpsilon) ||
875 (fabs(z-0.288324) >= ReferenceEpsilon))
880 static MagickBooleanType ValidateXYZToRGB()
887 (void) FormatLocaleFile(stdout," XYZToRGB");
888 ConvertXYZToRGB(0.470646,0.730178,0.288324,&r,&g,&b);
889 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
890 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
891 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
896 static MagickBooleanType ValidateYDbDrToRGB()
903 (void) FormatLocaleFile(stdout," YDbDrToRGB");
904 ConvertYDbDrToRGB(0.783460,-0.480932+0.5,0.451670+0.5,&r,&g,&b);
905 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
906 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
907 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
912 static MagickBooleanType ValidateRGBToYDbDr()
919 (void) FormatLocaleFile(stdout," RGBToYDbDr");
920 ConvertRGBToYDbDr(0.545877*QuantumRange,0.966567*QuantumRange,
921 0.463759*QuantumRange,&Y,&Db,&Dr);
922 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
923 (fabs(Db-(-0.480932)) >= ReferenceEpsilon) ||
924 (fabs(Dr-0.451670) >= ReferenceEpsilon))
929 static MagickBooleanType ValidateRGBToYIQ()
936 (void) FormatLocaleFile(stdout," RGBToYIQ");
937 ConvertRGBToYIQ(0.545877*QuantumRange,0.966567*QuantumRange,
938 0.463759*QuantumRange,&y,&i,&q);
939 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
940 (fabs(i-(-0.089078)) >= ReferenceEpsilon) ||
941 (fabs(q-(-0.245399)) >= ReferenceEpsilon))
946 static MagickBooleanType ValidateYIQToRGB()
953 (void) FormatLocaleFile(stdout," YIQToRGB");
954 ConvertYIQToRGB(0.783460,-0.089078+0.5,-0.245399+0.5,&r,&g,&b);
955 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
956 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
957 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
962 static MagickBooleanType ValidateRGBToYPbPr()
969 (void) FormatLocaleFile(stdout," RGBToYPbPr");
970 ConvertRGBToYPbPr(0.545877*QuantumRange,0.966567*QuantumRange,
971 0.463759*QuantumRange,&y,&Pb,&Pr);
972 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
973 (fabs(Pb-(-0.180419)) >= ReferenceEpsilon) ||
974 (fabs(Pr-(-0.169461)) >= ReferenceEpsilon))
979 static MagickBooleanType ValidateYPbPrToRGB()
986 (void) FormatLocaleFile(stdout," YPbPrToRGB");
987 ConvertYPbPrToRGB(0.783460,-0.180419+0.5,-0.169461+0.5,&r,&g,&b);
988 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
989 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
990 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
995 static MagickBooleanType ValidateRGBToYUV()
1002 (void) FormatLocaleFile(stdout," RGBToYUV");
1003 ConvertRGBToYUV(0.545877*QuantumRange,0.966567*QuantumRange,
1004 0.463759*QuantumRange,&Y,&U,&V);
1005 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
1006 (fabs(U-(-0.157383)) >= ReferenceEpsilon) ||
1007 (fabs(V-(-0.208443)) >= ReferenceEpsilon))
1008 return(MagickFalse);
1012 static MagickBooleanType ValidateYUVToRGB()
1019 (void) FormatLocaleFile(stdout," YUVToRGB");
1020 ConvertYUVToRGB(0.783460,-0.157383+0.5,-0.208443+0.5,&r,&g,&b);
1021 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1022 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1023 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1024 return(MagickFalse);
1028 static size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
1029 ExceptionInfo *exception)
1038 Reference: https://code.google.com/p/chroma.
1041 Observer = 2° (1931)
1043 XYZ 0.470645, 0.730177, 0.288323
1044 sRGB 0.545877, 0.966567, 0.463759
1045 CAT02 LMS 0.611749, 0.910088, 0.294880
1046 Y'DbDr 0.783460, -0.480932, 0.451670
1047 Y'IQ 0.783460, -0.089078, -0.245399
1048 Y'PbPr 0.783460, -0.180419, -0.169461
1049 Y'UV 0.783460, -0.157383, -0.208443
1050 JPEG-Y'CbCr 0.783460, 0.319581, 0.330539
1051 L*u*v* 88.456154, -51.330414, 76.405526
1052 L*a*b* 88.456154, -54.671483, 51.662818
1053 L*C*H* 88.456154, 75.219797, 136.620717
1054 HSV 110.200859, 0.520200, 0.966567
1055 HSL 110.200859, 0.882623, 0.715163
1056 HSI 111.244375, 0.295985, 0.658734
1057 Y'CbCr 187.577791, 87.586330, 90.040886
1059 (void) FormatLocaleFile(stdout,"validate colorspaces:\n");
1060 for (test=0; test < 26; test++)
1062 CatchException(exception);
1063 (void) FormatLocaleFile(stdout," test %.20g: ",(double) test);
1066 case 0: status=ValidateHSIToRGB(); break;
1067 case 1: status=ValidateRGBToHSI(); break;
1068 case 2: status=ValidateHSLToRGB(); break;
1069 case 3: status=ValidateRGBToHSL(); break;
1070 case 4: status=ValidateHSVToRGB(); break;
1071 case 5: status=ValidateRGBToHSV(); break;
1072 case 6: status=ValidateJPEGYCbCrToRGB(); break;
1073 case 7: status=ValidateRGBToJPEGYCbCr(); break;
1074 case 8: status=ValidateLabToRGB(); break;
1075 case 9: status=ValidateRGBToLab(); break;
1076 case 10: status=ValidateLchToRGB(); break;
1077 case 11: status=ValidateRGBToLch(); break;
1078 case 12: status=ValidateLMSToRGB(); break;
1079 case 13: status=ValidateRGBToLMS(); break;
1080 case 14: status=ValidateLuvToRGB(); break;
1081 case 15: status=ValidateRGBToLuv(); break;
1082 case 16: status=ValidateXYZToRGB(); break;
1083 case 17: status=ValidateRGBToXYZ(); break;
1084 case 18: status=ValidateYDbDrToRGB(); break;
1085 case 19: status=ValidateRGBToYDbDr(); break;
1086 case 20: status=ValidateYIQToRGB(); break;
1087 case 21: status=ValidateRGBToYIQ(); break;
1088 case 22: status=ValidateYPbPrToRGB(); break;
1089 case 23: status=ValidateRGBToYPbPr(); break;
1090 case 24: status=ValidateYUVToRGB(); break;
1091 case 25: status=ValidateRGBToYUV(); break;
1092 default: status=MagickFalse;
1094 if (status == MagickFalse)
1096 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1101 (void) FormatLocaleFile(stdout,"... pass.\n");
1103 (void) FormatLocaleFile(stdout,
1104 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1105 (double) (test-(*fail)),(double) *fail);
1110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1114 % V a l i d a t e C o m p a r e C o m m a n d %
1118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1120 % ValidateCompareCommand() validates the ImageMagick compare command line
1121 % program and returns the number of validation tests that passed and failed.
1123 % The format of the ValidateCompareCommand method is:
1125 % size_t ValidateCompareCommand(ImageInfo *image_info,
1126 % const char *reference_filename,const char *output_filename,
1127 % size_t *fail,ExceptionInfo *exception)
1129 % A description of each parameter follows:
1131 % o image_info: the image info.
1133 % o reference_filename: the reference image filename.
1135 % o output_filename: the output image filename.
1137 % o fail: return the number of validation tests that pass.
1139 % o exception: return any errors or warnings in this structure.
1142 static size_t ValidateCompareCommand(ImageInfo *image_info,
1143 const char *reference_filename,const char *output_filename,size_t *fail,
1144 ExceptionInfo *exception)
1148 command[MagickPathExtent];
1164 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
1165 for (i=0; compare_options[i] != (char *) NULL; i++)
1167 CatchException(exception);
1168 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1169 compare_options[i]);
1170 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
1171 compare_options[i],reference_filename,reference_filename,output_filename);
1172 arguments=StringToArgv(command,&number_arguments);
1173 if (arguments == (char **) NULL)
1175 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1177 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
1178 "%s",exception->reason);
1182 status=CompareImagesCommand(image_info,number_arguments,arguments,
1183 (char **) NULL,exception);
1184 for (j=0; j < (ssize_t) number_arguments; j++)
1185 arguments[j]=DestroyString(arguments[j]);
1186 arguments=(char **) RelinquishMagickMemory(arguments);
1187 if (status == MagickFalse)
1189 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1191 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
1192 "%s",exception->reason);
1196 (void) FormatLocaleFile(stdout,"... pass.\n");
1198 (void) FormatLocaleFile(stdout,
1199 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1200 (double) (test-(*fail)),(double) *fail);
1205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1209 % V a l i d a t e C o m p o s i t e C o m m a n d %
1213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1215 % ValidateCompositeCommand() validates the ImageMagick composite command line
1216 % program and returns the number of validation tests that passed and failed.
1218 % The format of the ValidateCompositeCommand method is:
1220 % size_t ValidateCompositeCommand(ImageInfo *image_info,
1221 % const char *reference_filename,const char *output_filename,
1222 % size_t *fail,ExceptionInfo *exception)
1224 % A description of each parameter follows:
1226 % o image_info: the image info.
1228 % o reference_filename: the reference image filename.
1230 % o output_filename: the output image filename.
1232 % o fail: return the number of validation tests that pass.
1234 % o exception: return any errors or warnings in this structure.
1237 static size_t ValidateCompositeCommand(ImageInfo *image_info,
1238 const char *reference_filename,const char *output_filename,size_t *fail,
1239 ExceptionInfo *exception)
1243 command[MagickPathExtent];
1259 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
1260 for (i=0; composite_options[i] != (char *) NULL; i++)
1262 CatchException(exception);
1263 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1264 composite_options[i]);
1265 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
1266 reference_filename,composite_options[i],reference_filename,
1268 arguments=StringToArgv(command,&number_arguments);
1269 if (arguments == (char **) NULL)
1271 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1276 status=CompositeImageCommand(image_info,number_arguments,arguments,
1277 (char **) NULL,exception);
1278 for (j=0; j < (ssize_t) number_arguments; j++)
1279 arguments[j]=DestroyString(arguments[j]);
1280 arguments=(char **) RelinquishMagickMemory(arguments);
1281 if (status == MagickFalse)
1283 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1288 (void) FormatLocaleFile(stdout,"... pass.\n");
1290 (void) FormatLocaleFile(stdout,
1291 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1292 (double) (test-(*fail)),(double) *fail);
1297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1301 % V a l i d a t e C o n v e r t C o m m a n d %
1305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1307 % ValidateConvertCommand() validates the ImageMagick convert command line
1308 % program and returns the number of validation tests that passed and failed.
1310 % The format of the ValidateConvertCommand method is:
1312 % size_t ValidateConvertCommand(ImageInfo *image_info,
1313 % const char *reference_filename,const char *output_filename,
1314 % size_t *fail,ExceptionInfo *exception)
1316 % A description of each parameter follows:
1318 % o image_info: the image info.
1320 % o reference_filename: the reference image filename.
1322 % o output_filename: the output image filename.
1324 % o fail: return the number of validation tests that pass.
1326 % o exception: return any errors or warnings in this structure.
1329 static size_t ValidateConvertCommand(ImageInfo *image_info,
1330 const char *reference_filename,const char *output_filename,size_t *fail,
1331 ExceptionInfo *exception)
1335 command[MagickPathExtent];
1351 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
1352 for (i=0; convert_options[i] != (char *) NULL; i++)
1354 CatchException(exception);
1355 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1356 convert_options[i]);
1357 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
1358 reference_filename,convert_options[i],reference_filename,output_filename);
1359 arguments=StringToArgv(command,&number_arguments);
1360 if (arguments == (char **) NULL)
1362 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1367 status=ConvertImageCommand(image_info,number_arguments,arguments,
1368 (char **) NULL,exception);
1369 for (j=0; j < (ssize_t) number_arguments; j++)
1370 arguments[j]=DestroyString(arguments[j]);
1371 arguments=(char **) RelinquishMagickMemory(arguments);
1372 if (status == MagickFalse)
1374 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1379 (void) FormatLocaleFile(stdout,"... pass.\n");
1381 (void) FormatLocaleFile(stdout,
1382 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1383 (double) (test-(*fail)),(double) *fail);
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1392 % V a l i d a t e I d e n t i f y C o m m a n d %
1396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1398 % ValidateIdentifyCommand() validates the ImageMagick identify command line
1399 % program and returns the number of validation tests that passed and failed.
1401 % The format of the ValidateIdentifyCommand method is:
1403 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
1404 % const char *reference_filename,const char *output_filename,
1405 % size_t *fail,ExceptionInfo *exception)
1407 % A description of each parameter follows:
1409 % o image_info: the image info.
1411 % o reference_filename: the reference image filename.
1413 % o output_filename: the output image filename.
1415 % o fail: return the number of validation tests that pass.
1417 % o exception: return any errors or warnings in this structure.
1420 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
1421 const char *reference_filename,const char *output_filename,size_t *fail,
1422 ExceptionInfo *exception)
1426 command[MagickPathExtent];
1441 (void) output_filename;
1443 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
1444 for (i=0; identify_options[i] != (char *) NULL; i++)
1446 CatchException(exception);
1447 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1448 identify_options[i]);
1449 (void) FormatLocaleString(command,MagickPathExtent,"%s %s",
1450 identify_options[i],reference_filename);
1451 arguments=StringToArgv(command,&number_arguments);
1452 if (arguments == (char **) NULL)
1454 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1459 status=IdentifyImageCommand(image_info,number_arguments,arguments,
1460 (char **) NULL,exception);
1461 for (j=0; j < (ssize_t) number_arguments; j++)
1462 arguments[j]=DestroyString(arguments[j]);
1463 arguments=(char **) RelinquishMagickMemory(arguments);
1464 if (status == MagickFalse)
1466 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1471 (void) FormatLocaleFile(stdout,"... pass.\n");
1473 (void) FormatLocaleFile(stdout,
1474 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1475 (double) (test-(*fail)),(double) *fail);
1480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % 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 %
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1490 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
1491 % memory and returns the number of validation tests that passed and failed.
1493 % The format of the ValidateImageFormatsInMemory method is:
1495 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1496 % const char *reference_filename,const char *output_filename,
1497 % size_t *fail,ExceptionInfo *exception)
1499 % A description of each parameter follows:
1501 % o image_info: the image info.
1503 % o reference_filename: the reference image filename.
1505 % o output_filename: the output image filename.
1507 % o fail: return the number of validation tests that pass.
1509 % o exception: return any errors or warnings in this structure.
1514 Enable this to count remaining $TMPDIR/magick-* files. Note that the count
1515 includes any files left over from other runs.
1517 #undef MagickCountTempFiles
1519 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1520 const char *reference_filename,const char *output_filename,size_t *fail,
1521 ExceptionInfo *exception)
1524 #ifdef MagickCountTempFiles
1525 path[MagickPathExtent],
1526 SystemCommand[MagickPathExtent],
1528 size[MagickPathExtent];
1558 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
1560 #ifdef MagickCountTempFiles
1561 (void)GetPathTemplate(path);
1562 /* Remove file template except for the leading "/path/to/magick-" */
1563 path[strlen(path)-17]='\0';
1564 (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
1567 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1569 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1570 if ((magick_info == (const MagickInfo *) NULL) ||
1571 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1572 (magick_info->encoder == (EncodeImageHandler *) NULL))
1574 for (j=0; reference_types[j].type != UndefinedType; j++)
1577 Generate reference image.
1579 CatchException(exception);
1580 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1581 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1582 MagickCompressOptions,reference_formats[i].compression),
1583 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1584 (double) reference_types[j].depth);
1585 (void) CopyMagickString(image_info->filename,reference_filename,
1587 reference_image=ReadImage(image_info,exception);
1588 if (reference_image == (Image *) NULL ||
1589 exception->severity >= ErrorException)
1591 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1593 if (exception->reason)
1594 (void) FormatLocaleFile(stdout,
1595 " reason:%s\n",exception->reason);
1596 CatchException(exception);
1601 Write reference image.
1603 (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",
1604 (double) reference_image->columns,(double) reference_image->rows);
1605 (void) CloneString(&image_info->size,size);
1606 image_info->depth=reference_types[j].depth;
1607 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
1608 "%s:%s",reference_formats[i].magick,output_filename);
1609 status=SetImageType(reference_image,reference_types[j].type,exception);
1610 if (status == MagickFalse || exception->severity >= ErrorException)
1612 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1614 if (exception->reason)
1615 (void) FormatLocaleFile(stdout,
1616 " reason:%s\n",exception->reason);
1617 CatchException(exception);
1619 reference_image=DestroyImage(reference_image);
1622 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1623 if (status == MagickFalse || exception->severity >= ErrorException)
1625 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1627 CatchException(exception);
1629 reference_image=DestroyImage(reference_image);
1632 reference_image->compression=reference_formats[i].compression;
1633 status=WriteImage(image_info,reference_image,exception);
1634 reference_image=DestroyImage(reference_image);
1635 if (status == MagickFalse || exception->severity >= ErrorException)
1637 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1639 if (exception->reason)
1640 (void) FormatLocaleFile(stdout,
1641 " reason:%s\n",exception->reason);
1642 CatchException(exception);
1647 Ping reference image.
1649 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
1650 reference_formats[i].magick,output_filename);
1651 ping_image=PingImage(image_info,exception);
1652 if (ping_image == (Image *) NULL ||
1653 exception->severity >= ErrorException)
1655 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1657 if (exception->reason)
1658 (void) FormatLocaleFile(stdout,
1659 " reason:%s\n",exception->reason);
1660 CatchException(exception);
1664 ping_image=DestroyImage(ping_image);
1666 Read reference image.
1668 reference_image=ReadImage(image_info,exception);
1669 if (reference_image == (Image *) NULL ||
1670 exception->severity >= ErrorException)
1672 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1674 if (exception->reason)
1675 (void) FormatLocaleFile(stdout,
1676 " reason:%s\n",exception->reason);
1677 CatchException(exception);
1682 Write reference image.
1684 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
1685 "%s:%s",reference_formats[i].magick,output_filename);
1686 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
1688 reference_image->depth=reference_types[j].depth;
1689 reference_image->compression=reference_formats[i].compression;
1691 blob=ImageToBlob(image_info,reference_image,&length,exception);
1692 if (blob == (unsigned char *) NULL ||
1693 exception->severity >= ErrorException)
1695 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1697 if (exception->reason)
1698 (void) FormatLocaleFile(stdout,
1699 " reason:%s\n",exception->reason);
1700 CatchException(exception);
1702 reference_image=DestroyImage(reference_image);
1706 Ping reference blob.
1708 ping_image=PingBlob(image_info,blob,length,exception);
1709 if (ping_image == (Image *) NULL ||
1710 exception->severity >= ErrorException)
1712 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1714 if (exception->reason)
1715 (void) FormatLocaleFile(stdout,
1716 " reason:%s\n",exception->reason);
1717 CatchException(exception);
1719 blob=(unsigned char *) RelinquishMagickMemory(blob);
1722 ping_image=DestroyImage(ping_image);
1724 Read reconstruct image.
1726 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
1727 reference_formats[i].magick,output_filename);
1728 reconstruct_image=BlobToImage(image_info,blob,length,exception);
1729 blob=(unsigned char *) RelinquishMagickMemory(blob);
1730 if (reconstruct_image == (Image *) NULL ||
1731 exception->severity >= ErrorException)
1733 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1735 if (exception->reason)
1736 (void) FormatLocaleFile(stdout,
1737 " reason:%s\n",exception->reason);
1738 CatchException(exception);
1740 reference_image=DestroyImage(reference_image);
1744 Compare reference to reconstruct image.
1746 fuzz=0.003; /* grayscale */
1747 if (reference_formats[i].fuzz != 0.0)
1748 fuzz=reference_formats[i].fuzz;
1749 difference_image=CompareImages(reference_image,reconstruct_image,
1750 RootMeanSquaredErrorMetric,&distortion,exception);
1751 reconstruct_image=DestroyImage(reconstruct_image);
1752 reference_image=DestroyImage(reference_image);
1753 if (difference_image == (Image *) NULL ||
1754 exception->severity >= ErrorException)
1756 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1758 if (exception->reason)
1759 (void) FormatLocaleFile(stdout,
1760 " reason:%s\n",exception->reason);
1761 CatchException(exception);
1765 difference_image=DestroyImage(difference_image);
1766 if ((QuantumScale*distortion) > fuzz)
1768 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1769 QuantumScale*distortion);
1773 #ifdef MagickCountTempFiles
1774 (void) FormatLocaleFile(stdout,"... pass, ");
1775 (void) fflush(stdout);
1776 SystemCommand[0]='\0';
1777 (void) strncat(SystemCommand,"echo `ls ",9);
1778 (void) strncat(SystemCommand,path,MagickPathExtent-31);
1779 (void) strncat(SystemCommand,"* | wc -w` tmp files.",20);
1780 (void) system(SystemCommand);
1781 (void) fflush(stdout);
1783 (void) FormatLocaleFile(stdout,"... pass\n");
1787 (void) FormatLocaleFile(stdout,
1788 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1789 (double) (test-(*fail)),(double) *fail);
1794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1798 % 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 %
1802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1804 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
1805 % and returns the number of validation tests that passed and failed.
1807 % The format of the ValidateImageFormatsOnDisk method is:
1809 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1810 % const char *reference_filename,const char *output_filename,
1811 % size_t *fail,ExceptionInfo *exception)
1813 % A description of each parameter follows:
1815 % o image_info: the image info.
1817 % o reference_filename: the reference image filename.
1819 % o output_filename: the output image filename.
1821 % o fail: return the number of validation tests that pass.
1823 % o exception: return any errors or warnings in this structure.
1826 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1827 const char *reference_filename,const char *output_filename,size_t *fail,
1828 ExceptionInfo *exception)
1831 size[MagickPathExtent];
1856 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
1857 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1859 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1860 if ((magick_info == (const MagickInfo *) NULL) ||
1861 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1862 (magick_info->encoder == (EncodeImageHandler *) NULL))
1864 for (j=0; reference_types[j].type != UndefinedType; j++)
1867 Generate reference image.
1869 CatchException(exception);
1870 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1871 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1872 MagickCompressOptions,reference_formats[i].compression),
1873 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1874 (double) reference_types[j].depth);
1875 (void) CopyMagickString(image_info->filename,reference_filename,
1877 reference_image=ReadImage(image_info,exception);
1878 if (reference_image == (Image *) NULL ||
1879 exception->severity >= ErrorException)
1881 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1883 if (exception->reason)
1884 (void) FormatLocaleFile(stdout,
1885 " reason:%s\n",exception->reason);
1886 CatchException(exception);
1891 Write reference image.
1893 (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",
1894 (double) reference_image->columns,(double) reference_image->rows);
1895 (void) CloneString(&image_info->size,size);
1896 image_info->depth=reference_types[j].depth;
1897 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
1898 "%s:%s",reference_formats[i].magick,output_filename);
1899 status=SetImageType(reference_image,reference_types[j].type,exception);
1900 if (status == MagickFalse || exception->severity >= ErrorException)
1902 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1904 if (exception->reason)
1905 (void) FormatLocaleFile(stdout,
1906 " reason:%s\n",exception->reason);
1907 CatchException(exception);
1909 reference_image=DestroyImage(reference_image);
1912 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1913 if (status == MagickFalse || exception->severity >= ErrorException)
1915 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1917 CatchException(exception);
1919 reference_image=DestroyImage(reference_image);
1922 reference_image->compression=reference_formats[i].compression;
1923 status=WriteImage(image_info,reference_image,exception);
1924 reference_image=DestroyImage(reference_image);
1925 if (status == MagickFalse || exception->severity >= ErrorException)
1927 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1929 if (exception->reason)
1930 (void) FormatLocaleFile(stdout,
1931 " reason:%s\n",exception->reason);
1932 CatchException(exception);
1937 Read reference image.
1939 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
1940 reference_formats[i].magick,output_filename);
1941 reference_image=ReadImage(image_info,exception);
1942 if (reference_image == (Image *) NULL ||
1943 exception->severity >= ErrorException)
1945 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1947 CatchException(exception);
1952 Write reference image.
1954 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
1955 "%s:%s",reference_formats[i].magick,output_filename);
1956 reference_image->depth=reference_types[j].depth;
1957 reference_image->compression=reference_formats[i].compression;
1958 status=WriteImage(image_info,reference_image,exception);
1959 if (status == MagickFalse ||exception->severity >= ErrorException)
1961 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1963 CatchException(exception);
1965 reference_image=DestroyImage(reference_image);
1969 Read reconstruct image.
1971 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
1972 reference_formats[i].magick,output_filename);
1973 reconstruct_image=ReadImage(image_info,exception);
1974 if (reconstruct_image == (Image *) NULL ||
1975 exception->severity >= ErrorException)
1977 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1979 CatchException(exception);
1981 reference_image=DestroyImage(reference_image);
1985 Compare reference to reconstruct image.
1987 fuzz=0.003; /* grayscale */
1988 if (reference_formats[i].fuzz != 0.0)
1989 fuzz=reference_formats[i].fuzz;
1990 difference_image=CompareImages(reference_image,reconstruct_image,
1991 RootMeanSquaredErrorMetric,&distortion,exception);
1992 reconstruct_image=DestroyImage(reconstruct_image);
1993 reference_image=DestroyImage(reference_image);
1994 if (difference_image == (Image *) NULL ||
1995 exception->severity >= ErrorException)
1997 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1999 CatchException(exception);
2003 difference_image=DestroyImage(difference_image);
2004 if ((QuantumScale*distortion) > fuzz)
2006 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2007 QuantumScale*distortion);
2011 (void) FormatLocaleFile(stdout,"... pass.\n");
2014 (void) FormatLocaleFile(stdout,
2015 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2016 (double) (test-(*fail)),(double) *fail);
2021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2025 % 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 %
2029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2031 % ValidateImportExportPixels() validates the pixel import and export methods.
2032 % It returns the number of validation tests that passed and failed.
2034 % The format of the ValidateImportExportPixels method is:
2036 % size_t ValidateImportExportPixels(ImageInfo *image_info,
2037 % const char *reference_filename,const char *output_filename,
2038 % size_t *fail,ExceptionInfo *exception)
2040 % A description of each parameter follows:
2042 % o image_info: the image info.
2044 % o reference_filename: the reference image filename.
2046 % o output_filename: the output image filename.
2048 % o fail: return the number of validation tests that pass.
2050 % o exception: return any errors or warnings in this structure.
2053 static size_t ValidateImportExportPixels(ImageInfo *image_info,
2054 const char *reference_filename,const char *output_filename,size_t *fail,
2055 ExceptionInfo *exception)
2081 (void) output_filename;
2083 (void) FormatLocaleFile(stdout,
2084 "validate the import and export of image pixels:\n");
2085 for (i=0; reference_map[i] != (char *) NULL; i++)
2087 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
2090 Generate reference image.
2092 CatchException(exception);
2093 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
2094 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
2095 reference_storage[j].type));
2096 (void) CopyMagickString(image_info->filename,reference_filename,
2098 reference_image=ReadImage(image_info,exception);
2099 if (reference_image == (Image *) NULL ||
2100 exception->severity >= ErrorException)
2102 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2104 CatchException(exception);
2108 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
2109 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
2110 length=strlen(reference_map[i])*reference_image->columns*
2111 reference_image->rows*reference_storage[j].quantum;
2112 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
2113 if (pixels == (unsigned char *) NULL ||
2114 exception->severity >= ErrorException)
2116 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2118 CatchException(exception);
2120 reference_image=DestroyImage(reference_image);
2123 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
2124 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
2125 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
2127 if (status == MagickFalse || exception->severity >= ErrorException)
2129 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2131 CatchException(exception);
2133 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2134 reference_image=DestroyImage(reference_image);
2137 (void) SetImageBackgroundColor(reference_image,exception);
2138 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
2139 reference_image->rows,reference_map[i],reference_storage[j].type,
2141 if (status == MagickFalse || exception->severity >= ErrorException)
2143 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2145 CatchException(exception);
2147 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2148 reference_image=DestroyImage(reference_image);
2152 Read reconstruct image.
2154 reconstruct_image=AcquireImage(image_info,exception);
2155 (void) SetImageExtent(reconstruct_image,reference_image->columns,
2156 reference_image->rows,exception);
2157 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
2159 (void) SetImageBackgroundColor(reconstruct_image,exception);
2160 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
2161 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
2163 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2164 if (status == MagickFalse || exception->severity >= ErrorException)
2166 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2168 CatchException(exception);
2170 reference_image=DestroyImage(reference_image);
2174 Compare reference to reconstruct image.
2176 difference_image=CompareImages(reference_image,reconstruct_image,
2177 RootMeanSquaredErrorMetric,&distortion,exception);
2178 reconstruct_image=DestroyImage(reconstruct_image);
2179 reference_image=DestroyImage(reference_image);
2180 if (difference_image == (Image *) NULL ||
2181 exception->severity >= ErrorException)
2183 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2185 CatchException(exception);
2189 difference_image=DestroyImage(difference_image);
2190 if ((QuantumScale*distortion) > 0.0)
2192 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2193 QuantumScale*distortion);
2197 (void) FormatLocaleFile(stdout,"... pass.\n");
2200 (void) FormatLocaleFile(stdout,
2201 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2202 (double) (test-(*fail)),(double) *fail);
2207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2211 % V a l i d a t e M o n t a g e C o m m a n d %
2215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2217 % ValidateMontageCommand() validates the ImageMagick montage command line
2218 % program and returns the number of validation tests that passed and failed.
2220 % The format of the ValidateMontageCommand method is:
2222 % size_t ValidateMontageCommand(ImageInfo *image_info,
2223 % const char *reference_filename,const char *output_filename,
2224 % size_t *fail,ExceptionInfo *exception)
2226 % A description of each parameter follows:
2228 % o image_info: the image info.
2230 % o reference_filename: the reference image filename.
2232 % o output_filename: the output image filename.
2234 % o fail: return the number of validation tests that pass.
2236 % o exception: return any errors or warnings in this structure.
2239 static size_t ValidateMontageCommand(ImageInfo *image_info,
2240 const char *reference_filename,const char *output_filename,size_t *fail,
2241 ExceptionInfo *exception)
2245 command[MagickPathExtent];
2261 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
2262 for (i=0; montage_options[i] != (char *) NULL; i++)
2264 CatchException(exception);
2265 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2266 montage_options[i]);
2267 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
2268 reference_filename,montage_options[i],reference_filename,
2270 arguments=StringToArgv(command,&number_arguments);
2271 if (arguments == (char **) NULL)
2273 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2278 status=MontageImageCommand(image_info,number_arguments,arguments,
2279 (char **) NULL,exception);
2280 for (j=0; j < (ssize_t) number_arguments; j++)
2281 arguments[j]=DestroyString(arguments[j]);
2282 arguments=(char **) RelinquishMagickMemory(arguments);
2283 if (status == MagickFalse)
2285 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2290 (void) FormatLocaleFile(stdout,"... pass.\n");
2292 (void) FormatLocaleFile(stdout,
2293 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2294 (double) (test-(*fail)),(double) *fail);
2299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2303 % V a l i d a t e S t r e a m C o m m a n d %
2307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2309 % ValidateStreamCommand() validates the ImageMagick stream command line
2310 % program and returns the number of validation tests that passed and failed.
2312 % The format of the ValidateStreamCommand method is:
2314 % size_t ValidateStreamCommand(ImageInfo *image_info,
2315 % const char *reference_filename,const char *output_filename,
2316 % size_t *fail,ExceptionInfo *exception)
2318 % A description of each parameter follows:
2320 % o image_info: the image info.
2322 % o reference_filename: the reference image filename.
2324 % o output_filename: the output image filename.
2326 % o fail: return the number of validation tests that pass.
2328 % o exception: return any errors or warnings in this structure.
2331 static size_t ValidateStreamCommand(ImageInfo *image_info,
2332 const char *reference_filename,const char *output_filename,size_t *fail,
2333 ExceptionInfo *exception)
2337 command[MagickPathExtent];
2353 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
2354 for (i=0; stream_options[i] != (char *) NULL; i++)
2356 CatchException(exception);
2357 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2359 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s",
2360 stream_options[i],reference_filename,output_filename);
2361 arguments=StringToArgv(command,&number_arguments);
2362 if (arguments == (char **) NULL)
2364 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2369 status=StreamImageCommand(image_info,number_arguments,arguments,
2370 (char **) NULL,exception);
2371 for (j=0; j < (ssize_t) number_arguments; j++)
2372 arguments[j]=DestroyString(arguments[j]);
2373 arguments=(char **) RelinquishMagickMemory(arguments);
2374 if (status == MagickFalse)
2376 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2381 (void) FormatLocaleFile(stdout,"... pass.\n");
2383 (void) FormatLocaleFile(stdout,
2384 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2385 (double) (test-(*fail)),(double) *fail);
2390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2403 static MagickBooleanType ValidateUsage(void)
2411 "-debug events display copious debugging information",
2412 "-help print program options",
2413 "-log format format of debugging information",
2414 "-validate type validation type",
2415 "-version print version information",
2420 "-regard-warnings pay attention to warning messages",
2421 "-verbose print detailed information about the image",
2425 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
2426 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
2427 (void) printf("Features: %s\n",GetMagickFeatures());
2428 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
2429 (void) printf("\nValidate Settings:\n");
2430 for (p=settings; *p != (char *) NULL; p++)
2431 (void) printf(" %s\n",*p);
2432 (void) printf("\nMiscellaneous Options:\n");
2433 for (p=miscellaneous; *p != (char *) NULL; p++)
2434 (void) printf(" %s\n",*p);
2438 int main(int argc,char **argv)
2440 #define DestroyValidate() \
2442 image_info=DestroyImageInfo(image_info); \
2443 exception=DestroyExceptionInfo(exception); \
2445 #define ThrowValidateException(asperity,tag,option) \
2447 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
2449 CatchException(exception); \
2450 DestroyValidate(); \
2451 return(MagickFalse); \
2455 output_filename[MagickPathExtent],
2456 reference_filename[MagickPathExtent],
2495 Validate the ImageMagick image processing suite.
2497 MagickCoreGenesis(*argv,MagickTrue);
2498 (void) setlocale(LC_ALL,"");
2499 (void) setlocale(LC_NUMERIC,"C");
2503 regard_warnings=MagickFalse;
2504 (void) regard_warnings;
2505 exception=AcquireExceptionInfo();
2506 image_info=AcquireImageInfo();
2507 (void) CopyMagickString(image_info->filename,ReferenceFilename,MagickPathExtent);
2508 for (i=1; i < (ssize_t) argc; i++)
2511 if (IsCommandOption(option) == MagickFalse)
2513 (void) CopyMagickString(image_info->filename,option,MagickPathExtent);
2516 switch (*(option+1))
2520 if (LocaleCompare("bench",option+1) == 0)
2522 iterations=StringToUnsignedLong(argv[++i]);
2525 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2529 if (LocaleCompare("debug",option+1) == 0)
2531 (void) SetLogEventMask(argv[++i]);
2534 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2538 if (LocaleCompare("help",option+1) == 0)
2540 (void) ValidateUsage();
2543 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2547 if (LocaleCompare("log",option+1) == 0)
2550 (void) SetLogFormat(argv[i+1]);
2553 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2557 if (LocaleCompare("regard-warnings",option+1) == 0)
2559 regard_warnings=MagickTrue;
2562 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2566 if (LocaleCompare("validate",option+1) == 0)
2574 if (i >= (ssize_t) argc)
2575 ThrowValidateException(OptionError,"MissingArgument",option);
2576 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
2579 ThrowValidateException(OptionError,"UnrecognizedValidateType",
2581 type=(ValidateType) validate;
2584 if ((LocaleCompare("version",option+1) == 0) ||
2585 (LocaleCompare("-version",option+1) == 0))
2587 (void) FormatLocaleFile(stdout,"Version: %s\n",
2588 GetMagickVersion((size_t *) NULL));
2589 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2590 GetMagickCopyright());
2591 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
2592 GetMagickFeatures());
2595 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2598 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2601 timer=(TimerInfo *) NULL;
2603 timer=AcquireTimerInfo();
2604 reference_image=ReadImage(image_info,exception);
2607 if (reference_image == (Image *) NULL)
2611 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
2612 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
2614 (void) AcquireUniqueFilename(reference_filename);
2615 (void) AcquireUniqueFilename(output_filename);
2616 (void) CopyMagickString(reference_image->filename,reference_filename,
2618 status=WriteImage(image_info,reference_image,exception);
2619 reference_image=DestroyImage(reference_image);
2620 if (status == MagickFalse)
2624 (void) FormatLocaleFile(stdout,"Version: %s\n",
2625 GetMagickVersion((size_t *) NULL));
2626 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2627 GetMagickCopyright());
2628 (void) FormatLocaleFile(stdout,
2629 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
2630 MagickValidateOptions,(ssize_t) type));
2631 if ((type & ColorspaceValidate) != 0)
2632 tests+=ValidateColorspaces(image_info,&fail,exception);
2633 if ((type & CompareValidate) != 0)
2634 tests+=ValidateCompareCommand(image_info,reference_filename,
2635 output_filename,&fail,exception);
2636 if ((type & CompositeValidate) != 0)
2637 tests+=ValidateCompositeCommand(image_info,reference_filename,
2638 output_filename,&fail,exception);
2639 if ((type & ConvertValidate) != 0)
2640 tests+=ValidateConvertCommand(image_info,reference_filename,
2641 output_filename,&fail,exception);
2642 if ((type & FormatsDiskValidate) != 0)
2644 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2645 map_resource=SetMagickResourceLimit(MapResource,0);
2646 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2647 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2648 output_filename,&fail,exception);
2649 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2650 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2651 output_filename,&fail,exception);
2652 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2653 (void) SetMagickResourceLimit(MapResource,map_resource);
2655 if ((type & FormatsMapValidate) != 0)
2657 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2658 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2659 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2660 output_filename,&fail,exception);
2661 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2662 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2663 output_filename,&fail,exception);
2664 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2666 if ((type & FormatsMemoryValidate) != 0)
2668 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2669 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2670 output_filename,&fail,exception);
2671 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2672 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2673 output_filename,&fail,exception);
2675 if ((type & IdentifyValidate) != 0)
2676 tests+=ValidateIdentifyCommand(image_info,reference_filename,
2677 output_filename,&fail,exception);
2678 if ((type & ImportExportValidate) != 0)
2679 tests+=ValidateImportExportPixels(image_info,reference_filename,
2680 output_filename,&fail,exception);
2681 if ((type & MontageValidate) != 0)
2682 tests+=ValidateMontageCommand(image_info,reference_filename,
2683 output_filename,&fail,exception);
2684 if ((type & StreamValidate) != 0)
2685 tests+=ValidateStreamCommand(image_info,reference_filename,
2686 output_filename,&fail,exception);
2687 (void) FormatLocaleFile(stdout,
2688 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
2689 (double) tests,(double) (tests-fail),(double) fail);
2691 (void) RelinquishUniqueFileResource(output_filename);
2692 (void) RelinquishUniqueFileResource(reference_filename);
2694 if (exception->severity != UndefinedException)
2695 CatchException(exception);
2698 elapsed_time=GetElapsedTime(timer);
2699 user_time=GetUserTime(timer);
2700 (void) FormatLocaleFile(stderr,
2701 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
2702 iterations,1.0*iterations/elapsed_time,user_time,(long)
2703 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
2704 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
2705 timer=DestroyTimerInfo(timer);
2708 MagickCoreTerminus();
2709 return(fail == 0 ? 0 : 1);