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