MagickCore  7.1.2-29
Convert, Edit, Or Compose Bitmap Images
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 % Cristy %
17 % September 1994 %
18 % %
19 % %
20 % Copyright @ 1999 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 % https://imagemagick.org/license/ %
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 ␌
42 /*
43  Include declarations.
44 */
45 #include "MagickCore/studio.h"
46 #include "MagickCore/annotate.h"
47 #include "MagickCore/artifact.h"
48 #include "MagickCore/attribute.h"
49 #include "MagickCore/blob.h"
50 #include "MagickCore/blob-private.h"
51 #include "MagickCore/cache.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/coder.h"
54 #include "MagickCore/color.h"
55 #include "MagickCore/configure.h"
56 #include "MagickCore/constitute.h"
57 #include "MagickCore/constitute-private.h"
58 #include "MagickCore/decorate.h"
59 #include "MagickCore/delegate.h"
60 #include "MagickCore/draw.h"
61 #include "MagickCore/effect.h"
62 #include "MagickCore/exception.h"
63 #include "MagickCore/exception-private.h"
64 #include "MagickCore/feature.h"
65 #include "MagickCore/gem.h"
66 #include "MagickCore/geometry.h"
67 #include "MagickCore/histogram.h"
68 #include "MagickCore/identify.h"
69 #include "MagickCore/image.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/locale_.h"
73 #include "MagickCore/log.h"
74 #include "MagickCore/magic.h"
75 #include "MagickCore/magick.h"
76 #include "MagickCore/memory_.h"
77 #include "MagickCore/module.h"
78 #include "MagickCore/monitor.h"
79 #include "MagickCore/montage.h"
80 #include "MagickCore/option.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/pixel-private.h"
83 #include "MagickCore/prepress.h"
84 #include "MagickCore/profile.h"
85 #include "MagickCore/property.h"
86 #include "MagickCore/quantize.h"
87 #include "MagickCore/quantum.h"
88 #include "MagickCore/random_.h"
89 #include "MagickCore/registry.h"
90 #include "MagickCore/resize.h"
91 #include "MagickCore/resource_.h"
92 #include "MagickCore/signature.h"
93 #include "MagickCore/statistic.h"
94 #include "MagickCore/string_.h"
95 #include "MagickCore/string-private.h"
96 #include "MagickCore/timer.h"
97 #include "MagickCore/timer-private.h"
98 #include "MagickCore/token.h"
99 #include "MagickCore/utility.h"
100 #include "MagickCore/utility-private.h"
101 #include "MagickCore/version.h"
102 ␌
103 /*
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 % %
106 % %
107 % %
108 % I d e n t i f y I m a g e %
109 % %
110 % %
111 % %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %
114 % IdentifyImage() identifies an image by printing its attributes to the file.
115 % Attributes include the image width, height, size, and others.
116 %
117 % The format of the IdentifyImage method is:
118 %
119 % MagickBooleanType IdentifyImage(Image *image,FILE *file,
120 % const MagickBooleanType verbose,ExceptionInfo *exception)
121 %
122 % A description of each parameter follows:
123 %
124 % o image: the image.
125 %
126 % o file: the file, typically stdout.
127 %
128 % o verbose: A value other than zero prints more detailed information
129 % about the image.
130 %
131 % o exception: return any errors or warnings in this structure.
132 %
133 */
134 
135 static ChannelStatistics *GetLocationStatistics(const Image *image,
136  const StatisticType type,ExceptionInfo *exception)
137 {
139  *channel_statistics;
140 
141  ssize_t
142  i,
143  y;
144 
145  assert(image != (Image *) NULL);
146  assert(image->signature == MagickCoreSignature);
147  if (IsEventLogging() != MagickFalse)
148  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
149  channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
150  MaxPixelChannels+1,sizeof(*channel_statistics));
151  if (channel_statistics == (ChannelStatistics *) NULL)
152  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
153  (void) memset(channel_statistics,0,(MaxPixelChannels+1)*
154  sizeof(*channel_statistics));
155  for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
156  {
157  switch (type)
158  {
159  case MaximumStatistic:
160  default:
161  {
162  channel_statistics[i].maxima=(-MagickMaximumValue);
163  break;
164  }
165  case MinimumStatistic:
166  {
167  channel_statistics[i].minima=MagickMaximumValue;
168  break;
169  }
170  }
171  }
172  for (y=0; y < (ssize_t) image->rows; y++)
173  {
174  const Quantum
175  *magick_restrict p;
176 
177  ssize_t
178  x;
179 
180  p=GetVirtualPixels(image,0,y,image->columns,1,exception);
181  if (p == (const Quantum *) NULL)
182  break;
183  for (x=0; x < (ssize_t) image->columns; x++)
184  {
185  if (GetPixelReadMask(image,p) <= (QuantumRange/2))
186  {
187  p+=(ptrdiff_t) GetPixelChannels(image);
188  continue;
189  }
190  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
191  {
192  PixelChannel channel = GetPixelChannelChannel(image,i);
193  PixelTrait traits = GetPixelChannelTraits(image,channel);
194  if (traits == UndefinedPixelTrait)
195  continue;
196  switch (type)
197  {
198  case MaximumStatistic:
199  default:
200  {
201  if ((double) p[i] > channel_statistics[channel].maxima)
202  channel_statistics[channel].maxima=(double) p[i];
203  break;
204  }
205  case MinimumStatistic:
206  {
207  if ((double) p[i] < channel_statistics[channel].minima)
208  channel_statistics[channel].minima=(double) p[i];
209  break;
210  }
211  }
212  }
213  p+=(ptrdiff_t) GetPixelChannels(image);
214  }
215  }
216  return(channel_statistics);
217 }
218 
219 static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
220  const char *name,const ChannelFeatures *channel_features)
221 {
222 #define PrintFeature(feature) \
223  GetMagickPrecision(),(feature)[0], \
224  GetMagickPrecision(),(feature)[1], \
225  GetMagickPrecision(),(feature)[2], \
226  GetMagickPrecision(),(feature)[3], \
227  GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
228 
229 #define FeaturesFormat " %s:\n" \
230  " Angular Second Moment:\n" \
231  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
232  " Contrast:\n" \
233  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
234  " Correlation:\n" \
235  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
236  " Sum of Squares Variance:\n" \
237  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
238  " Inverse Difference Moment:\n" \
239  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
240  " Sum Average:\n" \
241  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
242  " Sum Variance:\n" \
243  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
244  " Sum Entropy:\n" \
245  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
246  " Entropy:\n" \
247  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
248  " Difference Variance:\n" \
249  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
250  " Difference Entropy:\n" \
251  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
252  " Information Measure of Correlation 1:\n" \
253  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
254  " Information Measure of Correlation 2:\n" \
255  " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
256  " Maximum Correlation Coefficient:\n" \
257  " %.*g, %.*g, %.*g, %.*g, %.*g\n"
258 
259  ssize_t
260  n;
261 
262  n=FormatLocaleFile(file,FeaturesFormat,name,
263  PrintFeature(channel_features[channel].angular_second_moment),
264  PrintFeature(channel_features[channel].contrast),
265  PrintFeature(channel_features[channel].correlation),
266  PrintFeature(channel_features[channel].variance_sum_of_squares),
267  PrintFeature(channel_features[channel].inverse_difference_moment),
268  PrintFeature(channel_features[channel].sum_average),
269  PrintFeature(channel_features[channel].sum_variance),
270  PrintFeature(channel_features[channel].sum_entropy),
271  PrintFeature(channel_features[channel].entropy),
272  PrintFeature(channel_features[channel].difference_variance),
273  PrintFeature(channel_features[channel].difference_entropy),
274  PrintFeature(channel_features[channel].measure_of_correlation_1),
275  PrintFeature(channel_features[channel].measure_of_correlation_2),
276  PrintFeature(channel_features[channel].maximum_correlation_coefficient));
277  return(n);
278 }
279 
280 static ssize_t PrintChannelLocations(FILE *file,const Image *image,
281  const PixelChannel channel,const char *name,const StatisticType type,
282  const size_t locations,const ChannelStatistics *channel_statistics)
283 {
284  double
285  target;
286 
288  *exception;
289 
290  ssize_t
291  n,
292  y;
293 
294  switch (type)
295  {
296  case MaximumStatistic:
297  default:
298  {
299  target=channel_statistics[channel].maxima;
300  break;
301  }
302  case MinimumStatistic:
303  {
304  target=channel_statistics[channel].minima;
305  break;
306  }
307  }
308  (void) FormatLocaleFile(file," %s: %.*g (%.*g)",name,GetMagickPrecision(),
309  target,GetMagickPrecision(),QuantumScale*target);
310  exception=AcquireExceptionInfo();
311  n=0;
312  for (y=0; y < (ssize_t) image->rows; y++)
313  {
314  const Quantum
315  *p;
316 
317  ssize_t
318  offset,
319  x;
320 
321  p=GetVirtualPixels(image,0,y,image->columns,1,exception);
322  if (p == (const Quantum *) NULL)
323  break;
324  for (x=0; x < (ssize_t) image->columns; x++)
325  {
326  MagickBooleanType
327  match;
328 
329  PixelTrait traits = GetPixelChannelTraits(image,channel);
330  if (traits == UndefinedPixelTrait)
331  continue;
332  offset=GetPixelChannelOffset(image,channel);
333  match=fabs((double) p[offset]-target) < MagickEpsilon ? MagickTrue :
334  MagickFalse;
335  if (match != MagickFalse)
336  {
337  if ((locations != 0) && (n >= (ssize_t) locations))
338  break;
339  (void) FormatLocaleFile(file," %.17g,%.17g",(double) x,(double) y);
340  n++;
341  }
342  p+=(ptrdiff_t) GetPixelChannels(image);
343  }
344  if (x < (ssize_t) image->columns)
345  break;
346  }
347  (void) FormatLocaleFile(file,"\n");
348  return(n);
349 }
350 
351 static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
352  const char *name,const double scale,const ChannelMoments *channel_moments)
353 {
354  double
355  powers[MaximumNumberOfImageMoments] =
356  { 1.0, 2.0, 3.0, 3.0, 6.0, 4.0, 6.0, 4.0 };
357 
358  ssize_t
359  i;
360 
361  ssize_t
362  n;
363 
364  n=FormatLocaleFile(file," %s:\n",name);
365  n+=FormatLocaleFile(file," Centroid: %.*g,%.*g\n",
366  GetMagickPrecision(),channel_moments[channel].centroid.x,
367  GetMagickPrecision(),channel_moments[channel].centroid.y);
368  n+=FormatLocaleFile(file," Ellipse Semi-Major/Minor axis: %.*g,%.*g\n",
369  GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
370  GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
371  n+=FormatLocaleFile(file," Ellipse angle: %.*g\n",
372  GetMagickPrecision(),channel_moments[channel].ellipse_angle);
373  n+=FormatLocaleFile(file," Ellipse eccentricity: %.*g\n",
374  GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
375  n+=FormatLocaleFile(file," Ellipse intensity: %.*g (%.*g)\n",
376  GetMagickPrecision(),pow(scale,powers[0])*
377  channel_moments[channel].ellipse_intensity,GetMagickPrecision(),
378  channel_moments[channel].ellipse_intensity);
379  for (i=0; i < MaximumNumberOfImageMoments; i++)
380  n+=FormatLocaleFile(file," I%.17g: %.*g (%.*g)\n",i+1.0,
381  GetMagickPrecision(),channel_moments[channel].invariant[i]/pow(scale,
382  powers[i]),GetMagickPrecision(),channel_moments[channel].invariant[i]);
383  return(n);
384 }
385 
386 static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
387  const ChannelPerceptualHash *channel_phash)
388 {
389  ssize_t
390  i;
391 
392  ssize_t
393  n;
394 
395  (void) FormatLocaleFile(file," Channel perceptual hash: ");
396  for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
397  {
398  (void) FormatLocaleFile(file,"%s",CommandOptionToMnemonic(
399  MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
400  if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
401  (void) FormatLocaleFile(file,", ");
402  }
403  (void) FormatLocaleFile(file,"\n");
404  n=0;
405  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
406  {
407  PixelChannel
408  channel;
409 
410  PixelTrait
411  traits;
412 
413  ssize_t
414  j;
415 
416  channel=GetPixelChannelChannel(image,i);
417  if (channel == IndexPixelChannel)
418  continue;
419  traits=GetPixelChannelTraits(image,channel);
420  if (traits == UndefinedPixelTrait)
421  continue;
422  n=FormatLocaleFile(file," Channel %.17g:\n",(double) channel);
423  for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
424  {
425  ssize_t
426  k;
427 
428  n+=FormatLocaleFile(file," PH%.17g: ",(double) j+1);
429  for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
430  {
431  n+=FormatLocaleFile(file,"%.*g",GetMagickPrecision(),
432  channel_phash[channel].phash[k][j]);
433  if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
434  n+=FormatLocaleFile(file,", ");
435  }
436  n+=FormatLocaleFile(file,"\n");
437  }
438  }
439  return(n);
440 }
441 
442 static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
443  const char *name,const double scale,
444  const ChannelStatistics *channel_statistics)
445 {
446 #define StatisticsFormat " %s:\n min: %.*g (%.*g)\n " \
447  "max: %.*g (%.*g)\n mean: %.*g (%.*g)\n median: %.*g (%.*g)\n " \
448  "standard deviation: %.*g (%.*g)\n kurtosis: %.*g\n " \
449  "skewness: %.*g\n entropy: %.*g\n"
450 
451  ssize_t
452  n;
453 
454  n=FormatLocaleFile(file,StatisticsFormat,name,GetMagickPrecision(),
455  (double) ClampToQuantum((MagickRealType) (scale*
456  channel_statistics[channel].minima)),GetMagickPrecision(),
457  channel_statistics[channel].minima/(double) QuantumRange,
458  GetMagickPrecision(),(double) ClampToQuantum((MagickRealType) (scale*
459  channel_statistics[channel].maxima)),GetMagickPrecision(),
460  channel_statistics[channel].maxima/(double) QuantumRange,
461  GetMagickPrecision(),scale*channel_statistics[channel].mean,
462  GetMagickPrecision(),channel_statistics[channel].mean/(double) QuantumRange,
463  GetMagickPrecision(),scale*channel_statistics[channel].median,
464  GetMagickPrecision(),channel_statistics[channel].median/(double) QuantumRange,
465  GetMagickPrecision(),scale*channel_statistics[channel].standard_deviation,
466  GetMagickPrecision(),channel_statistics[channel].standard_deviation/
467  (double) QuantumRange,GetMagickPrecision(),
468  channel_statistics[channel].kurtosis,GetMagickPrecision(),
469  channel_statistics[channel].skewness,GetMagickPrecision(),
470  channel_statistics[channel].entropy);
471  return(n);
472 }
473 
474 MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
475  const MagickBooleanType verbose,ExceptionInfo *exception)
476 {
477  char
478  buffer[MagickPathExtent],
479  color[MagickPathExtent],
480  key[MagickPathExtent];
481 
483  *channel_features;
484 
486  *channel_moments;
487 
489  *channel_phash;
490 
492  *channel_statistics;
493 
494  ColorspaceType
495  colorspace;
496 
497  const char
498  *artifact,
499  *locate,
500  *name,
501  *property,
502  *registry,
503  *value;
504 
505  const MagickInfo
506  *magick_info;
507 
508  const Quantum
509  *p;
510 
511  double
512  elapsed_time,
513  scale,
514  user_time;
515 
516  ImageType
517  type;
518 
519  int
520  expired;
521 
522  MagickBooleanType
523  ping;
524 
525  size_t
526  depth,
527  distance;
528 
529  ssize_t
530  i,
531  x,
532  y;
533 
534  struct stat
535  properties;
536 
537  assert(image != (Image *) NULL);
538  assert(image->signature == MagickCoreSignature);
539  if (IsEventLogging() != MagickFalse)
540  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
541  if (file == (FILE *) NULL)
542  file=stdout;
543  colorspace=image->colorspace;
544  locate=GetImageArtifact(image,"identify:locate");
545  if (locate != (const char *) NULL)
546  {
547  const char
548  *limit;
549 
550  size_t
551  locations;
552 
553  StatisticType
554  statistic_type;
555 
556  /*
557  Display minimum, maximum, or mean pixel locations.
558  */
559  statistic_type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
560  MagickFalse,locate);
561  limit=GetImageArtifact(image,"identify:limit");
562  locations=0;
563  if (limit != (const char *) NULL)
564  locations=StringToUnsignedLong(limit);
565  channel_statistics=GetLocationStatistics(image,statistic_type,exception);
566  if (channel_statistics == (ChannelStatistics *) NULL)
567  return(MagickFalse);
568  (void) FormatLocaleFile(file,"Channel %s locations:\n",locate);
569  switch (colorspace)
570  {
571  case RGBColorspace:
572  case sRGBColorspace:
573  {
574  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
575  (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
576  statistic_type,locations,channel_statistics);
577  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
578  (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
579  statistic_type,locations,channel_statistics);
580  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
581  (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
582  statistic_type,locations,channel_statistics);
583  break;
584  }
585  case CMYKColorspace:
586  {
587  if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
588  (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
589  statistic_type,locations,channel_statistics);
590  if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
591  (void) PrintChannelLocations(file,image,MagentaPixelChannel,
592  "Magenta",statistic_type,locations,channel_statistics);
593  if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
594  (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
595  statistic_type,locations,channel_statistics);
596  if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
597  (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
598  statistic_type,locations,channel_statistics);
599  break;
600  }
601  case LinearGRAYColorspace:
602  case GRAYColorspace:
603  {
604  if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
605  (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
606  statistic_type,locations,channel_statistics);
607  break;
608  }
609  default:
610  {
611  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
612  {
613  PixelChannel channel = GetPixelChannelChannel(image,i);
614  PixelTrait traits = GetPixelChannelTraits(image,channel);
615  if ((traits & UpdatePixelTrait) != 0)
616  (void) PrintChannelLocations(file,image,channel,"Channel",
617  statistic_type,locations,channel_statistics);
618  }
619  break;
620  }
621  }
622  if (image->alpha_trait != UndefinedPixelTrait)
623  (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
624  statistic_type,locations,channel_statistics);
625  channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
626  channel_statistics);
627  return(ferror(file) != 0 ? MagickFalse : MagickTrue);
628  }
629  elapsed_time=GetElapsedTime(&image->timer);
630  user_time=GetUserTime(&image->timer);
631  GetTimerInfo(&image->timer);
632  if (verbose == MagickFalse)
633  {
634  /*
635  Display summary info about the image.
636  */
637  if (*image->magick_filename != '\0')
638  if (LocaleCompare(image->magick_filename,image->filename) != 0)
639  (void) FormatLocaleFile(file,"%s=>",image->magick_filename);
640  if ((GetPreviousImageInList(image) == (Image *) NULL) &&
641  (GetNextImageInList(image) == (Image *) NULL) &&
642  (image->scene == 0))
643  (void) FormatLocaleFile(file,"%s ",image->filename);
644  else
645  (void) FormatLocaleFile(file,"%s[%.17g] ",image->filename,(double)
646  image->scene);
647  (void) FormatLocaleFile(file,"%s ",image->magick);
648  if ((image->magick_columns != 0) || (image->magick_rows != 0))
649  if ((image->magick_columns != image->columns) ||
650  (image->magick_rows != image->rows))
651  (void) FormatLocaleFile(file,"%.17gx%.17g=>",(double)
652  image->magick_columns,(double) image->magick_rows);
653  (void) FormatLocaleFile(file,"%.17gx%.17g ",(double) image->columns,
654  (double) image->rows);
655  if ((image->page.width != 0) || (image->page.height != 0) ||
656  (image->page.x != 0) || (image->page.y != 0))
657  (void) FormatLocaleFile(file,"%.17gx%.17g%+.20g%+.20g ",(double)
658  image->page.width,(double) image->page.height,(double) image->page.x,
659  (double) image->page.y);
660  (void) FormatLocaleFile(file,"%.17g-bit ",(double) image->depth);
661  if (image->type != UndefinedType)
662  (void) FormatLocaleFile(file,"%s ",CommandOptionToMnemonic(
663  MagickTypeOptions,(ssize_t) image->type));
664  if (colorspace != UndefinedColorspace)
665  (void) FormatLocaleFile(file,"%s ",CommandOptionToMnemonic(
666  MagickColorspaceOptions,(ssize_t) colorspace));
667  if (image->storage_class == DirectClass)
668  {
669  if (image->total_colors != 0)
670  {
671  (void) FormatMagickSize(image->total_colors,MagickFalse,"B",
672  MagickPathExtent,buffer);
673  (void) FormatLocaleFile(file,"%s ",buffer);
674  }
675  }
676  else
677  if (image->total_colors <= image->colors)
678  (void) FormatLocaleFile(file,"%.17gc ",(double)
679  image->colors);
680  else
681  (void) FormatLocaleFile(file,"%.17g=>%.17gc ",(double)
682  image->total_colors,(double) image->colors);
683  if (image->error.mean_error_per_pixel != 0.0)
684  (void) FormatLocaleFile(file,"%.17g/%f/%fdb ",(double)
685  (image->error.mean_error_per_pixel+0.5),
686  image->error.normalized_mean_error,
687  image->error.normalized_maximum_error);
688  if (image->extent != 0)
689  {
690  (void) FormatMagickSize(image->extent,MagickTrue,"B",
691  MagickPathExtent,buffer);
692  (void) FormatLocaleFile(file,"%s ",buffer);
693  }
694  (void) FormatLocaleFile(file,"%0.3fu %lu:%02lu.%03lu",user_time,
695  (unsigned long) (elapsed_time/60.0),(unsigned long) floor(fmod(
696  elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-
697  floor(elapsed_time))));
698  (void) FormatLocaleFile(file,"\n");
699  (void) fflush(file);
700  return(ferror(file) != 0 ? MagickFalse : MagickTrue);
701  }
702  /*
703  Display verbose info about the image.
704  */
705  p=GetVirtualPixels(image,0,0,1,1,exception);
706  ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
707  (void) SignatureImage(image,exception);
708  channel_statistics=(ChannelStatistics *) NULL;
709  channel_moments=(ChannelMoments *) NULL;
710  channel_phash=(ChannelPerceptualHash *) NULL;
711  channel_features=(ChannelFeatures *) NULL;
712  depth=0;
713  if (ping == MagickFalse)
714  {
715  depth=GetImageDepth(image,exception);
716  channel_statistics=GetImageStatistics(image,exception);
717  artifact=GetImageArtifact(image,"identify:moments");
718  if (artifact != (const char *) NULL)
719  {
720  channel_moments=GetImageMoments(image,exception);
721  channel_phash=GetImagePerceptualHash(image,exception);
722  }
723  artifact=GetImageArtifact(image,"identify:features");
724  if (artifact != (const char *) NULL)
725  {
726  distance=StringToUnsignedLong(artifact);
727  channel_features=GetImageFeatures(image,distance,exception);
728  }
729  }
730  (void) FormatLocaleFile(file,"Image:\n Filename: %s\n",image->filename);
731  if (*image->magick_filename != '\0')
732  if (LocaleCompare(image->magick_filename,image->filename) != 0)
733  {
734  char
735  filename[MagickPathExtent];
736 
737  GetPathComponent(image->magick_filename,TailPath,filename);
738  (void) FormatLocaleFile(file," Base filename: %s\n",filename);
739  }
740  properties=(*GetBlobProperties(image));
741  if (properties.st_mode != 0)
742  {
743  static const char *rwx[] =
744  { "---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
745  (void) FormatLocaleFile(file," Permissions: %s%s%s\n",
746  rwx[(properties.st_mode >> 6) & 0x07],
747  rwx[(properties.st_mode >> 3) & 0x07],
748  rwx[(properties.st_mode >> 0) & 0x07]);
749  }
750  magick_info=GetMagickInfo(image->magick,exception);
751  if ((magick_info == (const MagickInfo *) NULL) ||
752  (GetMagickDescription(magick_info) == (const char *) NULL))
753  (void) FormatLocaleFile(file," Format: %s\n",image->magick);
754  else
755  {
756  (void) FormatLocaleFile(file," Format: %s (%s)\n",image->magick,
757  GetMagickDescription(magick_info));
758  if (GetMagickMimeType(magick_info) != (const char *) NULL)
759  (void) FormatLocaleFile(file," Mime type: %s\n",GetMagickMimeType(
760  magick_info));
761  }
762  (void) FormatLocaleFile(file," Class: %s\n",CommandOptionToMnemonic(
763  MagickClassOptions,(ssize_t) image->storage_class));
764  (void) FormatLocaleFile(file," Geometry: %.17gx%.17g%+.20g%+.20g\n",(double)
765  image->columns,(double) image->rows,(double) image->tile_offset.x,(double)
766  image->tile_offset.y);
767  if ((image->magick_columns != 0) || (image->magick_rows != 0))
768  if ((image->magick_columns != image->columns) ||
769  (image->magick_rows != image->rows))
770  (void) FormatLocaleFile(file," Base geometry: %.17gx%.17g\n",(double)
771  image->magick_columns,(double) image->magick_rows);
772  if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
773  {
774  (void) FormatLocaleFile(file," Resolution: %gx%g\n",image->resolution.x,
775  image->resolution.y);
776  (void) FormatLocaleFile(file," Print size: %gx%g\n",(double)
777  image->columns/image->resolution.x,(double) image->rows/
778  image->resolution.y);
779  }
780  (void) FormatLocaleFile(file," Units: %s\n",CommandOptionToMnemonic(
781  MagickResolutionOptions,(ssize_t) image->units));
782  (void) FormatLocaleFile(file," Colorspace: %s\n",CommandOptionToMnemonic(
783  MagickColorspaceOptions,(ssize_t) colorspace));
784  type=IdentifyImageType(image,exception);
785  (void) FormatLocaleFile(file," Type: %s\n",CommandOptionToMnemonic(
786  MagickTypeOptions,(ssize_t) type));
787  if (image->type != type)
788  (void) FormatLocaleFile(file," Base type: %s\n",CommandOptionToMnemonic(
789  MagickTypeOptions,(ssize_t) image->type));
790  (void) FormatLocaleFile(file," Endianness: %s\n",CommandOptionToMnemonic(
791  MagickEndianOptions,(ssize_t) image->endian));
792  if (depth != 0)
793  {
794  if (image->depth == depth)
795  (void) FormatLocaleFile(file," Depth: %.17g-bit\n",(double)
796  image->depth);
797  else
798  (void) FormatLocaleFile(file," Depth: %.17g/%.17g-bit\n",(double)
799  image->depth,(double) depth);
800  }
801  (void) FormatLocaleFile(file," Channels: %g.%g\n",(double)
802  image->number_channels,(double) image->number_meta_channels);
803  if (channel_statistics != (ChannelStatistics *) NULL)
804  {
805  /*
806  Detail channel depth and extrema.
807  */
808  (void) FormatLocaleFile(file," Channel depth:\n");
809  switch (colorspace)
810  {
811  case RGBColorspace:
812  case sRGBColorspace:
813  {
814  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
815  (void) FormatLocaleFile(file," Red: %.17g-bit\n",(double)
816  channel_statistics[RedPixelChannel].depth);
817  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
818  (void) FormatLocaleFile(file," Green: %.17g-bit\n",(double)
819  channel_statistics[GreenPixelChannel].depth);
820  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
821  (void) FormatLocaleFile(file," Blue: %.17g-bit\n",(double)
822  channel_statistics[BluePixelChannel].depth);
823  break;
824  }
825  case CMYKColorspace:
826  {
827  if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
828  (void) FormatLocaleFile(file," Cyan: %.17g-bit\n",(double)
829  channel_statistics[CyanPixelChannel].depth);
830  if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
831  (void) FormatLocaleFile(file," Magenta: %.17g-bit\n",(double)
832  channel_statistics[MagentaPixelChannel].depth);
833  if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
834  (void) FormatLocaleFile(file," Yellow: %.17g-bit\n",(double)
835  channel_statistics[YellowPixelChannel].depth);
836  if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
837  (void) FormatLocaleFile(file," Black: %.17g-bit\n",(double)
838  channel_statistics[BlackPixelChannel].depth);
839  break;
840  }
841  case LinearGRAYColorspace:
842  case GRAYColorspace:
843  {
844  if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
845  (void) FormatLocaleFile(file," Gray: %.17g-bit\n",(double)
846  channel_statistics[GrayPixelChannel].depth);
847  break;
848  }
849  default:
850  {
851  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
852  {
853  PixelChannel channel = GetPixelChannelChannel(image,i);
854  PixelTrait traits = GetPixelChannelTraits(image,channel);
855  if ((traits & UpdatePixelTrait) != 0)
856  (void) FormatLocaleFile(file," Channel %.17g: %.17g-bit\n",
857  (double) i,(double) channel_statistics[channel].depth);
858  }
859  break;
860  }
861  }
862  if (image->alpha_trait != UndefinedPixelTrait)
863  (void) FormatLocaleFile(file," Alpha: %.17g-bit\n",(double)
864  channel_statistics[AlphaPixelChannel].depth);
865  if ((image->channels & ReadMaskChannel) != 0)
866  (void) FormatLocaleFile(file," Read mask: %.17g-bit\n",(double)
867  channel_statistics[ReadMaskPixelChannel].depth);
868  if ((image->channels & WriteMaskChannel) != 0)
869  (void) FormatLocaleFile(file," Write mask: %.17g-bit\n",(double)
870  channel_statistics[WriteMaskPixelChannel].depth);
871  if ((image->channels & CompositeMaskChannel) != 0)
872  (void) FormatLocaleFile(file," Composite mask: %.17g-bit\n",
873  (double) channel_statistics[CompositeMaskPixelChannel].depth);
874  if (image->number_meta_channels != 0)
875  for (i=0; i < (ssize_t) image->number_meta_channels; i++)
876  {
877  PixelChannel
878  channel = (PixelChannel) (MetaPixelChannels+i);
879 
880  (void) FormatLocaleFile(file," Meta channel[%.17g]: %.17g-bit\n",
881  (double) i,(double) channel_statistics[channel].depth);
882  }
883  scale=1.0;
884  if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
885  scale=(double) (QuantumRange/((size_t) QuantumRange >> ((size_t)
886  MAGICKCORE_QUANTUM_DEPTH-image->depth)));
887  (void) FormatLocaleFile(file," Channel statistics:\n");
888  (void) FormatLocaleFile(file," Pixels: %.17g\n",(double)
889  image->columns*image->rows);
890  switch (colorspace)
891  {
892  case RGBColorspace:
893  case sRGBColorspace:
894  {
895  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
896  (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/
897  scale,channel_statistics);
898  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
899  (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
900  scale,channel_statistics);
901  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
902  (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/
903  scale,channel_statistics);
904  break;
905  }
906  case CMYKColorspace:
907  {
908  if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
909  (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/
910  scale,channel_statistics);
911  if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
912  (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",
913  1.0/scale,channel_statistics);
914  if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
915  (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
916  scale,channel_statistics);
917  if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
918  (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
919  scale,channel_statistics);
920  break;
921  }
922  case LinearGRAYColorspace:
923  case GRAYColorspace:
924  {
925  if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
926  (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/
927  scale,channel_statistics);
928  break;
929  }
930  default:
931  {
932  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
933  {
934  char
935  label[MagickPathExtent];
936 
937  PixelChannel channel = GetPixelChannelChannel(image,i);
938  PixelTrait traits = GetPixelChannelTraits(image,channel);
939  if ((traits & UpdatePixelTrait) != 0)
940  {
941  (void) FormatLocaleString(label,MagickPathExtent,
942  "Channel %.17g",(double) i);
943  (void) PrintChannelStatistics(file,channel,label,1.0/scale,
944  channel_statistics);
945  }
946  }
947  break;
948  }
949  }
950  if (image->alpha_trait != UndefinedPixelTrait)
951  (void) PrintChannelStatistics(file,AlphaPixelChannel,
952  "Alpha",1.0/scale,channel_statistics);
953  if ((image->channels & ReadMaskChannel) != 0)
954  (void) PrintChannelStatistics(file,ReadMaskPixelChannel,
955  "Read mask",1.0/scale,channel_statistics);
956  if ((image->channels & WriteMaskChannel) != 0)
957  (void) PrintChannelStatistics(file,WriteMaskPixelChannel,
958  "Write mask",1.0/scale,channel_statistics);
959  if ((image->channels & CompositeMaskChannel) != 0)
960  (void) PrintChannelStatistics(file,WriteMaskPixelChannel,
961  "Composite mask",1.0/scale,channel_statistics);
962  if (image->number_meta_channels != 0)
963  for (i=0; i < (ssize_t) image->number_meta_channels; i++)
964  {
965  char
966  label[MagickPathExtent];
967 
968  PixelChannel
969  channel = (PixelChannel) (MetaPixelChannels+i);
970 
971  (void) FormatLocaleString(label,MagickPathExtent,
972  "Meta channel[%.17g]",(double) i);
973  (void) PrintChannelStatistics(file,channel,label,1.0/scale,
974  channel_statistics);
975  }
976  if ((colorspace != LinearGRAYColorspace) &&
977  (colorspace != GRAYColorspace))
978  {
979  (void) FormatLocaleFile(file," Image statistics:\n");
980  (void) PrintChannelStatistics(file,CompositePixelChannel,"Overall",
981  1.0/scale,channel_statistics);
982  }
983  channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
984  channel_statistics);
985  }
986  if (channel_moments != (ChannelMoments *) NULL)
987  {
988  scale=(double) ((1UL << image->depth)-1);
989  (void) FormatLocaleFile(file," Channel Hu moments:\n");
990  switch (colorspace)
991  {
992  case RGBColorspace:
993  case sRGBColorspace:
994  {
995  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
996  (void) PrintChannelMoments(file,RedPixelChannel,"Red",scale,
997  channel_moments);
998  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
999  (void) PrintChannelMoments(file,GreenPixelChannel,"Green",scale,
1000  channel_moments);
1001  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1002  (void) PrintChannelMoments(file,BluePixelChannel,"Blue",scale,
1003  channel_moments);
1004  break;
1005  }
1006  case CMYKColorspace:
1007  {
1008  if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
1009  (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",scale,
1010  channel_moments);
1011  if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
1012  (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",scale,
1013  channel_moments);
1014  if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
1015  (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",scale,
1016  channel_moments);
1017  if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
1018  (void) PrintChannelMoments(file,BlackPixelChannel,"Black",scale,
1019  channel_moments);
1020  break;
1021  }
1022  case GRAYColorspace:
1023  {
1024  if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
1025  (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",scale,
1026  channel_moments);
1027  break;
1028  }
1029  default:
1030  {
1031  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1032  {
1033  char
1034  label[MagickPathExtent];
1035 
1036  PixelChannel channel = GetPixelChannelChannel(image,i);
1037  PixelTrait traits = GetPixelChannelTraits(image,channel);
1038  if ((traits & UpdatePixelTrait) != 0)
1039  {
1040  (void) FormatLocaleString(label,MagickPathExtent,
1041  "Channel %.17g",(double) i);
1042  (void) PrintChannelMoments(file,channel,label,scale,
1043  channel_moments);
1044  }
1045  }
1046  break;
1047  }
1048  }
1049  if (image->alpha_trait != UndefinedPixelTrait)
1050  (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",scale,
1051  channel_moments);
1052  if (colorspace != GRAYColorspace)
1053  {
1054  (void) FormatLocaleFile(file," Image moments:\n");
1055  (void) PrintChannelMoments(file,CompositePixelChannel,"Overall",scale,
1056  channel_moments);
1057  }
1058  channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1059  channel_moments);
1060  }
1061  if (channel_phash != (ChannelPerceptualHash *) NULL)
1062  {
1063  (void) PrintChannelPerceptualHash(image,file,channel_phash);
1064  channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1065  channel_phash);
1066  }
1067  if (channel_features != (ChannelFeatures *) NULL)
1068  {
1069  (void) FormatLocaleFile(file," Channel features (horizontal, vertical, "
1070  "left and right diagonals, average):\n");
1071  switch (colorspace)
1072  {
1073  case RGBColorspace:
1074  case sRGBColorspace:
1075  {
1076  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1077  (void) PrintChannelFeatures(file,RedPixelChannel,"Red",
1078  channel_features);
1079  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1080  (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
1081  channel_features);
1082  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1083  (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",
1084  channel_features);
1085  break;
1086  }
1087  case CMYKColorspace:
1088  {
1089  if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
1090  (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",
1091  channel_features);
1092  if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
1093  (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
1094  channel_features);
1095  if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
1096  (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
1097  channel_features);
1098  if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
1099  (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
1100  channel_features);
1101  break;
1102  }
1103  case GRAYColorspace:
1104  {
1105  if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
1106  (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",
1107  channel_features);
1108  break;
1109  }
1110  default:
1111  {
1112  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1113  {
1114  char
1115  label[MagickPathExtent];
1116 
1117  PixelChannel channel = GetPixelChannelChannel(image,i);
1118  PixelTrait traits = GetPixelChannelTraits(image,channel);
1119  if ((traits & UpdatePixelTrait) != 0)
1120  {
1121  (void) FormatLocaleString(label,MagickPathExtent,
1122  "Channel %.17g",(double) i);
1123  (void) PrintChannelFeatures(file,channel,label,
1124  channel_features);
1125  }
1126  }
1127  break;
1128  }
1129  }
1130  if (image->alpha_trait != UndefinedPixelTrait)
1131  (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",
1132  channel_features);
1133  channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1134  channel_features);
1135  }
1136  if (ping == MagickFalse)
1137  {
1138  if (colorspace == CMYKColorspace)
1139  (void) FormatLocaleFile(file," Total ink density: %.*g%%\n",
1140  GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1141  (double) QuantumRange);
1142  x=0;
1143  if (image->alpha_trait != UndefinedPixelTrait)
1144  {
1145  MagickBooleanType
1146  found = MagickFalse;
1147 
1148  p=(const Quantum *) NULL;
1149  for (y=0; y < (ssize_t) image->rows; y++)
1150  {
1151  p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1152  if (p == (const Quantum *) NULL)
1153  break;
1154  for (x=0; x < (ssize_t) image->columns; x++)
1155  {
1156  if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
1157  {
1158  found=MagickTrue;
1159  break;
1160  }
1161  p+=(ptrdiff_t) GetPixelChannels(image);
1162  }
1163  if (found != MagickFalse)
1164  break;
1165  }
1166  if (found != MagickFalse)
1167  {
1168  char
1169  tuple[MagickPathExtent];
1170 
1171  PixelInfo
1172  pixel;
1173 
1174  GetPixelInfo(image,&pixel);
1175  GetPixelInfoPixel(image,p,&pixel);
1176  (void) QueryColorname(image,&pixel,SVGCompliance,tuple,
1177  exception);
1178  (void) FormatLocaleFile(file," Alpha: %s ",tuple);
1179  GetColorTuple(&pixel,MagickTrue,tuple);
1180  (void) FormatLocaleFile(file," %s\n",tuple);
1181  }
1182  }
1183  if (IsHistogramImage(image,exception) != MagickFalse)
1184  {
1185  (void) FormatLocaleFile(file," Colors: %.17g\n",(double)
1186  GetNumberColors(image,(FILE *) NULL,exception));
1187  (void) FormatLocaleFile(file," Histogram:\n");
1188  (void) GetNumberColors(image,file,exception);
1189  }
1190  else
1191  {
1192  artifact=GetImageArtifact(image,"identify:unique-colors");
1193  if (IsStringTrue(artifact) != MagickFalse)
1194  (void) FormatLocaleFile(file," Colors: %.17g\n",(double)
1195  GetNumberColors(image,(FILE *) NULL,exception));
1196  }
1197  }
1198  if (image->storage_class == PseudoClass)
1199  {
1200  (void) FormatLocaleFile(file," Colormap entries: %.17g\n",(double)
1201  image->colors);
1202  (void) FormatLocaleFile(file," Colormap:\n");
1203  if (image->colors <= 1024)
1204  {
1205  char
1206  hex[MagickPathExtent],
1207  tuple[MagickPathExtent];
1208 
1209  PixelInfo
1210  pixel;
1211 
1212  PixelInfo
1213  *magick_restrict c;
1214 
1215  GetPixelInfo(image,&pixel);
1216  c=image->colormap;
1217  for (i=0; i < (ssize_t) image->colors; i++)
1218  {
1219  pixel=(*c);
1220  (void) CopyMagickString(tuple,"(",MagickPathExtent);
1221  ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,
1222  tuple);
1223  (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1224  ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,
1225  tuple);
1226  (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1227  ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,
1228  tuple);
1229  if (pixel.colorspace == CMYKColorspace)
1230  {
1231  (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1232  ConcatenateColorComponent(&pixel,BlackPixelChannel,
1233  X11Compliance,tuple);
1234  }
1235  if (pixel.alpha_trait != UndefinedPixelTrait)
1236  {
1237  (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1238  ConcatenateColorComponent(&pixel,AlphaPixelChannel,
1239  X11Compliance,tuple);
1240  }
1241  (void) ConcatenateMagickString(tuple,")",MagickPathExtent);
1242  (void) QueryColorname(image,&pixel,SVGCompliance,color,
1243  exception);
1244  GetColorTuple(&pixel,MagickTrue,hex);
1245  (void) FormatLocaleFile(file," %g: %s %s %s\n",(double) i,tuple,
1246  hex,color);
1247  c++;
1248  }
1249  }
1250  }
1251  if (image->error.mean_error_per_pixel != 0.0)
1252  (void) FormatLocaleFile(file," Mean error per pixel: %g\n",
1253  image->error.mean_error_per_pixel);
1254  if (image->error.normalized_mean_error != 0.0)
1255  (void) FormatLocaleFile(file," Normalized mean error: %g\n",
1256  image->error.normalized_mean_error);
1257  if (image->error.normalized_maximum_error != 0.0)
1258  (void) FormatLocaleFile(file," Normalized maximum error: %g\n",
1259  image->error.normalized_maximum_error);
1260  (void) FormatLocaleFile(file," Rendering intent: %s\n",
1261  CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1262  image->rendering_intent));
1263  if (image->gamma != 0.0)
1264  (void) FormatLocaleFile(file," Gamma: %g\n",image->gamma);
1265  if ((image->chromaticity.red_primary.x != 0.0) ||
1266  (image->chromaticity.green_primary.x != 0.0) ||
1267  (image->chromaticity.blue_primary.x != 0.0) ||
1268  (image->chromaticity.white_point.x != 0.0))
1269  {
1270  /*
1271  Display image chromaticity.
1272  */
1273  (void) FormatLocaleFile(file," Chromaticity:\n");
1274  (void) FormatLocaleFile(file," red primary: (%g,%g,%g)\n",
1275  image->chromaticity.red_primary.x,image->chromaticity.red_primary.y,
1276  image->chromaticity.red_primary.z);
1277  (void) FormatLocaleFile(file," green primary: (%g,%g,%g)\n",
1278  image->chromaticity.green_primary.x,image->chromaticity.green_primary.y,
1279  image->chromaticity.green_primary.z);
1280  (void) FormatLocaleFile(file," blue primary: (%g,%g,%g)\n",
1281  image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y,
1282  image->chromaticity.blue_primary.z);
1283  (void) FormatLocaleFile(file," white point: (%g,%g,%g)\n",
1284  image->chromaticity.white_point.x,image->chromaticity.white_point.y,
1285  image->chromaticity.white_point.z);
1286  }
1287  if ((image->extract_info.width*image->extract_info.height) != 0)
1288  (void) FormatLocaleFile(file," Tile geometry: %.17gx%.17g%+.20g%+.20g\n",
1289  (double) image->extract_info.width,(double) image->extract_info.height,
1290  (double) image->extract_info.x,(double) image->extract_info.y);
1291  (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
1292  exception);
1293  (void) FormatLocaleFile(file," Matte color: %s\n",color);
1294  (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
1295  exception);
1296  (void) FormatLocaleFile(file," Background color: %s\n",color);
1297  (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
1298  exception);
1299  (void) FormatLocaleFile(file," Border color: %s\n",color);
1300  (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
1301  exception);
1302  (void) FormatLocaleFile(file," Transparent color: %s\n",color);
1303  (void) FormatLocaleFile(file," Interlace: %s\n",CommandOptionToMnemonic(
1304  MagickInterlaceOptions,(ssize_t) image->interlace));
1305  (void) FormatLocaleFile(file," Intensity: %s\n",CommandOptionToMnemonic(
1306  MagickPixelIntensityOptions,(ssize_t) image->intensity));
1307  (void) FormatLocaleFile(file," Compose: %s\n",CommandOptionToMnemonic(
1308  MagickComposeOptions,(ssize_t) image->compose));
1309  if ((image->page.width != 0) || (image->page.height != 0) ||
1310  (image->page.x != 0) || (image->page.y != 0))
1311  (void) FormatLocaleFile(file," Page geometry: %.17gx%.17g%+.20g%+.20g\n",
1312  (double) image->page.width,(double) image->page.height,(double)
1313  image->page.x,(double) image->page.y);
1314  if ((image->page.x != 0) || (image->page.y != 0))
1315  (void) FormatLocaleFile(file," Origin geometry: %+.20g%+.20g\n",(double)
1316  image->page.x,(double) image->page.y);
1317  (void) FormatLocaleFile(file," Dispose: %s\n",CommandOptionToMnemonic(
1318  MagickDisposeOptions,(ssize_t) image->dispose));
1319  if (image->delay != 0)
1320  (void) FormatLocaleFile(file," Delay: %.17gx%.17g\n",(double) image->delay,
1321  (double) image->ticks_per_second);
1322  if (image->iterations != 1)
1323  (void) FormatLocaleFile(file," Iterations: %.17g\n",(double)
1324  image->iterations);
1325  if (image->duration != 0)
1326  (void) FormatLocaleFile(file," Duration: %.17g\n",(double)
1327  image->duration);
1328  if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
1329  (void) FormatLocaleFile(file," Scene: %.17g of %.17g\n",(double)
1330  image->scene,(double) GetImageListLength(image));
1331  else
1332  if (image->scene != 0)
1333  (void) FormatLocaleFile(file," Scene: %.17g\n",(double) image->scene);
1334  (void) FormatLocaleFile(file," Compression: %s\n",CommandOptionToMnemonic(
1335  MagickCompressOptions,(ssize_t) image->compression));
1336  if (image->quality != UndefinedCompressionQuality)
1337  (void) FormatLocaleFile(file," Quality: %.17g\n",(double) image->quality);
1338  (void) FormatLocaleFile(file," Orientation: %s\n",CommandOptionToMnemonic(
1339  MagickOrientationOptions,(ssize_t) image->orientation));
1340  if (image->montage != (char *) NULL)
1341  (void) FormatLocaleFile(file," Montage: %s\n",image->montage);
1342  if (image->directory != (char *) NULL)
1343  {
1344  Image
1345  *tile;
1346 
1347  ImageInfo
1348  *image_info;
1349 
1350  char
1351  *d,
1352  *q;
1353 
1354  WarningHandler
1355  handler;
1356 
1357  /*
1358  Display visual image directory.
1359  */
1360  image_info=AcquireImageInfo();
1361  (void) CloneString(&image_info->size,"64x64");
1362  (void) FormatLocaleFile(file," Directory:\n");
1363  for (d=image->directory; *d != '\0'; d++)
1364  {
1365  q=d;
1366  while ((*q != '\xff') && (*q != '\0') &&
1367  ((size_t) (q-d+1) < sizeof(image_info->filename)))
1368  q++;
1369  (void) CopyMagickString(image_info->filename,d,(size_t) (q-d+1));
1370  d=q;
1371  (void) FormatLocaleFile(file," %s",image_info->filename);
1372  handler=SetWarningHandler((WarningHandler) NULL);
1373  tile=StrictReadImage(image_info,exception);
1374  (void) SetWarningHandler(handler);
1375  if (tile == (Image *) NULL)
1376  {
1377  (void) FormatLocaleFile(file,"\n");
1378  continue;
1379  }
1380  (void) FormatLocaleFile(file," %.17gx%.17g %s\n",(double)
1381  tile->magick_columns,(double) tile->magick_rows,tile->magick);
1382  (void) SignatureImage(tile,exception);
1383  ResetImagePropertyIterator(tile);
1384  property=GetNextImageProperty(tile);
1385  while (property != (const char *) NULL)
1386  {
1387  (void) FormatLocaleFile(file," %s:\n",property);
1388  value=GetImageProperty(tile,property,exception);
1389  if (value != (const char *) NULL)
1390  (void) FormatLocaleFile(file,"%s\n",value);
1391  property=GetNextImageProperty(tile);
1392  }
1393  tile=DestroyImage(tile);
1394  }
1395  image_info=DestroyImageInfo(image_info);
1396  }
1397  (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
1398  value=GetImageProperty(image,key,exception);
1399  if (value != (const char *) NULL)
1400  {
1401  /*
1402  Display clipping path.
1403  */
1404  (void) FormatLocaleFile(file," Clipping path: ");
1405  if (strlen(value) > 80)
1406  (void) fputc('\n',file);
1407  (void) FormatLocaleFile(file,"%s\n",value);
1408  }
1409  artifact=GetImageArtifact(image,"identify:convex-hull");
1410  if (IsStringTrue(artifact) != MagickFalse)
1411  {
1412  char
1413  *points;
1414 
1415  PointInfo
1416  *bounding_box,
1417  *convex_hull;
1418 
1419  ssize_t
1420  n;
1421 
1422  size_t
1423  number_points;
1424 
1425  /*
1426  Display convex hull & minimum bounding box.
1427  */
1428  convex_hull=GetImageConvexHull(image,&number_points,exception);
1429  if (convex_hull != (PointInfo *) NULL)
1430  {
1431  points=AcquireString("");
1432  for (n=0; n < (ssize_t) number_points; n++)
1433  {
1434  (void) FormatLocaleString(buffer,MagickPathExtent,"%g,%g ",
1435  convex_hull[n].x,convex_hull[n].y);
1436  (void) ConcatenateString(&points,buffer);
1437  }
1438  convex_hull=(PointInfo *) RelinquishMagickMemory(convex_hull);
1439  (void) FormatLocaleFile(file," Convex hull: ");
1440  (void) FormatLocaleFile(file,"%s\n",points);
1441  points=DestroyString(points);
1442  }
1443  bounding_box=GetImageMinimumBoundingBox(image,&number_points,exception);
1444  if (bounding_box != (PointInfo *) NULL)
1445  {
1446  points=AcquireString("");
1447  for (n=0; n < (ssize_t) number_points; n++)
1448  {
1449  (void) FormatLocaleString(buffer,MagickPathExtent,"%g,%g ",
1450  bounding_box[n].x,bounding_box[n].y);
1451  (void) ConcatenateString(&points,buffer);
1452  }
1453  bounding_box=(PointInfo *) RelinquishMagickMemory(bounding_box);
1454  (void) FormatLocaleFile(file," Minimum bounding box: ");
1455  (void) FormatLocaleFile(file,"%s\n",points);
1456  points=DestroyString(points);
1457  }
1458  }
1459  ResetImageProfileIterator(image);
1460  name=GetNextImageProfile(image);
1461  if (name != (char *) NULL)
1462  {
1463  const StringInfo
1464  *profile;
1465 
1466  /*
1467  Identify image profiles.
1468  */
1469  (void) FormatLocaleFile(file," Profiles:\n");
1470  while (name != (char *) NULL)
1471  {
1472  profile=GetImageProfile(image,name);
1473  if (profile == (StringInfo *) NULL)
1474  continue;
1475  (void) FormatLocaleFile(file," Profile-%s: %.17g bytes\n",name,
1476  (double) GetStringInfoLength(profile));
1477  if (LocaleCompare(name,"iptc") == 0)
1478  {
1479  char
1480  *attribute,
1481  **attribute_list;
1482 
1483  const char
1484  *tag;
1485 
1486  long
1487  dataset,
1488  record,
1489  sentinel;
1490 
1491  ssize_t
1492  j;
1493 
1494  size_t
1495  length,
1496  profile_length;
1497 
1498  profile_length=GetStringInfoLength(profile);
1499  for (i=0; i < (ssize_t) profile_length-5; i+=(ssize_t) length)
1500  {
1501  length=1;
1502  sentinel=GetStringInfoDatum(profile)[i++];
1503  if (sentinel != 0x1c)
1504  continue;
1505  dataset=GetStringInfoDatum(profile)[i++];
1506  record=GetStringInfoDatum(profile)[i++];
1507  switch (record)
1508  {
1509  case 5: tag="Image Name"; break;
1510  case 7: tag="Edit Status"; break;
1511  case 10: tag="Priority"; break;
1512  case 15: tag="Category"; break;
1513  case 20: tag="Supplemental Category"; break;
1514  case 22: tag="Fixture Identifier"; break;
1515  case 25: tag="Keyword"; break;
1516  case 30: tag="Release Date"; break;
1517  case 35: tag="Release Time"; break;
1518  case 40: tag="Special Instructions"; break;
1519  case 45: tag="Reference Service"; break;
1520  case 47: tag="Reference Date"; break;
1521  case 50: tag="Reference Number"; break;
1522  case 55: tag="Created Date"; break;
1523  case 60: tag="Created Time"; break;
1524  case 65: tag="Originating Program"; break;
1525  case 70: tag="Program Version"; break;
1526  case 75: tag="Object Cycle"; break;
1527  case 80: tag="Byline"; break;
1528  case 85: tag="Byline Title"; break;
1529  case 90: tag="City"; break;
1530  case 92: tag="Sub-Location"; break;
1531  case 95: tag="Province State"; break;
1532  case 100: tag="Country Code"; break;
1533  case 101: tag="Country"; break;
1534  case 103: tag="Original Transmission Reference"; break;
1535  case 105: tag="Headline"; break;
1536  case 110: tag="Credit"; break;
1537  case 115: tag="Src"; break;
1538  case 116: tag="Copyright String"; break;
1539  case 120: tag="Caption"; break;
1540  case 121: tag="Local Caption"; break;
1541  case 122: tag="Caption Writer"; break;
1542  case 200: tag="Custom Field 1"; break;
1543  case 201: tag="Custom Field 2"; break;
1544  case 202: tag="Custom Field 3"; break;
1545  case 203: tag="Custom Field 4"; break;
1546  case 204: tag="Custom Field 5"; break;
1547  case 205: tag="Custom Field 6"; break;
1548  case 206: tag="Custom Field 7"; break;
1549  case 207: tag="Custom Field 8"; break;
1550  case 208: tag="Custom Field 9"; break;
1551  case 209: tag="Custom Field 10"; break;
1552  case 210: tag="Custom Field 11"; break;
1553  case 211: tag="Custom Field 12"; break;
1554  case 212: tag="Custom Field 13"; break;
1555  case 213: tag="Custom Field 14"; break;
1556  case 214: tag="Custom Field 15"; break;
1557  case 215: tag="Custom Field 16"; break;
1558  case 216: tag="Custom Field 17"; break;
1559  case 217: tag="Custom Field 18"; break;
1560  case 218: tag="Custom Field 19"; break;
1561  case 219: tag="Custom Field 20"; break;
1562  default: tag="unknown"; break;
1563  }
1564  (void) FormatLocaleFile(file," %s[%.17g,%.17g]: ",tag,
1565  (double) dataset,(double) record);
1566  length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
1567  length|=GetStringInfoDatum(profile)[i++];
1568  length=MagickMin(length,profile_length-(size_t) i);
1569  attribute=(char *) NULL;
1570  if (~length >= (MagickPathExtent-1))
1571  attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1572  sizeof(*attribute));
1573  if (attribute != (char *) NULL)
1574  {
1575  (void) CopyMagickString(attribute,(char *)
1576  GetStringInfoDatum(profile)+i,length+1);
1577  attribute_list=StringToList(attribute);
1578  if (attribute_list != (char **) NULL)
1579  {
1580  for (j=0; attribute_list[j] != (char *) NULL; j++)
1581  {
1582  (void) fputs(attribute_list[j],file);
1583  (void) fputs("\n",file);
1584  attribute_list[j]=(char *) RelinquishMagickMemory(
1585  attribute_list[j]);
1586  }
1587  attribute_list=(char **) RelinquishMagickMemory(
1588  attribute_list);
1589  }
1590  attribute=DestroyString(attribute);
1591  }
1592  }
1593  }
1594  if (image->debug != MagickFalse)
1595  PrintStringInfo(file,name,profile);
1596  name=GetNextImageProfile(image);
1597  }
1598  }
1599  ResetImagePropertyIterator(image);
1600  property=GetNextImageProperty(image);
1601  if (property != (const char *) NULL)
1602  {
1603  /*
1604  Display image properties.
1605  */
1606  (void) FormatLocaleFile(file," Properties:\n");
1607  while (property != (const char *) NULL)
1608  {
1609  (void) FormatLocaleFile(file," %s: ",property);
1610  value=GetImageProperty(image,property,exception);
1611  if (value != (const char *) NULL)
1612  (void) FormatLocaleFile(file,"%s\n",value);
1613  property=GetNextImageProperty(image);
1614  }
1615  }
1616  ResetImageArtifactIterator(image);
1617  artifact=GetNextImageArtifact(image);
1618  if (artifact != (const char *) NULL)
1619  {
1620  /*
1621  Display image artifacts.
1622  */
1623  (void) FormatLocaleFile(file," Artifacts:\n");
1624  while (artifact != (const char *) NULL)
1625  {
1626  (void) FormatLocaleFile(file," %s: ",artifact);
1627  value=GetImageArtifact(image,artifact);
1628  if (value != (const char *) NULL)
1629  (void) FormatLocaleFile(file,"%s\n",value);
1630  artifact=GetNextImageArtifact(image);
1631  }
1632  }
1633  ResetImageRegistryIterator();
1634  registry=GetNextImageRegistry();
1635  if (registry != (const char *) NULL)
1636  {
1637  /*
1638  Display image registry.
1639  */
1640  (void) FormatLocaleFile(file," Registry:\n");
1641  while (registry != (const char *) NULL)
1642  {
1643  (void) FormatLocaleFile(file," %s: ",registry);
1644  value=(const char *) GetImageRegistry(StringRegistryType,registry,
1645  exception);
1646  if (value != (const char *) NULL)
1647  (void) FormatLocaleFile(file,"%s\n",value);
1648  registry=GetNextImageRegistry();
1649  }
1650  }
1651  (void) FormatLocaleFile(file," Tainted: %s\n",CommandOptionToMnemonic(
1652  MagickBooleanOptions,(ssize_t) image->taint));
1653  (void) FormatMagickSize(image->extent,MagickTrue,"B",MagickPathExtent,buffer);
1654  (void) FormatLocaleFile(file," Filesize: %s\n",buffer);
1655  (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1656  MagickFalse,"P",MagickPathExtent,buffer);
1657  if (strlen(buffer) > 1)
1658  buffer[strlen(buffer)-1]='\0';
1659  (void) FormatLocaleFile(file," Number pixels: %s\n",buffer);
1660  (void) FormatLocaleString(buffer,MagickPathExtent,"%s",
1661  CommandOptionToMnemonic(MagickCacheOptions,(ssize_t)
1662  GetImagePixelCacheType(image)));
1663  (void) FormatLocaleFile(file," Pixel cache type: %s\n",buffer);
1664  if (elapsed_time > MagickEpsilon)
1665  {
1666  (void) FormatMagickSize((MagickSizeType) ((double) image->columns*
1667  image->rows/elapsed_time+0.5),MagickFalse,"P",MagickPathExtent,buffer);
1668  (void) FormatLocaleFile(file," Pixels per second: %s\n",buffer);
1669  }
1670  if (image->ttl != (time_t) 0)
1671  {
1672  char
1673  iso8601[sizeof("9999-99-99T99:99:99Z")];
1674 
1675  int
1676  seconds;
1677 
1678  struct tm
1679  timestamp;
1680 
1681  (void) GetMagickUTCTime(&image->ttl,&timestamp);
1682  (void) strftime(iso8601,sizeof(iso8601),"%Y-%m-%dT%H:%M:%SZ",&timestamp);
1683  seconds=MagickMax((int)(image->ttl-GetMagickTime()),0);
1684  expired=' ';
1685  if (seconds == 0)
1686  expired='*';
1687  (void) FormatLocaleFile(file," Time-to-live: %g:%02g:%02g:%02g%c %s\n",
1688  ceil((double) (seconds/(3600*24))),
1689  ceil((double) ((seconds % (24*3600))/3600)),
1690  ceil((double) ((seconds % 3600)/60)),
1691  ceil((double) ((seconds % 3600) % 60)),expired,iso8601);
1692  }
1693  (void) FormatLocaleFile(file," User time: %0.3fu\n",user_time);
1694  (void) FormatLocaleFile(file," Elapsed time: %lu:%02lu.%03lu\n",
1695  (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(elapsed_time,
1696  60.0)),(unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))));
1697  (void) FormatLocaleFile(file," Version: %s\n",GetMagickVersion((size_t *)
1698  NULL));
1699  (void) fflush(file);
1700  return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1701 }
Definition: image.h:132