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-2015 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/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 double PerceptibleReciprocal(const double x)
489 Return 1/x where x is perceptible (not unlimited or infinitesimal).
491 sign=x < 0.0 ? -1.0 : 1.0;
492 if ((sign*x) >= MagickEpsilon)
494 return(sign/MagickEpsilon);
497 static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
498 double *L,double *u,double *v)
503 if ((Y/D65Y) > CIEEpsilon)
504 *L=(double) (116.0*pow(Y/D65Y,1.0/3.0)-16.0);
507 alpha=PerceptibleReciprocal(X+15.0*Y+3.0*Z);
508 *u=13.0*(*L)*((4.0*alpha*X)-(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z)));
509 *v=13.0*(*L)*((9.0*alpha*Y)-(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z)));
515 static void ConvertRGBToLuv(const double red,const double green,
516 const double blue,double *L,double *u,double *v)
523 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
524 ConvertXYZToLuv(X,Y,Z,L,u,v);
527 static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
528 double *X,double *Y,double *Z)
530 if (L > (CIEK*CIEEpsilon))
531 *Y=(double) pow((L+16.0)/116.0,3.0);
534 *X=((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
535 5.0*(*Y))/((((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/
537 *Z=(*X*(((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
541 static inline void ConvertLuvToRGB(const double L,const double u,
542 const double v,double *red,double *green,double *blue)
549 ConvertLuvToXYZ(100.0*L,354.0*u-134.0,262.0*v-140.0,&X,&Y,&Z);
550 ConvertXYZToRGB(X,Y,Z,red,green,blue);
553 static void ConvertRGBToYDbDr(const double red,const double green,
554 const double blue,double *Y,double *Db,double *Dr)
556 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
557 *Db=QuantumScale*(-0.450*red-0.883*green+1.333*blue)+0.5;
558 *Dr=QuantumScale*(-1.333*red+1.116*green+0.217*blue)+0.5;
561 static void ConvertYDbDrToRGB(const double Y,const double Db,const double Dr,
562 double *red,double *green,double *blue)
564 *red=QuantumRange*(Y+9.2303716147657e-05*(Db-0.5)-0.52591263066186533*
566 *green=QuantumRange*(Y-0.12913289889050927*(Db-0.5)+0.26789932820759876*
568 *blue=QuantumRange*(Y+0.66467905997895482*(Db-0.5)-7.9202543533108e-05*
572 static void ConvertRGBToYIQ(const double red,const double green,
573 const double blue,double *Y,double *I,double *Q)
575 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
576 *I=QuantumScale*(0.595716*red-0.274453*green-0.321263*blue)+0.5;
577 *Q=QuantumScale*(0.211456*red-0.522591*green+0.311135*blue)+0.5;
580 static void ConvertYIQToRGB(const double Y,const double I,const double Q,
581 double *red,double *green,double *blue)
583 *red=QuantumRange*(Y+0.9562957197589482261*(I-0.5)+0.6210244164652610754*
585 *green=QuantumRange*(Y-0.2721220993185104464*(I-0.5)-0.6473805968256950427*
587 *blue=QuantumRange*(Y-1.1069890167364901945*(I-0.5)+1.7046149983646481374*
591 static void ConvertRGBToYUV(const double red,const double green,
592 const double blue,double *Y,double *U,double *V)
594 *Y=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
595 *U=QuantumScale*((-0.147)*red-0.289*green+0.436*blue)+0.5;
596 *V=QuantumScale*(0.615*red-0.515*green-0.100*blue)+0.5;
599 static void ConvertYUVToRGB(const double Y,const double U,const double V,
600 double *red,double *green,double *blue)
602 *red=QuantumRange*(Y-3.945707070708279e-05*(U-0.5)+1.1398279671717170825*
604 *green=QuantumRange*(Y-0.3946101641414141437*(U-0.5)-0.5805003156565656797*
606 *blue=QuantumRange*(Y+2.0319996843434342537*(U-0.5)-4.813762626262513e-04*
610 static MagickBooleanType ValidateHSIToRGB()
617 (void) FormatLocaleFile(stdout," HSIToRGB");
618 ConvertHSIToRGB(111.244375/360.0,0.295985,0.658734,&r,&g,&b);
619 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
620 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
621 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
626 static MagickBooleanType ValidateRGBToHSI()
633 (void) FormatLocaleFile(stdout," RGBToHSI");
634 ConvertRGBToHSI(0.545877*QuantumRange,0.966567*QuantumRange,
635 0.463759*QuantumRange,&h,&s,&i);
636 if ((fabs(h-111.244374/360.0) >= ReferenceEpsilon) ||
637 (fabs(s-0.295985) >= ReferenceEpsilon) ||
638 (fabs(i-0.658734) >= ReferenceEpsilon))
643 static MagickBooleanType ValidateHSLToRGB()
650 (void) FormatLocaleFile(stdout," HSLToRGB");
651 ConvertHSLToRGB(110.200859/360.0,0.882623,0.715163,&r,&g,&b);
652 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
653 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
654 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
659 static MagickBooleanType ValidateRGBToHSL()
666 (void) FormatLocaleFile(stdout," RGBToHSL");
667 ConvertRGBToHSL(0.545877*QuantumRange,0.966567*QuantumRange,
668 0.463759*QuantumRange,&h,&s,&l);
669 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
670 (fabs(s-0.882623) >= ReferenceEpsilon) ||
671 (fabs(l-0.715163) >= ReferenceEpsilon))
676 static MagickBooleanType ValidateHSVToRGB()
683 (void) FormatLocaleFile(stdout," HSVToRGB");
684 ConvertHSVToRGB(110.200859/360.0,0.520200,0.966567,&r,&g,&b);
685 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
686 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
687 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
692 static MagickBooleanType ValidateRGBToHSV()
699 (void) FormatLocaleFile(stdout," RGBToHSV");
700 ConvertRGBToHSV(0.545877*QuantumRange,0.966567*QuantumRange,
701 0.463759*QuantumRange,&h,&s,&v);
702 if ((fabs(h-110.200859/360.0) >= ReferenceEpsilon) ||
703 (fabs(s-0.520200) >= ReferenceEpsilon) ||
704 (fabs(v-0.966567) >= ReferenceEpsilon))
709 static MagickBooleanType ValidateRGBToJPEGYCbCr()
716 (void) FormatLocaleFile(stdout," RGBToJPEGYCbCr");
717 ConvertRGBToYCbCr(0.545877*QuantumRange,0.966567*QuantumRange,
718 0.463759*QuantumRange,&Y,&Cb,&Cr);
719 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
720 (fabs(Cb-0.319581) >= ReferenceEpsilon) ||
721 (fabs(Cr-0.330539) >= ReferenceEpsilon))
726 static MagickBooleanType ValidateJPEGYCbCrToRGB()
733 (void) FormatLocaleFile(stdout," JPEGYCbCrToRGB");
734 ConvertYCbCrToRGB(0.783460,0.319581,0.330539,&r,&g,&b);
735 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
736 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
737 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
742 static MagickBooleanType ValidateLabToRGB()
749 (void) FormatLocaleFile(stdout," LabToRGB");
750 ConvertLabToRGB(88.456154/100.0,-54.671483/255+0.5,51.662818/255.0+0.5,
752 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
753 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
754 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
759 static MagickBooleanType ValidateRGBToLab()
766 (void) FormatLocaleFile(stdout," RGBToLab");
767 ConvertRGBToLab(0.545877*QuantumRange,0.966567*QuantumRange,
768 0.463759*QuantumRange,&L,&a,&b);
769 if ((fabs(L-(88.456154/100.0)) >= ReferenceEpsilon) ||
770 (fabs(a-(-54.671483/255.0+0.5)) >= ReferenceEpsilon) ||
771 (fabs(b-(51.662818/255.0+0.5)) >= ReferenceEpsilon))
776 static MagickBooleanType ValidateLchToRGB()
783 (void) FormatLocaleFile(stdout," LchToRGB");
784 ConvertLCHabToRGB(88.456154/100.0,75.219797/255.0+0.5,136.620717/360.0,
786 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
787 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
788 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
793 static MagickBooleanType ValidateRGBToLch()
800 (void) FormatLocaleFile(stdout," RGBToLch");
801 ConvertRGBToLCHab(0.545877*QuantumRange,0.966567*QuantumRange,
802 0.463759*QuantumRange,&L,&c,&h);
803 if ((fabs(L-88.456154/100.0) >= ReferenceEpsilon) ||
804 (fabs(c-(75.219797/255.0+0.5)) >= ReferenceEpsilon) ||
805 (fabs(h-(136.620717/255.0+0.5)) >= ReferenceEpsilon))
810 static MagickBooleanType ValidateRGBToLMS()
817 (void) FormatLocaleFile(stdout," RGBToLMS");
818 ConvertRGBToLMS(0.545877*QuantumRange,0.966567*QuantumRange,
819 0.463759*QuantumRange,&L,&M,&S);
820 if ((fabs(L-0.611749) >= ReferenceEpsilon) ||
821 (fabs(M-0.910088) >= ReferenceEpsilon) ||
822 (fabs(S-0.294880) >= ReferenceEpsilon))
827 static MagickBooleanType ValidateLMSToRGB()
834 (void) FormatLocaleFile(stdout," LMSToRGB");
835 ConvertLMSToRGB(0.611749,0.910088,0.294880,&r,&g,&b);
836 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
837 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
838 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
843 static MagickBooleanType ValidateRGBToLuv()
850 (void) FormatLocaleFile(stdout," RGBToLuv");
851 ConvertRGBToLuv(0.545877*QuantumRange,0.966567*QuantumRange,
852 0.463759*QuantumRange,&l,&u,&v);
853 if ((fabs(l-88.456154/262.0) >= ReferenceEpsilon) ||
854 (fabs(u-(-51.330414+134.0)/354.0) >= ReferenceEpsilon) ||
855 (fabs(v-(76.405526+140.0)/262.0) >= ReferenceEpsilon))
860 static MagickBooleanType ValidateLuvToRGB()
867 (void) FormatLocaleFile(stdout," LuvToRGB");
868 ConvertLuvToRGB(88.456154/100.0,(-51.330414+134.0)/354.0,
869 (76.405526+140.0)/262.0,&r,&g,&b);
870 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
871 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
872 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
877 static MagickBooleanType ValidateRGBToXYZ()
884 (void) FormatLocaleFile(stdout," RGBToXYZ");
885 ConvertRGBToXYZ(0.545877*QuantumRange,0.966567*QuantumRange,
886 0.463759*QuantumRange,&x,&y,&z);
887 if ((fabs(x-0.470646) >= ReferenceEpsilon) ||
888 (fabs(y-0.730178) >= ReferenceEpsilon) ||
889 (fabs(z-0.288324) >= ReferenceEpsilon))
894 static MagickBooleanType ValidateXYZToRGB()
901 (void) FormatLocaleFile(stdout," XYZToRGB");
902 ConvertXYZToRGB(0.470646,0.730178,0.288324,&r,&g,&b);
903 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
904 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
905 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
910 static MagickBooleanType ValidateYDbDrToRGB()
917 (void) FormatLocaleFile(stdout," YDbDrToRGB");
918 ConvertYDbDrToRGB(0.783460,-0.480932+0.5,0.451670+0.5,&r,&g,&b);
919 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
920 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
921 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
926 static MagickBooleanType ValidateRGBToYDbDr()
933 (void) FormatLocaleFile(stdout," RGBToYDbDr");
934 ConvertRGBToYDbDr(0.545877*QuantumRange,0.966567*QuantumRange,
935 0.463759*QuantumRange,&Y,&Db,&Dr);
936 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
937 (fabs(Db-(-0.480932)) >= ReferenceEpsilon) ||
938 (fabs(Dr-0.451670) >= ReferenceEpsilon))
943 static MagickBooleanType ValidateRGBToYIQ()
950 (void) FormatLocaleFile(stdout," RGBToYIQ");
951 ConvertRGBToYIQ(0.545877*QuantumRange,0.966567*QuantumRange,
952 0.463759*QuantumRange,&y,&i,&q);
953 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
954 (fabs(i-(-0.089078)) >= ReferenceEpsilon) ||
955 (fabs(q-(-0.245399)) >= ReferenceEpsilon))
960 static MagickBooleanType ValidateYIQToRGB()
967 (void) FormatLocaleFile(stdout," YIQToRGB");
968 ConvertYIQToRGB(0.783460,-0.089078+0.5,-0.245399+0.5,&r,&g,&b);
969 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
970 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
971 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
976 static MagickBooleanType ValidateRGBToYPbPr()
983 (void) FormatLocaleFile(stdout," RGBToYPbPr");
984 ConvertRGBToYPbPr(0.545877*QuantumRange,0.966567*QuantumRange,
985 0.463759*QuantumRange,&y,&Pb,&Pr);
986 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
987 (fabs(Pb-(-0.180419)) >= ReferenceEpsilon) ||
988 (fabs(Pr-(-0.169461)) >= ReferenceEpsilon))
993 static MagickBooleanType ValidateYPbPrToRGB()
1000 (void) FormatLocaleFile(stdout," YPbPrToRGB");
1001 ConvertYPbPrToRGB(0.783460,-0.180419+0.5,-0.169461+0.5,&r,&g,&b);
1002 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1003 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1004 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1005 return(MagickFalse);
1009 static MagickBooleanType ValidateRGBToYUV()
1016 (void) FormatLocaleFile(stdout," RGBToYUV");
1017 ConvertRGBToYUV(0.545877*QuantumRange,0.966567*QuantumRange,
1018 0.463759*QuantumRange,&Y,&U,&V);
1019 if ((fabs(Y-0.783460) >= ReferenceEpsilon) ||
1020 (fabs(U-(-0.157383)) >= ReferenceEpsilon) ||
1021 (fabs(V-(-0.208443)) >= ReferenceEpsilon))
1022 return(MagickFalse);
1026 static MagickBooleanType ValidateYUVToRGB()
1033 (void) FormatLocaleFile(stdout," YUVToRGB");
1034 ConvertYUVToRGB(0.783460,-0.157383+0.5,-0.208443+0.5,&r,&g,&b);
1035 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
1036 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
1037 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
1038 return(MagickFalse);
1042 static size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
1043 ExceptionInfo *exception)
1052 Reference: https://code.google.com/p/chroma.
1055 Observer = 2° (1931)
1057 XYZ 0.470645, 0.730177, 0.288323
1058 sRGB 0.545877, 0.966567, 0.463759
1059 CAT02 LMS 0.611749, 0.910088, 0.294880
1060 Y'DbDr 0.783460, -0.480932, 0.451670
1061 Y'IQ 0.783460, -0.089078, -0.245399
1062 Y'PbPr 0.783460, -0.180419, -0.169461
1063 Y'UV 0.783460, -0.157383, -0.208443
1064 JPEG-Y'CbCr 0.783460, 0.319581, 0.330539
1065 L*u*v* 88.456154, -51.330414, 76.405526
1066 L*a*b* 88.456154, -54.671483, 51.662818
1067 L*C*H* 88.456154, 75.219797, 136.620717
1068 HSV 110.200859, 0.520200, 0.966567
1069 HSL 110.200859, 0.882623, 0.715163
1070 HSI 111.244375, 0.295985, 0.658734
1071 Y'CbCr 187.577791, 87.586330, 90.040886
1073 (void) FormatLocaleFile(stdout,"validate colorspaces:\n");
1074 for (test=0; test < 26; test++)
1076 CatchException(exception);
1077 (void) FormatLocaleFile(stdout," test %.20g: ",(double) test);
1080 case 0: status=ValidateHSIToRGB(); break;
1081 case 1: status=ValidateRGBToHSI(); break;
1082 case 2: status=ValidateHSLToRGB(); break;
1083 case 3: status=ValidateRGBToHSL(); break;
1084 case 4: status=ValidateHSVToRGB(); break;
1085 case 5: status=ValidateRGBToHSV(); break;
1086 case 6: status=ValidateJPEGYCbCrToRGB(); break;
1087 case 7: status=ValidateRGBToJPEGYCbCr(); break;
1088 case 8: status=ValidateLabToRGB(); break;
1089 case 9: status=ValidateRGBToLab(); break;
1090 case 10: status=ValidateLchToRGB(); break;
1091 case 11: status=ValidateRGBToLch(); break;
1092 case 12: status=ValidateLMSToRGB(); break;
1093 case 13: status=ValidateRGBToLMS(); break;
1094 case 14: status=ValidateLuvToRGB(); break;
1095 case 15: status=ValidateRGBToLuv(); break;
1096 case 16: status=ValidateXYZToRGB(); break;
1097 case 17: status=ValidateRGBToXYZ(); break;
1098 case 18: status=ValidateYDbDrToRGB(); break;
1099 case 19: status=ValidateRGBToYDbDr(); break;
1100 case 20: status=ValidateYIQToRGB(); break;
1101 case 21: status=ValidateRGBToYIQ(); break;
1102 case 22: status=ValidateYPbPrToRGB(); break;
1103 case 23: status=ValidateRGBToYPbPr(); break;
1104 case 24: status=ValidateYUVToRGB(); break;
1105 case 25: status=ValidateRGBToYUV(); break;
1106 default: status=MagickFalse;
1108 if (status == MagickFalse)
1110 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1115 (void) FormatLocaleFile(stdout,"... pass.\n");
1117 (void) FormatLocaleFile(stdout,
1118 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1119 (double) (test-(*fail)),(double) *fail);
1124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1128 % V a l i d a t e C o m p a r e C o m m a n d %
1132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1134 % ValidateCompareCommand() validates the ImageMagick compare command line
1135 % program and returns the number of validation tests that passed and failed.
1137 % The format of the ValidateCompareCommand method is:
1139 % size_t ValidateCompareCommand(ImageInfo *image_info,
1140 % const char *reference_filename,const char *output_filename,
1141 % size_t *fail,ExceptionInfo *exception)
1143 % A description of each parameter follows:
1145 % o image_info: the image info.
1147 % o reference_filename: the reference image filename.
1149 % o output_filename: the output image filename.
1151 % o fail: return the number of validation tests that pass.
1153 % o exception: return any errors or warnings in this structure.
1156 static size_t ValidateCompareCommand(ImageInfo *image_info,
1157 const char *reference_filename,const char *output_filename,size_t *fail,
1158 ExceptionInfo *exception)
1162 command[MaxTextExtent];
1178 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
1179 for (i=0; compare_options[i] != (char *) NULL; i++)
1181 CatchException(exception);
1182 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1183 compare_options[i]);
1184 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1185 compare_options[i],reference_filename,reference_filename,output_filename);
1186 arguments=StringToArgv(command,&number_arguments);
1187 if (arguments == (char **) NULL)
1189 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1194 status=CompareImagesCommand(image_info,number_arguments,arguments,
1195 (char **) NULL,exception);
1196 for (j=0; j < (ssize_t) number_arguments; j++)
1197 arguments[j]=DestroyString(arguments[j]);
1198 arguments=(char **) RelinquishMagickMemory(arguments);
1199 if (status == MagickFalse)
1201 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1206 (void) FormatLocaleFile(stdout,"... pass.\n");
1208 (void) FormatLocaleFile(stdout,
1209 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1210 (double) (test-(*fail)),(double) *fail);
1215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1219 % V a l i d a t e C o m p o s i t e C o m m a n d %
1223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1225 % ValidateCompositeCommand() validates the ImageMagick composite command line
1226 % program and returns the number of validation tests that passed and failed.
1228 % The format of the ValidateCompositeCommand method is:
1230 % size_t ValidateCompositeCommand(ImageInfo *image_info,
1231 % const char *reference_filename,const char *output_filename,
1232 % size_t *fail,ExceptionInfo *exception)
1234 % A description of each parameter follows:
1236 % o image_info: the image info.
1238 % o reference_filename: the reference image filename.
1240 % o output_filename: the output image filename.
1242 % o fail: return the number of validation tests that pass.
1244 % o exception: return any errors or warnings in this structure.
1247 static size_t ValidateCompositeCommand(ImageInfo *image_info,
1248 const char *reference_filename,const char *output_filename,size_t *fail,
1249 ExceptionInfo *exception)
1253 command[MaxTextExtent];
1269 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
1270 for (i=0; composite_options[i] != (char *) NULL; i++)
1272 CatchException(exception);
1273 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
1274 composite_options[i]);
1275 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1276 reference_filename,composite_options[i],reference_filename,
1278 arguments=StringToArgv(command,&number_arguments);
1279 if (arguments == (char **) NULL)
1281 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1286 status=CompositeImageCommand(image_info,number_arguments,arguments,
1287 (char **) NULL,exception);
1288 for (j=0; j < (ssize_t) number_arguments; j++)
1289 arguments[j]=DestroyString(arguments[j]);
1290 arguments=(char **) RelinquishMagickMemory(arguments);
1291 if (status == MagickFalse)
1293 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1298 (void) FormatLocaleFile(stdout,"... pass.\n");
1300 (void) FormatLocaleFile(stdout,
1301 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1302 (double) (test-(*fail)),(double) *fail);
1307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1311 % V a l i d a t e C o n v e r t C o m m a n d %
1315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1317 % ValidateConvertCommand() validates the ImageMagick convert command line
1318 % program and returns the number of validation tests that passed and failed.
1320 % The format of the ValidateConvertCommand method is:
1322 % size_t ValidateConvertCommand(ImageInfo *image_info,
1323 % const char *reference_filename,const char *output_filename,
1324 % size_t *fail,ExceptionInfo *exception)
1326 % A description of each parameter follows:
1328 % o image_info: the image info.
1330 % o reference_filename: the reference image filename.
1332 % o output_filename: the output image filename.
1334 % o fail: return the number of validation tests that pass.
1336 % o exception: return any errors or warnings in this structure.
1339 static size_t ValidateConvertCommand(ImageInfo *image_info,
1340 const char *reference_filename,const char *output_filename,size_t *fail,
1341 ExceptionInfo *exception)
1345 command[MaxTextExtent];
1361 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
1362 for (i=0; convert_options[i] != (char *) NULL; i++)
1364 CatchException(exception);
1365 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1366 convert_options[i]);
1367 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
1368 reference_filename,convert_options[i],reference_filename,output_filename);
1369 arguments=StringToArgv(command,&number_arguments);
1370 if (arguments == (char **) NULL)
1372 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1377 status=ConvertImageCommand(image_info,number_arguments,arguments,
1378 (char **) NULL,exception);
1379 for (j=0; j < (ssize_t) number_arguments; j++)
1380 arguments[j]=DestroyString(arguments[j]);
1381 arguments=(char **) RelinquishMagickMemory(arguments);
1382 if (status == MagickFalse)
1384 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1389 (void) FormatLocaleFile(stdout,"... pass.\n");
1391 (void) FormatLocaleFile(stdout,
1392 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1393 (double) (test-(*fail)),(double) *fail);
1398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1402 % V a l i d a t e I d e n t i f y C o m m a n d %
1406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408 % ValidateIdentifyCommand() validates the ImageMagick identify command line
1409 % program and returns the number of validation tests that passed and failed.
1411 % The format of the ValidateIdentifyCommand method is:
1413 % size_t ValidateIdentifyCommand(ImageInfo *image_info,
1414 % const char *reference_filename,const char *output_filename,
1415 % size_t *fail,ExceptionInfo *exception)
1417 % A description of each parameter follows:
1419 % o image_info: the image info.
1421 % o reference_filename: the reference image filename.
1423 % o output_filename: the output image filename.
1425 % o fail: return the number of validation tests that pass.
1427 % o exception: return any errors or warnings in this structure.
1430 static size_t ValidateIdentifyCommand(ImageInfo *image_info,
1431 const char *reference_filename,const char *output_filename,size_t *fail,
1432 ExceptionInfo *exception)
1436 command[MaxTextExtent];
1451 (void) output_filename;
1453 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
1454 for (i=0; identify_options[i] != (char *) NULL; i++)
1456 CatchException(exception);
1457 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
1458 identify_options[i]);
1459 (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
1460 identify_options[i],reference_filename);
1461 arguments=StringToArgv(command,&number_arguments);
1462 if (arguments == (char **) NULL)
1464 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1469 status=IdentifyImageCommand(image_info,number_arguments,arguments,
1470 (char **) NULL,exception);
1471 for (j=0; j < (ssize_t) number_arguments; j++)
1472 arguments[j]=DestroyString(arguments[j]);
1473 arguments=(char **) RelinquishMagickMemory(arguments);
1474 if (status == MagickFalse)
1476 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1481 (void) FormatLocaleFile(stdout,"... pass.\n");
1483 (void) FormatLocaleFile(stdout,
1484 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1485 (double) (test-(*fail)),(double) *fail);
1490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1494 % 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 %
1498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1500 % ValidateImageFormatsInMemory() validates the ImageMagick image formats in
1501 % memory and returns the number of validation tests that passed and failed.
1503 % The format of the ValidateImageFormatsInMemory method is:
1505 % size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1506 % const char *reference_filename,const char *output_filename,
1507 % size_t *fail,ExceptionInfo *exception)
1509 % A description of each parameter follows:
1511 % o image_info: the image info.
1513 % o reference_filename: the reference image filename.
1515 % o output_filename: the output image filename.
1517 % o fail: return the number of validation tests that pass.
1519 % o exception: return any errors or warnings in this structure.
1524 Enable this to count remaining $TMPDIR/magick-* files. Note that the count
1525 includes any files left over from other runs.
1527 #undef MagickCountTempFiles
1529 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
1530 const char *reference_filename,const char *output_filename,size_t *fail,
1531 ExceptionInfo *exception)
1534 #ifdef MagickCountTempFiles
1535 path[MaxTextExtent],
1536 SystemCommand[MaxTextExtent],
1538 size[MaxTextExtent];
1568 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
1570 #ifdef MagickCountTempFiles
1571 (void)GetPathTemplate(path);
1572 /* Remove file template except for the leading "/path/to/magick-" */
1573 path[strlen(path)-17]='\0';
1574 (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
1577 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1579 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1580 if ((magick_info == (const MagickInfo *) NULL) ||
1581 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1582 (magick_info->encoder == (EncodeImageHandler *) NULL))
1584 for (j=0; reference_types[j].type != UndefinedType; j++)
1587 Generate reference image.
1589 CatchException(exception);
1590 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1591 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1592 MagickCompressOptions,reference_formats[i].compression),
1593 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1594 (double) reference_types[j].depth);
1595 (void) CopyMagickString(image_info->filename,reference_filename,
1597 reference_image=ReadImage(image_info,exception);
1598 if (reference_image == (Image *) NULL ||
1599 exception->severity >= ErrorException)
1601 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1603 CatchException(exception);
1608 Write reference image.
1610 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
1611 (double) reference_image->columns,(double) reference_image->rows);
1612 (void) CloneString(&image_info->size,size);
1613 image_info->depth=reference_types[j].depth;
1614 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1615 reference_formats[i].magick,output_filename);
1616 status=SetImageType(reference_image,reference_types[j].type,exception);
1617 if (status == MagickFalse || exception->severity >= ErrorException)
1619 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1621 CatchException(exception);
1623 reference_image=DestroyImage(reference_image);
1626 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1627 if (status == MagickFalse || exception->severity >= ErrorException)
1629 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1631 CatchException(exception);
1633 reference_image=DestroyImage(reference_image);
1636 reference_image->compression=reference_formats[i].compression;
1637 status=WriteImage(image_info,reference_image,exception);
1638 reference_image=DestroyImage(reference_image);
1639 if (status == MagickFalse || exception->severity >= ErrorException)
1641 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1643 CatchException(exception);
1648 Ping reference image.
1650 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1651 reference_formats[i].magick,output_filename);
1652 ping_image=PingImage(image_info,exception);
1653 if (ping_image == (Image *) NULL ||
1654 exception->severity >= ErrorException)
1656 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1658 CatchException(exception);
1662 ping_image=DestroyImage(ping_image);
1664 Read reference image.
1666 reference_image=ReadImage(image_info,exception);
1667 if (reference_image == (Image *) NULL ||
1668 exception->severity >= ErrorException)
1670 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1672 CatchException(exception);
1677 Write reference image.
1679 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1680 reference_formats[i].magick,output_filename);
1681 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
1683 reference_image->depth=reference_types[j].depth;
1684 reference_image->compression=reference_formats[i].compression;
1686 blob=ImageToBlob(image_info,reference_image,&length,exception);
1687 if (blob == (unsigned char *) NULL ||
1688 exception->severity >= ErrorException)
1690 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1692 CatchException(exception);
1694 reference_image=DestroyImage(reference_image);
1698 Ping reference blob.
1700 ping_image=PingBlob(image_info,blob,length,exception);
1701 if (ping_image == (Image *) NULL ||
1702 exception->severity >= ErrorException)
1704 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1706 CatchException(exception);
1708 blob=(unsigned char *) RelinquishMagickMemory(blob);
1711 ping_image=DestroyImage(ping_image);
1713 Read reconstruct image.
1715 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1716 reference_formats[i].magick,output_filename);
1717 reconstruct_image=BlobToImage(image_info,blob,length,exception);
1718 blob=(unsigned char *) RelinquishMagickMemory(blob);
1719 if (reconstruct_image == (Image *) NULL ||
1720 exception->severity >= ErrorException)
1722 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1724 CatchException(exception);
1726 reference_image=DestroyImage(reference_image);
1730 Compare reference to reconstruct image.
1732 fuzz=0.003; /* grayscale */
1733 if (reference_formats[i].fuzz != 0.0)
1734 fuzz=reference_formats[i].fuzz;
1735 difference_image=CompareImages(reference_image,reconstruct_image,
1736 RootMeanSquaredErrorMetric,&distortion,exception);
1737 reconstruct_image=DestroyImage(reconstruct_image);
1738 reference_image=DestroyImage(reference_image);
1739 if (difference_image == (Image *) NULL ||
1740 exception->severity >= ErrorException)
1742 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1744 CatchException(exception);
1748 difference_image=DestroyImage(difference_image);
1749 if ((QuantumScale*distortion) > fuzz)
1751 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1752 QuantumScale*distortion);
1756 #ifdef MagickCountTempFiles
1757 (void) FormatLocaleFile(stdout,"... pass, ");
1758 (void) fflush(stdout);
1759 SystemCommand[0]='\0';
1760 (void) strncat(SystemCommand,"echo `ls ",9);
1761 (void) strncat(SystemCommand,path,MaxTextExtent-31);
1762 (void) strncat(SystemCommand,"* | wc -w` tmp files.",20);
1763 (void) system(SystemCommand);
1764 (void) fflush(stdout);
1766 (void) FormatLocaleFile(stdout,"... pass\n");
1770 (void) FormatLocaleFile(stdout,
1771 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1772 (double) (test-(*fail)),(double) *fail);
1777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1781 % 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 %
1785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1787 % ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
1788 % and returns the number of validation tests that passed and failed.
1790 % The format of the ValidateImageFormatsOnDisk method is:
1792 % size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1793 % const char *reference_filename,const char *output_filename,
1794 % size_t *fail,ExceptionInfo *exception)
1796 % A description of each parameter follows:
1798 % o image_info: the image info.
1800 % o reference_filename: the reference image filename.
1802 % o output_filename: the output image filename.
1804 % o fail: return the number of validation tests that pass.
1806 % o exception: return any errors or warnings in this structure.
1809 static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
1810 const char *reference_filename,const char *output_filename,size_t *fail,
1811 ExceptionInfo *exception)
1814 size[MaxTextExtent];
1839 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
1840 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1842 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1843 if ((magick_info == (const MagickInfo *) NULL) ||
1844 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1845 (magick_info->encoder == (EncodeImageHandler *) NULL))
1847 for (j=0; reference_types[j].type != UndefinedType; j++)
1850 Generate reference image.
1852 CatchException(exception);
1853 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1854 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
1855 MagickCompressOptions,reference_formats[i].compression),
1856 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
1857 (double) reference_types[j].depth);
1858 (void) CopyMagickString(image_info->filename,reference_filename,
1860 reference_image=ReadImage(image_info,exception);
1861 if (reference_image == (Image *) NULL ||
1862 exception->severity >= ErrorException)
1864 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1866 CatchException(exception);
1871 Write reference image.
1873 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
1874 (double) reference_image->columns,(double) reference_image->rows);
1875 (void) CloneString(&image_info->size,size);
1876 image_info->depth=reference_types[j].depth;
1877 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1878 reference_formats[i].magick,output_filename);
1879 status=SetImageType(reference_image,reference_types[j].type,exception);
1880 if (status == MagickFalse || exception->severity >= ErrorException)
1882 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1884 CatchException(exception);
1886 reference_image=DestroyImage(reference_image);
1889 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
1890 if (status == MagickFalse || exception->severity >= ErrorException)
1892 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1894 CatchException(exception);
1896 reference_image=DestroyImage(reference_image);
1899 reference_image->compression=reference_formats[i].compression;
1900 status=WriteImage(image_info,reference_image,exception);
1901 reference_image=DestroyImage(reference_image);
1902 if (status == MagickFalse || exception->severity >= ErrorException)
1904 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1906 CatchException(exception);
1911 Read reference image.
1913 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1914 reference_formats[i].magick,output_filename);
1915 reference_image=ReadImage(image_info,exception);
1916 if (reference_image == (Image *) NULL ||
1917 exception->severity >= ErrorException)
1919 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1921 CatchException(exception);
1926 Write reference image.
1928 (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
1929 reference_formats[i].magick,output_filename);
1930 reference_image->depth=reference_types[j].depth;
1931 reference_image->compression=reference_formats[i].compression;
1932 status=WriteImage(image_info,reference_image,exception);
1933 if (status == MagickFalse ||exception->severity >= ErrorException)
1935 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1937 CatchException(exception);
1939 reference_image=DestroyImage(reference_image);
1943 Read reconstruct image.
1945 (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
1946 reference_formats[i].magick,output_filename);
1947 reconstruct_image=ReadImage(image_info,exception);
1948 if (reconstruct_image == (Image *) NULL ||
1949 exception->severity >= ErrorException)
1951 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1953 CatchException(exception);
1955 reference_image=DestroyImage(reference_image);
1959 Compare reference to reconstruct image.
1961 fuzz=0.003; /* grayscale */
1962 if (reference_formats[i].fuzz != 0.0)
1963 fuzz=reference_formats[i].fuzz;
1964 difference_image=CompareImages(reference_image,reconstruct_image,
1965 RootMeanSquaredErrorMetric,&distortion,exception);
1966 reconstruct_image=DestroyImage(reconstruct_image);
1967 reference_image=DestroyImage(reference_image);
1968 if (difference_image == (Image *) NULL ||
1969 exception->severity >= ErrorException)
1971 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1973 CatchException(exception);
1977 difference_image=DestroyImage(difference_image);
1978 if ((QuantumScale*distortion) > fuzz)
1980 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
1981 QuantumScale*distortion);
1985 (void) FormatLocaleFile(stdout,"... pass.\n");
1988 (void) FormatLocaleFile(stdout,
1989 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1990 (double) (test-(*fail)),(double) *fail);
1995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % 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 %
2003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 % ValidateImportExportPixels() validates the pixel import and export methods.
2006 % It returns the number of validation tests that passed and failed.
2008 % The format of the ValidateImportExportPixels method is:
2010 % size_t ValidateImportExportPixels(ImageInfo *image_info,
2011 % const char *reference_filename,const char *output_filename,
2012 % size_t *fail,ExceptionInfo *exception)
2014 % A description of each parameter follows:
2016 % o image_info: the image info.
2018 % o reference_filename: the reference image filename.
2020 % o output_filename: the output image filename.
2022 % o fail: return the number of validation tests that pass.
2024 % o exception: return any errors or warnings in this structure.
2027 static size_t ValidateImportExportPixels(ImageInfo *image_info,
2028 const char *reference_filename,const char *output_filename,size_t *fail,
2029 ExceptionInfo *exception)
2055 (void) output_filename;
2057 (void) FormatLocaleFile(stdout,
2058 "validate the import and export of image pixels:\n");
2059 for (i=0; reference_map[i] != (char *) NULL; i++)
2061 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
2064 Generate reference image.
2066 CatchException(exception);
2067 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
2068 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
2069 reference_storage[j].type));
2070 (void) CopyMagickString(image_info->filename,reference_filename,
2072 reference_image=ReadImage(image_info,exception);
2073 if (reference_image == (Image *) NULL ||
2074 exception->severity >= ErrorException)
2076 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2078 CatchException(exception);
2082 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
2083 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
2084 length=strlen(reference_map[i])*reference_image->columns*
2085 reference_image->rows*reference_storage[j].quantum;
2086 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
2087 if (pixels == (unsigned char *) NULL ||
2088 exception->severity >= ErrorException)
2090 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2092 CatchException(exception);
2094 reference_image=DestroyImage(reference_image);
2097 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
2098 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
2099 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
2101 if (status == MagickFalse || exception->severity >= ErrorException)
2103 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2105 CatchException(exception);
2107 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2108 reference_image=DestroyImage(reference_image);
2111 (void) SetImageBackgroundColor(reference_image,exception);
2112 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
2113 reference_image->rows,reference_map[i],reference_storage[j].type,
2115 if (status == MagickFalse || exception->severity >= ErrorException)
2117 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2119 CatchException(exception);
2121 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2122 reference_image=DestroyImage(reference_image);
2126 Read reconstruct image.
2128 reconstruct_image=AcquireImage(image_info,exception);
2129 (void) SetImageExtent(reconstruct_image,reference_image->columns,
2130 reference_image->rows,exception);
2131 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
2133 (void) SetImageBackgroundColor(reconstruct_image,exception);
2134 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
2135 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
2137 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2138 if (status == MagickFalse || exception->severity >= ErrorException)
2140 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2142 CatchException(exception);
2144 reference_image=DestroyImage(reference_image);
2148 Compare reference to reconstruct image.
2150 difference_image=CompareImages(reference_image,reconstruct_image,
2151 RootMeanSquaredErrorMetric,&distortion,exception);
2152 reconstruct_image=DestroyImage(reconstruct_image);
2153 reference_image=DestroyImage(reference_image);
2154 if (difference_image == (Image *) NULL ||
2155 exception->severity >= ErrorException)
2157 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2159 CatchException(exception);
2163 difference_image=DestroyImage(difference_image);
2164 if ((QuantumScale*distortion) > 0.0)
2166 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
2167 QuantumScale*distortion);
2171 (void) FormatLocaleFile(stdout,"... pass.\n");
2174 (void) FormatLocaleFile(stdout,
2175 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2176 (double) (test-(*fail)),(double) *fail);
2181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2185 % V a l i d a t e M o n t a g e C o m m a n d %
2189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2191 % ValidateMontageCommand() validates the ImageMagick montage command line
2192 % program and returns the number of validation tests that passed and failed.
2194 % The format of the ValidateMontageCommand method is:
2196 % size_t ValidateMontageCommand(ImageInfo *image_info,
2197 % const char *reference_filename,const char *output_filename,
2198 % size_t *fail,ExceptionInfo *exception)
2200 % A description of each parameter follows:
2202 % o image_info: the image info.
2204 % o reference_filename: the reference image filename.
2206 % o output_filename: the output image filename.
2208 % o fail: return the number of validation tests that pass.
2210 % o exception: return any errors or warnings in this structure.
2213 static size_t ValidateMontageCommand(ImageInfo *image_info,
2214 const char *reference_filename,const char *output_filename,size_t *fail,
2215 ExceptionInfo *exception)
2219 command[MaxTextExtent];
2235 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
2236 for (i=0; montage_options[i] != (char *) NULL; i++)
2238 CatchException(exception);
2239 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2240 montage_options[i]);
2241 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
2242 reference_filename,montage_options[i],reference_filename,
2244 arguments=StringToArgv(command,&number_arguments);
2245 if (arguments == (char **) NULL)
2247 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2252 status=MontageImageCommand(image_info,number_arguments,arguments,
2253 (char **) NULL,exception);
2254 for (j=0; j < (ssize_t) number_arguments; j++)
2255 arguments[j]=DestroyString(arguments[j]);
2256 arguments=(char **) RelinquishMagickMemory(arguments);
2257 if (status == MagickFalse)
2259 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2264 (void) FormatLocaleFile(stdout,"... pass.\n");
2266 (void) FormatLocaleFile(stdout,
2267 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2268 (double) (test-(*fail)),(double) *fail);
2273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2277 % V a l i d a t e S t r e a m C o m m a n d %
2281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2283 % ValidateStreamCommand() validates the ImageMagick stream command line
2284 % program and returns the number of validation tests that passed and failed.
2286 % The format of the ValidateStreamCommand method is:
2288 % size_t ValidateStreamCommand(ImageInfo *image_info,
2289 % const char *reference_filename,const char *output_filename,
2290 % size_t *fail,ExceptionInfo *exception)
2292 % A description of each parameter follows:
2294 % o image_info: the image info.
2296 % o reference_filename: the reference image filename.
2298 % o output_filename: the output image filename.
2300 % o fail: return the number of validation tests that pass.
2302 % o exception: return any errors or warnings in this structure.
2305 static size_t ValidateStreamCommand(ImageInfo *image_info,
2306 const char *reference_filename,const char *output_filename,size_t *fail,
2307 ExceptionInfo *exception)
2311 command[MaxTextExtent];
2327 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
2328 for (i=0; stream_options[i] != (char *) NULL; i++)
2330 CatchException(exception);
2331 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
2333 (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
2334 stream_options[i],reference_filename,output_filename);
2335 arguments=StringToArgv(command,&number_arguments);
2336 if (arguments == (char **) NULL)
2338 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2343 status=StreamImageCommand(image_info,number_arguments,arguments,
2344 (char **) NULL,exception);
2345 for (j=0; j < (ssize_t) number_arguments; j++)
2346 arguments[j]=DestroyString(arguments[j]);
2347 arguments=(char **) RelinquishMagickMemory(arguments);
2348 if (status == MagickFalse)
2350 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2355 (void) FormatLocaleFile(stdout,"... pass.\n");
2357 (void) FormatLocaleFile(stdout,
2358 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2359 (double) (test-(*fail)),(double) *fail);
2364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2377 static MagickBooleanType ValidateUsage(void)
2385 "-debug events display copious debugging information",
2386 "-help print program options",
2387 "-log format format of debugging information",
2388 "-validate type validation type",
2389 "-version print version information",
2394 "-regard-warnings pay attention to warning messages",
2395 "-verbose print detailed information about the image",
2399 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
2400 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
2401 (void) printf("Features: %s\n",GetMagickFeatures());
2402 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
2403 (void) printf("\nValidate Settings:\n");
2404 for (p=settings; *p != (char *) NULL; p++)
2405 (void) printf(" %s\n",*p);
2406 (void) printf("\nMiscellaneous Options:\n");
2407 for (p=miscellaneous; *p != (char *) NULL; p++)
2408 (void) printf(" %s\n",*p);
2412 int main(int argc,char **argv)
2414 #define DestroyValidate() \
2416 image_info=DestroyImageInfo(image_info); \
2417 exception=DestroyExceptionInfo(exception); \
2419 #define ThrowValidateException(asperity,tag,option) \
2421 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
2423 CatchException(exception); \
2424 DestroyValidate(); \
2425 return(MagickFalse); \
2429 output_filename[MaxTextExtent],
2430 reference_filename[MaxTextExtent],
2469 Validate the ImageMagick image processing suite.
2471 MagickCoreGenesis(*argv,MagickTrue);
2472 (void) setlocale(LC_ALL,"");
2473 (void) setlocale(LC_NUMERIC,"C");
2477 regard_warnings=MagickFalse;
2478 (void) regard_warnings;
2479 exception=AcquireExceptionInfo();
2480 image_info=AcquireImageInfo();
2481 (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
2482 for (i=1; i < (ssize_t) argc; i++)
2485 if (IsCommandOption(option) == MagickFalse)
2487 (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
2490 switch (*(option+1))
2494 if (LocaleCompare("bench",option+1) == 0)
2496 iterations=StringToUnsignedLong(argv[++i]);
2499 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2503 if (LocaleCompare("debug",option+1) == 0)
2505 (void) SetLogEventMask(argv[++i]);
2508 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2512 if (LocaleCompare("help",option+1) == 0)
2514 (void) ValidateUsage();
2517 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2521 if (LocaleCompare("log",option+1) == 0)
2524 (void) SetLogFormat(argv[i+1]);
2527 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2531 if (LocaleCompare("regard-warnings",option+1) == 0)
2533 regard_warnings=MagickTrue;
2536 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2540 if (LocaleCompare("validate",option+1) == 0)
2548 if (i >= (ssize_t) argc)
2549 ThrowValidateException(OptionError,"MissingArgument",option);
2550 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
2553 ThrowValidateException(OptionError,"UnrecognizedValidateType",
2555 type=(ValidateType) validate;
2558 if ((LocaleCompare("version",option+1) == 0) ||
2559 (LocaleCompare("-version",option+1) == 0))
2561 (void) FormatLocaleFile(stdout,"Version: %s\n",
2562 GetMagickVersion((size_t *) NULL));
2563 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2564 GetMagickCopyright());
2565 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
2566 GetMagickFeatures());
2569 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2572 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2575 timer=(TimerInfo *) NULL;
2577 timer=AcquireTimerInfo();
2578 reference_image=ReadImage(image_info,exception);
2581 if (reference_image == (Image *) NULL)
2585 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
2586 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
2588 (void) AcquireUniqueFilename(reference_filename);
2589 (void) AcquireUniqueFilename(output_filename);
2590 (void) CopyMagickString(reference_image->filename,reference_filename,
2592 status=WriteImage(image_info,reference_image,exception);
2593 reference_image=DestroyImage(reference_image);
2594 if (status == MagickFalse)
2598 (void) FormatLocaleFile(stdout,"Version: %s\n",
2599 GetMagickVersion((size_t *) NULL));
2600 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2601 GetMagickCopyright());
2602 (void) FormatLocaleFile(stdout,
2603 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
2604 MagickValidateOptions,(ssize_t) type));
2605 if ((type & ColorspaceValidate) != 0)
2606 tests+=ValidateColorspaces(image_info,&fail,exception);
2607 if ((type & CompareValidate) != 0)
2608 tests+=ValidateCompareCommand(image_info,reference_filename,
2609 output_filename,&fail,exception);
2610 if ((type & CompositeValidate) != 0)
2611 tests+=ValidateCompositeCommand(image_info,reference_filename,
2612 output_filename,&fail,exception);
2613 if ((type & ConvertValidate) != 0)
2614 tests+=ValidateConvertCommand(image_info,reference_filename,
2615 output_filename,&fail,exception);
2616 if ((type & FormatsDiskValidate) != 0)
2618 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2619 map_resource=SetMagickResourceLimit(MapResource,0);
2620 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2621 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2622 output_filename,&fail,exception);
2623 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
2624 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2625 output_filename,&fail,exception);
2626 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2627 (void) SetMagickResourceLimit(MapResource,map_resource);
2629 if ((type & FormatsMapValidate) != 0)
2631 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2632 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2633 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2634 output_filename,&fail,exception);
2635 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2636 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2637 output_filename,&fail,exception);
2638 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2640 if ((type & FormatsMemoryValidate) != 0)
2642 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2643 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2644 output_filename,&fail,exception);
2645 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2646 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2647 output_filename,&fail,exception);
2649 if ((type & IdentifyValidate) != 0)
2650 tests+=ValidateIdentifyCommand(image_info,reference_filename,
2651 output_filename,&fail,exception);
2652 if ((type & ImportExportValidate) != 0)
2653 tests+=ValidateImportExportPixels(image_info,reference_filename,
2654 output_filename,&fail,exception);
2655 if ((type & MontageValidate) != 0)
2656 tests+=ValidateMontageCommand(image_info,reference_filename,
2657 output_filename,&fail,exception);
2658 if ((type & StreamValidate) != 0)
2659 tests+=ValidateStreamCommand(image_info,reference_filename,
2660 output_filename,&fail,exception);
2661 (void) FormatLocaleFile(stdout,
2662 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
2663 (double) tests,(double) (tests-fail),(double) fail);
2665 (void) RelinquishUniqueFileResource(output_filename);
2666 (void) RelinquishUniqueFileResource(reference_filename);
2668 if (exception->severity != UndefinedException)
2669 CatchException(exception);
2672 elapsed_time=GetElapsedTime(timer);
2673 user_time=GetUserTime(timer);
2674 (void) FormatLocaleFile(stderr,
2675 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
2676 iterations,1.0*iterations/elapsed_time,user_time,(long)
2677 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
2678 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
2679 timer=DestroyTimerInfo(timer);
2682 MagickCoreTerminus();
2683 return(fail == 0 ? 0 : 1);