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