]> granicus.if.org Git - imagemagick/blob - magick/identify.c
(no commit message)
[imagemagick] / magick / identify.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %           IIIII  DDDD   EEEEE  N   N  TTTTT  IIIII  FFFFF  Y   Y            %
7 %             I    D   D  E      NN  N    T      I    F       Y Y             %
8 %             I    D   D  EEE    N N N    T      I    FFF      Y              %
9 %             I    D   D  E      N  NN    T      I    F        Y              %
10 %           IIIII  DDDD   EEEEE  N   N    T    IIIII  F        Y              %
11 %                                                                             %
12 %                                                                             %
13 %               Identify an Image Format and Characteristics.                 %
14 %                                                                             %
15 %                           Software Design                                   %
16 %                             John Cristy                                     %
17 %                            September 1994                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %  Identify describes the format and characteristics of one or more image
37 %  files.  It will also report if an image is incomplete or corrupt.
38 %
39 %
40 */
41 \f
42 /*
43   Include declarations.
44 */
45 #include "magick/studio.h"
46 #include "magick/annotate.h"
47 #include "magick/artifact.h"
48 #include "magick/attribute.h"
49 #include "magick/blob.h"
50 #include "magick/cache.h"
51 #include "magick/client.h"
52 #include "magick/coder.h"
53 #include "magick/color.h"
54 #include "magick/configure.h"
55 #include "magick/constitute.h"
56 #include "magick/decorate.h"
57 #include "magick/delegate.h"
58 #include "magick/draw.h"
59 #include "magick/effect.h"
60 #include "magick/exception.h"
61 #include "magick/exception-private.h"
62 #include "magick/feature.h"
63 #include "magick/gem.h"
64 #include "magick/geometry.h"
65 #include "magick/histogram.h"
66 #include "magick/identify.h"
67 #include "magick/image.h"
68 #include "magick/image-private.h"
69 #include "magick/list.h"
70 #include "magick/locale_.h"
71 #include "magick/log.h"
72 #include "magick/magic.h"
73 #include "magick/magick.h"
74 #include "magick/memory_.h"
75 #include "magick/module.h"
76 #include "magick/monitor.h"
77 #include "magick/montage.h"
78 #include "magick/option.h"
79 #include "magick/pixel-private.h"
80 #include "magick/prepress.h"
81 #include "magick/profile.h"
82 #include "magick/property.h"
83 #include "magick/quantize.h"
84 #include "magick/quantum.h"
85 #include "magick/random_.h"
86 #include "magick/registry.h"
87 #include "magick/resize.h"
88 #include "magick/resource_.h"
89 #include "magick/signature.h"
90 #include "magick/statistic.h"
91 #include "magick/string_.h"
92 #include "magick/string-private.h"
93 #include "magick/timer.h"
94 #include "magick/utility.h"
95 #include "magick/version.h"
96 #if defined(MAGICKCORE_LCMS_DELEGATE)
97 #if defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
98 #include <lcms/lcms.h>
99 #else
100 #include "lcms.h"
101 #endif
102 #endif
103 \f
104 /*
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %                                                                             %
107 %                                                                             %
108 %                                                                             %
109 %   I d e n t i f y I m a g e                                                 %
110 %                                                                             %
111 %                                                                             %
112 %                                                                             %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 %
115 %  IdentifyImage() identifies an image by printing its attributes to the file.
116 %  Attributes include the image width, height, size, and others.
117 %
118 %  The format of the IdentifyImage method is:
119 %
120 %      MagickBooleanType IdentifyImage(Image *image,FILE *file,
121 %        const MagickBooleanType verbose)
122 %
123 %  A description of each parameter follows:
124 %
125 %    o image: the image.
126 %
127 %    o file: the file, typically stdout.
128 %
129 %    o verbose: A value other than zero prints more detailed information
130 %      about the image.
131 %
132 */
133
134 static int PrintChannelFeatures(FILE *file,const ChannelType channel,
135   const char *name,const ChannelFeatures *channel_features)
136 {
137 #define PrintFeature(feature) \
138   GetMagickPrecision(),(feature)[0], \
139   GetMagickPrecision(),(feature)[1], \
140   GetMagickPrecision(),(feature)[2], \
141   GetMagickPrecision(),(feature)[3], \
142   GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
143
144 #define FeaturesFormat "    %s:\n" \
145   "      Angular Second Moment:\n" \
146   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
147   "      Contrast:\n" \
148   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
149   "      Correlation:\n" \
150   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
151   "      Sum of Squares: Variance:\n" \
152   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
153   "      Inverse Difference Moment:\n" \
154   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
155   "      Sum Average:\n" \
156   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
157   "      Sum Variance:\n" \
158   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
159   "      Sum Entropy:\n" \
160   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
161   "      Entropy:\n" \
162   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
163   "      Difference Variance:\n" \
164   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
165   "      Difference Entropy:\n" \
166   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
167   "      Information Measure of Correlation 1:\n" \
168   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
169   "      Information Measure of Correlation 2:\n" \
170   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" \
171   "      Maximum Correlation Coefficient:\n" \
172   "        %.*g, %.*g, %.*g, %.*g, %.*g\n" 
173
174   int
175     status;
176
177   status=fprintf(file,FeaturesFormat,name,
178     PrintFeature(channel_features[channel].angular_second_moment),
179     PrintFeature(channel_features[channel].contrast),
180     PrintFeature(channel_features[channel].correlation),
181     PrintFeature(channel_features[channel].variance_sum_of_squares),
182     PrintFeature(channel_features[channel].inverse_difference_moment),
183     PrintFeature(channel_features[channel].sum_average),
184     PrintFeature(channel_features[channel].sum_variance),
185     PrintFeature(channel_features[channel].sum_entropy),
186     PrintFeature(channel_features[channel].entropy),
187     PrintFeature(channel_features[channel].difference_variance),
188     PrintFeature(channel_features[channel].difference_entropy),
189     PrintFeature(channel_features[channel].measure_of_correlation_1),
190     PrintFeature(channel_features[channel].measure_of_correlation_2),
191     PrintFeature(channel_features[channel].maximum_correlation_coefficient));
192   return(status);
193 }
194
195 static int PrintChannelStatistics(FILE *file,const ChannelType channel,
196   const char *name,const double scale,
197   const ChannelStatistics *channel_statistics)
198 {
199 #define StatisticsFormat "    %s:\n      min: " QuantumFormat  \
200   " (%g)\n      max: " QuantumFormat " (%g)\n"  \
201   "      mean: %g (%g)\n      standard deviation: %g (%g)\n"  \
202   "      kurtosis: %g\n      skewness: %g\n"
203
204   int
205     status;
206
207   status=fprintf(file,StatisticsFormat,name,(Quantum) (scale*
208     channel_statistics[channel].minima+0.5),channel_statistics[channel].minima/
209     (double) QuantumRange,(Quantum) (scale*channel_statistics[channel].maxima+
210     0.5),channel_statistics[channel].maxima/(double) QuantumRange,scale*
211     channel_statistics[channel].mean,channel_statistics[channel].mean/
212     (double) QuantumRange,scale*channel_statistics[channel].standard_deviation,
213     channel_statistics[channel].standard_deviation/(double) QuantumRange,
214     channel_statistics[channel].kurtosis,channel_statistics[channel].skewness);
215   return(status);
216 }
217
218 MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
219   const MagickBooleanType verbose)
220 {
221   char
222     color[MaxTextExtent],
223     format[MaxTextExtent],
224     key[MaxTextExtent];
225
226   ChannelFeatures
227     *channel_features;
228
229   ChannelStatistics
230     *channel_statistics;
231
232   ColorspaceType
233     colorspace;
234
235   const char
236     *artifact,
237     *name,
238     *property,
239     *registry,
240     *value;
241
242   const MagickInfo
243     *magick_info;
244
245   const PixelPacket
246     *pixels;
247
248   double
249     elapsed_time,
250     user_time;
251
252   ExceptionInfo
253     *exception;
254
255   ImageType
256     type;
257
258   long
259     y;
260
261   MagickBooleanType
262     ping;
263
264   register long
265     i,
266     x;
267
268   unsigned long
269     distance,
270     scale;
271
272   assert(image != (Image *) NULL);
273   assert(image->signature == MagickSignature);
274   if (image->debug != MagickFalse)
275     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
276   if (file == (FILE *) NULL)
277     file=stdout;
278   *format='\0';
279   elapsed_time=GetElapsedTime(&image->timer);
280   user_time=GetUserTime(&image->timer);
281   GetTimerInfo(&image->timer);
282   if (verbose == MagickFalse)
283     {
284       /*
285         Display summary info about the image.
286       */
287       if (*image->magick_filename != '\0')
288         if (LocaleCompare(image->magick_filename,image->filename) != 0)
289           (void) fprintf(file,"%s=>",image->magick_filename);
290        if ((GetPreviousImageInList(image) == (Image *) NULL) &&
291            (GetNextImageInList(image) == (Image *) NULL) &&
292            (image->scene == 0))
293         (void) fprintf(file,"%s ",image->filename);
294       else
295         (void) fprintf(file,"%s[%lu] ",image->filename,image->scene);
296       (void) fprintf(file,"%s ",image->magick);
297       if ((image->magick_columns != 0) || (image->magick_rows != 0))
298         if ((image->magick_columns != image->columns) ||
299             (image->magick_rows != image->rows))
300           (void) fprintf(file,"%lux%lu=>",image->magick_columns,
301             image->magick_rows);
302       (void) fprintf(file,"%lux%lu ",image->columns,image->rows);
303       if ((image->page.width != 0) || (image->page.height != 0) ||
304           (image->page.x != 0) || (image->page.y != 0))
305         (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width,
306           image->page.height,image->page.x,image->page.y);
307       (void) fprintf(file,"%lu-bit ",image->depth);
308       if (image->type != UndefinedType)
309         (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
310           (long) image->type));
311       if (image->storage_class == DirectClass)
312         {
313           (void) fprintf(file,"DirectClass ");
314           if (image->total_colors != 0)
315             {
316               (void) FormatMagickSize(image->total_colors,MagickFalse,format);
317               (void) fprintf(file,"%s ",format);
318             }
319         }
320       else
321         if (image->total_colors <= image->colors)
322           (void) fprintf(file,"PseudoClass %luc ",image->colors);
323         else
324           (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors,
325             image->colors);
326       if (image->error.mean_error_per_pixel != 0.0)
327         (void) fprintf(file,"%ld/%f/%fdb ",(long)
328           (image->error.mean_error_per_pixel+0.5),
329           image->error.normalized_mean_error,
330           image->error.normalized_maximum_error);
331       if (GetBlobSize(image) != 0)
332         {
333           (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
334           (void) fprintf(file,"%sB ",format);
335         }
336       (void) fprintf(file,"%0.3fu %ld:%02ld.%03ld",user_time,(long)
337         (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
338         (long) (1000.0*(elapsed_time-floor(elapsed_time))));
339       (void) fprintf(file,"\n");
340       (void) fflush(file);
341       return(ferror(file) != 0 ? MagickFalse : MagickTrue);
342     }
343   /*
344     Display verbose info about the image.
345   */
346   exception=AcquireExceptionInfo();
347   pixels=GetVirtualPixels(image,0,0,1,1,exception);
348   exception=DestroyExceptionInfo(exception);
349   ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
350   type=GetImageType(image,&image->exception);
351   (void) SignatureImage(image);
352   (void) fprintf(file,"Image: %s\n",image->filename);
353   if (*image->magick_filename != '\0')
354     if (LocaleCompare(image->magick_filename,image->filename) != 0)
355       {
356         char
357           filename[MaxTextExtent];
358
359         GetPathComponent(image->magick_filename,TailPath,filename);
360         (void) fprintf(file,"  Base filename: %s\n",filename);
361       }
362   magick_info=GetMagickInfo(image->magick,&image->exception);
363   if ((magick_info == (const MagickInfo *) NULL) ||
364       (*GetMagickDescription(magick_info) == '\0'))
365     (void) fprintf(file,"  Format: %s\n",image->magick);
366   else
367     (void) fprintf(file,"  Format: %s (%s)\n",image->magick,
368       GetMagickDescription(magick_info));
369   (void) fprintf(file,"  Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
370     (long) image->storage_class));
371   (void) fprintf(file,"  Geometry: %lux%lu%+ld%+ld\n",image->columns,
372     image->rows,image->tile_offset.x,image->tile_offset.y);
373   if ((image->magick_columns != 0) || (image->magick_rows != 0))
374     if ((image->magick_columns != image->columns) ||
375         (image->magick_rows != image->rows))
376       (void) fprintf(file,"  Base geometry: %lux%lu\n",image->magick_columns,
377         image->magick_rows);
378   if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
379     {
380       (void) fprintf(file,"  Resolution: %gx%g\n",image->x_resolution,
381         image->y_resolution);
382       (void) fprintf(file,"  Print size: %gx%g\n",(double) image->columns/
383         image->x_resolution,(double) image->rows/image->y_resolution);
384     }
385   (void) fprintf(file,"  Units: %s\n",MagickOptionToMnemonic(
386     MagickResolutionOptions,(long) image->units));
387   (void) fprintf(file,"  Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
388     (long) type));
389   if (image->type != UndefinedType)
390     (void) fprintf(file,"  Base type: %s\n",MagickOptionToMnemonic(
391       MagickTypeOptions,(long) image->type));
392   (void) fprintf(file,"  Endianess: %s\n",MagickOptionToMnemonic(
393     MagickEndianOptions,(long) image->endian));
394   /*
395     Detail channel depth and extrema.
396   */
397   (void) fprintf(file,"  Colorspace: %s\n",MagickOptionToMnemonic(
398     MagickColorspaceOptions,(long) image->colorspace));
399   channel_statistics=(ChannelStatistics *) NULL;
400   channel_features=(ChannelFeatures *) NULL;
401   colorspace=image->colorspace;
402   if (ping == MagickFalse)
403     {
404       unsigned long
405         depth;
406
407       channel_statistics=GetImageChannelStatistics(image,&image->exception);
408       artifact=GetImageArtifact(image,"identify:features");
409       if (artifact != (const char *) NULL)
410         {
411           distance=StringToUnsignedLong(artifact);
412           channel_features=GetImageChannelFeatures(image,distance,
413             &image->exception);
414         }
415       depth=GetImageDepth(image,&image->exception);
416       if (image->depth == depth)
417         (void) fprintf(file,"  Depth: %lu-bit\n",image->depth);
418       else
419         (void) fprintf(file,"  Depth: %lu/%lu-bit\n",image->depth,depth);
420       (void) fprintf(file,"  Channel depth:\n");
421       if (IsGrayImage(image,&image->exception) != MagickFalse)
422         colorspace=GRAYColorspace;
423       switch (colorspace)
424       {
425         case RGBColorspace:
426         default:
427         {
428           (void) fprintf(file,"    red: %lu-bit\n",
429             channel_statistics[RedChannel].depth);
430           (void) fprintf(file,"    green: %lu-bit\n",
431             channel_statistics[GreenChannel].depth);
432           (void) fprintf(file,"    blue: %lu-bit\n",
433             channel_statistics[BlueChannel].depth);
434           if (image->matte != MagickFalse)
435             (void) fprintf(file,"    alpha: %lu-bit\n",
436               channel_statistics[OpacityChannel].depth);
437           break;
438         }
439         case CMYKColorspace:
440         {
441           (void) fprintf(file,"    cyan: %lu-bit\n",
442             channel_statistics[CyanChannel].depth);
443           (void) fprintf(file,"    magenta: %lu-bit\n",
444             channel_statistics[MagentaChannel].depth);
445           (void) fprintf(file,"    yellow: %lu-bit\n",
446             channel_statistics[YellowChannel].depth);
447           (void) fprintf(file,"    black: %lu-bit\n",
448             channel_statistics[BlackChannel].depth);
449           if (image->matte != MagickFalse)
450             (void) fprintf(file,"    alpha: %lu-bit\n",
451               channel_statistics[OpacityChannel].depth);
452           break;
453         }
454         case GRAYColorspace:
455         {
456           (void) fprintf(file,"    gray: %lu-bit\n",
457             channel_statistics[GrayChannel].depth);
458           if (image->matte != MagickFalse)
459             (void) fprintf(file,"    alpha: %lu-bit\n",
460               channel_statistics[OpacityChannel].depth);
461           break;
462         }
463       }
464       scale=1;
465       if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
466         scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long)
467           MAGICKCORE_QUANTUM_DEPTH-image->depth));
468     }
469   if (channel_statistics != (ChannelStatistics *) NULL)
470     {
471       (void) fprintf(file,"  Channel statistics:\n");
472       switch (colorspace)
473       {
474         case RGBColorspace:
475         default:
476         {
477           (void) PrintChannelStatistics(file,RedChannel,"Red",1.0/scale,
478             channel_statistics);
479           (void) PrintChannelStatistics(file,GreenChannel,"Green",1.0/scale,
480             channel_statistics);
481           (void) PrintChannelStatistics(file,BlueChannel,"Blue",1.0/scale,
482             channel_statistics);
483           break;
484         }
485         case CMYKColorspace:
486         {
487           (void) PrintChannelStatistics(file,CyanChannel,"Cyan",1.0/scale,
488             channel_statistics);
489           (void) PrintChannelStatistics(file,MagentaChannel,"Magenta",1.0/scale,
490             channel_statistics);
491           (void) PrintChannelStatistics(file,YellowChannel,"Yellow",1.0/scale,
492             channel_statistics);
493           (void) PrintChannelStatistics(file,BlackChannel,"Black",1.0/scale,
494             channel_statistics);
495           break;
496         }
497         case GRAYColorspace:
498         {
499           (void) PrintChannelStatistics(file,GrayChannel,"Gray",1.0/scale,
500             channel_statistics);
501           break;
502         }
503       }
504       if (image->matte != MagickFalse)
505         (void) PrintChannelStatistics(file,AlphaChannel,"Alpha",1.0/scale,
506           channel_statistics);
507       if (colorspace != GRAYColorspace)
508         {
509           (void) fprintf(file,"  Image statistics:\n");
510           (void) PrintChannelStatistics(file,AllChannels,"Overall",1.0/scale,
511             channel_statistics);
512         }
513       channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
514         channel_statistics);
515     }
516   if (channel_features != (ChannelFeatures *) NULL)
517     {
518       (void) fprintf(file,"  Channel features (horizontal, vertical, left and right diagonals, average):\n");
519       switch (colorspace)
520       {
521         case RGBColorspace:
522         default:
523         {
524           (void) PrintChannelFeatures(file,RedChannel,"Red",channel_features);
525           (void) PrintChannelFeatures(file,GreenChannel,"Green",
526             channel_features);
527           (void) PrintChannelFeatures(file,BlueChannel,"Blue",channel_features);
528           break;
529         }
530         case CMYKColorspace:
531         {
532           (void) PrintChannelFeatures(file,CyanChannel,"Cyan",channel_features);
533           (void) PrintChannelFeatures(file,MagentaChannel,"Magenta",
534             channel_features);
535           (void) PrintChannelFeatures(file,YellowChannel,"Yellow",
536             channel_features);
537           (void) PrintChannelFeatures(file,BlackChannel,"Black",
538             channel_features);
539           break;
540         }
541         case GRAYColorspace:
542         {
543           (void) PrintChannelFeatures(file,GrayChannel,"Gray",channel_features);
544           break;
545         }
546       }
547       if (image->matte != MagickFalse)
548         (void) PrintChannelFeatures(file,AlphaChannel,"Alpha",channel_features);
549       channel_features=(ChannelFeatures *) RelinquishMagickMemory(
550         channel_features);
551     }
552   if (ping == MagickFalse)
553     {
554       if (image->colorspace == CMYKColorspace)
555         (void) fprintf(file,"  Total ink density: %.0f%%\n",100.0*
556           GetImageTotalInkDensity(image)/(double) QuantumRange);
557       x=0;
558       if (image->matte != MagickFalse)
559         {
560           register const IndexPacket
561             *indexes;
562
563           register const PixelPacket
564             *p;
565
566           p=(PixelPacket *) NULL;
567           indexes=(IndexPacket *) NULL;
568           for (y=0; y < (long) image->rows; y++)
569           {
570             p=GetVirtualPixels(image,0,y,image->columns,1,exception);
571             if (p == (const PixelPacket *) NULL)
572               break;
573             indexes=GetVirtualIndexQueue(image);
574             for (x=0; x < (long) image->columns; x++)
575             {
576               if (p->opacity == (Quantum) TransparentOpacity)
577                 break;
578               p++;
579             }
580             if (x < (long) image->columns)
581               break;
582           }
583           if ((x < (long) image->columns) || (y < (long) image->rows))
584             {
585               char
586                 tuple[MaxTextExtent];
587
588               MagickPixelPacket
589                 pixel;
590
591               GetMagickPixelPacket(image,&pixel);
592               SetMagickPixelPacket(image,p,indexes+x,&pixel);
593               (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
594                 &image->exception);
595               (void) fprintf(file,"  Alpha: %s ",tuple);
596               GetColorTuple(&pixel,MagickTrue,tuple);
597               (void) fprintf(file,"  %s\n",tuple);
598             }
599         }
600       artifact=GetImageArtifact(image,"identify:unique");
601       if ((artifact != (const char *) NULL) &&
602           (IsMagickTrue(artifact) != MagickFalse))
603         (void) fprintf(file,"  Colors: %lu\n",GetNumberColors(image,
604           (FILE *) NULL,&image->exception));
605       if (IsHistogramImage(image,&image->exception) != MagickFalse)
606         {
607           (void) fprintf(file,"  Histogram:\n");
608           (void) GetNumberColors(image,file,&image->exception);
609         }
610     }
611   if (image->storage_class == PseudoClass)
612     {
613       (void) fprintf(file,"  Colormap: %lu\n",image->colors);
614       if (image->colors <= 1024)
615         {
616           char
617             color[MaxTextExtent],
618             hex[MaxTextExtent],
619             tuple[MaxTextExtent];
620
621           MagickPixelPacket
622             pixel;
623
624           register PixelPacket
625             *restrict p;
626
627           GetMagickPixelPacket(image,&pixel);
628           p=image->colormap;
629           for (i=0; i < (long) image->colors; i++)
630           {
631             SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
632             (void) CopyMagickString(tuple,"(",MaxTextExtent);
633             ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
634             (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
635             ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
636             (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
637             ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
638             if (pixel.colorspace == CMYKColorspace)
639               {
640                 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
641                 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
642                   tuple);
643               }
644             if (pixel.matte != MagickFalse)
645               {
646                 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
647                 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,
648                   tuple);
649               }
650             (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
651             (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
652               &image->exception);
653             GetColorTuple(&pixel,MagickTrue,hex);
654             (void) fprintf(file,"  %8ld: %s %s %s\n",i,tuple,hex,color);
655             p++;
656           }
657         }
658     }
659   if (image->error.mean_error_per_pixel != 0.0)
660     (void) fprintf(file,"  Mean error per pixel: %g\n",
661       image->error.mean_error_per_pixel);
662   if (image->error.normalized_mean_error != 0.0)
663     (void) fprintf(file,"  Normalized mean error: %g\n",
664       image->error.normalized_mean_error);
665   if (image->error.normalized_maximum_error != 0.0)
666     (void) fprintf(file,"  Normalized maximum error: %g\n",
667       image->error.normalized_maximum_error);
668   (void) fprintf(file,"  Rendering intent: %s\n",MagickOptionToMnemonic(
669     MagickIntentOptions,(long) image->rendering_intent));
670   if (image->gamma != 0.0)
671     (void) fprintf(file,"  Gamma: %g\n",image->gamma);
672   if ((image->chromaticity.red_primary.x != 0.0) ||
673       (image->chromaticity.green_primary.x != 0.0) ||
674       (image->chromaticity.blue_primary.x != 0.0) ||
675       (image->chromaticity.white_point.x != 0.0))
676     {
677       /*
678         Display image chromaticity.
679       */
680       (void) fprintf(file,"  Chromaticity:\n");
681       (void) fprintf(file,"    red primary: (%g,%g)\n",
682         image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
683       (void) fprintf(file,"    green primary: (%g,%g)\n",
684         image->chromaticity.green_primary.x,
685         image->chromaticity.green_primary.y);
686       (void) fprintf(file,"    blue primary: (%g,%g)\n",
687         image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
688       (void) fprintf(file,"    white point: (%g,%g)\n",
689         image->chromaticity.white_point.x,image->chromaticity.white_point.y);
690     }
691   if ((image->extract_info.width*image->extract_info.height) != 0)
692     (void) fprintf(file,"  Tile geometry: %lux%lu%+ld%+ld\n",
693       image->extract_info.width,image->extract_info.height,
694       image->extract_info.x,image->extract_info.y);
695   (void) fprintf(file,"  Interlace: %s\n",MagickOptionToMnemonic(
696     MagickInterlaceOptions,(long) image->interlace));
697   (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
698     &image->exception);
699   (void) fprintf(file,"  Background color: %s\n",color);
700   (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
701     &image->exception);
702   (void) fprintf(file,"  Border color: %s\n",color);
703   (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
704     &image->exception);
705   (void) fprintf(file,"  Matte color: %s\n",color);
706   (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
707     &image->exception);
708   (void) fprintf(file,"  Transparent color: %s\n",color);
709   (void) fprintf(file,"  Compose: %s\n",MagickOptionToMnemonic(
710     MagickComposeOptions,(long) image->compose));
711   if ((image->page.width != 0) || (image->page.height != 0) ||
712       (image->page.x != 0) || (image->page.y != 0))
713     (void) fprintf(file,"  Page geometry: %lux%lu%+ld%+ld\n",image->page.width,
714       image->page.height,image->page.x,image->page.y);
715   if ((image->page.x != 0) || (image->page.y != 0))
716     (void) fprintf(file,"  Origin geometry: %+ld%+ld\n",image->page.x,
717       image->page.y);
718   (void) fprintf(file,"  Dispose: %s\n",MagickOptionToMnemonic(
719     MagickDisposeOptions,(long) image->dispose));
720   if (image->delay != 0)
721     (void) fprintf(file,"  Delay: %lux%ld\n",image->delay,
722       image->ticks_per_second);
723   if (image->iterations != 1)
724     (void) fprintf(file,"  Iterations: %lu\n",image->iterations);
725   if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
726     (void) fprintf(file,"  Scene: %lu of %lu\n",image->scene,
727       GetImageListLength(image));
728   else
729     if (image->scene != 0)
730       (void) fprintf(file,"  Scene: %lu\n",image->scene);
731   (void) fprintf(file,"  Compression: %s\n",MagickOptionToMnemonic(
732     MagickCompressOptions,(long) image->compression));
733   if (image->quality != UndefinedCompressionQuality)
734     (void) fprintf(file,"  Quality: %lu\n",image->quality);
735   (void) fprintf(file,"  Orientation: %s\n",MagickOptionToMnemonic(
736     MagickOrientationOptions,(long) image->orientation));
737   if (image->montage != (char *) NULL)
738     (void) fprintf(file,"  Montage: %s\n",image->montage);
739   if (image->directory != (char *) NULL)
740     {
741       Image
742         *tile;
743
744       ImageInfo
745         *image_info;
746
747       register char
748         *p,
749         *q;
750
751       WarningHandler
752         handler;
753
754       /*
755         Display visual image directory.
756       */
757       image_info=AcquireImageInfo();
758       (void) CloneString(&image_info->size,"64x64");
759       (void) fprintf(file,"  Directory:\n");
760       for (p=image->directory; *p != '\0'; p++)
761       {
762         q=p;
763         while ((*q != '\n') && (*q != '\0'))
764           q++;
765         (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
766         p=q;
767         (void) fprintf(file,"    %s",image_info->filename);
768         handler=SetWarningHandler((WarningHandler) NULL);
769         tile=ReadImage(image_info,&image->exception);
770         (void) SetWarningHandler(handler);
771         if (tile == (Image *) NULL)
772           {
773             (void) fprintf(file,"\n");
774             continue;
775           }
776         (void) fprintf(file," %lux%lu %s\n",tile->magick_columns,
777           tile->magick_rows,tile->magick);
778         (void) SignatureImage(tile);
779         ResetImagePropertyIterator(tile);
780         property=GetNextImageProperty(tile);
781         while (property != (const char *) NULL)
782         {
783           (void) fprintf(file,"  %s:\n",property);
784           value=GetImageProperty(tile,property);
785           if (value != (const char *) NULL)
786             (void) fprintf(file,"%s\n",value);
787           property=GetNextImageProperty(tile);
788         }
789         tile=DestroyImage(tile);
790       }
791       image_info=DestroyImageInfo(image_info);
792     }
793   (void) GetImageProperty(image,"exif:*");
794   ResetImagePropertyIterator(image);
795   property=GetNextImageProperty(image);
796   if (property != (const char *) NULL)
797     {
798       /*
799         Display image properties.
800       */
801       (void) fprintf(file,"  Properties:\n");
802       while (property != (const char *) NULL)
803       {
804         (void) fprintf(file,"    %c",*property);
805         if (strlen(property) > 1)
806           (void) fprintf(file,"%s: ",property+1);
807         if (strlen(property) > 80)
808           (void) fputc('\n',file);
809         value=GetImageProperty(image,property);
810         if (value != (const char *) NULL)
811           (void) fprintf(file,"%s\n",value);
812         property=GetNextImageProperty(image);
813       }
814     }
815   (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
816   value=GetImageProperty(image,key);
817   if (value != (const char *) NULL)
818     {
819       /*
820         Display clipping path.
821       */
822       (void) fprintf(file,"  Clipping path: ");
823       if (strlen(value) > 80)
824         (void) fputc('\n',file);
825       (void) fprintf(file,"%s\n",value);
826     }
827   ResetImageProfileIterator(image);
828   name=GetNextImageProfile(image);
829   if (name != (char *) NULL)
830     {
831       const StringInfo
832         *profile;
833
834       /*
835         Identify image profiles.
836       */
837       (void) fprintf(file,"  Profiles:\n");
838       while (name != (char *) NULL)
839       {
840         profile=GetImageProfile(image,name);
841         if (profile == (StringInfo *) NULL)
842           continue;
843         (void) fprintf(file,"    Profile-%s: %lu bytes\n",name,(unsigned long)
844           GetStringInfoLength(profile));
845 #if defined(MAGICKCORE_LCMS_DELEGATE)
846         if ((LocaleCompare(name,"icc") == 0) ||
847             (LocaleCompare(name,"icm") == 0))
848           {
849             cmsHPROFILE
850               icc_profile;
851
852             icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
853               (DWORD) GetStringInfoLength(profile));
854             if (icc_profile != (cmsHPROFILE *) NULL)
855               {
856                 const char
857                   *name;
858
859                 name=cmsTakeProductName(icc_profile);
860                 if (name != (const char *) NULL)
861                   (void) fprintf(file,"      %s\n",name);
862                 (void) cmsCloseProfile(icc_profile);
863               }
864           }
865 #endif
866         if (LocaleCompare(name,"iptc") == 0)
867           {
868             char
869               *attribute,
870               **attribute_list;
871
872             const char
873               *tag;
874
875             long
876               dataset,
877               record,
878               sentinel;
879
880             register long
881               j;
882
883             size_t
884               length,
885               profile_length;
886
887             profile_length=GetStringInfoLength(profile);
888             for (i=0; i < (long) profile_length; i+=(long) length)
889             {
890               length=1;
891               sentinel=GetStringInfoDatum(profile)[i++];
892               if (sentinel != 0x1c)
893                 continue;
894               dataset=GetStringInfoDatum(profile)[i++];
895               record=GetStringInfoDatum(profile)[i++];
896               switch (record)
897               {
898                 case 5: tag="Image Name"; break;
899                 case 7: tag="Edit Status"; break;
900                 case 10: tag="Priority"; break;
901                 case 15: tag="Category"; break;
902                 case 20: tag="Supplemental Category"; break;
903                 case 22: tag="Fixture Identifier"; break;
904                 case 25: tag="Keyword"; break;
905                 case 30: tag="Release Date"; break;
906                 case 35: tag="Release Time"; break;
907                 case 40: tag="Special Instructions"; break;
908                 case 45: tag="Reference Service"; break;
909                 case 47: tag="Reference Date"; break;
910                 case 50: tag="Reference Number"; break;
911                 case 55: tag="Created Date"; break;
912                 case 60: tag="Created Time"; break;
913                 case 65: tag="Originating Program"; break;
914                 case 70: tag="Program Version"; break;
915                 case 75: tag="Object Cycle"; break;
916                 case 80: tag="Byline"; break;
917                 case 85: tag="Byline Title"; break;
918                 case 90: tag="City"; break;
919                 case 95: tag="Province State"; break;
920                 case 100: tag="Country Code"; break;
921                 case 101: tag="Country"; break;
922                 case 103: tag="Original Transmission Reference"; break;
923                 case 105: tag="Headline"; break;
924                 case 110: tag="Credit"; break;
925                 case 115: tag="Src"; break;
926                 case 116: tag="Copyright String"; break;
927                 case 120: tag="Caption"; break;
928                 case 121: tag="Local Caption"; break;
929                 case 122: tag="Caption Writer"; break;
930                 case 200: tag="Custom Field 1"; break;
931                 case 201: tag="Custom Field 2"; break;
932                 case 202: tag="Custom Field 3"; break;
933                 case 203: tag="Custom Field 4"; break;
934                 case 204: tag="Custom Field 5"; break;
935                 case 205: tag="Custom Field 6"; break;
936                 case 206: tag="Custom Field 7"; break;
937                 case 207: tag="Custom Field 8"; break;
938                 case 208: tag="Custom Field 9"; break;
939                 case 209: tag="Custom Field 10"; break;
940                 case 210: tag="Custom Field 11"; break;
941                 case 211: tag="Custom Field 12"; break;
942                 case 212: tag="Custom Field 13"; break;
943                 case 213: tag="Custom Field 14"; break;
944                 case 214: tag="Custom Field 15"; break;
945                 case 215: tag="Custom Field 16"; break;
946                 case 216: tag="Custom Field 17"; break;
947                 case 217: tag="Custom Field 18"; break;
948                 case 218: tag="Custom Field 19"; break;
949                 case 219: tag="Custom Field 20"; break;
950                 default: tag="unknown"; break;
951               }
952               (void) fprintf(file,"      %s[%ld,%ld]: ",tag,dataset,record);
953               length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
954               length|=GetStringInfoDatum(profile)[i++];
955               attribute=(char *) NULL;
956               if (~length >= MaxTextExtent)
957                 attribute=(char *) AcquireQuantumMemory(length+
958                   MaxTextExtent,sizeof(*attribute));
959               if (attribute != (char *) NULL)
960                 {
961                   (void) CopyMagickString(attribute,(char *)
962                     GetStringInfoDatum(profile)+i,length+1);
963                   attribute_list=StringToList(attribute);
964                   if (attribute_list != (char **) NULL)
965                     {
966                       for (j=0; attribute_list[j] != (char *) NULL; j++)
967                       {
968                         (void) fputs(attribute_list[j],file);
969                         (void) fputs("\n",file);
970                         attribute_list[j]=(char *) RelinquishMagickMemory(
971                           attribute_list[j]);
972                       }
973                       attribute_list=(char **) RelinquishMagickMemory(
974                         attribute_list);
975                     }
976                   attribute=DestroyString(attribute);
977                 }
978             }
979           }
980         if (image->debug != MagickFalse)
981           PrintStringInfo(file,name,profile);
982         name=GetNextImageProfile(image);
983       }
984     }
985   ResetImageArtifactIterator(image);
986   artifact=GetNextImageArtifact(image);
987   if (artifact != (const char *) NULL)
988     {
989       /*
990         Display image artifacts.
991       */
992       (void) fprintf(file,"  Artifacts:\n");
993       while (artifact != (const char *) NULL)
994       {
995         (void) fprintf(file,"    %c",*artifact);
996         if (strlen(artifact) > 1)
997           (void) fprintf(file,"%s: ",artifact+1);
998         if (strlen(artifact) > 80)
999           (void) fputc('\n',file);
1000         value=GetImageArtifact(image,artifact);
1001         if (value != (const char *) NULL)
1002           (void) fprintf(file,"%s\n",value);
1003         artifact=GetNextImageArtifact(image);
1004       }
1005     }
1006   ResetImageRegistryIterator();
1007   registry=GetNextImageRegistry();
1008   if (registry != (const char *) NULL)
1009     {
1010       /*
1011         Display image registry.
1012       */
1013       (void) fprintf(file,"  Registry:\n");
1014       while (registry != (const char *) NULL)
1015       {
1016         (void) fprintf(file,"    %c",*registry);
1017         if (strlen(registry) > 1)
1018           (void) fprintf(file,"%s: ",registry+1);
1019         if (strlen(registry) > 80)
1020           (void) fputc('\n',file);
1021         value=(const char *) GetImageRegistry(StringRegistryType,registry,
1022           &image->exception);
1023         if (value != (const char *) NULL)
1024           (void) fprintf(file,"%s\n",value);
1025         registry=GetNextImageRegistry();
1026       }
1027     }
1028   (void) fprintf(file,"  Tainted: %s\n",MagickOptionToMnemonic(
1029     MagickBooleanOptions,(long) image->taint));
1030   (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
1031   (void) fprintf(file,"  Filesize: %sB\n",format);
1032   (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1033      MagickFalse,format);
1034   (void) fprintf(file,"  Number pixels: %s\n",format);
1035   (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
1036     elapsed_time+0.5),MagickFalse,format);
1037   (void) fprintf(file,"  Pixels per second: %s\n",format);
1038   (void) fprintf(file,"  User time: %0.3fu\n",user_time);
1039   (void) fprintf(file,"  Elapsed time: %ld:%02ld.%03ld\n",(long)
1040     (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),(long)
1041     (1000.0*(elapsed_time-floor(elapsed_time))));
1042   (void) fprintf(file,"  Version: %s\n",GetMagickVersion((unsigned long *)
1043     NULL));
1044   (void) fflush(file);
1045   return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1046 }