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