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