]> 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[%.20g] ",image->filename,(double) image->scene);
325       (void) fprintf(file,"%s ",image->magick);
326       if ((image->magick_columns != 0) || (image->magick_rows != 0))
327         if ((image->magick_columns != image->columns) ||
328             (image->magick_rows != image->rows))
329           (void) fprintf(file,"%.20gx%.20g=>",(double) image->magick_columns,
330             (double) image->magick_rows);
331       (void) fprintf(file,"%.20gx%.20g ",(double) image->columns,(double)
332         image->rows);
333       if ((image->page.width != 0) || (image->page.height != 0) ||
334           (image->page.x != 0) || (image->page.y != 0))
335         (void) fprintf(file,"%.20gx%.20g%+.20g%+.20g ",(double)
336           image->page.width,(double) image->page.height,(double) image->page.x,
337           (double) image->page.y);
338       (void) fprintf(file,"%.20g-bit ",(double) image->depth);
339       if (image->type != UndefinedType)
340         (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
341           (ssize_t) image->type));
342       if (image->storage_class == DirectClass)
343         {
344           (void) fprintf(file,"DirectClass ");
345           if (image->total_colors != 0)
346             {
347               (void) FormatMagickSize(image->total_colors,MagickFalse,format);
348               (void) fprintf(file,"%s ",format);
349             }
350         }
351       else
352         if (image->total_colors <= image->colors)
353           (void) fprintf(file,"PseudoClass %.20gc ",(double) image->colors);
354         else
355           (void) fprintf(file,"PseudoClass %.20g=>%.20gc ",(double)
356             image->total_colors,(double) image->colors);
357       if (image->error.mean_error_per_pixel != 0.0)
358         (void) fprintf(file,"%.20g/%f/%fdb ",(double)
359           (image->error.mean_error_per_pixel+0.5),
360           image->error.normalized_mean_error,
361           image->error.normalized_maximum_error);
362       if (GetBlobSize(image) != 0)
363         {
364           (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
365           (void) fprintf(file,"%sB ",format);
366         }
367       (void) fprintf(file,"%0.3fu %lu:%02lu.%03lu",user_time,(unsigned long)
368         (elapsed_time/60.0),(unsigned long) floor(fmod(elapsed_time,60.0)),
369         (unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))));
370       (void) fprintf(file,"\n");
371       (void) fflush(file);
372       return(ferror(file) != 0 ? MagickFalse : MagickTrue);
373     }
374   /*
375     Display verbose info about the image.
376   */
377   exception=AcquireExceptionInfo();
378   pixels=GetVirtualPixels(image,0,0,1,1,exception);
379   exception=DestroyExceptionInfo(exception);
380   ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
381   type=GetImageType(image,&image->exception);
382   (void) SignatureImage(image);
383   (void) fprintf(file,"Image: %s\n",image->filename);
384   if (*image->magick_filename != '\0')
385     if (LocaleCompare(image->magick_filename,image->filename) != 0)
386       {
387         char
388           filename[MaxTextExtent];
389
390         GetPathComponent(image->magick_filename,TailPath,filename);
391         (void) fprintf(file,"  Base filename: %s\n",filename);
392       }
393   magick_info=GetMagickInfo(image->magick,&image->exception);
394   if ((magick_info == (const MagickInfo *) NULL) ||
395       (*GetMagickDescription(magick_info) == '\0'))
396     (void) fprintf(file,"  Format: %s\n",image->magick);
397   else
398     (void) fprintf(file,"  Format: %s (%s)\n",image->magick,
399       GetMagickDescription(magick_info));
400   (void) fprintf(file,"  Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
401     (ssize_t) image->storage_class));
402   (void) fprintf(file,"  Geometry: %.20gx%.20g%+.20g%+.20g\n",(double)
403     image->columns,(double) image->rows,(double) image->tile_offset.x,(double)
404     image->tile_offset.y);
405   if ((image->magick_columns != 0) || (image->magick_rows != 0))
406     if ((image->magick_columns != image->columns) ||
407         (image->magick_rows != image->rows))
408       (void) fprintf(file,"  Base geometry: %.20gx%.20g\n",(double)
409         image->magick_columns,(double) image->magick_rows);
410   if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
411     {
412       (void) fprintf(file,"  Resolution: %gx%g\n",image->x_resolution,
413         image->y_resolution);
414       (void) fprintf(file,"  Print size: %gx%g\n",(double) image->columns/
415         image->x_resolution,(double) image->rows/image->y_resolution);
416     }
417   (void) fprintf(file,"  Units: %s\n",MagickOptionToMnemonic(
418     MagickResolutionOptions,(ssize_t) image->units));
419   (void) fprintf(file,"  Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
420     (ssize_t) type));
421   if (image->type != UndefinedType)
422     (void) fprintf(file,"  Base type: %s\n",MagickOptionToMnemonic(
423       MagickTypeOptions,(ssize_t) image->type));
424   (void) fprintf(file,"  Endianess: %s\n",MagickOptionToMnemonic(
425     MagickEndianOptions,(ssize_t) image->endian));
426   /*
427     Detail channel depth and extrema.
428   */
429   (void) fprintf(file,"  Colorspace: %s\n",MagickOptionToMnemonic(
430     MagickColorspaceOptions,(ssize_t) image->colorspace));
431   channel_statistics=(ChannelStatistics *) NULL;
432   channel_features=(ChannelFeatures *) NULL;
433   colorspace=image->colorspace;
434   if (ping == MagickFalse)
435     {
436       size_t
437         depth;
438
439       channel_statistics=GetImageChannelStatistics(image,&image->exception);
440       artifact=GetImageArtifact(image,"identify:features");
441       if (artifact != (const char *) NULL)
442         {
443           distance=StringToUnsignedLong(artifact);
444           channel_features=GetImageChannelFeatures(image,distance,
445             &image->exception);
446         }
447       depth=GetImageDepth(image,&image->exception);
448       if (image->depth == depth)
449         (void) fprintf(file,"  Depth: %.20g-bit\n",(double) image->depth);
450       else
451         (void) fprintf(file,"  Depth: %.20g/%.20g-bit\n",(double)
452           image->depth,(double) depth);
453       (void) fprintf(file,"  Channel depth:\n");
454       if (IsGrayImage(image,&image->exception) != MagickFalse)
455         colorspace=GRAYColorspace;
456       switch (colorspace)
457       {
458         case RGBColorspace:
459         default:
460         {
461           (void) fprintf(file,"    red: %.20g-bit\n",(double)
462             channel_statistics[RedChannel].depth);
463           (void) fprintf(file,"    green: %.20g-bit\n",(double)
464             channel_statistics[GreenChannel].depth);
465           (void) fprintf(file,"    blue: %.20g-bit\n",(double)
466             channel_statistics[BlueChannel].depth);
467           break;
468         }
469         case CMYKColorspace:
470         {
471           (void) fprintf(file,"    cyan: %.20g-bit\n",(double)
472             channel_statistics[CyanChannel].depth);
473           (void) fprintf(file,"    magenta: %.20g-bit\n",(double)
474             channel_statistics[MagentaChannel].depth);
475           (void) fprintf(file,"    yellow: %.20g-bit\n",(double)
476             channel_statistics[YellowChannel].depth);
477           (void) fprintf(file,"    black: %.20g-bit\n",(double)
478             channel_statistics[BlackChannel].depth);
479           break;
480         }
481         case GRAYColorspace:
482         {
483           (void) fprintf(file,"    gray: %.20g-bit\n",(double)
484             channel_statistics[GrayChannel].depth);
485           break;
486         }
487       }
488       if (image->matte != MagickFalse)
489         (void) fprintf(file,"    alpha: %.20g-bit\n",(double)
490           channel_statistics[OpacityChannel].depth);
491       scale=1;
492       if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
493         scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
494           MAGICKCORE_QUANTUM_DEPTH-image->depth));
495     }
496   if (channel_statistics != (ChannelStatistics *) NULL)
497     {
498       (void) fprintf(file,"  Channel statistics:\n");
499       switch (colorspace)
500       {
501         case RGBColorspace:
502         default:
503         {
504           (void) PrintChannelStatistics(file,RedChannel,"Red",1.0/scale,
505             channel_statistics);
506           (void) PrintChannelStatistics(file,GreenChannel,"Green",1.0/scale,
507             channel_statistics);
508           (void) PrintChannelStatistics(file,BlueChannel,"Blue",1.0/scale,
509             channel_statistics);
510           break;
511         }
512         case CMYKColorspace:
513         {
514           (void) PrintChannelStatistics(file,CyanChannel,"Cyan",1.0/scale,
515             channel_statistics);
516           (void) PrintChannelStatistics(file,MagentaChannel,"Magenta",1.0/scale,
517             channel_statistics);
518           (void) PrintChannelStatistics(file,YellowChannel,"Yellow",1.0/scale,
519             channel_statistics);
520           (void) PrintChannelStatistics(file,BlackChannel,"Black",1.0/scale,
521             channel_statistics);
522           break;
523         }
524         case GRAYColorspace:
525         {
526           (void) PrintChannelStatistics(file,GrayChannel,"Gray",1.0/scale,
527             channel_statistics);
528           break;
529         }
530       }
531       if (image->matte != MagickFalse)
532         (void) PrintChannelStatistics(file,AlphaChannel,"Alpha",1.0/scale,
533           channel_statistics);
534       if (colorspace != GRAYColorspace)
535         {
536           (void) fprintf(file,"  Image statistics:\n");
537           (void) PrintChannelStatistics(file,AllChannels,"Overall",1.0/scale,
538             channel_statistics);
539         }
540       channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
541         channel_statistics);
542     }
543   if (channel_features != (ChannelFeatures *) NULL)
544     {
545       (void) fprintf(file,"  Channel features (horizontal, vertical, left and right diagonals, average):\n");
546       switch (colorspace)
547       {
548         case RGBColorspace:
549         default:
550         {
551           (void) PrintChannelFeatures(file,RedChannel,"Red",channel_features);
552           (void) PrintChannelFeatures(file,GreenChannel,"Green",
553             channel_features);
554           (void) PrintChannelFeatures(file,BlueChannel,"Blue",channel_features);
555           break;
556         }
557         case CMYKColorspace:
558         {
559           (void) PrintChannelFeatures(file,CyanChannel,"Cyan",channel_features);
560           (void) PrintChannelFeatures(file,MagentaChannel,"Magenta",
561             channel_features);
562           (void) PrintChannelFeatures(file,YellowChannel,"Yellow",
563             channel_features);
564           (void) PrintChannelFeatures(file,BlackChannel,"Black",
565             channel_features);
566           break;
567         }
568         case GRAYColorspace:
569         {
570           (void) PrintChannelFeatures(file,GrayChannel,"Gray",channel_features);
571           break;
572         }
573       }
574       if (image->matte != MagickFalse)
575         (void) PrintChannelFeatures(file,AlphaChannel,"Alpha",channel_features);
576       channel_features=(ChannelFeatures *) RelinquishMagickMemory(
577         channel_features);
578     }
579   if (ping == MagickFalse)
580     {
581       if (image->colorspace == CMYKColorspace)
582         (void) fprintf(file,"  Total ink density: %.0f%%\n",100.0*
583           GetImageTotalInkDensity(image)/(double) QuantumRange);
584       x=0;
585       if (image->matte != MagickFalse)
586         {
587           register const IndexPacket
588             *indexes;
589
590           register const PixelPacket
591             *p;
592
593           p=(PixelPacket *) NULL;
594           indexes=(IndexPacket *) NULL;
595           for (y=0; y < (ssize_t) image->rows; y++)
596           {
597             p=GetVirtualPixels(image,0,y,image->columns,1,exception);
598             if (p == (const PixelPacket *) NULL)
599               break;
600             indexes=GetVirtualIndexQueue(image);
601             for (x=0; x < (ssize_t) image->columns; x++)
602             {
603               if (p->opacity == (Quantum) TransparentOpacity)
604                 break;
605               p++;
606             }
607             if (x < (ssize_t) image->columns)
608               break;
609           }
610           if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
611             {
612               char
613                 tuple[MaxTextExtent];
614
615               MagickPixelPacket
616                 pixel;
617
618               GetMagickPixelPacket(image,&pixel);
619               SetMagickPixelPacket(image,p,indexes+x,&pixel);
620               (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
621                 &image->exception);
622               (void) fprintf(file,"  Alpha: %s ",tuple);
623               GetColorTuple(&pixel,MagickTrue,tuple);
624               (void) fprintf(file,"  %s\n",tuple);
625             }
626         }
627       artifact=GetImageArtifact(image,"identify:unique-colors");
628       if ((artifact != (const char *) NULL) &&
629           (IsMagickTrue(artifact) != MagickFalse))
630         (void) fprintf(file,"  Colors: %.20g\n",(double)
631           GetNumberColors(image,(FILE *) NULL,&image->exception));
632       if (IsHistogramImage(image,&image->exception) != MagickFalse)
633         {
634           (void) fprintf(file,"  Histogram:\n");
635           (void) GetNumberColors(image,file,&image->exception);
636         }
637     }
638   if (image->storage_class == PseudoClass)
639     {
640       (void) fprintf(file,"  Colormap: %.20g\n",(double) image->colors);
641       if (image->colors <= 1024)
642         {
643           char
644             color[MaxTextExtent],
645             hex[MaxTextExtent],
646             tuple[MaxTextExtent];
647
648           MagickPixelPacket
649             pixel;
650
651           register PixelPacket
652             *restrict p;
653
654           GetMagickPixelPacket(image,&pixel);
655           p=image->colormap;
656           for (i=0; i < (ssize_t) image->colors; i++)
657           {
658             SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
659             (void) CopyMagickString(tuple,"(",MaxTextExtent);
660             ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
661             (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
662             ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
663             (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
664             ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
665             if (pixel.colorspace == CMYKColorspace)
666               {
667                 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
668                 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
669                   tuple);
670               }
671             if (pixel.matte != MagickFalse)
672               {
673                 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
674                 ConcatenateColorComponent(&pixel,AlphaChannel,X11Compliance,
675                   tuple);
676               }
677             (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
678             (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
679               &image->exception);
680             GetColorTuple(&pixel,MagickTrue,hex);
681             (void) fprintf(file,"  %8ld: %s %s %s\n",(long) i,tuple,hex,color);
682             p++;
683           }
684         }
685     }
686   if (image->error.mean_error_per_pixel != 0.0)
687     (void) fprintf(file,"  Mean error per pixel: %g\n",
688       image->error.mean_error_per_pixel);
689   if (image->error.normalized_mean_error != 0.0)
690     (void) fprintf(file,"  Normalized mean error: %g\n",
691       image->error.normalized_mean_error);
692   if (image->error.normalized_maximum_error != 0.0)
693     (void) fprintf(file,"  Normalized maximum error: %g\n",
694       image->error.normalized_maximum_error);
695   (void) fprintf(file,"  Rendering intent: %s\n",MagickOptionToMnemonic(
696     MagickIntentOptions,(ssize_t) image->rendering_intent));
697   if (image->gamma != 0.0)
698     (void) fprintf(file,"  Gamma: %g\n",image->gamma);
699   if ((image->chromaticity.red_primary.x != 0.0) ||
700       (image->chromaticity.green_primary.x != 0.0) ||
701       (image->chromaticity.blue_primary.x != 0.0) ||
702       (image->chromaticity.white_point.x != 0.0))
703     {
704       /*
705         Display image chromaticity.
706       */
707       (void) fprintf(file,"  Chromaticity:\n");
708       (void) fprintf(file,"    red primary: (%g,%g)\n",
709         image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
710       (void) fprintf(file,"    green primary: (%g,%g)\n",
711         image->chromaticity.green_primary.x,
712         image->chromaticity.green_primary.y);
713       (void) fprintf(file,"    blue primary: (%g,%g)\n",
714         image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
715       (void) fprintf(file,"    white point: (%g,%g)\n",
716         image->chromaticity.white_point.x,image->chromaticity.white_point.y);
717     }
718   if ((image->extract_info.width*image->extract_info.height) != 0)
719     (void) fprintf(file,"  Tile geometry: %.20gx%.20g%+.20g%+.20g\n",(double)
720       image->extract_info.width,(double) image->extract_info.height,(double)
721       image->extract_info.x,(double) image->extract_info.y);
722   (void) fprintf(file,"  Interlace: %s\n",MagickOptionToMnemonic(
723     MagickInterlaceOptions,(ssize_t) image->interlace));
724   (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
725     &image->exception);
726   (void) fprintf(file,"  Background color: %s\n",color);
727   (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
728     &image->exception);
729   (void) fprintf(file,"  Border color: %s\n",color);
730   (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
731     &image->exception);
732   (void) fprintf(file,"  Matte color: %s\n",color);
733   (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
734     &image->exception);
735   (void) fprintf(file,"  Transparent color: %s\n",color);
736   (void) fprintf(file,"  Compose: %s\n",MagickOptionToMnemonic(
737     MagickComposeOptions,(ssize_t) image->compose));
738   if ((image->page.width != 0) || (image->page.height != 0) ||
739       (image->page.x != 0) || (image->page.y != 0))
740     (void) fprintf(file,"  Page geometry: %.20gx%.20g%+.20g%+.20g\n",(double)
741       image->page.width,(double) image->page.height,(double)
742       image->page.x,(double) image->page.y);
743   if ((image->page.x != 0) || (image->page.y != 0))
744     (void) fprintf(file,"  Origin geometry: %+.20g%+.20g\n",(double)
745       image->page.x,(double) image->page.y);
746   (void) fprintf(file,"  Dispose: %s\n",MagickOptionToMnemonic(
747     MagickDisposeOptions,(ssize_t) image->dispose));
748   if (image->delay != 0)
749     (void) fprintf(file,"  Delay: %.20gx%.20g\n",(double) image->delay,
750       (double) image->ticks_per_second);
751   if (image->iterations != 1)
752     (void) fprintf(file,"  Iterations: %.20g\n",(double) image->iterations);
753   if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
754     (void) fprintf(file,"  Scene: %.20g of %.20g\n",(double) image->scene,
755       (double) GetImageListLength(image));
756   else
757     if (image->scene != 0)
758       (void) fprintf(file,"  Scene: %.20g\n",(double) image->scene);
759   (void) fprintf(file,"  Compression: %s\n",MagickOptionToMnemonic(
760     MagickCompressOptions,(ssize_t) image->compression));
761   if (image->quality != UndefinedCompressionQuality)
762     (void) fprintf(file,"  Quality: %.20g\n",(double) image->quality);
763   (void) fprintf(file,"  Orientation: %s\n",MagickOptionToMnemonic(
764     MagickOrientationOptions,(ssize_t) image->orientation));
765   if (image->montage != (char *) NULL)
766     (void) fprintf(file,"  Montage: %s\n",image->montage);
767   if (image->directory != (char *) NULL)
768     {
769       Image
770         *tile;
771
772       ImageInfo
773         *image_info;
774
775       register char
776         *p,
777         *q;
778
779       WarningHandler
780         handler;
781
782       /*
783         Display visual image directory.
784       */
785       image_info=AcquireImageInfo();
786       (void) CloneString(&image_info->size,"64x64");
787       (void) fprintf(file,"  Directory:\n");
788       for (p=image->directory; *p != '\0'; p++)
789       {
790         q=p;
791         while ((*q != '\n') && (*q != '\0'))
792           q++;
793         (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
794         p=q;
795         (void) fprintf(file,"    %s",image_info->filename);
796         handler=SetWarningHandler((WarningHandler) NULL);
797         tile=ReadImage(image_info,&image->exception);
798         (void) SetWarningHandler(handler);
799         if (tile == (Image *) NULL)
800           {
801             (void) fprintf(file,"\n");
802             continue;
803           }
804         (void) fprintf(file," %.20gx%.20g %s\n",(double) tile->magick_columns,
805           (double) tile->magick_rows,tile->magick);
806         (void) SignatureImage(tile);
807         ResetImagePropertyIterator(tile);
808         property=GetNextImageProperty(tile);
809         while (property != (const char *) NULL)
810         {
811           (void) fprintf(file,"  %s:\n",property);
812           value=GetImageProperty(tile,property);
813           if (value != (const char *) NULL)
814             (void) fprintf(file,"%s\n",value);
815           property=GetNextImageProperty(tile);
816         }
817         tile=DestroyImage(tile);
818       }
819       image_info=DestroyImageInfo(image_info);
820     }
821   (void) GetImageProperty(image,"exif:*");
822   ResetImagePropertyIterator(image);
823   property=GetNextImageProperty(image);
824   if (property != (const char *) NULL)
825     {
826       /*
827         Display image properties.
828       */
829       (void) fprintf(file,"  Properties:\n");
830       while (property != (const char *) NULL)
831       {
832         (void) fprintf(file,"    %s: ",property);
833         value=GetImageProperty(image,property);
834         if (value != (const char *) NULL)
835           (void) fprintf(file,"%s\n",value);
836         property=GetNextImageProperty(image);
837       }
838     }
839   (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
840   value=GetImageProperty(image,key);
841   if (value != (const char *) NULL)
842     {
843       /*
844         Display clipping path.
845       */
846       (void) fprintf(file,"  Clipping path: ");
847       if (strlen(value) > 80)
848         (void) fputc('\n',file);
849       (void) fprintf(file,"%s\n",value);
850     }
851   ResetImageProfileIterator(image);
852   name=GetNextImageProfile(image);
853   if (name != (char *) NULL)
854     {
855       const StringInfo
856         *profile;
857
858       /*
859         Identify image profiles.
860       */
861       (void) fprintf(file,"  Profiles:\n");
862       while (name != (char *) NULL)
863       {
864         profile=GetImageProfile(image,name);
865         if (profile == (StringInfo *) NULL)
866           continue;
867         (void) fprintf(file,"    Profile-%s: %.20g bytes\n",name,(double)
868           GetStringInfoLength(profile));
869 #if defined(MAGICKCORE_LCMS_DELEGATE)
870         if ((LocaleCompare(name,"icc") == 0) ||
871             (LocaleCompare(name,"icm") == 0))
872           {
873             cmsHPROFILE
874               icc_profile;
875
876             icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
877               (cmsUInt32Number) GetStringInfoLength(profile));
878             if (icc_profile != (cmsHPROFILE *) NULL)
879               {
880 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
881                 const char
882                   *name;
883
884                 name=cmsTakeProductName(icc_profile);
885                 if (name != (const char *) NULL)
886                   (void) fprintf(file,"      %s\n",name);
887 #else
888                 char
889                   info[MaxTextExtent];
890
891                 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
892                   "en","US",info,MaxTextExtent);
893                 (void) fprintf(file,"      Description: %s\n",info);
894                 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,
895                   "en","US",info,MaxTextExtent);
896                 (void) fprintf(file,"      Manufacturer: %s\n",info);
897                 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en",
898                   "US",info,MaxTextExtent);
899                 (void) fprintf(file,"      Model: %s\n",info);
900                 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,
901                   "en","US",info,MaxTextExtent);
902                 (void) fprintf(file,"      Copyright: %s\n",info);
903 #endif
904                 (void) cmsCloseProfile(icc_profile);
905               }
906           }
907 #endif
908         if (LocaleCompare(name,"iptc") == 0)
909           {
910             char
911               *attribute,
912               **attribute_list;
913
914             const char
915               *tag;
916
917             long
918               dataset,
919               record,
920               sentinel;
921
922             register ssize_t
923               j;
924
925             size_t
926               length,
927               profile_length;
928
929             profile_length=GetStringInfoLength(profile);
930             for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
931             {
932               length=1;
933               sentinel=GetStringInfoDatum(profile)[i++];
934               if (sentinel != 0x1c)
935                 continue;
936               dataset=GetStringInfoDatum(profile)[i++];
937               record=GetStringInfoDatum(profile)[i++];
938               switch (record)
939               {
940                 case 5: tag="Image Name"; break;
941                 case 7: tag="Edit Status"; break;
942                 case 10: tag="Priority"; break;
943                 case 15: tag="Category"; break;
944                 case 20: tag="Supplemental Category"; break;
945                 case 22: tag="Fixture Identifier"; break;
946                 case 25: tag="Keyword"; break;
947                 case 30: tag="Release Date"; break;
948                 case 35: tag="Release Time"; break;
949                 case 40: tag="Special Instructions"; break;
950                 case 45: tag="Reference Service"; break;
951                 case 47: tag="Reference Date"; break;
952                 case 50: tag="Reference Number"; break;
953                 case 55: tag="Created Date"; break;
954                 case 60: tag="Created Time"; break;
955                 case 65: tag="Originating Program"; break;
956                 case 70: tag="Program Version"; break;
957                 case 75: tag="Object Cycle"; break;
958                 case 80: tag="Byline"; break;
959                 case 85: tag="Byline Title"; break;
960                 case 90: tag="City"; break;
961                 case 95: tag="Province State"; break;
962                 case 100: tag="Country Code"; break;
963                 case 101: tag="Country"; break;
964                 case 103: tag="Original Transmission Reference"; break;
965                 case 105: tag="Headline"; break;
966                 case 110: tag="Credit"; break;
967                 case 115: tag="Src"; break;
968                 case 116: tag="Copyright String"; break;
969                 case 120: tag="Caption"; break;
970                 case 121: tag="Local Caption"; break;
971                 case 122: tag="Caption Writer"; break;
972                 case 200: tag="Custom Field 1"; break;
973                 case 201: tag="Custom Field 2"; break;
974                 case 202: tag="Custom Field 3"; break;
975                 case 203: tag="Custom Field 4"; break;
976                 case 204: tag="Custom Field 5"; break;
977                 case 205: tag="Custom Field 6"; break;
978                 case 206: tag="Custom Field 7"; break;
979                 case 207: tag="Custom Field 8"; break;
980                 case 208: tag="Custom Field 9"; break;
981                 case 209: tag="Custom Field 10"; break;
982                 case 210: tag="Custom Field 11"; break;
983                 case 211: tag="Custom Field 12"; break;
984                 case 212: tag="Custom Field 13"; break;
985                 case 213: tag="Custom Field 14"; break;
986                 case 214: tag="Custom Field 15"; break;
987                 case 215: tag="Custom Field 16"; break;
988                 case 216: tag="Custom Field 17"; break;
989                 case 217: tag="Custom Field 18"; break;
990                 case 218: tag="Custom Field 19"; break;
991                 case 219: tag="Custom Field 20"; break;
992                 default: tag="unknown"; break;
993               }
994               (void) fprintf(file,"      %s[%.20g,%.20g]: ",tag,(double)
995                 dataset,(double) record);
996               length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
997               length|=GetStringInfoDatum(profile)[i++];
998               attribute=(char *) NULL;
999               if (~length >= MaxTextExtent)
1000                 attribute=(char *) AcquireQuantumMemory(length+
1001                   MaxTextExtent,sizeof(*attribute));
1002               if (attribute != (char *) NULL)
1003                 {
1004                   (void) CopyMagickString(attribute,(char *)
1005                     GetStringInfoDatum(profile)+i,length+1);
1006                   attribute_list=StringToList(attribute);
1007                   if (attribute_list != (char **) NULL)
1008                     {
1009                       for (j=0; attribute_list[j] != (char *) NULL; j++)
1010                       {
1011                         (void) fputs(attribute_list[j],file);
1012                         (void) fputs("\n",file);
1013                         attribute_list[j]=(char *) RelinquishMagickMemory(
1014                           attribute_list[j]);
1015                       }
1016                       attribute_list=(char **) RelinquishMagickMemory(
1017                         attribute_list);
1018                     }
1019                   attribute=DestroyString(attribute);
1020                 }
1021             }
1022           }
1023         if (image->debug != MagickFalse)
1024           PrintStringInfo(file,name,profile);
1025         name=GetNextImageProfile(image);
1026       }
1027     }
1028   ResetImageArtifactIterator(image);
1029   artifact=GetNextImageArtifact(image);
1030   if (artifact != (const char *) NULL)
1031     {
1032       /*
1033         Display image artifacts.
1034       */
1035       (void) fprintf(file,"  Artifacts:\n");
1036       while (artifact != (const char *) NULL)
1037       {
1038         (void) fprintf(file,"    %s: ",artifact);
1039         value=GetImageArtifact(image,artifact);
1040         if (value != (const char *) NULL)
1041           (void) fprintf(file,"%s\n",value);
1042         artifact=GetNextImageArtifact(image);
1043       }
1044     }
1045   ResetImageRegistryIterator();
1046   registry=GetNextImageRegistry();
1047   if (registry != (const char *) NULL)
1048     {
1049       /*
1050         Display image registry.
1051       */
1052       (void) fprintf(file,"  Registry:\n");
1053       while (registry != (const char *) NULL)
1054       {
1055         (void) fprintf(file,"    %s: ",registry);
1056         value=(const char *) GetImageRegistry(StringRegistryType,registry,
1057           &image->exception);
1058         if (value != (const char *) NULL)
1059           (void) fprintf(file,"%s\n",value);
1060         registry=GetNextImageRegistry();
1061       }
1062     }
1063   (void) fprintf(file,"  Tainted: %s\n",MagickOptionToMnemonic(
1064     MagickBooleanOptions,(ssize_t) image->taint));
1065   (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
1066   (void) fprintf(file,"  Filesize: %sB\n",format);
1067   (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1068      MagickFalse,format);
1069   (void) fprintf(file,"  Number pixels: %s\n",format);
1070   (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
1071     elapsed_time+0.5),MagickFalse,format);
1072   (void) fprintf(file,"  Pixels per second: %s\n",format);
1073   (void) fprintf(file,"  User time: %0.3fu\n",user_time);
1074   (void) fprintf(file,"  Elapsed time: %lu:%02lu.%03lu\n",(unsigned long) 
1075     (elapsed_time/60.0),(unsigned long) ceil(fmod(elapsed_time,60.0)),
1076     (unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))));
1077   (void) fprintf(file,"  Version: %s\n",GetMagickVersion((size_t *)
1078     NULL));
1079   (void) fflush(file);
1080   return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1081 }