blob: 9feddef22c58269ac9820e97b7b554d8e4ec1ee9 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% IIIII DDDD EEEEE N N TTTTT IIIII FFFFF Y Y %
7% I D D E NN N T I F Y Y %
8% I D D EEE N N N T I FFF Y %
9% I D D E N NN T I F Y %
10% IIIII DDDD EEEEE N N T IIIII F Y %
11% %
12% %
13% Identify an Image Format and Characteristics. %
14% %
15% Software Design %
16% John Cristy %
17% September 1994 %
18% %
19% %
20% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
21% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Identify describes the format and characteristics of one or more image
37% files. It will also report if an image is incomplete or corrupt.
38%
39%
40*/
41
42/*
43 Include declarations.
44*/
45#include "magick/studio.h"
46#include "magick/annotate.h"
47#include "magick/artifact.h"
48#include "magick/blob.h"
49#include "magick/cache.h"
50#include "magick/client.h"
51#include "magick/coder.h"
52#include "magick/color.h"
53#include "magick/configure.h"
54#include "magick/constitute.h"
55#include "magick/decorate.h"
56#include "magick/delegate.h"
57#include "magick/draw.h"
58#include "magick/effect.h"
59#include "magick/exception.h"
60#include "magick/exception-private.h"
61#include "magick/gem.h"
62#include "magick/geometry.h"
63#include "magick/identify.h"
64#include "magick/image.h"
65#include "magick/image-private.h"
66#include "magick/list.h"
67#include "magick/locale_.h"
68#include "magick/log.h"
69#include "magick/magic.h"
70#include "magick/magick.h"
71#include "magick/memory_.h"
72#include "magick/module.h"
73#include "magick/monitor.h"
74#include "magick/montage.h"
75#include "magick/option.h"
76#include "magick/pixel-private.h"
77#include "magick/prepress.h"
78#include "magick/profile.h"
79#include "magick/property.h"
80#include "magick/quantize.h"
81#include "magick/quantum.h"
82#include "magick/random_.h"
83#include "magick/registry.h"
84#include "magick/resize.h"
85#include "magick/resource_.h"
86#include "magick/signature.h"
87#include "magick/statistic.h"
88#include "magick/string_.h"
89#include "magick/timer.h"
90#include "magick/utility.h"
91#include "magick/version.h"
92#if defined(MAGICKCORE_LCMS_DELEGATE)
93#if defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
94#include <lcms/lcms.h>
95#else
96#include "lcms.h"
97#endif
98#endif
99
100/*
101%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102% %
103% %
104% %
105% I d e n t i f y I m a g e %
106% %
107% %
108% %
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110%
111% IdentifyImage() identifies an image by printing its attributes to the file.
112% Attributes include the image width, height, size, and others.
113%
114% The format of the IdentifyImage method is:
115%
116% MagickBooleanType IdentifyImage(Image *image,FILE *file,
117% const MagickBooleanType verbose)
118%
119% A description of each parameter follows:
120%
121% o image: the image.
122%
123% o file: the file, typically stdout.
124%
125% o verbose: A value other than zero prints more detailed information
126% about the image.
127%
128*/
129
130MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
131 const MagickBooleanType verbose)
132{
133#define IdentifyFormat " %s:\n min: " QuantumFormat \
134 " (%g)\n max: " QuantumFormat " (%g)\n" \
135 " mean: %g (%g)\n standard deviation: %g (%g)\n" \
136 " kurtosis: %g\n skewness: %g\n"
137
138 char
139 color[MaxTextExtent],
140 format[MaxTextExtent],
141 key[MaxTextExtent];
142
143 ColorspaceType
144 colorspace;
145
146 const char
147 *artifact,
148 *name,
149 *property,
150 *registry,
151 *value;
152
153 const MagickInfo
154 *magick_info;
155
156 const PixelPacket
157 *pixels;
158
159 double
160 elapsed_time,
161 user_time;
162
163 ExceptionInfo
164 *exception;
165
166 ImageType
167 type;
168
169 long
170 y;
171
172 MagickBooleanType
173 ping;
174
175 register long
176 i,
177 x;
178
179 unsigned long
180 scale;
181
182 assert(image != (Image *) NULL);
183 assert(image->signature == MagickSignature);
184 if (image->debug != MagickFalse)
185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
186 if (file == (FILE *) NULL)
187 file=stdout;
188 *format='\0';
189 elapsed_time=GetElapsedTime(&image->timer);
190 user_time=GetUserTime(&image->timer);
191 GetTimerInfo(&image->timer);
192 if (verbose == MagickFalse)
193 {
194 /*
195 Display summary info about the image.
196 */
197 if (*image->magick_filename != '\0')
198 if (LocaleCompare(image->magick_filename,image->filename) != 0)
199 (void) fprintf(file,"%s=>",image->magick_filename);
200 if ((GetPreviousImageInList(image) == (Image *) NULL) &&
201 (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0))
202 (void) fprintf(file,"%s ",image->filename);
203 else
204 (void) fprintf(file,"%s[%lu] ",image->filename,image->scene);
205 (void) fprintf(file,"%s ",image->magick);
206 if ((image->magick_columns != 0) || (image->magick_rows != 0))
207 if ((image->magick_columns != image->columns) ||
208 (image->magick_rows != image->rows))
209 (void) fprintf(file,"%lux%lu=>",image->magick_columns,
210 image->magick_rows);
211 (void) fprintf(file,"%lux%lu ",image->columns,image->rows);
212 if ((image->page.width != 0) || (image->page.height != 0) ||
213 (image->page.x != 0) || (image->page.y != 0))
214 (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width,
215 image->page.height,image->page.x,image->page.y);
216 (void) fprintf(file,"%lu-bit ",image->depth);
217 if (image->type != UndefinedType)
218 (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
219 (long) image->type));
220 if (image->storage_class == DirectClass)
221 {
222 (void) fprintf(file,"DirectClass ");
223 if (image->total_colors != 0)
224 {
225 (void) FormatMagickSize(image->total_colors,format);
226 (void) fprintf(file,"%s ",format);
227 }
228 }
229 else
230 if (image->total_colors <= image->colors)
231 (void) fprintf(file,"PseudoClass %luc ",image->colors);
232 else
233 (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors,
234 image->colors);
235 if (image->error.mean_error_per_pixel != 0.0)
236 (void) fprintf(file,"%ld/%f/%fdb ",(long)
237 (image->error.mean_error_per_pixel+0.5),
238 image->error.normalized_mean_error,
239 image->error.normalized_maximum_error);
240 if (GetBlobSize(image) != 0)
241 {
242 (void) FormatMagickSize(GetBlobSize(image),format);
243 (void) fprintf(file,"%s ",format);
244 }
245 if (elapsed_time > 0.06)
246 (void) fprintf(file,"%0.3fu %ld:%02ld",user_time,(long)
247 (elapsed_time/60.0+0.5),(long) ceil(fmod(elapsed_time,60.0)));
248 (void) fprintf(file,"\n");
249 (void) fflush(file);
250 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
251 }
252 /*
253 Display verbose info about the image.
254 */
255 exception=AcquireExceptionInfo();
256 pixels=GetVirtualPixels(image,0,0,1,1,exception);
257 exception=DestroyExceptionInfo(exception);
258 ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
259 type=GetImageType(image,&image->exception);
260 (void) SignatureImage(image);
261 (void) fprintf(file,"Image: %s\n",image->filename);
262 if (*image->magick_filename != '\0')
263 if (LocaleCompare(image->magick_filename,image->filename) != 0)
264 {
265 char
266 filename[MaxTextExtent];
267
268 GetPathComponent(image->magick_filename,TailPath,filename);
269 (void) fprintf(file," Base filename: %s\n",filename);
270 }
271 magick_info=GetMagickInfo(image->magick,&image->exception);
272 if ((magick_info == (const MagickInfo *) NULL) ||
273 (*GetMagickDescription(magick_info) == '\0'))
274 (void) fprintf(file," Format: %s\n",image->magick);
275 else
276 (void) fprintf(file," Format: %s (%s)\n",image->magick,
277 GetMagickDescription(magick_info));
278 (void) fprintf(file," Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
279 (long) image->storage_class));
280 (void) fprintf(file," Geometry: %lux%lu%+ld%+ld\n",image->columns,
281 image->rows,image->tile_offset.x,image->tile_offset.y);
282 if ((image->magick_columns != 0) || (image->magick_rows != 0))
283 if ((image->magick_columns != image->columns) ||
284 (image->magick_rows != image->rows))
285 (void) fprintf(file," Base geometry: %lux%lu\n",image->magick_columns,
286 image->magick_rows);
287 if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
288 {
289 (void) fprintf(file," Resolution: %gx%g\n",image->x_resolution,
290 image->y_resolution);
291 (void) fprintf(file," Print size: %gx%g\n",(double) image->columns/
292 image->x_resolution,(double) image->rows/image->y_resolution);
293 }
294 (void) fprintf(file," Units: %s\n",MagickOptionToMnemonic(
295 MagickResolutionOptions,(long) image->units));
296 (void) fprintf(file," Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
297 (long) type));
298 if (image->type != UndefinedType)
299 (void) fprintf(file," Base type: %s\n",MagickOptionToMnemonic(
300 MagickTypeOptions,(long) image->type));
301 (void) fprintf(file," Endianess: %s\n",MagickOptionToMnemonic(
302 MagickEndianOptions,(long) image->endian));
303 /*
304 Detail channel depth and extrema.
305 */
306 (void) fprintf(file," Colorspace: %s\n",MagickOptionToMnemonic(
307 MagickColorspaceOptions,(long) image->colorspace));
308 if (ping == MagickFalse)
309 {
310 ChannelStatistics
311 *channel_statistics;
312
313 unsigned long
314 depth;
315
316 depth=GetImageDepth(image,&image->exception);
317 if (image->depth == depth)
318 (void) fprintf(file," Depth: %lu-bit\n",image->depth);
319 else
320 (void) fprintf(file," Depth: %lu/%lu-bit\n",image->depth,depth);
321 channel_statistics=GetImageChannelStatistics(image,&image->exception);
322 (void) fprintf(file," Channel depth:\n");
323 colorspace=image->colorspace;
324 if (IsGrayImage(image,&image->exception) != MagickFalse)
325 colorspace=GRAYColorspace;
326 switch (colorspace)
327 {
328 case RGBColorspace:
329 default:
330 {
331 (void) fprintf(file," red: %lu-bit\n",
332 channel_statistics[RedChannel].depth);
333 (void) fprintf(file," green: %lu-bit\n",
334 channel_statistics[GreenChannel].depth);
335 (void) fprintf(file," blue: %lu-bit\n",
336 channel_statistics[BlueChannel].depth);
337 if (image->matte != MagickFalse)
338 (void) fprintf(file," alpha: %lu-bit\n",
339 channel_statistics[OpacityChannel].depth);
340 break;
341 }
342 case CMYKColorspace:
343 {
344 (void) fprintf(file," cyan: %lu-bit\n",
345 channel_statistics[CyanChannel].depth);
346 (void) fprintf(file," magenta: %lu-bit\n",
347 channel_statistics[MagentaChannel].depth);
348 (void) fprintf(file," yellow: %lu-bit\n",
349 channel_statistics[YellowChannel].depth);
350 (void) fprintf(file," black: %lu-bit\n",
351 channel_statistics[BlackChannel].depth);
352 if (image->matte != MagickFalse)
353 (void) fprintf(file," alpha: %lu-bit\n",
354 channel_statistics[OpacityChannel].depth);
355 break;
356 }
357 case GRAYColorspace:
358 {
359 (void) fprintf(file," gray: %lu-bit\n",
360 channel_statistics[GrayChannel].depth);
361 if (image->matte != MagickFalse)
362 (void) fprintf(file," alpha: %lu-bit\n",
363 channel_statistics[OpacityChannel].depth);
364 break;
365 }
366 }
367 scale=1;
368 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
369 scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long)
370 MAGICKCORE_QUANTUM_DEPTH-image->depth));
371 (void) fprintf(file," Channel statistics:\n");
372 switch (colorspace)
373 {
374 case RGBColorspace:
375 default:
376 {
377 (void) fprintf(file,IdentifyFormat,"red",(Quantum)
378 (channel_statistics[RedChannel].minima/scale),(double)
379 channel_statistics[RedChannel].minima/(double) QuantumRange,
380 (Quantum) (channel_statistics[RedChannel].maxima/scale),(double)
381 channel_statistics[RedChannel].maxima/(double) QuantumRange,
382 channel_statistics[RedChannel].mean/(double) scale,
383 channel_statistics[RedChannel].mean/(double) QuantumRange,
384 channel_statistics[RedChannel].standard_deviation/(double) scale,
385 channel_statistics[RedChannel].standard_deviation/(double)
386 QuantumRange,channel_statistics[RedChannel].kurtosis,
387 channel_statistics[RedChannel].skewness);
388 (void) fprintf(file,IdentifyFormat,"green",(Quantum)
389 (channel_statistics[GreenChannel].minima/scale),(double)
390 channel_statistics[GreenChannel].minima/(double) QuantumRange,
391 (Quantum) (channel_statistics[GreenChannel].maxima/scale),(double)
392 channel_statistics[GreenChannel].maxima/(double) QuantumRange,
393 channel_statistics[GreenChannel].mean/(double) scale,
394 channel_statistics[GreenChannel].mean/(double) QuantumRange,
395 channel_statistics[GreenChannel].standard_deviation/(double) scale,
396 channel_statistics[GreenChannel].standard_deviation/(double)
397 QuantumRange,
398 channel_statistics[GreenChannel].kurtosis,
399 channel_statistics[GreenChannel].skewness);
400 (void) fprintf(file,IdentifyFormat,"blue",(Quantum)
401 (channel_statistics[BlueChannel].minima/scale),(double)
402 channel_statistics[BlueChannel].minima/(double) QuantumRange,
403 (Quantum) (channel_statistics[BlueChannel].maxima/scale),(double)
404 channel_statistics[BlueChannel].maxima/(double) QuantumRange,
405 channel_statistics[BlueChannel].mean/(double) scale,
406 channel_statistics[BlueChannel].mean/(double) QuantumRange,
407 channel_statistics[BlueChannel].standard_deviation/(double) scale,
408 channel_statistics[BlueChannel].standard_deviation/(double)
409 QuantumRange,channel_statistics[BlueChannel].kurtosis,
410 channel_statistics[BlueChannel].skewness);
411 break;
412 }
413 case CMYKColorspace:
414 {
415 (void) fprintf(file,IdentifyFormat,"cyan",(Quantum)
416 (channel_statistics[CyanChannel].minima/scale),(double)
417 channel_statistics[CyanChannel].minima/(double) QuantumRange,
418 (Quantum) (channel_statistics[CyanChannel].maxima/scale),(double)
419 channel_statistics[CyanChannel].maxima/(double) QuantumRange,
420 channel_statistics[CyanChannel].mean/(double) scale,
421 channel_statistics[CyanChannel].mean/(double) QuantumRange,
422 channel_statistics[CyanChannel].standard_deviation/(double) scale,
423 channel_statistics[CyanChannel].standard_deviation/(double)
424 QuantumRange,channel_statistics[CyanChannel].kurtosis,
425 channel_statistics[CyanChannel].skewness);
426 (void) fprintf(file,IdentifyFormat,"magenta",(Quantum)
427 (channel_statistics[MagentaChannel].minima/scale),(double)
428 channel_statistics[MagentaChannel].minima/(double) QuantumRange,
429 (Quantum) (channel_statistics[MagentaChannel].maxima/scale),(double)
430 channel_statistics[MagentaChannel].maxima/(double) QuantumRange,
431 channel_statistics[MagentaChannel].mean/(double) scale,
432 channel_statistics[MagentaChannel].mean/(double) QuantumRange,
433 channel_statistics[MagentaChannel].standard_deviation/(double)
434 scale,channel_statistics[MagentaChannel].standard_deviation/(double)
435 QuantumRange,channel_statistics[MagentaChannel].kurtosis,
436 channel_statistics[MagentaChannel].skewness);
437 (void) fprintf(file,IdentifyFormat,"yellow",(Quantum)
438 (channel_statistics[YellowChannel].minima/scale),(double)
439 channel_statistics[YellowChannel].minima/(double) QuantumRange,
440 (Quantum) (channel_statistics[YellowChannel].maxima/scale),(double)
441 channel_statistics[YellowChannel].maxima/(double) QuantumRange,
442 channel_statistics[YellowChannel].mean/(double) scale,
443 channel_statistics[YellowChannel].mean/(double) QuantumRange,
444 channel_statistics[YellowChannel].standard_deviation/(double) scale,
445 channel_statistics[YellowChannel].standard_deviation/(double)
446 QuantumRange,channel_statistics[YellowChannel].kurtosis,
447 channel_statistics[YellowChannel].skewness);
448 (void) fprintf(file,IdentifyFormat,"black",(Quantum)
449 (channel_statistics[BlackChannel].minima/scale),(double)
450 channel_statistics[BlackChannel].minima/(double) QuantumRange,
451 (Quantum) (channel_statistics[BlackChannel].maxima/scale),(double)
452 channel_statistics[BlackChannel].maxima/(double) QuantumRange,
453 channel_statistics[BlackChannel].mean/(double) scale,
454 channel_statistics[BlackChannel].mean/(double) QuantumRange,
455 channel_statistics[BlackChannel].standard_deviation/(double) scale,
456 channel_statistics[BlackChannel].standard_deviation/(double)
457 QuantumRange,channel_statistics[BlackChannel].kurtosis,
458 channel_statistics[BlackChannel].skewness);
459 break;
460 }
461 case GRAYColorspace:
462 {
463 (void) fprintf(file,IdentifyFormat,"gray",(Quantum)
464 (channel_statistics[GrayChannel].minima/scale),(double)
465 channel_statistics[GrayChannel].minima/(double) QuantumRange,
466 (Quantum) (channel_statistics[GrayChannel].maxima/scale),(double)
467 channel_statistics[GrayChannel].maxima/(double) QuantumRange,
468 channel_statistics[GrayChannel].mean/(double) scale,
469 channel_statistics[GrayChannel].mean/(double) QuantumRange,
470 channel_statistics[GrayChannel].standard_deviation/(double) scale,
471 channel_statistics[GrayChannel].standard_deviation/(double)
472 QuantumRange,channel_statistics[GrayChannel].kurtosis,
473 channel_statistics[GrayChannel].skewness);
474 break;
475 }
476 }
477 if (image->matte != MagickFalse)
478 (void) fprintf(file,IdentifyFormat,"alpha",(Quantum)
479 ((QuantumRange-channel_statistics[AlphaChannel].maxima)/scale),
480 (double) (QuantumRange-channel_statistics[AlphaChannel].maxima)/
481 (double) QuantumRange, (Quantum) ((QuantumRange-
482 channel_statistics[AlphaChannel].minima)/scale),(double)
483 (QuantumRange-channel_statistics[AlphaChannel].minima)/(double)
484 QuantumRange,(QuantumRange-channel_statistics[AlphaChannel].mean)/
485 (double) scale,(QuantumRange-channel_statistics[AlphaChannel].mean)/
486 (double) QuantumRange,
487 channel_statistics[AlphaChannel].standard_deviation/(double) scale,
488 channel_statistics[AlphaChannel].standard_deviation/(double)
489 QuantumRange,channel_statistics[AlphaChannel].kurtosis,
490 channel_statistics[AlphaChannel].skewness);
491 if (colorspace != GRAYColorspace)
492 {
493 (void) fprintf(file," Image statistics:\n");
494 (void) fprintf(file,IdentifyFormat,"Overall",(Quantum)
495 (channel_statistics[AllChannels].minima/scale),(double)
496 channel_statistics[AllChannels].minima/(double) QuantumRange,
497 (Quantum) (channel_statistics[AllChannels].maxima/scale),(double)
498 channel_statistics[AllChannels].maxima/(double) QuantumRange,
499 channel_statistics[AllChannels].mean/(double) scale,
500 channel_statistics[AllChannels].mean/(double) QuantumRange,
501 channel_statistics[AllChannels].standard_deviation/(double) scale,
502 channel_statistics[AllChannels].standard_deviation/(double)
503 QuantumRange,channel_statistics[AllChannels].kurtosis,
504 channel_statistics[AllChannels].skewness);
505 }
506 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
507 channel_statistics);
508 if (image->colorspace == CMYKColorspace)
509 (void) fprintf(file," Total ink density: %.0f%%\n",100.0*
510 GetImageTotalInkDensity(image)/(double) QuantumRange);
511 x=0;
512 if (image->matte != MagickFalse)
513 {
514 register const IndexPacket
515 *indexes;
516
517 register const PixelPacket
518 *p;
519
520 p=(PixelPacket *) NULL;
521 indexes=(IndexPacket *) NULL;
522 for (y=0; y < (long) image->rows; y++)
523 {
524 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
525 if (p == (const PixelPacket *) NULL)
526 break;
527 indexes=GetVirtualIndexQueue(image);
528 for (x=0; x < (long) image->columns; x++)
529 {
530 if (p->opacity == (Quantum) TransparentOpacity)
531 break;
532 p++;
533 }
534 if (x < (long) image->columns)
535 break;
536 }
537 if ((x < (long) image->columns) || (y < (long) image->rows))
538 {
539 char
540 tuple[MaxTextExtent];
541
542 MagickPixelPacket
543 pixel;
544
545 GetMagickPixelPacket(image,&pixel);
546 SetMagickPixelPacket(image,p,indexes+x,&pixel);
547 (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
548 &image->exception);
549 (void) fprintf(file," Alpha: %s ",tuple);
550 GetColorTuple(&pixel,MagickTrue,tuple);
551 (void) fprintf(file," %s\n",tuple);
552 }
553 }
554 if (ping == MagickFalse)
555 {
556 artifact=GetImageArtifact(image,"identify:unique");
557 if ((artifact != (const char *) NULL) &&
558 (IsMagickTrue(artifact) != MagickFalse))
559 (void) fprintf(file," Colors: %lu\n",GetNumberColors(image,
560 (FILE *) NULL,&image->exception));
561 if (IsHistogramImage(image,&image->exception) != MagickFalse)
562 {
563 (void) fprintf(file," Histogram:\n");
564 (void) GetNumberColors(image,file,&image->exception);
565 }
566 }
567 }
568 if (image->storage_class == PseudoClass)
569 {
570 (void) fprintf(file," Colormap: %lu\n",image->colors);
571 if (image->colors <= 1024)
572 {
573 char
574 color[MaxTextExtent],
575 hex[MaxTextExtent],
576 tuple[MaxTextExtent];
577
578 MagickPixelPacket
579 pixel;
580
581 register PixelPacket
582 *__restrict p;
583
584 GetMagickPixelPacket(image,&pixel);
585 p=image->colormap;
586 for (i=0; i < (long) image->colors; i++)
587 {
588 SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
589 (void) CopyMagickString(tuple,"(",MaxTextExtent);
590 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
591 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
592 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
593 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
594 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
595 if (pixel.colorspace == CMYKColorspace)
596 {
597 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
598 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
599 tuple);
600 }
601 if (pixel.matte != MagickFalse)
602 {
603 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
604 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,
605 tuple);
606 }
607 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
608 (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
609 &image->exception);
610 GetColorTuple(&pixel,MagickTrue,hex);
611 (void) fprintf(file," %8ld: %s %s %s\n",i,tuple,hex,color);
612 p++;
613 }
614 }
615 }
616 if (image->error.mean_error_per_pixel != 0.0)
617 (void) fprintf(file," Mean error per pixel: %g\n",
618 image->error.mean_error_per_pixel);
619 if (image->error.normalized_mean_error != 0.0)
620 (void) fprintf(file," Normalized mean error: %g\n",
621 image->error.normalized_mean_error);
622 if (image->error.normalized_maximum_error != 0.0)
623 (void) fprintf(file," Normalized maximum error: %g\n",
624 image->error.normalized_maximum_error);
625 (void) fprintf(file," Rendering intent: %s\n",MagickOptionToMnemonic(
626 MagickIntentOptions,(long) image->rendering_intent));
627 if (image->gamma != 0.0)
628 (void) fprintf(file," Gamma: %g\n",image->gamma);
629 if ((image->chromaticity.red_primary.x != 0.0) ||
630 (image->chromaticity.green_primary.x != 0.0) ||
631 (image->chromaticity.blue_primary.x != 0.0) ||
632 (image->chromaticity.white_point.x != 0.0))
633 {
634 /*
635 Display image chromaticity.
636 */
637 (void) fprintf(file," Chromaticity:\n");
638 (void) fprintf(file," red primary: (%g,%g)\n",
639 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
640 (void) fprintf(file," green primary: (%g,%g)\n",
641 image->chromaticity.green_primary.x,
642 image->chromaticity.green_primary.y);
643 (void) fprintf(file," blue primary: (%g,%g)\n",
644 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
645 (void) fprintf(file," white point: (%g,%g)\n",
646 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
647 }
648 if ((image->extract_info.width*image->extract_info.height) != 0)
649 (void) fprintf(file," Tile geometry: %lux%lu%+ld%+ld\n",
650 image->extract_info.width,image->extract_info.height,
651 image->extract_info.x,image->extract_info.y);
652 (void) fprintf(file," Interlace: %s\n",MagickOptionToMnemonic(
653 MagickInterlaceOptions,(long) image->interlace));
654 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
655 &image->exception);
656 (void) fprintf(file," Background color: %s\n",color);
657 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
658 &image->exception);
659 (void) fprintf(file," Border color: %s\n",color);
660 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
661 &image->exception);
662 (void) fprintf(file," Matte color: %s\n",color);
663 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
664 &image->exception);
665 (void) fprintf(file," Transparent color: %s\n",color);
666 if ((image->page.width != 0) || (image->page.height != 0) ||
667 (image->page.x != 0) || (image->page.y != 0))
668 (void) fprintf(file," Page geometry: %lux%lu%+ld%+ld\n",image->page.width,
669 image->page.height,image->page.x,image->page.y);
670 if ((image->page.x != 0) || (image->page.y != 0))
671 (void) fprintf(file," Origin geometry: %+ld%+ld\n",image->page.x,
672 image->page.y);
673 (void) fprintf(file," Dispose: %s\n",MagickOptionToMnemonic(
674 MagickDisposeOptions,(long) image->dispose));
675 if (image->delay != 0)
676 (void) fprintf(file," Delay: %lux%ld\n",image->delay,
677 image->ticks_per_second);
678 if (image->iterations != 1)
679 (void) fprintf(file," Iterations: %lu\n",image->iterations);
680 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
681 (void) fprintf(file," Scene: %lu of %lu\n",image->scene,
682 GetImageListLength(image));
683 else
684 if (image->scene != 0)
685 (void) fprintf(file," Scene: %lu\n",image->scene);
686 (void) fprintf(file," Compression: %s\n",MagickOptionToMnemonic(
687 MagickCompressOptions,(long) image->compression));
688 if (image->quality != UndefinedCompressionQuality)
689 (void) fprintf(file," Quality: %lu\n",image->quality);
690 (void) fprintf(file," Orientation: %s\n",MagickOptionToMnemonic(
691 MagickOrientationOptions,(long) image->orientation));
692 if (image->montage != (char *) NULL)
693 (void) fprintf(file," Montage: %s\n",image->montage);
694 if (image->directory != (char *) NULL)
695 {
696 Image
697 *tile;
698
699 ImageInfo
700 *image_info;
701
702 register char
703 *p,
704 *q;
705
706 WarningHandler
707 handler;
708
709 /*
710 Display visual image directory.
711 */
712 image_info=AcquireImageInfo();
713 (void) CloneString(&image_info->size,"64x64");
714 (void) fprintf(file," Directory:\n");
715 for (p=image->directory; *p != '\0'; p++)
716 {
717 q=p;
718 while ((*q != '\n') && (*q != '\0'))
719 q++;
720 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
721 p=q;
722 (void) fprintf(file," %s",image_info->filename);
723 handler=SetWarningHandler((WarningHandler) NULL);
724 tile=ReadImage(image_info,&image->exception);
725 (void) SetWarningHandler(handler);
726 if (tile == (Image *) NULL)
727 {
728 (void) fprintf(file,"\n");
729 continue;
730 }
731 (void) fprintf(file," %lux%lu %s\n",tile->magick_columns,
732 tile->magick_rows,tile->magick);
733 (void) SignatureImage(tile);
734 ResetImagePropertyIterator(tile);
735 property=GetNextImageProperty(tile);
736 while (property != (const char *) NULL)
737 {
738 (void) fprintf(file," %s:\n",property);
739 value=GetImageProperty(tile,property);
740 if (value != (const char *) NULL)
741 (void) fprintf(file,"%s\n",value);
742 property=GetNextImageProperty(tile);
743 }
744 tile=DestroyImage(tile);
745 }
746 image_info=DestroyImageInfo(image_info);
747 }
748 (void) GetImageProperty(image,"exif:*");
749 ResetImagePropertyIterator(image);
750 property=GetNextImageProperty(image);
751 if (property != (const char *) NULL)
752 {
753 /*
754 Display image properties.
755 */
756 (void) fprintf(file," Properties:\n");
757 while (property != (const char *) NULL)
758 {
759 (void) fprintf(file," %c",*property);
760 if (strlen(property) > 1)
761 (void) fprintf(file,"%s: ",property+1);
762 if (strlen(property) > 80)
763 (void) fputc('\n',file);
764 value=GetImageProperty(image,property);
765 if (value != (const char *) NULL)
766 (void) fprintf(file,"%s\n",value);
767 property=GetNextImageProperty(image);
768 }
769 }
770 (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
771 value=GetImageProperty(image,key);
772 if (value != (const char *) NULL)
773 {
774 /*
775 Display clipping path.
776 */
777 (void) fprintf(file," Clipping path: ");
778 if (strlen(value) > 80)
779 (void) fputc('\n',file);
780 (void) fprintf(file,"%s\n",value);
781 }
782 ResetImageProfileIterator(image);
783 name=GetNextImageProfile(image);
784 if (name != (char *) NULL)
785 {
786 const StringInfo
787 *profile;
788
789 /*
790 Identify image profiles.
791 */
792 (void) fprintf(file," Profiles:\n");
793 while (name != (char *) NULL)
794 {
795 profile=GetImageProfile(image,name);
796 if (profile == (StringInfo *) NULL)
797 continue;
798 (void) fprintf(file," Profile-%s: %lu bytes\n",name,(unsigned long)
799 GetStringInfoLength(profile));
800#if defined(MAGICKCORE_LCMS_DELEGATE)
801 if ((LocaleCompare(name,"icc") == 0) ||
802 (LocaleCompare(name,"icm") == 0))
803 {
804 cmsHPROFILE
805 icc_profile;
806
807 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
808 (DWORD) GetStringInfoLength(profile));
809 if (icc_profile != (cmsHPROFILE *) NULL)
810 {
811 const char
812 *name;
813
814 name=cmsTakeProductName(icc_profile);
815 if (name != (const char *) NULL)
816 (void) fprintf(file," %s\n",name);
817 (void) cmsCloseProfile(icc_profile);
818 }
819 }
820#endif
821 if (LocaleCompare(name,"iptc") == 0)
822 {
823 char
824 *attribute,
825 **attribute_list;
826
827 const char
828 *tag;
829
830 long
831 dataset,
832 record,
833 sentinel;
834
835 register long
836 j;
837
838 size_t
839 length,
840 profile_length;
841
842 profile_length=GetStringInfoLength(profile);
843 for (i=0; i < (long) profile_length; i+=(long) length)
844 {
845 length=1;
846 sentinel=GetStringInfoDatum(profile)[i++];
847 if (sentinel != 0x1c)
848 continue;
849 dataset=GetStringInfoDatum(profile)[i++];
850 record=GetStringInfoDatum(profile)[i++];
851 switch (record)
852 {
853 case 5: tag="Image Name"; break;
854 case 7: tag="Edit Status"; break;
855 case 10: tag="Priority"; break;
856 case 15: tag="Category"; break;
857 case 20: tag="Supplemental Category"; break;
858 case 22: tag="Fixture Identifier"; break;
859 case 25: tag="Keyword"; break;
860 case 30: tag="Release Date"; break;
861 case 35: tag="Release Time"; break;
862 case 40: tag="Special Instructions"; break;
863 case 45: tag="Reference Service"; break;
864 case 47: tag="Reference Date"; break;
865 case 50: tag="Reference Number"; break;
866 case 55: tag="Created Date"; break;
867 case 60: tag="Created Time"; break;
868 case 65: tag="Originating Program"; break;
869 case 70: tag="Program Version"; break;
870 case 75: tag="Object Cycle"; break;
871 case 80: tag="Byline"; break;
872 case 85: tag="Byline Title"; break;
873 case 90: tag="City"; break;
874 case 95: tag="Province State"; break;
875 case 100: tag="Country Code"; break;
876 case 101: tag="Country"; break;
877 case 103: tag="Original Transmission Reference"; break;
878 case 105: tag="Headline"; break;
879 case 110: tag="Credit"; break;
880 case 115: tag="Src"; break;
881 case 116: tag="Copyright String"; break;
882 case 120: tag="Caption"; break;
883 case 121: tag="Local Caption"; break;
884 case 122: tag="Caption Writer"; break;
885 case 200: tag="Custom Field 1"; break;
886 case 201: tag="Custom Field 2"; break;
887 case 202: tag="Custom Field 3"; break;
888 case 203: tag="Custom Field 4"; break;
889 case 204: tag="Custom Field 5"; break;
890 case 205: tag="Custom Field 6"; break;
891 case 206: tag="Custom Field 7"; break;
892 case 207: tag="Custom Field 8"; break;
893 case 208: tag="Custom Field 9"; break;
894 case 209: tag="Custom Field 10"; break;
895 case 210: tag="Custom Field 11"; break;
896 case 211: tag="Custom Field 12"; break;
897 case 212: tag="Custom Field 13"; break;
898 case 213: tag="Custom Field 14"; break;
899 case 214: tag="Custom Field 15"; break;
900 case 215: tag="Custom Field 16"; break;
901 case 216: tag="Custom Field 17"; break;
902 case 217: tag="Custom Field 18"; break;
903 case 218: tag="Custom Field 19"; break;
904 case 219: tag="Custom Field 20"; break;
905 default: tag="unknown"; break;
906 }
907 (void) fprintf(file," %s[%ld,%ld]: ",tag,dataset,record);
908 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
909 length|=GetStringInfoDatum(profile)[i++];
910 attribute=(char *) NULL;
911 if (~length >= MaxTextExtent)
912 attribute=(char *) AcquireQuantumMemory(length+
913 MaxTextExtent,sizeof(*attribute));
914 if (attribute != (char *) NULL)
915 {
916 (void) CopyMagickString(attribute,(char *)
917 GetStringInfoDatum(profile)+i,length+1);
918 attribute_list=StringToList(attribute);
919 if (attribute_list != (char **) NULL)
920 {
921 for (j=0; attribute_list[j] != (char *) NULL; j++)
922 {
923 (void) fputs(attribute_list[j],file);
924 (void) fputs("\n",file);
925 attribute_list[j]=(char *) RelinquishMagickMemory(
926 attribute_list[j]);
927 }
928 attribute_list=(char **) RelinquishMagickMemory(
929 attribute_list);
930 }
931 attribute=DestroyString(attribute);
932 }
933 }
934 }
935 if (image->debug != MagickFalse)
936 PrintStringInfo(file,name,profile);
937 name=GetNextImageProfile(image);
938 }
939 }
940 ResetImageArtifactIterator(image);
941 artifact=GetNextImageArtifact(image);
942 if (artifact != (const char *) NULL)
943 {
944 /*
945 Display image artifacts.
946 */
947 (void) fprintf(file," Artifacts:\n");
948 while (artifact != (const char *) NULL)
949 {
950 (void) fprintf(file," %c",*artifact);
951 if (strlen(artifact) > 1)
952 (void) fprintf(file,"%s: ",artifact+1);
953 if (strlen(artifact) > 80)
954 (void) fputc('\n',file);
955 value=GetImageArtifact(image,artifact);
956 if (value != (const char *) NULL)
957 (void) fprintf(file,"%s\n",value);
958 artifact=GetNextImageArtifact(image);
959 }
960 }
961 ResetImageRegistryIterator();
962 registry=GetNextImageRegistry();
963 if (registry != (const char *) NULL)
964 {
965 /*
966 Display image registry.
967 */
968 (void) fprintf(file," Registry:\n");
969 while (registry != (const char *) NULL)
970 {
971 (void) fprintf(file," %c",*registry);
972 if (strlen(registry) > 1)
973 (void) fprintf(file,"%s: ",registry+1);
974 if (strlen(registry) > 80)
975 (void) fputc('\n',file);
976 value=(const char *) GetImageRegistry(StringRegistryType,registry,
977 &image->exception);
978 if (value != (const char *) NULL)
979 (void) fprintf(file,"%s\n",value);
980 registry=GetNextImageRegistry();
981 }
982 }
983 (void) fprintf(file," Tainted: %s\n",MagickOptionToMnemonic(
984 MagickBooleanOptions,(long) image->taint));
985 (void) FormatMagickSize(GetBlobSize(image),format);
986 (void) fprintf(file," Filesize: %s\n",format);
987 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,format);
988 (void) fprintf(file," Number pixels: %s\n",format);
989 if (elapsed_time > 0.06)
990 {
991 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*
992 image->rows/elapsed_time+0.5),format);
993 (void) fprintf(file," Pixels per second: %s\n",format);
994 (void) fprintf(file," User time: %0.3fu\n",user_time);
995 (void) fprintf(file," Elapsed time: %ld:%02ld\n",(long) (elapsed_time/
996 60.0+0.5),(long) ceil(fmod(elapsed_time,60.0)));
997 }
998 (void) fprintf(file," Version: %s\n",GetMagickVersion(
999 (unsigned long *) NULL));
1000 (void) fflush(file);
1001 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1002}