MagickCore 7.1.1
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/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Identify describes the format and characteristics of one or more image
37% files. It will also report if an image is incomplete or corrupt.
38%
39%
40*/
41
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/decorate.h"
58#include "MagickCore/delegate.h"
59#include "MagickCore/draw.h"
60#include "MagickCore/effect.h"
61#include "MagickCore/exception.h"
62#include "MagickCore/exception-private.h"
63#include "MagickCore/feature.h"
64#include "MagickCore/gem.h"
65#include "MagickCore/geometry.h"
66#include "MagickCore/histogram.h"
67#include "MagickCore/identify.h"
68#include "MagickCore/image.h"
69#include "MagickCore/image-private.h"
70#include "MagickCore/list.h"
71#include "MagickCore/locale_.h"
72#include "MagickCore/log.h"
73#include "MagickCore/magic.h"
74#include "MagickCore/magick.h"
75#include "MagickCore/memory_.h"
76#include "MagickCore/module.h"
77#include "MagickCore/monitor.h"
78#include "MagickCore/montage.h"
79#include "MagickCore/option.h"
80#include "MagickCore/pixel-accessor.h"
81#include "MagickCore/pixel-private.h"
82#include "MagickCore/prepress.h"
83#include "MagickCore/profile.h"
84#include "MagickCore/property.h"
85#include "MagickCore/quantize.h"
86#include "MagickCore/quantum.h"
87#include "MagickCore/random_.h"
88#include "MagickCore/registry.h"
89#include "MagickCore/resize.h"
90#include "MagickCore/resource_.h"
91#include "MagickCore/signature.h"
92#include "MagickCore/statistic.h"
93#include "MagickCore/string_.h"
94#include "MagickCore/string-private.h"
95#include "MagickCore/timer.h"
96#include "MagickCore/timer-private.h"
97#include "MagickCore/token.h"
98#include "MagickCore/utility.h"
99#include "MagickCore/utility-private.h"
100#include "MagickCore/version.h"
101
102/*
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104% %
105% %
106% %
107% I d e n t i f y I m a g e %
108% %
109% %
110% %
111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112%
113% IdentifyImage() identifies an image by printing its attributes to the file.
114% Attributes include the image width, height, size, and others.
115%
116% The format of the IdentifyImage method is:
117%
118% MagickBooleanType IdentifyImage(Image *image,FILE *file,
119% const MagickBooleanType verbose,ExceptionInfo *exception)
120%
121% A description of each parameter follows:
122%
123% o image: the image.
124%
125% o file: the file, typically stdout.
126%
127% o verbose: A value other than zero prints more detailed information
128% about the image.
129%
130% o exception: return any errors or warnings in this structure.
131%
132*/
133
134static ChannelStatistics *GetLocationStatistics(const Image *image,
135 const StatisticType type,ExceptionInfo *exception)
136{
138 *channel_statistics;
139
140 ssize_t
141 i;
142
143 ssize_t
144 y;
145
146 assert(image != (Image *) NULL);
147 assert(image->signature == MagickCoreSignature);
148 if (IsEventLogging() != MagickFalse)
149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
150 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
151 MaxPixelChannels+1,sizeof(*channel_statistics));
152 if (channel_statistics == (ChannelStatistics *) NULL)
153 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
154 (void) memset(channel_statistics,0,(MaxPixelChannels+1)*
155 sizeof(*channel_statistics));
156 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
157 {
158 switch (type)
159 {
160 case MaximumStatistic:
161 default:
162 {
163 channel_statistics[i].maxima=(-MagickMaximumValue);
164 break;
165 }
166 case MinimumStatistic:
167 {
168 channel_statistics[i].minima=MagickMaximumValue;
169 break;
170 }
171 }
172 }
173 for (y=0; y < (ssize_t) image->rows; y++)
174 {
175 const Quantum
176 *magick_restrict p;
177
178 ssize_t
179 x;
180
181 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
182 if (p == (const Quantum *) NULL)
183 break;
184 for (x=0; x < (ssize_t) image->columns; x++)
185 {
186 if (GetPixelReadMask(image,p) <= (QuantumRange/2))
187 {
188 p+=GetPixelChannels(image);
189 continue;
190 }
191 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
192 {
193 PixelChannel channel = GetPixelChannelChannel(image,i);
194 PixelTrait traits = GetPixelChannelTraits(image,channel);
195 if (traits == UndefinedPixelTrait)
196 continue;
197 switch (type)
198 {
199 case MaximumStatistic:
200 default:
201 {
202 if ((double) p[i] > channel_statistics[channel].maxima)
203 channel_statistics[channel].maxima=(double) p[i];
204 break;
205 }
206 case MinimumStatistic:
207 {
208 if ((double) p[i] < channel_statistics[channel].minima)
209 channel_statistics[channel].minima=(double) p[i];
210 break;
211 }
212 }
213 }
214 p+=GetPixelChannels(image);
215 }
216 }
217 return(channel_statistics);
218}
219
220static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
221 const char *name,const ChannelFeatures *channel_features)
222{
223#define PrintFeature(feature) \
224 GetMagickPrecision(),(feature)[0], \
225 GetMagickPrecision(),(feature)[1], \
226 GetMagickPrecision(),(feature)[2], \
227 GetMagickPrecision(),(feature)[3], \
228 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
229
230#define FeaturesFormat " %s:\n" \
231 " Angular Second Moment:\n" \
232 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
233 " Contrast:\n" \
234 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
235 " Correlation:\n" \
236 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
237 " Sum of Squares Variance:\n" \
238 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
239 " Inverse Difference Moment:\n" \
240 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
241 " Sum Average:\n" \
242 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
243 " Sum Variance:\n" \
244 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
245 " Sum Entropy:\n" \
246 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
247 " Entropy:\n" \
248 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
249 " Difference Variance:\n" \
250 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
251 " Difference Entropy:\n" \
252 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
253 " Information Measure of Correlation 1:\n" \
254 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
255 " Information Measure of Correlation 2:\n" \
256 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
257 " Maximum Correlation Coefficient:\n" \
258 " %.*g, %.*g, %.*g, %.*g, %.*g\n"
259
260 ssize_t
261 n;
262
263 n=FormatLocaleFile(file,FeaturesFormat,name,
264 PrintFeature(channel_features[channel].angular_second_moment),
265 PrintFeature(channel_features[channel].contrast),
266 PrintFeature(channel_features[channel].correlation),
267 PrintFeature(channel_features[channel].variance_sum_of_squares),
268 PrintFeature(channel_features[channel].inverse_difference_moment),
269 PrintFeature(channel_features[channel].sum_average),
270 PrintFeature(channel_features[channel].sum_variance),
271 PrintFeature(channel_features[channel].sum_entropy),
272 PrintFeature(channel_features[channel].entropy),
273 PrintFeature(channel_features[channel].difference_variance),
274 PrintFeature(channel_features[channel].difference_entropy),
275 PrintFeature(channel_features[channel].measure_of_correlation_1),
276 PrintFeature(channel_features[channel].measure_of_correlation_2),
277 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
278 return(n);
279}
280
281static ssize_t PrintChannelLocations(FILE *file,const Image *image,
282 const PixelChannel channel,const char *name,const StatisticType type,
283 const size_t max_locations,const ChannelStatistics *channel_statistics)
284{
285 double
286 target;
287
289 *exception;
290
291 ssize_t
292 n,
293 y;
294
295 switch (type)
296 {
297 case MaximumStatistic:
298 default:
299 {
300 target=channel_statistics[channel].maxima;
301 break;
302 }
303 case MinimumStatistic:
304 {
305 target=channel_statistics[channel].minima;
306 break;
307 }
308 }
309 (void) FormatLocaleFile(file," %s: %.*g (%.*g)",name,GetMagickPrecision(),
310 target,GetMagickPrecision(),QuantumScale*target);
311 exception=AcquireExceptionInfo();
312 n=0;
313 for (y=0; y < (ssize_t) image->rows; y++)
314 {
315 const Quantum
316 *p;
317
318 ssize_t
319 offset,
320 x;
321
322 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
323 if (p == (const Quantum *) NULL)
324 break;
325 for (x=0; x < (ssize_t) image->columns; x++)
326 {
327 MagickBooleanType
328 match;
329
330 PixelTrait traits = GetPixelChannelTraits(image,channel);
331 if (traits == UndefinedPixelTrait)
332 continue;
333 offset=GetPixelChannelOffset(image,channel);
334 match=fabs((double) p[offset]-target) < 0.5 ? MagickTrue : MagickFalse;
335 if (match != MagickFalse)
336 {
337 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
338 break;
339 (void) FormatLocaleFile(file," %.20g,%.20g",(double) x,(double) y);
340 n++;
341 }
342 p+=GetPixelChannels(image);
343 }
344 if (x < (ssize_t) image->columns)
345 break;
346 }
347 (void) FormatLocaleFile(file,"\n");
348 return(n);
349}
350
351static 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%.20g: %.*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
386static 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 %.20g:\n",(double) channel);
423 for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
424 {
425 ssize_t
426 k;
427
428 n+=FormatLocaleFile(file," PH%.20g: ",(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
442static 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
474MagickExport 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 max_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 max_locations=0;
563 if (limit != (const char *) NULL)
564 max_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,max_locations,channel_statistics);
577 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
578 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
579 statistic_type,max_locations,channel_statistics);
580 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
581 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
582 statistic_type,max_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,max_locations,channel_statistics);
590 if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
591 (void) PrintChannelLocations(file,image,MagentaPixelChannel,
592 "Magenta",statistic_type,max_locations,channel_statistics);
593 if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
594 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
595 statistic_type,max_locations,channel_statistics);
596 if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
597 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
598 statistic_type,max_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,max_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,max_locations,channel_statistics);
618 }
619 break;
620 }
621 }
622 if (image->alpha_trait != UndefinedPixelTrait)
623 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
624 statistic_type,max_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[%.20g] ",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,"%.20gx%.20g=>",(double)
652 image->magick_columns,(double) image->magick_rows);
653 (void) FormatLocaleFile(file,"%.20gx%.20g ",(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,"%.20gx%.20g%+.20g%+.20g ",(double)
658 image->page.width,(double) image->page.height,(double) image->page.x,
659 (double) image->page.y);
660 (void) FormatLocaleFile(file,"%.20g-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,"%.20gc ",(double)
679 image->colors);
680 else
681 (void) FormatLocaleFile(file,"%.20g=>%.20gc ",(double)
682 image->total_colors,(double) image->colors);
683 if (image->error.mean_error_per_pixel != 0.0)
684 (void) FormatLocaleFile(file,"%.20g/%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 (void) FormatLocaleFile(file," Format: %s (%s)\n",image->magick,
756 GetMagickDescription(magick_info));
757 if ((magick_info != (const MagickInfo *) NULL) &&
758 (GetMagickMimeType(magick_info) != (const char *) NULL))
759 (void) FormatLocaleFile(file," Mime type: %s\n",GetMagickMimeType(
760 magick_info));
761 (void) FormatLocaleFile(file," Class: %s\n",CommandOptionToMnemonic(
762 MagickClassOptions,(ssize_t) image->storage_class));
763 (void) FormatLocaleFile(file," Geometry: %.20gx%.20g%+.20g%+.20g\n",(double)
764 image->columns,(double) image->rows,(double) image->tile_offset.x,(double)
765 image->tile_offset.y);
766 if ((image->magick_columns != 0) || (image->magick_rows != 0))
767 if ((image->magick_columns != image->columns) ||
768 (image->magick_rows != image->rows))
769 (void) FormatLocaleFile(file," Base geometry: %.20gx%.20g\n",(double)
770 image->magick_columns,(double) image->magick_rows);
771 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
772 {
773 (void) FormatLocaleFile(file," Resolution: %gx%g\n",image->resolution.x,
774 image->resolution.y);
775 (void) FormatLocaleFile(file," Print size: %gx%g\n",(double)
776 image->columns/image->resolution.x,(double) image->rows/
777 image->resolution.y);
778 }
779 (void) FormatLocaleFile(file," Units: %s\n",CommandOptionToMnemonic(
780 MagickResolutionOptions,(ssize_t) image->units));
781 (void) FormatLocaleFile(file," Colorspace: %s\n",CommandOptionToMnemonic(
782 MagickColorspaceOptions,(ssize_t) colorspace));
783 type=IdentifyImageType(image,exception);
784 (void) FormatLocaleFile(file," Type: %s\n",CommandOptionToMnemonic(
785 MagickTypeOptions,(ssize_t) type));
786 if (image->type != type)
787 (void) FormatLocaleFile(file," Base type: %s\n",CommandOptionToMnemonic(
788 MagickTypeOptions,(ssize_t) image->type));
789 (void) FormatLocaleFile(file," Endianness: %s\n",CommandOptionToMnemonic(
790 MagickEndianOptions,(ssize_t) image->endian));
791 if (depth != 0)
792 {
793 if (image->depth == depth)
794 (void) FormatLocaleFile(file," Depth: %.20g-bit\n",(double)
795 image->depth);
796 else
797 (void) FormatLocaleFile(file," Depth: %.20g/%.20g-bit\n",(double)
798 image->depth,(double) depth);
799 }
800 (void) FormatLocaleFile(file," Channels: %g.%g\n",(double)
801 image->number_channels,(double) image->number_meta_channels);
802 if (channel_statistics != (ChannelStatistics *) NULL)
803 {
804 /*
805 Detail channel depth and extrema.
806 */
807 (void) FormatLocaleFile(file," Channel depth:\n");
808 switch (colorspace)
809 {
810 case RGBColorspace:
811 case sRGBColorspace:
812 {
813 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
814 (void) FormatLocaleFile(file," Red: %.20g-bit\n",(double)
815 channel_statistics[RedPixelChannel].depth);
816 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
817 (void) FormatLocaleFile(file," Green: %.20g-bit\n",(double)
818 channel_statistics[GreenPixelChannel].depth);
819 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
820 (void) FormatLocaleFile(file," Blue: %.20g-bit\n",(double)
821 channel_statistics[BluePixelChannel].depth);
822 break;
823 }
824 case CMYKColorspace:
825 {
826 if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
827 (void) FormatLocaleFile(file," Cyan: %.20g-bit\n",(double)
828 channel_statistics[CyanPixelChannel].depth);
829 if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
830 (void) FormatLocaleFile(file," Magenta: %.20g-bit\n",(double)
831 channel_statistics[MagentaPixelChannel].depth);
832 if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
833 (void) FormatLocaleFile(file," Yellow: %.20g-bit\n",(double)
834 channel_statistics[YellowPixelChannel].depth);
835 if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
836 (void) FormatLocaleFile(file," Black: %.20g-bit\n",(double)
837 channel_statistics[BlackPixelChannel].depth);
838 break;
839 }
840 case LinearGRAYColorspace:
841 case GRAYColorspace:
842 {
843 if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
844 (void) FormatLocaleFile(file," Gray: %.20g-bit\n",(double)
845 channel_statistics[GrayPixelChannel].depth);
846 break;
847 }
848 default:
849 {
850 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
851 {
852 PixelChannel channel = GetPixelChannelChannel(image,i);
853 PixelTrait traits = GetPixelChannelTraits(image,channel);
854 if ((traits & UpdatePixelTrait) != 0)
855 (void) FormatLocaleFile(file," Channel %.20g: %.20g-bit\n",
856 (double) i,(double) channel_statistics[channel].depth);
857 }
858 break;
859 }
860 }
861 if (image->alpha_trait != UndefinedPixelTrait)
862 (void) FormatLocaleFile(file," Alpha: %.20g-bit\n",(double)
863 channel_statistics[AlphaPixelChannel].depth);
864 if ((image->channels & ReadMaskChannel) != 0)
865 (void) FormatLocaleFile(file," Read mask: %.20g-bit\n",(double)
866 channel_statistics[ReadMaskPixelChannel].depth);
867 if ((image->channels & WriteMaskChannel) != 0)
868 (void) FormatLocaleFile(file," Write mask: %.20g-bit\n",(double)
869 channel_statistics[WriteMaskPixelChannel].depth);
870 if ((image->channels & CompositeMaskChannel) != 0)
871 (void) FormatLocaleFile(file," Composite mask: %.20g-bit\n",
872 (double) channel_statistics[CompositeMaskPixelChannel].depth);
873 if (image->number_meta_channels != 0)
874 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
875 {
876 PixelChannel
877 channel = (PixelChannel) (MetaPixelChannels+i);
878
879 (void) FormatLocaleFile(file," Meta channel[%.20g]: %.20g-bit\n",
880 (double) i,(double) channel_statistics[channel].depth);
881 }
882 scale=1.0;
883 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
884 scale=(double) (QuantumRange/((size_t) QuantumRange >> ((size_t)
885 MAGICKCORE_QUANTUM_DEPTH-image->depth)));
886 (void) FormatLocaleFile(file," Channel statistics:\n");
887 (void) FormatLocaleFile(file," Pixels: %.20g\n",(double)
888 image->columns*image->rows);
889 switch (colorspace)
890 {
891 case RGBColorspace:
892 case sRGBColorspace:
893 {
894 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
895 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/
896 scale,channel_statistics);
897 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
898 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
899 scale,channel_statistics);
900 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
901 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/
902 scale,channel_statistics);
903 break;
904 }
905 case CMYKColorspace:
906 {
907 if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
908 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/
909 scale,channel_statistics);
910 if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
911 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",
912 1.0/scale,channel_statistics);
913 if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
914 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
915 scale,channel_statistics);
916 if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
917 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
918 scale,channel_statistics);
919 break;
920 }
921 case LinearGRAYColorspace:
922 case GRAYColorspace:
923 {
924 if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
925 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/
926 scale,channel_statistics);
927 break;
928 }
929 default:
930 {
931 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
932 {
933 char
934 label[MagickPathExtent];
935
936 PixelChannel channel = GetPixelChannelChannel(image,i);
937 PixelTrait traits = GetPixelChannelTraits(image,channel);
938 if ((traits & UpdatePixelTrait) != 0)
939 {
940 (void) FormatLocaleString(label,MagickPathExtent,
941 "Channel %.20g",(double) i);
942 (void) PrintChannelStatistics(file,channel,label,1.0/scale,
943 channel_statistics);
944 }
945 }
946 break;
947 }
948 }
949 if (image->alpha_trait != UndefinedPixelTrait)
950 (void) PrintChannelStatistics(file,AlphaPixelChannel,
951 "Alpha",1.0/scale,channel_statistics);
952 if ((image->channels & ReadMaskChannel) != 0)
953 (void) PrintChannelStatistics(file,ReadMaskPixelChannel,
954 "Read mask",1.0/scale,channel_statistics);
955 if ((image->channels & WriteMaskChannel) != 0)
956 (void) PrintChannelStatistics(file,WriteMaskPixelChannel,
957 "Write mask",1.0/scale,channel_statistics);
958 if ((image->channels & CompositeMaskChannel) != 0)
959 (void) PrintChannelStatistics(file,WriteMaskPixelChannel,
960 "Composite mask",1.0/scale,channel_statistics);
961 if (image->number_meta_channels != 0)
962 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
963 {
964 char
965 label[MagickPathExtent];
966
967 PixelChannel
968 channel = (PixelChannel) (MetaPixelChannels+i);
969
970 (void) FormatLocaleString(label,MagickPathExtent,
971 "Meta channel[%.20g]",(double) i);
972 (void) PrintChannelStatistics(file,channel,label,1.0/scale,
973 channel_statistics);
974 }
975 if ((colorspace != LinearGRAYColorspace) &&
976 (colorspace != GRAYColorspace))
977 {
978 (void) FormatLocaleFile(file," Image statistics:\n");
979 (void) PrintChannelStatistics(file,CompositePixelChannel,"Overall",
980 1.0/scale,channel_statistics);
981 }
982 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
983 channel_statistics);
984 }
985 if (channel_moments != (ChannelMoments *) NULL)
986 {
987 scale=(double) ((1UL << image->depth)-1);
988 (void) FormatLocaleFile(file," Channel moments:\n");
989 switch (colorspace)
990 {
991 case RGBColorspace:
992 case sRGBColorspace:
993 {
994 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
995 (void) PrintChannelMoments(file,RedPixelChannel,"Red",scale,
996 channel_moments);
997 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
998 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",scale,
999 channel_moments);
1000 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1001 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",scale,
1002 channel_moments);
1003 break;
1004 }
1005 case CMYKColorspace:
1006 {
1007 if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
1008 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",scale,
1009 channel_moments);
1010 if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
1011 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",scale,
1012 channel_moments);
1013 if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
1014 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",scale,
1015 channel_moments);
1016 if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
1017 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",scale,
1018 channel_moments);
1019 break;
1020 }
1021 case GRAYColorspace:
1022 {
1023 if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
1024 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",scale,
1025 channel_moments);
1026 break;
1027 }
1028 default:
1029 {
1030 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1031 {
1032 char
1033 label[MagickPathExtent];
1034
1035 PixelChannel channel = GetPixelChannelChannel(image,i);
1036 PixelTrait traits = GetPixelChannelTraits(image,channel);
1037 if ((traits & UpdatePixelTrait) != 0)
1038 {
1039 (void) FormatLocaleString(label,MagickPathExtent,
1040 "Channel %.20g",(double) i);
1041 (void) PrintChannelMoments(file,channel,label,scale,
1042 channel_moments);
1043 }
1044 }
1045 break;
1046 }
1047 }
1048 if (image->alpha_trait != UndefinedPixelTrait)
1049 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",scale,
1050 channel_moments);
1051 if (colorspace != GRAYColorspace)
1052 {
1053 (void) FormatLocaleFile(file," Image moments:\n");
1054 (void) PrintChannelMoments(file,CompositePixelChannel,"Overall",scale,
1055 channel_moments);
1056 }
1057 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1058 channel_moments);
1059 }
1060 if (channel_phash != (ChannelPerceptualHash *) NULL)
1061 {
1062 (void) PrintChannelPerceptualHash(image,file,channel_phash);
1063 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1064 channel_phash);
1065 }
1066 if (channel_features != (ChannelFeatures *) NULL)
1067 {
1068 (void) FormatLocaleFile(file," Channel features (horizontal, vertical, "
1069 "left and right diagonals, average):\n");
1070 switch (colorspace)
1071 {
1072 case RGBColorspace:
1073 case sRGBColorspace:
1074 {
1075 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1076 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",
1077 channel_features);
1078 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1079 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
1080 channel_features);
1081 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1082 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",
1083 channel_features);
1084 break;
1085 }
1086 case CMYKColorspace:
1087 {
1088 if ((GetPixelCyanTraits(image) & UpdatePixelTrait) != 0)
1089 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",
1090 channel_features);
1091 if ((GetPixelMagentaTraits(image) & UpdatePixelTrait) != 0)
1092 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
1093 channel_features);
1094 if ((GetPixelYellowTraits(image) & UpdatePixelTrait) != 0)
1095 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
1096 channel_features);
1097 if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
1098 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
1099 channel_features);
1100 break;
1101 }
1102 case GRAYColorspace:
1103 {
1104 if ((GetPixelGrayTraits(image) & UpdatePixelTrait) != 0)
1105 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",
1106 channel_features);
1107 break;
1108 }
1109 default:
1110 {
1111 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1112 {
1113 char
1114 label[MagickPathExtent];
1115
1116 PixelChannel channel = GetPixelChannelChannel(image,i);
1117 PixelTrait traits = GetPixelChannelTraits(image,channel);
1118 if ((traits & UpdatePixelTrait) != 0)
1119 {
1120 (void) FormatLocaleString(label,MagickPathExtent,
1121 "Channel %.20g",(double) i);
1122 (void) PrintChannelFeatures(file,channel,label,
1123 channel_features);
1124 }
1125 }
1126 break;
1127 }
1128 }
1129 if (image->alpha_trait != UndefinedPixelTrait)
1130 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",
1131 channel_features);
1132 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1133 channel_features);
1134 }
1135 if (ping == MagickFalse)
1136 {
1137 if (colorspace == CMYKColorspace)
1138 (void) FormatLocaleFile(file," Total ink density: %.*g%%\n",
1139 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1140 (double) QuantumRange);
1141 x=0;
1142 if (image->alpha_trait != UndefinedPixelTrait)
1143 {
1144 MagickBooleanType
1145 found = MagickFalse;
1146
1147 p=(const Quantum *) NULL;
1148 for (y=0; y < (ssize_t) image->rows; y++)
1149 {
1150 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1151 if (p == (const Quantum *) NULL)
1152 break;
1153 for (x=0; x < (ssize_t) image->columns; x++)
1154 {
1155 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
1156 {
1157 found=MagickTrue;
1158 break;
1159 }
1160 p+=GetPixelChannels(image);
1161 }
1162 if (found != MagickFalse)
1163 break;
1164 }
1165 if (found != MagickFalse)
1166 {
1167 char
1168 tuple[MagickPathExtent];
1169
1170 PixelInfo
1171 pixel;
1172
1173 GetPixelInfo(image,&pixel);
1174 GetPixelInfoPixel(image,p,&pixel);
1175 (void) QueryColorname(image,&pixel,SVGCompliance,tuple,
1176 exception);
1177 (void) FormatLocaleFile(file," Alpha: %s ",tuple);
1178 GetColorTuple(&pixel,MagickTrue,tuple);
1179 (void) FormatLocaleFile(file," %s\n",tuple);
1180 }
1181 }
1182 if (IsHistogramImage(image,exception) != MagickFalse)
1183 {
1184 (void) FormatLocaleFile(file," Colors: %.20g\n",(double)
1185 GetNumberColors(image,(FILE *) NULL,exception));
1186 (void) FormatLocaleFile(file," Histogram:\n");
1187 (void) GetNumberColors(image,file,exception);
1188 }
1189 else
1190 {
1191 artifact=GetImageArtifact(image,"identify:unique-colors");
1192 if (IsStringTrue(artifact) != MagickFalse)
1193 (void) FormatLocaleFile(file," Colors: %.20g\n",(double)
1194 GetNumberColors(image,(FILE *) NULL,exception));
1195 }
1196 }
1197 if (image->storage_class == PseudoClass)
1198 {
1199 (void) FormatLocaleFile(file," Colormap entries: %.20g\n",(double)
1200 image->colors);
1201 (void) FormatLocaleFile(file," Colormap:\n");
1202 if (image->colors <= 1024)
1203 {
1204 char
1205 hex[MagickPathExtent],
1206 tuple[MagickPathExtent];
1207
1208 PixelInfo
1209 pixel;
1210
1211 PixelInfo
1212 *magick_restrict c;
1213
1214 GetPixelInfo(image,&pixel);
1215 c=image->colormap;
1216 for (i=0; i < (ssize_t) image->colors; i++)
1217 {
1218 pixel=(*c);
1219 (void) CopyMagickString(tuple,"(",MagickPathExtent);
1220 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,
1221 tuple);
1222 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1223 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,
1224 tuple);
1225 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1226 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,
1227 tuple);
1228 if (pixel.colorspace == CMYKColorspace)
1229 {
1230 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1231 ConcatenateColorComponent(&pixel,BlackPixelChannel,
1232 X11Compliance,tuple);
1233 }
1234 if (pixel.alpha_trait != UndefinedPixelTrait)
1235 {
1236 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
1237 ConcatenateColorComponent(&pixel,AlphaPixelChannel,
1238 X11Compliance,tuple);
1239 }
1240 (void) ConcatenateMagickString(tuple,")",MagickPathExtent);
1241 (void) QueryColorname(image,&pixel,SVGCompliance,color,
1242 exception);
1243 GetColorTuple(&pixel,MagickTrue,hex);
1244 (void) FormatLocaleFile(file," %g: %s %s %s\n",(double) i,tuple,
1245 hex,color);
1246 c++;
1247 }
1248 }
1249 }
1250 if (image->error.mean_error_per_pixel != 0.0)
1251 (void) FormatLocaleFile(file," Mean error per pixel: %g\n",
1252 image->error.mean_error_per_pixel);
1253 if (image->error.normalized_mean_error != 0.0)
1254 (void) FormatLocaleFile(file," Normalized mean error: %g\n",
1255 image->error.normalized_mean_error);
1256 if (image->error.normalized_maximum_error != 0.0)
1257 (void) FormatLocaleFile(file," Normalized maximum error: %g\n",
1258 image->error.normalized_maximum_error);
1259 (void) FormatLocaleFile(file," Rendering intent: %s\n",
1260 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1261 image->rendering_intent));
1262 if (image->gamma != 0.0)
1263 (void) FormatLocaleFile(file," Gamma: %g\n",image->gamma);
1264 if ((image->chromaticity.red_primary.x != 0.0) ||
1265 (image->chromaticity.green_primary.x != 0.0) ||
1266 (image->chromaticity.blue_primary.x != 0.0) ||
1267 (image->chromaticity.white_point.x != 0.0))
1268 {
1269 /*
1270 Display image chromaticity.
1271 */
1272 (void) FormatLocaleFile(file," Chromaticity:\n");
1273 (void) FormatLocaleFile(file," red primary: (%g,%g,%g)\n",
1274 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y,
1275 image->chromaticity.red_primary.z);
1276 (void) FormatLocaleFile(file," green primary: (%g,%g,%g)\n",
1277 image->chromaticity.green_primary.x,image->chromaticity.green_primary.y,
1278 image->chromaticity.green_primary.z);
1279 (void) FormatLocaleFile(file," blue primary: (%g,%g,%g)\n",
1280 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y,
1281 image->chromaticity.blue_primary.z);
1282 (void) FormatLocaleFile(file," white point: (%g,%g,%g)\n",
1283 image->chromaticity.white_point.x,image->chromaticity.white_point.y,
1284 image->chromaticity.white_point.z);
1285 }
1286 if ((image->extract_info.width*image->extract_info.height) != 0)
1287 (void) FormatLocaleFile(file," Tile geometry: %.20gx%.20g%+.20g%+.20g\n",
1288 (double) image->extract_info.width,(double) image->extract_info.height,
1289 (double) image->extract_info.x,(double) image->extract_info.y);
1290 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
1291 exception);
1292 (void) FormatLocaleFile(file," Matte color: %s\n",color);
1293 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
1294 exception);
1295 (void) FormatLocaleFile(file," Background color: %s\n",color);
1296 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
1297 exception);
1298 (void) FormatLocaleFile(file," Border color: %s\n",color);
1299 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
1300 exception);
1301 (void) FormatLocaleFile(file," Transparent color: %s\n",color);
1302 (void) FormatLocaleFile(file," Interlace: %s\n",CommandOptionToMnemonic(
1303 MagickInterlaceOptions,(ssize_t) image->interlace));
1304 (void) FormatLocaleFile(file," Intensity: %s\n",CommandOptionToMnemonic(
1305 MagickPixelIntensityOptions,(ssize_t) image->intensity));
1306 (void) FormatLocaleFile(file," Compose: %s\n",CommandOptionToMnemonic(
1307 MagickComposeOptions,(ssize_t) image->compose));
1308 if ((image->page.width != 0) || (image->page.height != 0) ||
1309 (image->page.x != 0) || (image->page.y != 0))
1310 (void) FormatLocaleFile(file," Page geometry: %.20gx%.20g%+.20g%+.20g\n",
1311 (double) image->page.width,(double) image->page.height,(double)
1312 image->page.x,(double) image->page.y);
1313 if ((image->page.x != 0) || (image->page.y != 0))
1314 (void) FormatLocaleFile(file," Origin geometry: %+.20g%+.20g\n",(double)
1315 image->page.x,(double) image->page.y);
1316 (void) FormatLocaleFile(file," Dispose: %s\n",CommandOptionToMnemonic(
1317 MagickDisposeOptions,(ssize_t) image->dispose));
1318 if (image->delay != 0)
1319 (void) FormatLocaleFile(file," Delay: %.20gx%.20g\n",(double) image->delay,
1320 (double) image->ticks_per_second);
1321 if (image->iterations != 1)
1322 (void) FormatLocaleFile(file," Iterations: %.20g\n",(double)
1323 image->iterations);
1324 if (image->duration != 0)
1325 (void) FormatLocaleFile(file," Duration: %.20g\n",(double)
1326 image->duration);
1327 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
1328 (void) FormatLocaleFile(file," Scene: %.20g of %.20g\n",(double)
1329 image->scene,(double) GetImageListLength(image));
1330 else
1331 if (image->scene != 0)
1332 (void) FormatLocaleFile(file," Scene: %.20g\n",(double) image->scene);
1333 (void) FormatLocaleFile(file," Compression: %s\n",CommandOptionToMnemonic(
1334 MagickCompressOptions,(ssize_t) image->compression));
1335 if (image->quality != UndefinedCompressionQuality)
1336 (void) FormatLocaleFile(file," Quality: %.20g\n",(double) image->quality);
1337 (void) FormatLocaleFile(file," Orientation: %s\n",CommandOptionToMnemonic(
1338 MagickOrientationOptions,(ssize_t) image->orientation));
1339 if (image->montage != (char *) NULL)
1340 (void) FormatLocaleFile(file," Montage: %s\n",image->montage);
1341 if (image->directory != (char *) NULL)
1342 {
1343 Image
1344 *tile;
1345
1346 ImageInfo
1347 *image_info;
1348
1349 char
1350 *d,
1351 *q;
1352
1353 WarningHandler
1354 handler;
1355
1356 /*
1357 Display visual image directory.
1358 */
1359 image_info=AcquireImageInfo();
1360 (void) CloneString(&image_info->size,"64x64");
1361 (void) FormatLocaleFile(file," Directory:\n");
1362 for (d=image->directory; *d != '\0'; d++)
1363 {
1364 q=d;
1365 while ((*q != '\xff') && (*q != '\0') &&
1366 ((size_t) (q-d) < sizeof(image_info->filename)))
1367 q++;
1368 (void) CopyMagickString(image_info->filename,d,(size_t) (q-d+1));
1369 d=q;
1370 (void) FormatLocaleFile(file," %s",image_info->filename);
1371 handler=SetWarningHandler((WarningHandler) NULL);
1372 tile=ReadImage(image_info,exception);
1373 (void) SetWarningHandler(handler);
1374 if (tile == (Image *) NULL)
1375 {
1376 (void) FormatLocaleFile(file,"\n");
1377 continue;
1378 }
1379 (void) FormatLocaleFile(file," %.20gx%.20g %s\n",(double)
1380 tile->magick_columns,(double) tile->magick_rows,tile->magick);
1381 (void) SignatureImage(tile,exception);
1382 ResetImagePropertyIterator(tile);
1383 property=GetNextImageProperty(tile);
1384 while (property != (const char *) NULL)
1385 {
1386 (void) FormatLocaleFile(file," %s:\n",property);
1387 value=GetImageProperty(tile,property,exception);
1388 if (value != (const char *) NULL)
1389 (void) FormatLocaleFile(file,"%s\n",value);
1390 property=GetNextImageProperty(tile);
1391 }
1392 tile=DestroyImage(tile);
1393 }
1394 image_info=DestroyImageInfo(image_info);
1395 }
1396 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
1397 value=GetImageProperty(image,key,exception);
1398 if (value != (const char *) NULL)
1399 {
1400 /*
1401 Display clipping path.
1402 */
1403 (void) FormatLocaleFile(file," Clipping path: ");
1404 if (strlen(value) > 80)
1405 (void) fputc('\n',file);
1406 (void) FormatLocaleFile(file,"%s\n",value);
1407 }
1408 artifact=GetImageArtifact(image,"identify:convex-hull");
1409 if (IsStringTrue(artifact) != MagickFalse)
1410 {
1411 char
1412 *points;
1413
1414 PointInfo
1415 *bounding_box,
1416 *convex_hull;
1417
1418 ssize_t
1419 n;
1420
1421 size_t
1422 number_points;
1423
1424 /*
1425 Display convex hull & minimum bounding box.
1426 */
1427 convex_hull=GetImageConvexHull(image,&number_points,exception);
1428 if (convex_hull != (PointInfo *) NULL)
1429 {
1430 points=AcquireString("");
1431 for (n=0; n < (ssize_t) number_points; n++)
1432 {
1433 (void) FormatLocaleString(buffer,MagickPathExtent,"%g,%g ",
1434 convex_hull[n].x,convex_hull[n].y);
1435 (void) ConcatenateString(&points,buffer);
1436 }
1437 convex_hull=(PointInfo *) RelinquishMagickMemory(convex_hull);
1438 (void) FormatLocaleFile(file," Convex hull: ");
1439 (void) FormatLocaleFile(file,"%s\n",points);
1440 points=DestroyString(points);
1441 }
1442 bounding_box=GetImageMinimumBoundingBox(image,&number_points,exception);
1443 if (bounding_box != (PointInfo *) NULL)
1444 {
1445 points=AcquireString("");
1446 for (n=0; n < (ssize_t) number_points; n++)
1447 {
1448 (void) FormatLocaleString(buffer,MagickPathExtent,"%g,%g ",
1449 bounding_box[n].x,bounding_box[n].y);
1450 (void) ConcatenateString(&points,buffer);
1451 }
1452 bounding_box=(PointInfo *) RelinquishMagickMemory(bounding_box);
1453 (void) FormatLocaleFile(file," Minimum bounding box: ");
1454 (void) FormatLocaleFile(file,"%s\n",points);
1455 points=DestroyString(points);
1456 }
1457 }
1458 ResetImageProfileIterator(image);
1459 name=GetNextImageProfile(image);
1460 if (name != (char *) NULL)
1461 {
1462 const StringInfo
1463 *profile;
1464
1465 /*
1466 Identify image profiles.
1467 */
1468 (void) FormatLocaleFile(file," Profiles:\n");
1469 while (name != (char *) NULL)
1470 {
1471 profile=GetImageProfile(image,name);
1472 if (profile == (StringInfo *) NULL)
1473 continue;
1474 (void) FormatLocaleFile(file," Profile-%s: %.20g bytes\n",name,
1475 (double) GetStringInfoLength(profile));
1476 if (LocaleCompare(name,"iptc") == 0)
1477 {
1478 char
1479 *attribute,
1480 **attribute_list;
1481
1482 const char
1483 *tag;
1484
1485 long
1486 dataset,
1487 record,
1488 sentinel;
1489
1490 ssize_t
1491 j;
1492
1493 size_t
1494 length,
1495 profile_length;
1496
1497 profile_length=GetStringInfoLength(profile);
1498 for (i=0; i < (ssize_t) profile_length-5; i+=(ssize_t) length)
1499 {
1500 length=1;
1501 sentinel=GetStringInfoDatum(profile)[i++];
1502 if (sentinel != 0x1c)
1503 continue;
1504 dataset=GetStringInfoDatum(profile)[i++];
1505 record=GetStringInfoDatum(profile)[i++];
1506 switch (record)
1507 {
1508 case 5: tag="Image Name"; break;
1509 case 7: tag="Edit Status"; break;
1510 case 10: tag="Priority"; break;
1511 case 15: tag="Category"; break;
1512 case 20: tag="Supplemental Category"; break;
1513 case 22: tag="Fixture Identifier"; break;
1514 case 25: tag="Keyword"; break;
1515 case 30: tag="Release Date"; break;
1516 case 35: tag="Release Time"; break;
1517 case 40: tag="Special Instructions"; break;
1518 case 45: tag="Reference Service"; break;
1519 case 47: tag="Reference Date"; break;
1520 case 50: tag="Reference Number"; break;
1521 case 55: tag="Created Date"; break;
1522 case 60: tag="Created Time"; break;
1523 case 65: tag="Originating Program"; break;
1524 case 70: tag="Program Version"; break;
1525 case 75: tag="Object Cycle"; break;
1526 case 80: tag="Byline"; break;
1527 case 85: tag="Byline Title"; break;
1528 case 90: tag="City"; break;
1529 case 92: tag="Sub-Location"; break;
1530 case 95: tag="Province State"; break;
1531 case 100: tag="Country Code"; break;
1532 case 101: tag="Country"; break;
1533 case 103: tag="Original Transmission Reference"; break;
1534 case 105: tag="Headline"; break;
1535 case 110: tag="Credit"; break;
1536 case 115: tag="Src"; break;
1537 case 116: tag="Copyright String"; break;
1538 case 120: tag="Caption"; break;
1539 case 121: tag="Local Caption"; break;
1540 case 122: tag="Caption Writer"; break;
1541 case 200: tag="Custom Field 1"; break;
1542 case 201: tag="Custom Field 2"; break;
1543 case 202: tag="Custom Field 3"; break;
1544 case 203: tag="Custom Field 4"; break;
1545 case 204: tag="Custom Field 5"; break;
1546 case 205: tag="Custom Field 6"; break;
1547 case 206: tag="Custom Field 7"; break;
1548 case 207: tag="Custom Field 8"; break;
1549 case 208: tag="Custom Field 9"; break;
1550 case 209: tag="Custom Field 10"; break;
1551 case 210: tag="Custom Field 11"; break;
1552 case 211: tag="Custom Field 12"; break;
1553 case 212: tag="Custom Field 13"; break;
1554 case 213: tag="Custom Field 14"; break;
1555 case 214: tag="Custom Field 15"; break;
1556 case 215: tag="Custom Field 16"; break;
1557 case 216: tag="Custom Field 17"; break;
1558 case 217: tag="Custom Field 18"; break;
1559 case 218: tag="Custom Field 19"; break;
1560 case 219: tag="Custom Field 20"; break;
1561 default: tag="unknown"; break;
1562 }
1563 (void) FormatLocaleFile(file," %s[%.20g,%.20g]: ",tag,
1564 (double) dataset,(double) record);
1565 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
1566 length|=GetStringInfoDatum(profile)[i++];
1567 length=MagickMin(length,profile_length-(size_t) i);
1568 attribute=(char *) NULL;
1569 if (~length >= (MagickPathExtent-1))
1570 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1571 sizeof(*attribute));
1572 if (attribute != (char *) NULL)
1573 {
1574 (void) CopyMagickString(attribute,(char *)
1575 GetStringInfoDatum(profile)+i,length+1);
1576 attribute_list=StringToList(attribute);
1577 if (attribute_list != (char **) NULL)
1578 {
1579 for (j=0; attribute_list[j] != (char *) NULL; j++)
1580 {
1581 (void) fputs(attribute_list[j],file);
1582 (void) fputs("\n",file);
1583 attribute_list[j]=(char *) RelinquishMagickMemory(
1584 attribute_list[j]);
1585 }
1586 attribute_list=(char **) RelinquishMagickMemory(
1587 attribute_list);
1588 }
1589 attribute=DestroyString(attribute);
1590 }
1591 }
1592 }
1593 if (image->debug != MagickFalse)
1594 PrintStringInfo(file,name,profile);
1595 name=GetNextImageProfile(image);
1596 }
1597 }
1598 ResetImagePropertyIterator(image);
1599 property=GetNextImageProperty(image);
1600 if (property != (const char *) NULL)
1601 {
1602 /*
1603 Display image properties.
1604 */
1605 (void) FormatLocaleFile(file," Properties:\n");
1606 while (property != (const char *) NULL)
1607 {
1608 (void) FormatLocaleFile(file," %s: ",property);
1609 value=GetImageProperty(image,property,exception);
1610 if (value != (const char *) NULL)
1611 (void) FormatLocaleFile(file,"%s\n",value);
1612 property=GetNextImageProperty(image);
1613 }
1614 }
1615 ResetImageArtifactIterator(image);
1616 artifact=GetNextImageArtifact(image);
1617 if (artifact != (const char *) NULL)
1618 {
1619 /*
1620 Display image artifacts.
1621 */
1622 (void) FormatLocaleFile(file," Artifacts:\n");
1623 while (artifact != (const char *) NULL)
1624 {
1625 (void) FormatLocaleFile(file," %s: ",artifact);
1626 value=GetImageArtifact(image,artifact);
1627 if (value != (const char *) NULL)
1628 (void) FormatLocaleFile(file,"%s\n",value);
1629 artifact=GetNextImageArtifact(image);
1630 }
1631 }
1632 ResetImageRegistryIterator();
1633 registry=GetNextImageRegistry();
1634 if (registry != (const char *) NULL)
1635 {
1636 /*
1637 Display image registry.
1638 */
1639 (void) FormatLocaleFile(file," Registry:\n");
1640 while (registry != (const char *) NULL)
1641 {
1642 (void) FormatLocaleFile(file," %s: ",registry);
1643 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1644 exception);
1645 if (value != (const char *) NULL)
1646 (void) FormatLocaleFile(file,"%s\n",value);
1647 registry=GetNextImageRegistry();
1648 }
1649 }
1650 (void) FormatLocaleFile(file," Tainted: %s\n",CommandOptionToMnemonic(
1651 MagickBooleanOptions,(ssize_t) image->taint));
1652 (void) FormatMagickSize(image->extent,MagickTrue,"B",MagickPathExtent,buffer);
1653 (void) FormatLocaleFile(file," Filesize: %s\n",buffer);
1654 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1655 MagickFalse,"P",MagickPathExtent,buffer);
1656 if (strlen(buffer) > 1)
1657 buffer[strlen(buffer)-1]='\0';
1658 (void) FormatLocaleFile(file," Number pixels: %s\n",buffer);
1659 (void) FormatLocaleString(buffer,MagickPathExtent,"%s",
1660 CommandOptionToMnemonic(MagickCacheOptions,(ssize_t)
1661 GetImagePixelCacheType(image)));
1662 (void) FormatLocaleFile(file," Pixel cache type: %s\n",buffer);
1663 if (elapsed_time > MagickEpsilon)
1664 {
1665 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*
1666 image->rows/elapsed_time+0.5),MagickFalse,"P",MagickPathExtent,buffer);
1667 (void) FormatLocaleFile(file," Pixels per second: %s\n",buffer);
1668 }
1669 if (image->ttl != (time_t) 0)
1670 {
1671 char
1672 iso8601[sizeof("9999-99-99T99:99:99Z")];
1673
1674 int
1675 seconds;
1676
1677 struct tm
1678 timestamp;
1679
1680 (void) GetMagickUTCTime(&image->ttl,&timestamp);
1681 (void) strftime(iso8601,sizeof(iso8601),"%Y-%m-%dT%H:%M:%SZ",&timestamp);
1682 seconds=MagickMax((int)(image->ttl-GetMagickTime()),0);
1683 expired=' ';
1684 if (seconds == 0)
1685 expired='*';
1686 (void) FormatLocaleFile(file," Time-to-live: %g:%02g:%02g:%02g%c %s\n",
1687 ceil((double) (seconds/(3600*24))),
1688 ceil((double) ((seconds % (24*3600))/3600)),
1689 ceil((double) ((seconds % 3600)/60)),
1690 ceil((double) ((seconds % 3600) % 60)),expired,iso8601);
1691 }
1692 (void) FormatLocaleFile(file," User time: %0.3fu\n",user_time);
1693 (void) FormatLocaleFile(file," Elapsed time: %lu:%02lu.%03lu\n",
1694 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(elapsed_time,
1695 60.0)),(unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))));
1696 (void) FormatLocaleFile(file," Version: %s\n",GetMagickVersion((size_t *)
1697 NULL));
1698 (void) fflush(file);
1699 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1700}