blob: 5ec4dce7e142954ef7b74707f39ea00c5c2c0bae [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% %
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 %
12% %
13% %
14% ImageMagick Validation Suite %
15% %
16% Software Design %
cristyde984cd2013-12-01 14:49:27 +000017% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000018% March 2001 %
19% %
20% %
Cristy7ce65e72015-12-12 18:03:16 -050021% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000022% dedicated to making software imaging solutions freely available. %
23% %
24% You may not use this file except in compliance with the License. You may %
25% obtain a copy of the License at %
26% %
27% http://www.imagemagick.org/script/license.php %
28% %
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. %
34% %
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
43#include <stdio.h>
cristy5e8e9812009-12-17 15:13:38 +000044#include <stdlib.h>
cristy3ed852e2009-09-05 21:47:34 +000045#include <string.h>
cristy5e8e9812009-12-17 15:13:38 +000046#include <ctype.h>
cristy3ed852e2009-09-05 21:47:34 +000047#include <math.h>
cristye2605742012-12-12 11:18:34 +000048#include <locale.h>
cristy9883b452011-07-01 23:37:21 +000049#include "MagickWand/MagickWand.h"
cristy510d06a2011-07-06 23:43:54 +000050#include "MagickCore/colorspace-private.h"
dirk775194c2014-05-17 19:47:54 +000051#include "MagickCore/gem.h"
glennrp4084cda2012-12-11 14:13:35 +000052#include "MagickCore/resource_.h"
cristy9883b452011-07-01 23:37:21 +000053#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000054#include "validate.h"
55
56/*
cristy8d24e062013-05-07 12:48:19 +000057 Define declarations.
58*/
59#define CIEEpsilon (216.0/24389.0)
60#define CIEK (24389.0/27.0)
61#define D65X 0.950456
62#define D65Y 1.0
63#define D65Z 1.088754
cristya7230ee2013-07-25 11:51:29 +000064#define ReferenceEpsilon (QuantumRange*1.0e-2)
cristy8d24e062013-05-07 12:48:19 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68% %
69% %
70% %
cristy572e0972013-05-07 12:51:28 +000071% V a l i d a t e C o l o r s p a c e s %
cristy80e870e2013-05-07 12:23:02 +000072% %
73% %
74% %
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76%
cristy572e0972013-05-07 12:51:28 +000077% ValidateColorspaces() validates the ImageMagick colorspaces and returns the
78% number of validation tests that passed and failed.
cristy80e870e2013-05-07 12:23:02 +000079%
cristy572e0972013-05-07 12:51:28 +000080% The format of the ValidateColorspaces method is:
cristy80e870e2013-05-07 12:23:02 +000081%
cristy572e0972013-05-07 12:51:28 +000082% size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
83% ExceptionInfo *exception)
cristy80e870e2013-05-07 12:23:02 +000084%
85% A description of each parameter follows:
86%
87% o image_info: the image info.
88%
cristy80e870e2013-05-07 12:23:02 +000089% o fail: return the number of validation tests that pass.
90%
91% o exception: return any errors or warnings in this structure.
92%
93*/
cristy8d24e062013-05-07 12:48:19 +000094
95static void ConvertHSIToRGB(const double hue,const double saturation,
96 const double intensity,double *red,double *green,double *blue)
97{
98 double
99 h;
100
cristy8d24e062013-05-07 12:48:19 +0000101 h=360.0*hue;
102 h-=360.0*floor(h/360.0);
103 if (h < 120.0)
104 {
105 *blue=intensity*(1.0-saturation);
106 *red=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
107 (MagickPI/180.0)));
108 *green=3.0*intensity-*red-*blue;
109 }
110 else
111 if (h < 240.0)
112 {
113 h-=120.0;
114 *red=intensity*(1.0-saturation);
115 *green=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
116 (MagickPI/180.0)));
117 *blue=3.0*intensity-*red-*green;
118 }
119 else
120 {
121 h-=240.0;
122 *green=intensity*(1.0-saturation);
123 *blue=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
124 (MagickPI/180.0)));
125 *red=3.0*intensity-*green-*blue;
126 }
127 *red*=QuantumRange;
128 *green*=QuantumRange;
129 *blue*=QuantumRange;
130}
131
cristy8d24e062013-05-07 12:48:19 +0000132static void ConvertRGBToHSI(const double red,const double green,
133 const double blue,double *hue,double *saturation,double *intensity)
134{
135 double
136 alpha,
137 beta;
138
cristy8d24e062013-05-07 12:48:19 +0000139 *intensity=(QuantumScale*red+QuantumScale*green+QuantumScale*blue)/3.0;
140 if (*intensity <= 0.0)
141 {
142 *hue=0.0;
143 *saturation=0.0;
144 return;
145 }
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;
151 if (*hue < 0.0)
152 *hue+=1.0;
153}
154
cristy8d24e062013-05-07 12:48:19 +0000155static void ConvertHSVToRGB(const double hue,const double saturation,
156 const double value,double *red,double *green,double *blue)
157{
158 double
159 c,
160 h,
161 min,
162 x;
163
cristy8d24e062013-05-07 12:48:19 +0000164 h=hue*360.0;
165 c=value*saturation;
166 min=value-c;
167 h-=360.0*floor(h/360.0);
168 h/=60.0;
169 x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
170 switch ((int) floor(h))
171 {
172 case 0:
173 {
174 *red=QuantumRange*(min+c);
175 *green=QuantumRange*(min+x);
176 *blue=QuantumRange*min;
177 break;
178 }
179 case 1:
180 {
181 *red=QuantumRange*(min+x);
182 *green=QuantumRange*(min+c);
183 *blue=QuantumRange*min;
184 break;
185 }
186 case 2:
187 {
188 *red=QuantumRange*min;
189 *green=QuantumRange*(min+c);
190 *blue=QuantumRange*(min+x);
191 break;
192 }
193 case 3:
194 {
195 *red=QuantumRange*min;
196 *green=QuantumRange*(min+x);
197 *blue=QuantumRange*(min+c);
198 break;
199 }
200 case 4:
201 {
202 *red=QuantumRange*(min+x);
203 *green=QuantumRange*min;
204 *blue=QuantumRange*(min+c);
205 break;
206 }
207 case 5:
208 {
209 *red=QuantumRange*(min+c);
210 *green=QuantumRange*min;
211 *blue=QuantumRange*(min+x);
212 break;
213 }
214 default:
215 {
216 *red=0.0;
217 *green=0.0;
218 *blue=0.0;
219 }
220 }
221}
222
223static inline void ConvertRGBToXYZ(const double red,const double green,
224 const double blue,double *X,double *Y,double *Z)
225{
226 double
227 b,
228 g,
229 r;
230
cristy8d24e062013-05-07 12:48:19 +0000231 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;
237}
238
239static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
240 double *L,double *a,double *b)
241{
242 double
243 x,
244 y,
245 z;
246
247 if ((X/D65X) > CIEEpsilon)
248 x=pow(X/D65X,1.0/3.0);
249 else
250 x=(CIEK*X/D65X+16.0)/116.0;
251 if ((Y/D65Y) > CIEEpsilon)
252 y=pow(Y/D65Y,1.0/3.0);
253 else
254 y=(CIEK*Y/D65Y+16.0)/116.0;
255 if ((Z/D65Z) > CIEEpsilon)
256 z=pow(Z/D65Z,1.0/3.0);
257 else
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;
262}
263
264static void ConvertRGBToLab(const double red,const double green,
265 const double blue,double *L,double *a,double *b)
266{
267 double
268 X,
269 Y,
270 Z;
271
272 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
273 ConvertXYZToLab(X,Y,Z,L,a,b);
274}
275
276static inline void ConvertLabToXYZ(const double L,const double a,const double b,
277 double *X,double *Y,double *Z)
278{
279 double
280 x,
281 y,
282 z;
283
284 y=(L+16.0)/116.0;
285 x=y+a/500.0;
286 z=y-b/200.0;
287 if ((x*x*x) > CIEEpsilon)
288 x=(x*x*x);
289 else
290 x=(116.0*x-16.0)/CIEK;
291 if ((y*y*y) > CIEEpsilon)
292 y=(y*y*y);
293 else
294 y=L/CIEK;
295 if ((z*z*z) > CIEEpsilon)
296 z=(z*z*z);
297 else
298 z=(116.0*z-16.0)/CIEK;
299 *X=D65X*x;
300 *Y=D65Y*y;
301 *Z=D65Z*z;
302}
303
304static inline void ConvertXYZToRGB(const double x,const double y,const double z,
305 double *red,double *green,double *blue)
306{
307 double
308 b,
309 g,
310 r;
311
cristy8d24e062013-05-07 12:48:19 +0000312 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);
318}
319
320static inline void ConvertLabToRGB(const double L,const double a,
321 const double b,double *red,double *green,double *blue)
322{
323 double
324 X,
325 Y,
326 Z;
327
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);
330}
331
332static void ConvertRGBToYPbPr(const double red,const double green,
333 const double blue,double *Y,double *Pb,double *Pr)
334{
cristy8d24e062013-05-07 12:48:19 +0000335 *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;
338}
339
340static void ConvertRGBToYCbCr(const double red,const double green,
341 const double blue,double *Y,double *Cb,double *Cr)
342{
cristy8d24e062013-05-07 12:48:19 +0000343 ConvertRGBToYPbPr(red,green,blue,Y,Cb,Cr);
344}
345
346static void ConvertYPbPrToRGB(const double Y,const double Pb,const double Pr,
347 double *red,double *green,double *blue)
348{
cristy8d24e062013-05-07 12:48:19 +0000349 *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));
355}
356
357static void ConvertYCbCrToRGB(const double Y,const double Cb,
358 const double Cr,double *red,double *green,double *blue)
359{
cristy8d24e062013-05-07 12:48:19 +0000360 ConvertYPbPrToRGB(Y,Cb,Cr,red,green,blue);
361}
362
363static inline void ConvertLCHabToXYZ(const double luma,const double chroma,
364 const double hue,double *X,double *Y,double *Z)
365{
366 ConvertLabToXYZ(luma,chroma*cos(hue*MagickPI/180.0),chroma*
367 sin(hue*MagickPI/180.0),X,Y,Z);
368}
369
370static void ConvertLCHabToRGB(const double luma,const double chroma,
371 const double hue,double *red,double *green,double *blue)
372{
373 double
374 X,
375 Y,
376 Z;
377
cristy6d897c72013-06-19 19:20:40 +0000378 ConvertLCHabToXYZ(luma*100.0,255.0*(chroma-0.5),360.0*hue,&X,&Y,&Z);
cristy8d24e062013-05-07 12:48:19 +0000379 ConvertXYZToRGB(X,Y,Z,red,green,blue);
380}
381
382static void ConvertRGBToHSV(const double red,const double green,
383 const double blue,double *hue,double *saturation,double *value)
384{
385 double
386 c,
387 max,
388 min;
389
cristy8d24e062013-05-07 12:48:19 +0000390 max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
391 QuantumScale*blue));
392 min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
393 QuantumScale*blue));
394 c=max-min;
395 *value=max;
396 if (c <= 0.0)
397 {
398 *hue=0.0;
399 *saturation=0.0;
400 return;
401 }
402 if (max == (QuantumScale*red))
403 {
404 *hue=(QuantumScale*green-QuantumScale*blue)/c;
405 if ((QuantumScale*green) < (QuantumScale*blue))
406 *hue+=6.0;
407 }
408 else
409 if (max == (QuantumScale*green))
410 *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
411 else
412 *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
413 *hue*=60.0/360.0;
414 *saturation=c/max;
415}
416
417static inline void ConvertXYZToLCHab(const double X,const double Y,
418 const double Z,double *luma,double *chroma,double *hue)
419{
420 double
421 a,
422 b;
423
424 ConvertXYZToLab(X,Y,Z,luma,&a,&b);
cristy846740b2013-06-19 18:19:55 +0000425 *chroma=hypot(255.0*(a-0.5),255.0*(b-0.5))/255.0+0.5;
cristy6d897c72013-06-19 19:20:40 +0000426 *hue=180.0*atan2(255.0*(b-0.5),255.0*(a-0.5))/MagickPI/360.0;
cristy8d24e062013-05-07 12:48:19 +0000427 if (*hue < 0.0)
428 *hue+=1.0;
429}
430
431static void ConvertRGBToLCHab(const double red,const double green,
432 const double blue,double *luma,double *chroma,double *hue)
433{
434 double
435 X,
436 Y,
437 Z;
438
439 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
440 ConvertXYZToLCHab(X,Y,Z,luma,chroma,hue);
441}
442
443static inline void ConvertLMSToXYZ(const double L,const double M,const double S,
444 double *X,double *Y,double *Z)
445{
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;
449}
450
451static inline void ConvertLMSToRGB(const double L,const double M,
452 const double S,double *red,double *green,double *blue)
453{
454 double
455 X,
456 Y,
457 Z;
458
459 ConvertLMSToXYZ(L,M,S,&X,&Y,&Z);
460 ConvertXYZToRGB(X,Y,Z,red,green,blue);
461}
462
463static inline void ConvertXYZToLMS(const double x,const double y,
464 const double z,double *L,double *M,double *S)
465{
cristy8d24e062013-05-07 12:48:19 +0000466 *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;
469}
470
471static void ConvertRGBToLMS(const double red,const double green,
472 const double blue,double *L,double *M,double *S)
473{
474 double
475 X,
476 Y,
477 Z;
478
479 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
480 ConvertXYZToLMS(X,Y,Z,L,M,S);
481}
482
cristy8d24e062013-05-07 12:48:19 +0000483static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
484 double *L,double *u,double *v)
485{
486 double
487 alpha;
488
489 if ((Y/D65Y) > CIEEpsilon)
490 *L=(double) (116.0*pow(Y/D65Y,1.0/3.0)-16.0);
491 else
492 *L=CIEK*(Y/D65Y);
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)));
496 *L/=100.0;
497 *u=(*u+134.0)/354.0;
498 *v=(*v+140.0)/262.0;
499}
500
501static void ConvertRGBToLuv(const double red,const double green,
502 const double blue,double *L,double *u,double *v)
503{
504 double
505 X,
506 Y,
507 Z;
508
509 ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
510 ConvertXYZToLuv(X,Y,Z,L,u,v);
511}
512
513static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
514 double *X,double *Y,double *Z)
515{
516 if (L > (CIEK*CIEEpsilon))
517 *Y=(double) pow((L+16.0)/116.0,3.0);
518 else
519 *Y=L/CIEK;
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)/
522 3.0)-(-1.0/3.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))-
524 5.0*(*Y);
525}
526
527static inline void ConvertLuvToRGB(const double L,const double u,
528 const double v,double *red,double *green,double *blue)
529{
530 double
531 X,
532 Y,
533 Z;
534
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);
537}
538
539static void ConvertRGBToYDbDr(const double red,const double green,
540 const double blue,double *Y,double *Db,double *Dr)
541{
cristy8d24e062013-05-07 12:48:19 +0000542 *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;
545}
546
547static void ConvertYDbDrToRGB(const double Y,const double Db,const double Dr,
548 double *red,double *green,double *blue)
549{
cristy8d24e062013-05-07 12:48:19 +0000550 *red=QuantumRange*(Y+9.2303716147657e-05*(Db-0.5)-0.52591263066186533*
551 (Dr-0.5));
552 *green=QuantumRange*(Y-0.12913289889050927*(Db-0.5)+0.26789932820759876*
553 (Dr-0.5));
554 *blue=QuantumRange*(Y+0.66467905997895482*(Db-0.5)-7.9202543533108e-05*
555 (Dr-0.5));
556}
557
558static void ConvertRGBToYIQ(const double red,const double green,
559 const double blue,double *Y,double *I,double *Q)
560{
cristy8d24e062013-05-07 12:48:19 +0000561 *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;
564}
565
566static void ConvertYIQToRGB(const double Y,const double I,const double Q,
567 double *red,double *green,double *blue)
568{
cristy8d24e062013-05-07 12:48:19 +0000569 *red=QuantumRange*(Y+0.9562957197589482261*(I-0.5)+0.6210244164652610754*
570 (Q-0.5));
571 *green=QuantumRange*(Y-0.2721220993185104464*(I-0.5)-0.6473805968256950427*
572 (Q-0.5));
573 *blue=QuantumRange*(Y-1.1069890167364901945*(I-0.5)+1.7046149983646481374*
574 (Q-0.5));
575}
576
577static void ConvertRGBToYUV(const double red,const double green,
578 const double blue,double *Y,double *U,double *V)
579{
cristy8d24e062013-05-07 12:48:19 +0000580 *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;
583}
584
585static void ConvertYUVToRGB(const double Y,const double U,const double V,
586 double *red,double *green,double *blue)
587{
cristy8d24e062013-05-07 12:48:19 +0000588 *red=QuantumRange*(Y-3.945707070708279e-05*(U-0.5)+1.1398279671717170825*
589 (V-0.5));
590 *green=QuantumRange*(Y-0.3946101641414141437*(U-0.5)-0.5805003156565656797*
591 (V-0.5));
592 *blue=QuantumRange*(Y+2.0319996843434342537*(U-0.5)-4.813762626262513e-04*
593 (V-0.5));
594}
595
596static MagickBooleanType ValidateHSIToRGB()
597{
598 double
599 r,
600 g,
601 b;
602
cristyb8588ab2013-05-07 13:17:38 +0000603 (void) FormatLocaleFile(stdout," HSIToRGB");
cristy8d24e062013-05-07 12:48:19 +0000604 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))
608 return(MagickFalse);
609 return(MagickTrue);
610}
611
612static MagickBooleanType ValidateRGBToHSI()
613{
614 double
615 h,
616 i,
617 s;
618
cristyb8588ab2013-05-07 13:17:38 +0000619 (void) FormatLocaleFile(stdout," RGBToHSI");
cristy8d24e062013-05-07 12:48:19 +0000620 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))
625 return(MagickFalse);
626 return(MagickTrue);
627}
628
629static MagickBooleanType ValidateHSLToRGB()
630{
631 double
632 r,
633 g,
634 b;
635
cristyb8588ab2013-05-07 13:17:38 +0000636 (void) FormatLocaleFile(stdout," HSLToRGB");
cristy8d24e062013-05-07 12:48:19 +0000637 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))
641 return(MagickFalse);
642 return(MagickTrue);
643}
644
645static MagickBooleanType ValidateRGBToHSL()
646{
647 double
648 h,
649 l,
650 s;
651
cristyb8588ab2013-05-07 13:17:38 +0000652 (void) FormatLocaleFile(stdout," RGBToHSL");
cristy8d24e062013-05-07 12:48:19 +0000653 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))
658 return(MagickFalse);
659 return(MagickTrue);
660}
661
662static MagickBooleanType ValidateHSVToRGB()
663{
664 double
665 r,
666 g,
667 b;
668
cristyb8588ab2013-05-07 13:17:38 +0000669 (void) FormatLocaleFile(stdout," HSVToRGB");
cristy8d24e062013-05-07 12:48:19 +0000670 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))
674 return(MagickFalse);
675 return(MagickTrue);
676}
677
678static MagickBooleanType ValidateRGBToHSV()
679{
680 double
681 h,
682 s,
683 v;
684
cristyb8588ab2013-05-07 13:17:38 +0000685 (void) FormatLocaleFile(stdout," RGBToHSV");
cristy8d24e062013-05-07 12:48:19 +0000686 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))
691 return(MagickFalse);
692 return(MagickTrue);
693}
694
695static MagickBooleanType ValidateRGBToJPEGYCbCr()
696{
697 double
698 Cb,
699 Cr,
700 Y;
701
cristyb8588ab2013-05-07 13:17:38 +0000702 (void) FormatLocaleFile(stdout," RGBToJPEGYCbCr");
cristy8d24e062013-05-07 12:48:19 +0000703 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))
708 return(MagickFalse);
709 return(MagickTrue);
710}
711
712static MagickBooleanType ValidateJPEGYCbCrToRGB()
713{
714 double
715 r,
716 g,
717 b;
718
cristyb8588ab2013-05-07 13:17:38 +0000719 (void) FormatLocaleFile(stdout," JPEGYCbCrToRGB");
cristy8d24e062013-05-07 12:48:19 +0000720 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))
724 return(MagickFalse);
725 return(MagickTrue);
726}
727
728static MagickBooleanType ValidateLabToRGB()
729{
730 double
731 r,
732 g,
733 b;
734
cristyb8588ab2013-05-07 13:17:38 +0000735 (void) FormatLocaleFile(stdout," LabToRGB");
cristy8d24e062013-05-07 12:48:19 +0000736 ConvertLabToRGB(88.456154/100.0,-54.671483/255+0.5,51.662818/255.0+0.5,
737 &r,&g,&b);
738 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
739 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
740 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
741 return(MagickFalse);
742 return(MagickTrue);
743}
744
745static MagickBooleanType ValidateRGBToLab()
746{
747 double
748 a,
749 b,
750 L;
751
cristyb8588ab2013-05-07 13:17:38 +0000752 (void) FormatLocaleFile(stdout," RGBToLab");
cristy8d24e062013-05-07 12:48:19 +0000753 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))
758 return(MagickFalse);
759 return(MagickTrue);
760}
761
762static MagickBooleanType ValidateLchToRGB()
763{
764 double
765 b,
766 g,
767 r;
768
cristyb8588ab2013-05-07 13:17:38 +0000769 (void) FormatLocaleFile(stdout," LchToRGB");
cristya44ed132013-06-19 23:56:32 +0000770 ConvertLCHabToRGB(88.456154/100.0,75.219797/255.0+0.5,136.620717/360.0,
cristy8d24e062013-05-07 12:48:19 +0000771 &r,&g,&b);
772 if ((fabs(r-0.545877*QuantumRange) >= ReferenceEpsilon) ||
773 (fabs(g-0.966567*QuantumRange) >= ReferenceEpsilon) ||
774 (fabs(b-0.463759*QuantumRange) >= ReferenceEpsilon))
775 return(MagickFalse);
776 return(MagickTrue);
777}
778
779static MagickBooleanType ValidateRGBToLch()
780{
781 double
782 c,
783 h,
784 L;
785
cristyb8588ab2013-05-07 13:17:38 +0000786 (void) FormatLocaleFile(stdout," RGBToLch");
cristy8d24e062013-05-07 12:48:19 +0000787 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))
792 return(MagickFalse);
793 return(MagickTrue);
794}
795
796static MagickBooleanType ValidateRGBToLMS()
797{
798 double
799 L,
800 M,
801 S;
802
cristyb8588ab2013-05-07 13:17:38 +0000803 (void) FormatLocaleFile(stdout," RGBToLMS");
cristy8d24e062013-05-07 12:48:19 +0000804 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))
809 return(MagickFalse);
810 return(MagickTrue);
811}
812
813static MagickBooleanType ValidateLMSToRGB()
814{
815 double
816 r,
817 g,
818 b;
819
cristyb8588ab2013-05-07 13:17:38 +0000820 (void) FormatLocaleFile(stdout," LMSToRGB");
cristy8d24e062013-05-07 12:48:19 +0000821 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))
825 return(MagickFalse);
826 return(MagickTrue);
827}
828
829static MagickBooleanType ValidateRGBToLuv()
830{
831 double
832 l,
833 u,
834 v;
835
cristyb8588ab2013-05-07 13:17:38 +0000836 (void) FormatLocaleFile(stdout," RGBToLuv");
cristy8d24e062013-05-07 12:48:19 +0000837 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))
842 return(MagickFalse);
843 return(MagickTrue);
844}
845
846static MagickBooleanType ValidateLuvToRGB()
847{
848 double
849 r,
850 g,
851 b;
852
cristyb8588ab2013-05-07 13:17:38 +0000853 (void) FormatLocaleFile(stdout," LuvToRGB");
cristy8d24e062013-05-07 12:48:19 +0000854 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))
859 return(MagickFalse);
860 return(MagickTrue);
861}
862
863static MagickBooleanType ValidateRGBToXYZ()
864{
865 double
866 x,
867 y,
868 z;
869
cristyb8588ab2013-05-07 13:17:38 +0000870 (void) FormatLocaleFile(stdout," RGBToXYZ");
cristy8d24e062013-05-07 12:48:19 +0000871 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))
876 return(MagickFalse);
877 return(MagickTrue);
878}
879
880static MagickBooleanType ValidateXYZToRGB()
881{
882 double
883 r,
884 g,
885 b;
886
cristyb8588ab2013-05-07 13:17:38 +0000887 (void) FormatLocaleFile(stdout," XYZToRGB");
cristy8d24e062013-05-07 12:48:19 +0000888 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))
892 return(MagickFalse);
893 return(MagickTrue);
894}
895
896static MagickBooleanType ValidateYDbDrToRGB()
897{
898 double
899 r,
900 g,
901 b;
902
cristyb8588ab2013-05-07 13:17:38 +0000903 (void) FormatLocaleFile(stdout," YDbDrToRGB");
cristy8d24e062013-05-07 12:48:19 +0000904 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))
908 return(MagickFalse);
909 return(MagickTrue);
910}
911
912static MagickBooleanType ValidateRGBToYDbDr()
913{
914 double
915 Db,
916 Dr,
917 Y;
918
cristyb8588ab2013-05-07 13:17:38 +0000919 (void) FormatLocaleFile(stdout," RGBToYDbDr");
cristy8d24e062013-05-07 12:48:19 +0000920 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))
925 return(MagickFalse);
926 return(MagickTrue);
927}
928
929static MagickBooleanType ValidateRGBToYIQ()
930{
931 double
932 i,
933 q,
934 y;
935
cristyb8588ab2013-05-07 13:17:38 +0000936 (void) FormatLocaleFile(stdout," RGBToYIQ");
cristy8d24e062013-05-07 12:48:19 +0000937 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))
942 return(MagickFalse);
943 return(MagickTrue);
944}
945
946static MagickBooleanType ValidateYIQToRGB()
947{
948 double
949 r,
950 g,
951 b;
952
cristyb8588ab2013-05-07 13:17:38 +0000953 (void) FormatLocaleFile(stdout," YIQToRGB");
cristy8d24e062013-05-07 12:48:19 +0000954 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))
958 return(MagickFalse);
959 return(MagickTrue);
960}
961
962static MagickBooleanType ValidateRGBToYPbPr()
963{
964 double
cristy4ae2e762013-05-07 13:19:24 +0000965 Pb,
966 Pr,
cristy8d24e062013-05-07 12:48:19 +0000967 y;
968
cristyb8588ab2013-05-07 13:17:38 +0000969 (void) FormatLocaleFile(stdout," RGBToYPbPr");
cristy8d24e062013-05-07 12:48:19 +0000970 ConvertRGBToYPbPr(0.545877*QuantumRange,0.966567*QuantumRange,
cristy4ae2e762013-05-07 13:19:24 +0000971 0.463759*QuantumRange,&y,&Pb,&Pr);
cristy8d24e062013-05-07 12:48:19 +0000972 if ((fabs(y-0.783460) >= ReferenceEpsilon) ||
cristy4ae2e762013-05-07 13:19:24 +0000973 (fabs(Pb-(-0.180419)) >= ReferenceEpsilon) ||
974 (fabs(Pr-(-0.169461)) >= ReferenceEpsilon))
cristy8d24e062013-05-07 12:48:19 +0000975 return(MagickFalse);
976 return(MagickTrue);
977}
978
979static MagickBooleanType ValidateYPbPrToRGB()
980{
981 double
982 r,
983 g,
984 b;
985
cristyb8588ab2013-05-07 13:17:38 +0000986 (void) FormatLocaleFile(stdout," YPbPrToRGB");
cristy8d24e062013-05-07 12:48:19 +0000987 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))
991 return(MagickFalse);
992 return(MagickTrue);
993}
994
995static MagickBooleanType ValidateRGBToYUV()
996{
997 double
998 U,
999 V,
1000 Y;
1001
cristyb8588ab2013-05-07 13:17:38 +00001002 (void) FormatLocaleFile(stdout," RGBToYUV");
cristy8d24e062013-05-07 12:48:19 +00001003 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);
1009 return(MagickTrue);
1010}
1011
1012static MagickBooleanType ValidateYUVToRGB()
1013{
1014 double
1015 r,
1016 g,
1017 b;
1018
cristyb8588ab2013-05-07 13:17:38 +00001019 (void) FormatLocaleFile(stdout," YUVToRGB");
cristy8d24e062013-05-07 12:48:19 +00001020 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);
1025 return(MagickTrue);
1026}
1027
cristy572e0972013-05-07 12:51:28 +00001028static size_t ValidateColorspaces(ImageInfo *image_info,size_t *fail,
cristy80e870e2013-05-07 12:23:02 +00001029 ExceptionInfo *exception)
1030{
1031 MagickBooleanType
1032 status;
1033
cristy80e870e2013-05-07 12:23:02 +00001034 size_t
1035 test;
1036
cristy8d24e062013-05-07 12:48:19 +00001037 /*
cristy92e5cea2013-05-08 12:24:12 +00001038 Reference: https://code.google.com/p/chroma.
cristy8d24e062013-05-07 12:48:19 +00001039
1040 Illuminant = D65
1041 Observer = 2° (1931)
1042
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
cristy8d24e062013-05-07 12:48:19 +00001058 */
cristy80e870e2013-05-07 12:23:02 +00001059 (void) FormatLocaleFile(stdout,"validate colorspaces:\n");
cristy8d24e062013-05-07 12:48:19 +00001060 for (test=0; test < 26; test++)
1061 {
1062 CatchException(exception);
1063 (void) FormatLocaleFile(stdout," test %.20g: ",(double) test);
1064 switch (test)
cristy80e870e2013-05-07 12:23:02 +00001065 {
cristy8d24e062013-05-07 12:48:19 +00001066 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;
cristy80e870e2013-05-07 12:23:02 +00001093 }
cristyb8588ab2013-05-07 13:17:38 +00001094 if (status == MagickFalse)
cristy8d24e062013-05-07 12:48:19 +00001095 {
1096 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1097 GetMagickModule());
1098 (*fail)++;
1099 continue;
1100 }
1101 (void) FormatLocaleFile(stdout,"... pass.\n");
1102 }
cristy80e870e2013-05-07 12:23:02 +00001103 (void) FormatLocaleFile(stdout,
1104 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1105 (double) (test-(*fail)),(double) *fail);
1106 return(test);
1107}
1108
1109/*
1110%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111% %
1112% %
1113% %
cristy3ed852e2009-09-05 21:47:34 +00001114% V a l i d a t e C o m p a r e C o m m a n d %
1115% %
1116% %
1117% %
1118%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1119%
1120% ValidateCompareCommand() validates the ImageMagick compare command line
1121% program and returns the number of validation tests that passed and failed.
1122%
1123% The format of the ValidateCompareCommand method is:
1124%
cristybb503372010-05-27 20:51:26 +00001125% size_t ValidateCompareCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001126% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001127% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001128%
1129% A description of each parameter follows:
1130%
1131% o image_info: the image info.
1132%
1133% o reference_filename: the reference image filename.
1134%
1135% o output_filename: the output image filename.
1136%
1137% o fail: return the number of validation tests that pass.
1138%
1139% o exception: return any errors or warnings in this structure.
1140%
1141*/
cristybb503372010-05-27 20:51:26 +00001142static size_t ValidateCompareCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001143 const char *reference_filename,const char *output_filename,size_t *fail,
1144 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001145{
1146 char
1147 **arguments,
cristy151b66d2015-04-15 10:50:31 +00001148 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001149
1150 int
1151 number_arguments;
1152
1153 MagickBooleanType
1154 status;
1155
cristybb503372010-05-27 20:51:26 +00001156 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001157 i,
1158 j;
1159
cristybb503372010-05-27 20:51:26 +00001160 size_t
cristy3ed852e2009-09-05 21:47:34 +00001161 test;
1162
1163 test=0;
cristyb51dff52011-05-19 16:55:47 +00001164 (void) FormatLocaleFile(stdout,"validate compare command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00001165 for (i=0; compare_options[i] != (char *) NULL; i++)
1166 {
1167 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00001168 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +00001169 compare_options[i]);
cristy151b66d2015-04-15 10:50:31 +00001170 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00001171 compare_options[i],reference_filename,reference_filename,output_filename);
1172 arguments=StringToArgv(command,&number_arguments);
1173 if (arguments == (char **) NULL)
1174 {
cristy1e604812011-05-19 18:07:50 +00001175 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1176 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001177 (*fail)++;
1178 continue;
1179 }
cristy8a9106f2011-07-05 14:39:26 +00001180 status=CompareImagesCommand(image_info,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +00001181 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00001182 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00001183 arguments[j]=DestroyString(arguments[j]);
1184 arguments=(char **) RelinquishMagickMemory(arguments);
cristy35892192014-05-26 12:04:36 +00001185 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001186 {
cristy1e604812011-05-19 18:07:50 +00001187 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1188 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001189 (*fail)++;
1190 continue;
1191 }
cristyb51dff52011-05-19 16:55:47 +00001192 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001193 }
cristyb51dff52011-05-19 16:55:47 +00001194 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001195 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1196 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001197 return(test);
1198}
1199
1200/*
1201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1202% %
1203% %
1204% %
1205% V a l i d a t e C o m p o s i t e C o m m a n d %
1206% %
1207% %
1208% %
1209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1210%
1211% ValidateCompositeCommand() validates the ImageMagick composite command line
1212% program and returns the number of validation tests that passed and failed.
1213%
1214% The format of the ValidateCompositeCommand method is:
1215%
cristybb503372010-05-27 20:51:26 +00001216% size_t ValidateCompositeCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001217% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001218% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001219%
1220% A description of each parameter follows:
1221%
1222% o image_info: the image info.
1223%
1224% o reference_filename: the reference image filename.
1225%
1226% o output_filename: the output image filename.
1227%
1228% o fail: return the number of validation tests that pass.
1229%
1230% o exception: return any errors or warnings in this structure.
1231%
1232*/
cristybb503372010-05-27 20:51:26 +00001233static size_t ValidateCompositeCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001234 const char *reference_filename,const char *output_filename,size_t *fail,
1235 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001236{
1237 char
1238 **arguments,
cristy151b66d2015-04-15 10:50:31 +00001239 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001240
1241 int
1242 number_arguments;
1243
1244 MagickBooleanType
1245 status;
1246
cristybb503372010-05-27 20:51:26 +00001247 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001248 i,
1249 j;
1250
cristybb503372010-05-27 20:51:26 +00001251 size_t
cristy3ed852e2009-09-05 21:47:34 +00001252 test;
1253
1254 test=0;
cristyb51dff52011-05-19 16:55:47 +00001255 (void) FormatLocaleFile(stdout,"validate composite command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00001256 for (i=0; composite_options[i] != (char *) NULL; i++)
1257 {
1258 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00001259 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +00001260 composite_options[i]);
cristy151b66d2015-04-15 10:50:31 +00001261 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00001262 reference_filename,composite_options[i],reference_filename,
1263 output_filename);
1264 arguments=StringToArgv(command,&number_arguments);
1265 if (arguments == (char **) NULL)
1266 {
cristy1e604812011-05-19 18:07:50 +00001267 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1268 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001269 (*fail)++;
1270 continue;
1271 }
1272 status=CompositeImageCommand(image_info,number_arguments,arguments,
1273 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00001274 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00001275 arguments[j]=DestroyString(arguments[j]);
1276 arguments=(char **) RelinquishMagickMemory(arguments);
cristy35892192014-05-26 12:04:36 +00001277 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001278 {
cristy1e604812011-05-19 18:07:50 +00001279 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1280 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001281 (*fail)++;
1282 continue;
1283 }
cristyb51dff52011-05-19 16:55:47 +00001284 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001285 }
cristyb51dff52011-05-19 16:55:47 +00001286 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001287 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1288 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001289 return(test);
1290}
1291
1292/*
1293%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1294% %
1295% %
1296% %
1297% V a l i d a t e C o n v e r t C o m m a n d %
1298% %
1299% %
1300% %
1301%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1302%
1303% ValidateConvertCommand() validates the ImageMagick convert command line
1304% program and returns the number of validation tests that passed and failed.
1305%
1306% The format of the ValidateConvertCommand method is:
1307%
cristybb503372010-05-27 20:51:26 +00001308% size_t ValidateConvertCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001309% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001310% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001311%
1312% A description of each parameter follows:
1313%
1314% o image_info: the image info.
1315%
1316% o reference_filename: the reference image filename.
1317%
1318% o output_filename: the output image filename.
1319%
1320% o fail: return the number of validation tests that pass.
1321%
1322% o exception: return any errors or warnings in this structure.
1323%
1324*/
cristybb503372010-05-27 20:51:26 +00001325static size_t ValidateConvertCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001326 const char *reference_filename,const char *output_filename,size_t *fail,
1327 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001328{
1329 char
1330 **arguments,
cristy151b66d2015-04-15 10:50:31 +00001331 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001332
1333 int
1334 number_arguments;
1335
1336 MagickBooleanType
1337 status;
1338
cristybb503372010-05-27 20:51:26 +00001339 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001340 i,
1341 j;
1342
cristybb503372010-05-27 20:51:26 +00001343 size_t
cristy3ed852e2009-09-05 21:47:34 +00001344 test;
1345
1346 test=0;
cristyb51dff52011-05-19 16:55:47 +00001347 (void) FormatLocaleFile(stdout,"validate convert command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00001348 for (i=0; convert_options[i] != (char *) NULL; i++)
1349 {
1350 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00001351 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
cristy6aa47ad2010-05-28 19:32:32 +00001352 convert_options[i]);
cristy151b66d2015-04-15 10:50:31 +00001353 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00001354 reference_filename,convert_options[i],reference_filename,output_filename);
1355 arguments=StringToArgv(command,&number_arguments);
1356 if (arguments == (char **) NULL)
1357 {
cristy1e604812011-05-19 18:07:50 +00001358 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1359 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001360 (*fail)++;
1361 continue;
1362 }
1363 status=ConvertImageCommand(image_info,number_arguments,arguments,
1364 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00001365 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00001366 arguments[j]=DestroyString(arguments[j]);
1367 arguments=(char **) RelinquishMagickMemory(arguments);
cristy35892192014-05-26 12:04:36 +00001368 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001369 {
cristy1e604812011-05-19 18:07:50 +00001370 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1371 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001372 (*fail)++;
1373 continue;
1374 }
cristyb51dff52011-05-19 16:55:47 +00001375 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001376 }
cristyb51dff52011-05-19 16:55:47 +00001377 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001378 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1379 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001380 return(test);
1381}
1382
1383/*
1384%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1385% %
1386% %
1387% %
1388% V a l i d a t e I d e n t i f y C o m m a n d %
1389% %
1390% %
1391% %
1392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393%
1394% ValidateIdentifyCommand() validates the ImageMagick identify command line
1395% program and returns the number of validation tests that passed and failed.
1396%
1397% The format of the ValidateIdentifyCommand method is:
1398%
cristybb503372010-05-27 20:51:26 +00001399% size_t ValidateIdentifyCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001400% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001401% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001402%
1403% A description of each parameter follows:
1404%
1405% o image_info: the image info.
1406%
1407% o reference_filename: the reference image filename.
1408%
1409% o output_filename: the output image filename.
1410%
1411% o fail: return the number of validation tests that pass.
1412%
1413% o exception: return any errors or warnings in this structure.
1414%
1415*/
cristybb503372010-05-27 20:51:26 +00001416static size_t ValidateIdentifyCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001417 const char *reference_filename,const char *output_filename,size_t *fail,
1418 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001419{
1420 char
1421 **arguments,
cristy151b66d2015-04-15 10:50:31 +00001422 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001423
1424 int
1425 number_arguments;
1426
1427 MagickBooleanType
1428 status;
1429
cristybb503372010-05-27 20:51:26 +00001430 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001431 i,
1432 j;
1433
cristybb503372010-05-27 20:51:26 +00001434 size_t
cristy3ed852e2009-09-05 21:47:34 +00001435 test;
1436
1437 (void) output_filename;
1438 test=0;
cristyb51dff52011-05-19 16:55:47 +00001439 (void) FormatLocaleFile(stdout,"validate identify command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00001440 for (i=0; identify_options[i] != (char *) NULL; i++)
1441 {
1442 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00001443 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) test++,
cristy6aa47ad2010-05-28 19:32:32 +00001444 identify_options[i]);
cristy151b66d2015-04-15 10:50:31 +00001445 (void) FormatLocaleString(command,MagickPathExtent,"%s %s",
cristy3ed852e2009-09-05 21:47:34 +00001446 identify_options[i],reference_filename);
1447 arguments=StringToArgv(command,&number_arguments);
1448 if (arguments == (char **) NULL)
1449 {
cristy1e604812011-05-19 18:07:50 +00001450 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1451 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001452 (*fail)++;
1453 continue;
1454 }
1455 status=IdentifyImageCommand(image_info,number_arguments,arguments,
1456 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00001457 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00001458 arguments[j]=DestroyString(arguments[j]);
1459 arguments=(char **) RelinquishMagickMemory(arguments);
cristy35892192014-05-26 12:04:36 +00001460 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001461 {
cristy1e604812011-05-19 18:07:50 +00001462 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1463 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00001464 (*fail)++;
1465 continue;
1466 }
cristyb51dff52011-05-19 16:55:47 +00001467 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001468 }
cristyb51dff52011-05-19 16:55:47 +00001469 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001470 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1471 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001472 return(test);
1473}
1474
1475/*
1476%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1477% %
1478% %
1479% %
1480% 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 %
1481% %
1482% %
1483% %
1484%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1485%
1486% ValidateImageFormatsInMemory() validates the ImageMagick image formats in
1487% memory and returns the number of validation tests that passed and failed.
1488%
1489% The format of the ValidateImageFormatsInMemory method is:
1490%
cristybb503372010-05-27 20:51:26 +00001491% size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001492% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001493% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001494%
1495% A description of each parameter follows:
1496%
1497% o image_info: the image info.
1498%
1499% o reference_filename: the reference image filename.
1500%
1501% o output_filename: the output image filename.
1502%
1503% o fail: return the number of validation tests that pass.
1504%
1505% o exception: return any errors or warnings in this structure.
1506%
1507*/
glennrp4084cda2012-12-11 14:13:35 +00001508
cristy725833f2012-12-13 17:40:53 +00001509/*
1510 Enable this to count remaining $TMPDIR/magick-* files. Note that the count
1511 includes any files left over from other runs.
1512*/
1513#undef MagickCountTempFiles
glennrp4084cda2012-12-11 14:13:35 +00001514
cristybb503372010-05-27 20:51:26 +00001515static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001516 const char *reference_filename,const char *output_filename,size_t *fail,
1517 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001518{
1519 char
glennrp4084cda2012-12-11 14:13:35 +00001520#ifdef MagickCountTempFiles
cristy151b66d2015-04-15 10:50:31 +00001521 path[MagickPathExtent],
1522 SystemCommand[MagickPathExtent],
glennrp4084cda2012-12-11 14:13:35 +00001523#endif
cristy151b66d2015-04-15 10:50:31 +00001524 size[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001525
1526 const MagickInfo
1527 *magick_info;
1528
1529 double
1530 distortion,
1531 fuzz;
1532
1533 Image
1534 *difference_image,
cristy2c404222012-06-10 15:36:30 +00001535 *ping_image,
cristy6b9ae3f2012-06-10 15:39:34 +00001536 *reconstruct_image,
cristy100b8d92012-01-08 00:32:49 +00001537 *reference_image;
cristy3ed852e2009-09-05 21:47:34 +00001538
1539 MagickBooleanType
1540 status;
1541
cristybb503372010-05-27 20:51:26 +00001542 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001543 i,
1544 j;
1545
1546 size_t
cristy100b8d92012-01-08 00:32:49 +00001547 length,
1548 test;
cristy3ed852e2009-09-05 21:47:34 +00001549
1550 unsigned char
1551 *blob;
1552
cristy3ed852e2009-09-05 21:47:34 +00001553 test=0;
cristyb51dff52011-05-19 16:55:47 +00001554 (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
glennrp4084cda2012-12-11 14:13:35 +00001555
1556#ifdef MagickCountTempFiles
1557 (void)GetPathTemplate(path);
glennrp33fb8032013-01-07 18:43:03 +00001558 /* Remove file template except for the leading "/path/to/magick-" */
glennrp4084cda2012-12-11 14:13:35 +00001559 path[strlen(path)-17]='\0';
1560 (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
1561#endif
1562
cristy3ed852e2009-09-05 21:47:34 +00001563 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1564 {
1565 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1566 if ((magick_info == (const MagickInfo *) NULL) ||
1567 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1568 (magick_info->encoder == (EncodeImageHandler *) NULL))
1569 continue;
cristy5f1c1ff2010-12-23 21:38:06 +00001570 for (j=0; reference_types[j].type != UndefinedType; j++)
cristy3ed852e2009-09-05 21:47:34 +00001571 {
1572 /*
1573 Generate reference image.
1574 */
1575 CatchException(exception);
cristy1e604812011-05-19 18:07:50 +00001576 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1577 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
cristy7998e5f2009-10-08 02:45:33 +00001578 MagickCompressOptions,reference_formats[i].compression),
cristy042ee782011-04-22 18:48:30 +00001579 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
cristy75a26232010-06-03 17:15:02 +00001580 (double) reference_types[j].depth);
cristy3ed852e2009-09-05 21:47:34 +00001581 (void) CopyMagickString(image_info->filename,reference_filename,
cristy151b66d2015-04-15 10:50:31 +00001582 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001583 reference_image=ReadImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00001584 if (reference_image == (Image *) NULL ||
1585 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001586 {
cristy1e604812011-05-19 18:07:50 +00001587 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1588 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001589 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001590 (*fail)++;
1591 continue;
1592 }
1593 /*
1594 Write reference image.
1595 */
cristy151b66d2015-04-15 10:50:31 +00001596 (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",
cristy75a26232010-06-03 17:15:02 +00001597 (double) reference_image->columns,(double) reference_image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001598 (void) CloneString(&image_info->size,size);
1599 image_info->depth=reference_types[j].depth;
cristy151b66d2015-04-15 10:50:31 +00001600 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001601 reference_formats[i].magick,output_filename);
cristy018f07f2011-09-04 21:15:19 +00001602 status=SetImageType(reference_image,reference_types[j].type,exception);
dirk775194c2014-05-17 19:47:54 +00001603 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001604 {
cristy1e604812011-05-19 18:07:50 +00001605 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1606 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001607 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001608 (*fail)++;
1609 reference_image=DestroyImage(reference_image);
1610 continue;
1611 }
cristy8a11cb12011-10-19 23:53:34 +00001612 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
dirk775194c2014-05-17 19:47:54 +00001613 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001614 {
cristy1e604812011-05-19 18:07:50 +00001615 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1616 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001617 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001618 (*fail)++;
1619 reference_image=DestroyImage(reference_image);
1620 continue;
1621 }
cristy7998e5f2009-10-08 02:45:33 +00001622 reference_image->compression=reference_formats[i].compression;
cristy6f9e0d32011-08-28 16:32:09 +00001623 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001624 reference_image=DestroyImage(reference_image);
dirk775194c2014-05-17 19:47:54 +00001625 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001626 {
cristy1e604812011-05-19 18:07:50 +00001627 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1628 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001629 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001630 (*fail)++;
1631 continue;
1632 }
1633 /*
cristy2c404222012-06-10 15:36:30 +00001634 Ping reference image.
cristy3ed852e2009-09-05 21:47:34 +00001635 */
cristy151b66d2015-04-15 10:50:31 +00001636 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001637 reference_formats[i].magick,output_filename);
cristy2c404222012-06-10 15:36:30 +00001638 ping_image=PingImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00001639 if (ping_image == (Image *) NULL ||
1640 exception->severity >= ErrorException)
cristy2c404222012-06-10 15:36:30 +00001641 {
1642 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1643 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001644 CatchException(exception);
cristy2c404222012-06-10 15:36:30 +00001645 (*fail)++;
1646 continue;
1647 }
1648 ping_image=DestroyImage(ping_image);
1649 /*
1650 Read reference image.
1651 */
cristy3ed852e2009-09-05 21:47:34 +00001652 reference_image=ReadImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00001653 if (reference_image == (Image *) NULL ||
1654 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001655 {
cristy1e604812011-05-19 18:07:50 +00001656 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1657 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001658 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001659 (*fail)++;
1660 continue;
1661 }
1662 /*
1663 Write reference image.
1664 */
cristy151b66d2015-04-15 10:50:31 +00001665 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001666 reference_formats[i].magick,output_filename);
1667 (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
cristy151b66d2015-04-15 10:50:31 +00001668 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001669 reference_image->depth=reference_types[j].depth;
cristy7998e5f2009-10-08 02:45:33 +00001670 reference_image->compression=reference_formats[i].compression;
cristy3ed852e2009-09-05 21:47:34 +00001671 length=8192;
1672 blob=ImageToBlob(image_info,reference_image,&length,exception);
dirk775194c2014-05-17 19:47:54 +00001673 if (blob == (unsigned char *) NULL ||
1674 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001675 {
cristy1e604812011-05-19 18:07:50 +00001676 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1677 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001678 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001679 (*fail)++;
1680 reference_image=DestroyImage(reference_image);
1681 continue;
1682 }
1683 /*
cristy2c404222012-06-10 15:36:30 +00001684 Ping reference blob.
1685 */
1686 ping_image=PingBlob(image_info,blob,length,exception);
dirk775194c2014-05-17 19:47:54 +00001687 if (ping_image == (Image *) NULL ||
1688 exception->severity >= ErrorException)
cristy2c404222012-06-10 15:36:30 +00001689 {
1690 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1691 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001692 CatchException(exception);
cristy2c404222012-06-10 15:36:30 +00001693 (*fail)++;
1694 blob=(unsigned char *) RelinquishMagickMemory(blob);
1695 continue;
1696 }
1697 ping_image=DestroyImage(ping_image);
1698 /*
cristy3ed852e2009-09-05 21:47:34 +00001699 Read reconstruct image.
1700 */
cristy151b66d2015-04-15 10:50:31 +00001701 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001702 reference_formats[i].magick,output_filename);
1703 reconstruct_image=BlobToImage(image_info,blob,length,exception);
1704 blob=(unsigned char *) RelinquishMagickMemory(blob);
dirk775194c2014-05-17 19:47:54 +00001705 if (reconstruct_image == (Image *) NULL ||
1706 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001707 {
cristy1e604812011-05-19 18:07:50 +00001708 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1709 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001710 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001711 (*fail)++;
1712 reference_image=DestroyImage(reference_image);
1713 continue;
1714 }
1715 /*
1716 Compare reference to reconstruct image.
1717 */
cristy93540ab2013-03-30 19:59:41 +00001718 fuzz=0.003; /* grayscale */
cristy3ed852e2009-09-05 21:47:34 +00001719 if (reference_formats[i].fuzz != 0.0)
1720 fuzz=reference_formats[i].fuzz;
cristy8a9106f2011-07-05 14:39:26 +00001721 difference_image=CompareImages(reference_image,reconstruct_image,
cristy864c6a82012-06-19 16:45:22 +00001722 RootMeanSquaredErrorMetric,&distortion,exception);
cristy3ed852e2009-09-05 21:47:34 +00001723 reconstruct_image=DestroyImage(reconstruct_image);
1724 reference_image=DestroyImage(reference_image);
dirk775194c2014-05-17 19:47:54 +00001725 if (difference_image == (Image *) NULL ||
1726 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001727 {
cristy1e604812011-05-19 18:07:50 +00001728 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1729 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001730 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001731 (*fail)++;
1732 continue;
1733 }
1734 difference_image=DestroyImage(difference_image);
cristy14154222012-06-15 23:21:49 +00001735 if ((QuantumScale*distortion) > fuzz)
cristy3ed852e2009-09-05 21:47:34 +00001736 {
cristyb51dff52011-05-19 16:55:47 +00001737 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
cristy14154222012-06-15 23:21:49 +00001738 QuantumScale*distortion);
cristy3ed852e2009-09-05 21:47:34 +00001739 (*fail)++;
1740 continue;
1741 }
glennrp4084cda2012-12-11 14:13:35 +00001742#ifdef MagickCountTempFiles
1743 (void) FormatLocaleFile(stdout,"... pass, ");
1744 (void) fflush(stdout);
1745 SystemCommand[0]='\0';
cristy77b33ba2013-03-28 13:23:13 +00001746 (void) strncat(SystemCommand,"echo `ls ",9);
cristy151b66d2015-04-15 10:50:31 +00001747 (void) strncat(SystemCommand,path,MagickPathExtent-31);
cristy77b33ba2013-03-28 13:23:13 +00001748 (void) strncat(SystemCommand,"* | wc -w` tmp files.",20);
1749 (void) system(SystemCommand);
glennrp4084cda2012-12-11 14:13:35 +00001750 (void) fflush(stdout);
1751#else
1752 (void) FormatLocaleFile(stdout,"... pass\n");
1753#endif
cristy3ed852e2009-09-05 21:47:34 +00001754 }
1755 }
cristyb51dff52011-05-19 16:55:47 +00001756 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001757 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1758 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001759 return(test);
1760}
1761
1762/*
1763%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764% %
1765% %
1766% %
1767% 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 %
1768% %
1769% %
1770% %
1771%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1772%
1773% ValidateImageFormatsOnDisk() validates the ImageMagick image formats on disk
1774% and returns the number of validation tests that passed and failed.
1775%
1776% The format of the ValidateImageFormatsOnDisk method is:
1777%
cristybb503372010-05-27 20:51:26 +00001778% size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001779% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001780% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001781%
1782% A description of each parameter follows:
1783%
1784% o image_info: the image info.
1785%
1786% o reference_filename: the reference image filename.
1787%
1788% o output_filename: the output image filename.
1789%
1790% o fail: return the number of validation tests that pass.
1791%
1792% o exception: return any errors or warnings in this structure.
1793%
1794*/
cristybb503372010-05-27 20:51:26 +00001795static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00001796 const char *reference_filename,const char *output_filename,size_t *fail,
1797 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001798{
1799 char
cristy151b66d2015-04-15 10:50:31 +00001800 size[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001801
1802 const MagickInfo
1803 *magick_info;
1804
1805 double
1806 distortion,
1807 fuzz;
1808
1809 Image
1810 *difference_image,
1811 *reference_image,
1812 *reconstruct_image;
1813
1814 MagickBooleanType
1815 status;
1816
cristybb503372010-05-27 20:51:26 +00001817 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001818 i,
1819 j;
1820
cristybb503372010-05-27 20:51:26 +00001821 size_t
cristy3ed852e2009-09-05 21:47:34 +00001822 test;
1823
1824 test=0;
cristyb51dff52011-05-19 16:55:47 +00001825 (void) FormatLocaleFile(stdout,"validate image formats on disk:\n");
cristy3ed852e2009-09-05 21:47:34 +00001826 for (i=0; reference_formats[i].magick != (char *) NULL; i++)
1827 {
1828 magick_info=GetMagickInfo(reference_formats[i].magick,exception);
1829 if ((magick_info == (const MagickInfo *) NULL) ||
1830 (magick_info->decoder == (DecodeImageHandler *) NULL) ||
1831 (magick_info->encoder == (EncodeImageHandler *) NULL))
1832 continue;
cristy5f1c1ff2010-12-23 21:38:06 +00001833 for (j=0; reference_types[j].type != UndefinedType; j++)
cristy3ed852e2009-09-05 21:47:34 +00001834 {
1835 /*
1836 Generate reference image.
1837 */
1838 CatchException(exception);
cristy1e604812011-05-19 18:07:50 +00001839 (void) FormatLocaleFile(stdout," test %.20g: %s/%s/%s/%.20g-bits",
1840 (double) (test++),reference_formats[i].magick,CommandOptionToMnemonic(
cristy7998e5f2009-10-08 02:45:33 +00001841 MagickCompressOptions,reference_formats[i].compression),
cristy042ee782011-04-22 18:48:30 +00001842 CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
cristy75a26232010-06-03 17:15:02 +00001843 (double) reference_types[j].depth);
cristy3ed852e2009-09-05 21:47:34 +00001844 (void) CopyMagickString(image_info->filename,reference_filename,
cristy151b66d2015-04-15 10:50:31 +00001845 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001846 reference_image=ReadImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00001847 if (reference_image == (Image *) NULL ||
1848 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001849 {
cristy1e604812011-05-19 18:07:50 +00001850 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1851 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001852 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001853 (*fail)++;
1854 continue;
1855 }
1856 /*
1857 Write reference image.
1858 */
cristy151b66d2015-04-15 10:50:31 +00001859 (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",
cristy75a26232010-06-03 17:15:02 +00001860 (double) reference_image->columns,(double) reference_image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001861 (void) CloneString(&image_info->size,size);
1862 image_info->depth=reference_types[j].depth;
cristy151b66d2015-04-15 10:50:31 +00001863 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001864 reference_formats[i].magick,output_filename);
cristy018f07f2011-09-04 21:15:19 +00001865 status=SetImageType(reference_image,reference_types[j].type,exception);
dirk775194c2014-05-17 19:47:54 +00001866 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001867 {
cristy1e604812011-05-19 18:07:50 +00001868 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1869 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001870 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001871 (*fail)++;
1872 reference_image=DestroyImage(reference_image);
1873 continue;
1874 }
cristy8a11cb12011-10-19 23:53:34 +00001875 status=SetImageDepth(reference_image,reference_types[j].depth,exception);
dirk775194c2014-05-17 19:47:54 +00001876 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001877 {
cristy1e604812011-05-19 18:07:50 +00001878 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1879 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001880 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001881 (*fail)++;
1882 reference_image=DestroyImage(reference_image);
1883 continue;
1884 }
cristy7998e5f2009-10-08 02:45:33 +00001885 reference_image->compression=reference_formats[i].compression;
cristy6f9e0d32011-08-28 16:32:09 +00001886 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001887 reference_image=DestroyImage(reference_image);
dirk775194c2014-05-17 19:47:54 +00001888 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001889 {
cristy1e604812011-05-19 18:07:50 +00001890 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1891 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001892 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001893 (*fail)++;
1894 continue;
1895 }
1896 /*
1897 Read reference image.
1898 */
cristy151b66d2015-04-15 10:50:31 +00001899 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001900 reference_formats[i].magick,output_filename);
1901 reference_image=ReadImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00001902 if (reference_image == (Image *) NULL ||
1903 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001904 {
cristy1e604812011-05-19 18:07:50 +00001905 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1906 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001907 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001908 (*fail)++;
1909 continue;
1910 }
1911 /*
1912 Write reference image.
1913 */
cristy151b66d2015-04-15 10:50:31 +00001914 (void) FormatLocaleString(reference_image->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001915 reference_formats[i].magick,output_filename);
1916 reference_image->depth=reference_types[j].depth;
cristy7998e5f2009-10-08 02:45:33 +00001917 reference_image->compression=reference_formats[i].compression;
cristy6f9e0d32011-08-28 16:32:09 +00001918 status=WriteImage(image_info,reference_image,exception);
dirk775194c2014-05-17 19:47:54 +00001919 if (status == MagickFalse ||exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001920 {
cristy1e604812011-05-19 18:07:50 +00001921 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1922 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001923 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001924 (*fail)++;
1925 reference_image=DestroyImage(reference_image);
1926 continue;
1927 }
1928 /*
1929 Read reconstruct image.
1930 */
cristy151b66d2015-04-15 10:50:31 +00001931 (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
cristy3ed852e2009-09-05 21:47:34 +00001932 reference_formats[i].magick,output_filename);
1933 reconstruct_image=ReadImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00001934 if (reconstruct_image == (Image *) NULL ||
1935 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001936 {
cristy1e604812011-05-19 18:07:50 +00001937 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1938 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001939 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001940 (*fail)++;
1941 reference_image=DestroyImage(reference_image);
1942 continue;
1943 }
1944 /*
1945 Compare reference to reconstruct image.
1946 */
cristy93540ab2013-03-30 19:59:41 +00001947 fuzz=0.003; /* grayscale */
cristy3ed852e2009-09-05 21:47:34 +00001948 if (reference_formats[i].fuzz != 0.0)
1949 fuzz=reference_formats[i].fuzz;
cristy8a9106f2011-07-05 14:39:26 +00001950 difference_image=CompareImages(reference_image,reconstruct_image,
cristy864c6a82012-06-19 16:45:22 +00001951 RootMeanSquaredErrorMetric,&distortion,exception);
cristy3ed852e2009-09-05 21:47:34 +00001952 reconstruct_image=DestroyImage(reconstruct_image);
1953 reference_image=DestroyImage(reference_image);
dirk775194c2014-05-17 19:47:54 +00001954 if (difference_image == (Image *) NULL ||
1955 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00001956 {
cristy1e604812011-05-19 18:07:50 +00001957 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
1958 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00001959 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001960 (*fail)++;
1961 continue;
1962 }
1963 difference_image=DestroyImage(difference_image);
cristy14154222012-06-15 23:21:49 +00001964 if ((QuantumScale*distortion) > fuzz)
cristy3ed852e2009-09-05 21:47:34 +00001965 {
cristyb51dff52011-05-19 16:55:47 +00001966 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
cristy14154222012-06-15 23:21:49 +00001967 QuantumScale*distortion);
cristy3ed852e2009-09-05 21:47:34 +00001968 (*fail)++;
1969 continue;
1970 }
cristyb51dff52011-05-19 16:55:47 +00001971 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00001972 }
1973 }
cristyb51dff52011-05-19 16:55:47 +00001974 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00001975 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
1976 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00001977 return(test);
1978}
1979
1980/*
1981%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1982% %
1983% %
1984% %
1985% 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 %
1986% %
1987% %
1988% %
1989%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1990%
1991% ValidateImportExportPixels() validates the pixel import and export methods.
1992% It returns the number of validation tests that passed and failed.
1993%
1994% The format of the ValidateImportExportPixels method is:
1995%
cristybb503372010-05-27 20:51:26 +00001996% size_t ValidateImportExportPixels(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00001997% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00001998% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001999%
2000% A description of each parameter follows:
2001%
2002% o image_info: the image info.
2003%
2004% o reference_filename: the reference image filename.
2005%
2006% o output_filename: the output image filename.
2007%
2008% o fail: return the number of validation tests that pass.
2009%
2010% o exception: return any errors or warnings in this structure.
2011%
2012*/
cristybb503372010-05-27 20:51:26 +00002013static size_t ValidateImportExportPixels(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00002014 const char *reference_filename,const char *output_filename,size_t *fail,
2015 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002016{
2017 double
2018 distortion;
2019
2020 Image
2021 *difference_image,
2022 *reference_image,
2023 *reconstruct_image;
2024
2025 MagickBooleanType
2026 status;
2027
cristybb503372010-05-27 20:51:26 +00002028 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002029 i,
2030 j;
2031
2032 size_t
2033 length;
2034
2035 unsigned char
2036 *pixels;
2037
cristybb503372010-05-27 20:51:26 +00002038 size_t
cristy3ed852e2009-09-05 21:47:34 +00002039 test;
2040
2041 (void) output_filename;
2042 test=0;
cristy1e604812011-05-19 18:07:50 +00002043 (void) FormatLocaleFile(stdout,
2044 "validate the import and export of image pixels:\n");
cristy3ed852e2009-09-05 21:47:34 +00002045 for (i=0; reference_map[i] != (char *) NULL; i++)
2046 {
2047 for (j=0; reference_storage[j].type != UndefinedPixel; j++)
2048 {
2049 /*
2050 Generate reference image.
2051 */
2052 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00002053 (void) FormatLocaleFile(stdout," test %.20g: %s/%s",(double) (test++),
cristy042ee782011-04-22 18:48:30 +00002054 reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
cristy3ed852e2009-09-05 21:47:34 +00002055 reference_storage[j].type));
2056 (void) CopyMagickString(image_info->filename,reference_filename,
cristy151b66d2015-04-15 10:50:31 +00002057 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002058 reference_image=ReadImage(image_info,exception);
dirk775194c2014-05-17 19:47:54 +00002059 if (reference_image == (Image *) NULL ||
2060 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00002061 {
cristy1e604812011-05-19 18:07:50 +00002062 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2063 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00002064 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00002065 (*fail)++;
2066 continue;
2067 }
2068 if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
cristy2c404222012-06-10 15:36:30 +00002069 (void) SetImageColorspace(reference_image,CMYKColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00002070 length=strlen(reference_map[i])*reference_image->columns*
2071 reference_image->rows*reference_storage[j].quantum;
2072 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
dirk775194c2014-05-17 19:47:54 +00002073 if (pixels == (unsigned char *) NULL ||
2074 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00002075 {
cristy1e604812011-05-19 18:07:50 +00002076 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2077 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00002078 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00002079 (*fail)++;
2080 reference_image=DestroyImage(reference_image);
2081 continue;
2082 }
2083 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
2084 status=ExportImagePixels(reference_image,0,0,reference_image->columns,
2085 reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
2086 exception);
dirk775194c2014-05-17 19:47:54 +00002087 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00002088 {
cristy1e604812011-05-19 18:07:50 +00002089 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2090 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00002091 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00002092 (*fail)++;
2093 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2094 reference_image=DestroyImage(reference_image);
2095 continue;
2096 }
cristyd55c9352011-10-20 15:29:22 +00002097 (void) SetImageBackgroundColor(reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002098 status=ImportImagePixels(reference_image,0,0,reference_image->columns,
2099 reference_image->rows,reference_map[i],reference_storage[j].type,
cristy018f07f2011-09-04 21:15:19 +00002100 pixels,exception);
dirk775194c2014-05-17 19:47:54 +00002101 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00002102 {
cristy1e604812011-05-19 18:07:50 +00002103 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2104 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00002105 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00002106 (*fail)++;
2107 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2108 reference_image=DestroyImage(reference_image);
2109 continue;
2110 }
2111 /*
2112 Read reconstruct image.
2113 */
cristy9950d572011-10-01 18:22:35 +00002114 reconstruct_image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00002115 (void) SetImageExtent(reconstruct_image,reference_image->columns,
cristy655a8d12011-08-05 19:24:28 +00002116 reference_image->rows,exception);
2117 (void) SetImageColorspace(reconstruct_image,reference_image->colorspace,
2118 exception);
cristyd55c9352011-10-20 15:29:22 +00002119 (void) SetImageBackgroundColor(reconstruct_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002120 status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
2121 reconstruct_image->rows,reference_map[i],reference_storage[j].type,
cristy018f07f2011-09-04 21:15:19 +00002122 pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00002123 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
dirk775194c2014-05-17 19:47:54 +00002124 if (status == MagickFalse || exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00002125 {
cristy1e604812011-05-19 18:07:50 +00002126 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2127 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00002128 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00002129 (*fail)++;
2130 reference_image=DestroyImage(reference_image);
2131 continue;
2132 }
2133 /*
2134 Compare reference to reconstruct image.
2135 */
cristy8a9106f2011-07-05 14:39:26 +00002136 difference_image=CompareImages(reference_image,reconstruct_image,
cristy864c6a82012-06-19 16:45:22 +00002137 RootMeanSquaredErrorMetric,&distortion,exception);
cristy3ed852e2009-09-05 21:47:34 +00002138 reconstruct_image=DestroyImage(reconstruct_image);
2139 reference_image=DestroyImage(reference_image);
dirk775194c2014-05-17 19:47:54 +00002140 if (difference_image == (Image *) NULL ||
2141 exception->severity >= ErrorException)
cristy3ed852e2009-09-05 21:47:34 +00002142 {
cristy1e604812011-05-19 18:07:50 +00002143 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2144 GetMagickModule());
dirk775194c2014-05-17 19:47:54 +00002145 CatchException(exception);
cristy3ed852e2009-09-05 21:47:34 +00002146 (*fail)++;
2147 continue;
2148 }
2149 difference_image=DestroyImage(difference_image);
cristy14154222012-06-15 23:21:49 +00002150 if ((QuantumScale*distortion) > 0.0)
cristy3ed852e2009-09-05 21:47:34 +00002151 {
cristyb51dff52011-05-19 16:55:47 +00002152 (void) FormatLocaleFile(stdout,"... fail (with distortion %g).\n",
cristy14154222012-06-15 23:21:49 +00002153 QuantumScale*distortion);
cristy3ed852e2009-09-05 21:47:34 +00002154 (*fail)++;
2155 continue;
2156 }
cristyb51dff52011-05-19 16:55:47 +00002157 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00002158 }
2159 }
cristyb51dff52011-05-19 16:55:47 +00002160 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00002161 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2162 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00002163 return(test);
2164}
2165
2166/*
2167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2168% %
2169% %
2170% %
2171% V a l i d a t e M o n t a g e C o m m a n d %
2172% %
2173% %
2174% %
2175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2176%
2177% ValidateMontageCommand() validates the ImageMagick montage command line
2178% program and returns the number of validation tests that passed and failed.
2179%
2180% The format of the ValidateMontageCommand method is:
2181%
cristybb503372010-05-27 20:51:26 +00002182% size_t ValidateMontageCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00002183% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00002184% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002185%
2186% A description of each parameter follows:
2187%
2188% o image_info: the image info.
2189%
2190% o reference_filename: the reference image filename.
2191%
2192% o output_filename: the output image filename.
2193%
2194% o fail: return the number of validation tests that pass.
2195%
2196% o exception: return any errors or warnings in this structure.
2197%
2198*/
cristybb503372010-05-27 20:51:26 +00002199static size_t ValidateMontageCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00002200 const char *reference_filename,const char *output_filename,size_t *fail,
2201 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002202{
2203 char
2204 **arguments,
cristy151b66d2015-04-15 10:50:31 +00002205 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002206
2207 int
2208 number_arguments;
2209
2210 MagickBooleanType
2211 status;
2212
cristybb503372010-05-27 20:51:26 +00002213 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002214 i,
2215 j;
2216
cristybb503372010-05-27 20:51:26 +00002217 size_t
cristy3ed852e2009-09-05 21:47:34 +00002218 test;
2219
2220 test=0;
cristyb51dff52011-05-19 16:55:47 +00002221 (void) FormatLocaleFile(stdout,"validate montage command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00002222 for (i=0; montage_options[i] != (char *) NULL; i++)
2223 {
2224 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00002225 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +00002226 montage_options[i]);
cristy151b66d2015-04-15 10:50:31 +00002227 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00002228 reference_filename,montage_options[i],reference_filename,
2229 output_filename);
2230 arguments=StringToArgv(command,&number_arguments);
2231 if (arguments == (char **) NULL)
2232 {
cristy1e604812011-05-19 18:07:50 +00002233 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2234 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00002235 (*fail)++;
2236 continue;
2237 }
2238 status=MontageImageCommand(image_info,number_arguments,arguments,
2239 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00002240 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00002241 arguments[j]=DestroyString(arguments[j]);
2242 arguments=(char **) RelinquishMagickMemory(arguments);
cristy35892192014-05-26 12:04:36 +00002243 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002244 {
cristy1e604812011-05-19 18:07:50 +00002245 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2246 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00002247 (*fail)++;
2248 continue;
2249 }
cristyb51dff52011-05-19 16:55:47 +00002250 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00002251 }
cristyb51dff52011-05-19 16:55:47 +00002252 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00002253 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2254 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00002255 return(test);
2256}
2257
2258/*
2259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2260% %
2261% %
2262% %
2263% V a l i d a t e S t r e a m C o m m a n d %
2264% %
2265% %
2266% %
2267%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2268%
2269% ValidateStreamCommand() validates the ImageMagick stream command line
2270% program and returns the number of validation tests that passed and failed.
2271%
2272% The format of the ValidateStreamCommand method is:
2273%
cristybb503372010-05-27 20:51:26 +00002274% size_t ValidateStreamCommand(ImageInfo *image_info,
cristy3ed852e2009-09-05 21:47:34 +00002275% const char *reference_filename,const char *output_filename,
cristybb503372010-05-27 20:51:26 +00002276% size_t *fail,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002277%
2278% A description of each parameter follows:
2279%
2280% o image_info: the image info.
2281%
2282% o reference_filename: the reference image filename.
2283%
2284% o output_filename: the output image filename.
2285%
2286% o fail: return the number of validation tests that pass.
2287%
2288% o exception: return any errors or warnings in this structure.
2289%
2290*/
cristybb503372010-05-27 20:51:26 +00002291static size_t ValidateStreamCommand(ImageInfo *image_info,
cristy0d772ed2012-11-10 14:34:50 +00002292 const char *reference_filename,const char *output_filename,size_t *fail,
2293 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002294{
2295 char
2296 **arguments,
cristy151b66d2015-04-15 10:50:31 +00002297 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002298
2299 int
2300 number_arguments;
2301
2302 MagickBooleanType
2303 status;
2304
cristybb503372010-05-27 20:51:26 +00002305 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002306 i,
2307 j;
2308
cristybb503372010-05-27 20:51:26 +00002309 size_t
cristy3ed852e2009-09-05 21:47:34 +00002310 test;
2311
2312 test=0;
cristyb51dff52011-05-19 16:55:47 +00002313 (void) FormatLocaleFile(stdout,"validate stream command line program:\n");
cristy3ed852e2009-09-05 21:47:34 +00002314 for (i=0; stream_options[i] != (char *) NULL; i++)
2315 {
2316 CatchException(exception);
cristyb51dff52011-05-19 16:55:47 +00002317 (void) FormatLocaleFile(stdout," test %.20g: %s",(double) (test++),
cristy6aa47ad2010-05-28 19:32:32 +00002318 stream_options[i]);
cristy151b66d2015-04-15 10:50:31 +00002319 (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s",
cristy3ed852e2009-09-05 21:47:34 +00002320 stream_options[i],reference_filename,output_filename);
2321 arguments=StringToArgv(command,&number_arguments);
2322 if (arguments == (char **) NULL)
2323 {
cristy1e604812011-05-19 18:07:50 +00002324 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2325 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00002326 (*fail)++;
2327 continue;
2328 }
2329 status=StreamImageCommand(image_info,number_arguments,arguments,
2330 (char **) NULL,exception);
cristye42f6582012-02-11 17:59:50 +00002331 for (j=0; j < (ssize_t) number_arguments; j++)
cristy3ed852e2009-09-05 21:47:34 +00002332 arguments[j]=DestroyString(arguments[j]);
2333 arguments=(char **) RelinquishMagickMemory(arguments);
cristy35892192014-05-26 12:04:36 +00002334 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002335 {
cristy1e604812011-05-19 18:07:50 +00002336 (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
2337 GetMagickModule());
cristy3ed852e2009-09-05 21:47:34 +00002338 (*fail)++;
2339 continue;
2340 }
cristyb51dff52011-05-19 16:55:47 +00002341 (void) FormatLocaleFile(stdout,"... pass.\n");
cristy3ed852e2009-09-05 21:47:34 +00002342 }
cristyb51dff52011-05-19 16:55:47 +00002343 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00002344 " summary: %.20g subtests; %.20g passed; %.20g failed.\n",(double) test,
2345 (double) (test-(*fail)),(double) *fail);
cristy3ed852e2009-09-05 21:47:34 +00002346 return(test);
2347}
2348
2349/*
2350%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2351% %
2352% %
2353% %
2354% M a i n %
2355% %
2356% %
2357% %
2358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2359%
2360%
2361*/
2362
2363static MagickBooleanType ValidateUsage(void)
2364{
2365 const char
2366 **p;
2367
2368 static const char
2369 *miscellaneous[]=
2370 {
2371 "-debug events display copious debugging information",
2372 "-help print program options",
2373 "-log format format of debugging information",
2374 "-validate type validation type",
2375 "-version print version information",
2376 (char *) NULL
2377 },
2378 *settings[]=
2379 {
2380 "-regard-warnings pay attention to warning messages",
2381 "-verbose print detailed information about the image",
2382 (char *) NULL
2383 };
2384
cristybb503372010-05-27 20:51:26 +00002385 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy3ed852e2009-09-05 21:47:34 +00002386 (void) printf("Copyright: %s\n\n",GetMagickCopyright());
cristyb28d6472009-10-17 20:13:35 +00002387 (void) printf("Features: %s\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00002388 (void) printf("Usage: %s [options ...] reference-file\n",GetClientName());
2389 (void) printf("\nValidate Settings:\n");
2390 for (p=settings; *p != (char *) NULL; p++)
2391 (void) printf(" %s\n",*p);
2392 (void) printf("\nMiscellaneous Options:\n");
2393 for (p=miscellaneous; *p != (char *) NULL; p++)
2394 (void) printf(" %s\n",*p);
2395 return(MagickTrue);
2396}
2397
2398int main(int argc,char **argv)
2399{
2400#define DestroyValidate() \
2401{ \
cristy3ed852e2009-09-05 21:47:34 +00002402 image_info=DestroyImageInfo(image_info); \
2403 exception=DestroyExceptionInfo(exception); \
2404}
2405#define ThrowValidateException(asperity,tag,option) \
2406{ \
2407 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
2408 option); \
2409 CatchException(exception); \
2410 DestroyValidate(); \
2411 return(MagickFalse); \
2412}
2413
2414 char
cristy151b66d2015-04-15 10:50:31 +00002415 output_filename[MagickPathExtent],
2416 reference_filename[MagickPathExtent],
cristy3ed852e2009-09-05 21:47:34 +00002417 *option;
2418
2419 double
2420 elapsed_time,
2421 user_time;
2422
2423 ExceptionInfo
2424 *exception;
2425
2426 Image
2427 *reference_image;
2428
2429 ImageInfo
2430 *image_info;
2431
2432 MagickBooleanType
2433 regard_warnings,
2434 status;
2435
cristy9cafe592012-11-17 21:17:59 +00002436 MagickSizeType
2437 memory_resource,
2438 map_resource;
2439
cristybb503372010-05-27 20:51:26 +00002440 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002441 i;
2442
2443 TimerInfo
2444 *timer;
2445
cristybb503372010-05-27 20:51:26 +00002446 size_t
cristy3ed852e2009-09-05 21:47:34 +00002447 fail,
2448 iterations,
2449 tests;
2450
2451 ValidateType
2452 type;
2453
2454 /*
2455 Validate the ImageMagick image processing suite.
2456 */
cristyb4d552c2012-12-13 15:42:17 +00002457 MagickCoreGenesis(*argv,MagickTrue);
cristyef2fdc62012-12-12 11:16:48 +00002458 (void) setlocale(LC_ALL,"");
2459 (void) setlocale(LC_NUMERIC,"C");
cristy3ed852e2009-09-05 21:47:34 +00002460 iterations=1;
2461 status=MagickFalse;
2462 type=AllValidate;
2463 regard_warnings=MagickFalse;
cristyd8862902011-02-20 21:12:27 +00002464 (void) regard_warnings;
cristy3ed852e2009-09-05 21:47:34 +00002465 exception=AcquireExceptionInfo();
2466 image_info=AcquireImageInfo();
cristy151b66d2015-04-15 10:50:31 +00002467 (void) CopyMagickString(image_info->filename,ReferenceFilename,MagickPathExtent);
cristybb503372010-05-27 20:51:26 +00002468 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00002469 {
2470 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00002471 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002472 {
cristy151b66d2015-04-15 10:50:31 +00002473 (void) CopyMagickString(image_info->filename,option,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002474 continue;
2475 }
2476 switch (*(option+1))
2477 {
2478 case 'b':
2479 {
2480 if (LocaleCompare("bench",option+1) == 0)
2481 {
cristye27293e2009-12-18 02:53:20 +00002482 iterations=StringToUnsignedLong(argv[++i]);
cristy3ed852e2009-09-05 21:47:34 +00002483 break;
2484 }
2485 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2486 }
2487 case 'd':
2488 {
2489 if (LocaleCompare("debug",option+1) == 0)
2490 {
2491 (void) SetLogEventMask(argv[++i]);
2492 break;
2493 }
2494 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2495 }
2496 case 'h':
2497 {
2498 if (LocaleCompare("help",option+1) == 0)
2499 {
2500 (void) ValidateUsage();
2501 return(0);
2502 }
2503 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2504 }
2505 case 'l':
2506 {
2507 if (LocaleCompare("log",option+1) == 0)
2508 {
2509 if (*option != '+')
2510 (void) SetLogFormat(argv[i+1]);
2511 break;
2512 }
2513 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2514 }
2515 case 'r':
2516 {
2517 if (LocaleCompare("regard-warnings",option+1) == 0)
2518 {
2519 regard_warnings=MagickTrue;
2520 break;
2521 }
2522 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2523 }
2524 case 'v':
2525 {
2526 if (LocaleCompare("validate",option+1) == 0)
2527 {
cristybb503372010-05-27 20:51:26 +00002528 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002529 validate;
2530
2531 if (*option == '+')
2532 break;
2533 i++;
cristye81f5522014-05-07 01:25:59 +00002534 if (i >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00002535 ThrowValidateException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00002536 validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00002537 argv[i]);
2538 if (validate < 0)
2539 ThrowValidateException(OptionError,"UnrecognizedValidateType",
2540 argv[i]);
2541 type=(ValidateType) validate;
2542 break;
2543 }
2544 if ((LocaleCompare("version",option+1) == 0) ||
2545 (LocaleCompare("-version",option+1) == 0))
2546 {
cristyb51dff52011-05-19 16:55:47 +00002547 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00002548 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00002549 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
2550 GetMagickCopyright());
2551 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
2552 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00002553 return(0);
2554 }
2555 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2556 }
2557 default:
2558 ThrowValidateException(OptionError,"UnrecognizedOption",option)
2559 }
2560 }
cristy205e21f2009-09-28 19:01:46 +00002561 timer=(TimerInfo *) NULL;
cristy8b76e552009-09-28 18:20:20 +00002562 if (iterations > 1)
2563 timer=AcquireTimerInfo();
cristy3ed852e2009-09-05 21:47:34 +00002564 reference_image=ReadImage(image_info,exception);
2565 tests=0;
2566 fail=0;
2567 if (reference_image == (Image *) NULL)
2568 fail++;
2569 else
2570 {
2571 if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
2572 (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
cristy151b66d2015-04-15 10:50:31 +00002573 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002574 (void) AcquireUniqueFilename(reference_filename);
2575 (void) AcquireUniqueFilename(output_filename);
2576 (void) CopyMagickString(reference_image->filename,reference_filename,
cristy151b66d2015-04-15 10:50:31 +00002577 MagickPathExtent);
cristy6f9e0d32011-08-28 16:32:09 +00002578 status=WriteImage(image_info,reference_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002579 reference_image=DestroyImage(reference_image);
2580 if (status == MagickFalse)
2581 fail++;
2582 else
2583 {
cristyb51dff52011-05-19 16:55:47 +00002584 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00002585 GetMagickVersion((size_t *) NULL));
cristyb51dff52011-05-19 16:55:47 +00002586 (void) FormatLocaleFile(stdout,"Copyright: %s\n\n",
cristy3ed852e2009-09-05 21:47:34 +00002587 GetMagickCopyright());
cristy1e604812011-05-19 18:07:50 +00002588 (void) FormatLocaleFile(stdout,
2589 "ImageMagick Validation Suite (%s)\n\n",CommandOptionToMnemonic(
2590 MagickValidateOptions,(ssize_t) type));
cristy80e870e2013-05-07 12:23:02 +00002591 if ((type & ColorspaceValidate) != 0)
cristy572e0972013-05-07 12:51:28 +00002592 tests+=ValidateColorspaces(image_info,&fail,exception);
cristy3ed852e2009-09-05 21:47:34 +00002593 if ((type & CompareValidate) != 0)
2594 tests+=ValidateCompareCommand(image_info,reference_filename,
2595 output_filename,&fail,exception);
2596 if ((type & CompositeValidate) != 0)
2597 tests+=ValidateCompositeCommand(image_info,reference_filename,
2598 output_filename,&fail,exception);
2599 if ((type & ConvertValidate) != 0)
2600 tests+=ValidateConvertCommand(image_info,reference_filename,
2601 output_filename,&fail,exception);
cristy247eebde2013-06-13 01:01:43 +00002602 if ((type & FormatsDiskValidate) != 0)
cristyf044a4d2012-11-17 21:10:20 +00002603 {
cristy9cafe592012-11-17 21:17:59 +00002604 memory_resource=SetMagickResourceLimit(MemoryResource,0);
cristy247eebde2013-06-13 01:01:43 +00002605 map_resource=SetMagickResourceLimit(MapResource,0);
2606 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
cristyf044a4d2012-11-17 21:10:20 +00002607 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2608 output_filename,&fail,exception);
2609 (void) FormatLocaleFile(stdout,"[pixel-cache: disk] ");
cristy247eebde2013-06-13 01:01:43 +00002610 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
cristyf044a4d2012-11-17 21:10:20 +00002611 output_filename,&fail,exception);
cristy9cafe592012-11-17 21:17:59 +00002612 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
2613 (void) SetMagickResourceLimit(MapResource,map_resource);
cristyf044a4d2012-11-17 21:10:20 +00002614 }
cristy247eebde2013-06-13 01:01:43 +00002615 if ((type & FormatsMapValidate) != 0)
cristybda201a2012-11-08 16:44:00 +00002616 {
cristy247eebde2013-06-13 01:01:43 +00002617 memory_resource=SetMagickResourceLimit(MemoryResource,0);
2618 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
2619 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
cristybda201a2012-11-08 16:44:00 +00002620 output_filename,&fail,exception);
cristy34c290f2012-11-09 00:44:12 +00002621 (void) FormatLocaleFile(stdout,"[pixel-cache: memory-mapped] ");
cristybda201a2012-11-08 16:44:00 +00002622 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2623 output_filename,&fail,exception);
cristy9cafe592012-11-17 21:17:59 +00002624 (void) SetMagickResourceLimit(MemoryResource,memory_resource);
cristy247eebde2013-06-13 01:01:43 +00002625 }
2626 if ((type & FormatsMemoryValidate) != 0)
2627 {
2628 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2629 tests+=ValidateImageFormatsInMemory(image_info,reference_filename,
2630 output_filename,&fail,exception);
2631 (void) FormatLocaleFile(stdout,"[pixel-cache: memory] ");
2632 tests+=ValidateImageFormatsOnDisk(image_info,reference_filename,
2633 output_filename,&fail,exception);
cristybda201a2012-11-08 16:44:00 +00002634 }
cristy3ed852e2009-09-05 21:47:34 +00002635 if ((type & IdentifyValidate) != 0)
2636 tests+=ValidateIdentifyCommand(image_info,reference_filename,
2637 output_filename,&fail,exception);
2638 if ((type & ImportExportValidate) != 0)
2639 tests+=ValidateImportExportPixels(image_info,reference_filename,
2640 output_filename,&fail,exception);
2641 if ((type & MontageValidate) != 0)
2642 tests+=ValidateMontageCommand(image_info,reference_filename,
2643 output_filename,&fail,exception);
2644 if ((type & StreamValidate) != 0)
2645 tests+=ValidateStreamCommand(image_info,reference_filename,
2646 output_filename,&fail,exception);
cristyb51dff52011-05-19 16:55:47 +00002647 (void) FormatLocaleFile(stdout,
cristy75a26232010-06-03 17:15:02 +00002648 "validation suite: %.20g tests; %.20g passed; %.20g failed.\n",
2649 (double) tests,(double) (tests-fail),(double) fail);
cristy3ed852e2009-09-05 21:47:34 +00002650 }
2651 (void) RelinquishUniqueFileResource(output_filename);
2652 (void) RelinquishUniqueFileResource(reference_filename);
2653 }
2654 if (exception->severity != UndefinedException)
2655 CatchException(exception);
2656 if (iterations > 1)
2657 {
2658 elapsed_time=GetElapsedTime(timer);
2659 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +00002660 (void) FormatLocaleFile(stderr,
cristy75a26232010-06-03 17:15:02 +00002661 "Performance: %.20gi %gips %0.3fu %ld:%02ld.%03ld\n",(double)
cristy6aa47ad2010-05-28 19:32:32 +00002662 iterations,1.0*iterations/elapsed_time,user_time,(long)
2663 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),
2664 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy8b76e552009-09-28 18:20:20 +00002665 timer=DestroyTimerInfo(timer);
cristy3ed852e2009-09-05 21:47:34 +00002666 }
2667 DestroyValidate();
2668 MagickCoreTerminus();
2669 return(fail == 0 ? 0 : 1);
2670}