blob: a61f65f06ff6cc64e5cb4e55025e05881a41e4c6 [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"
cristy78e9c762009-10-14 19:36:18 +000048#include "magick/attribute.h"
cristy3ed852e2009-09-05 21:47:34 +000049#include "magick/blob.h"
50#include "magick/cache.h"
51#include "magick/client.h"
52#include "magick/coder.h"
53#include "magick/color.h"
54#include "magick/configure.h"
55#include "magick/constitute.h"
56#include "magick/decorate.h"
57#include "magick/delegate.h"
58#include "magick/draw.h"
59#include "magick/effect.h"
60#include "magick/exception.h"
61#include "magick/exception-private.h"
cristy549a37e2010-01-26 15:24:15 +000062#include "magick/feature.h"
cristy3ed852e2009-09-05 21:47:34 +000063#include "magick/gem.h"
64#include "magick/geometry.h"
cristyf2e11662009-10-14 01:24:43 +000065#include "magick/histogram.h"
cristy3ed852e2009-09-05 21:47:34 +000066#include "magick/identify.h"
67#include "magick/image.h"
68#include "magick/image-private.h"
69#include "magick/list.h"
70#include "magick/locale_.h"
71#include "magick/log.h"
72#include "magick/magic.h"
73#include "magick/magick.h"
74#include "magick/memory_.h"
75#include "magick/module.h"
76#include "magick/monitor.h"
77#include "magick/montage.h"
78#include "magick/option.h"
79#include "magick/pixel-private.h"
80#include "magick/prepress.h"
81#include "magick/profile.h"
82#include "magick/property.h"
83#include "magick/quantize.h"
84#include "magick/quantum.h"
85#include "magick/random_.h"
86#include "magick/registry.h"
87#include "magick/resize.h"
88#include "magick/resource_.h"
89#include "magick/signature.h"
90#include "magick/statistic.h"
91#include "magick/string_.h"
cristycd483f12010-01-26 15:30:08 +000092#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000093#include "magick/timer.h"
94#include "magick/utility.h"
95#include "magick/version.h"
96#if defined(MAGICKCORE_LCMS_DELEGATE)
97#if defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
98#include <lcms/lcms.h>
99#else
100#include "lcms.h"
101#endif
102#endif
103
104/*
105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106% %
107% %
108% %
109% I d e n t i f y I m a g e %
110% %
111% %
112% %
113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114%
115% IdentifyImage() identifies an image by printing its attributes to the file.
116% Attributes include the image width, height, size, and others.
117%
118% The format of the IdentifyImage method is:
119%
120% MagickBooleanType IdentifyImage(Image *image,FILE *file,
121% const MagickBooleanType verbose)
122%
123% A description of each parameter follows:
124%
125% o image: the image.
126%
127% o file: the file, typically stdout.
128%
129% o verbose: A value other than zero prints more detailed information
130% about the image.
131%
132*/
133
cristybd822072010-01-27 00:30:00 +0000134static int PrintChannelFeatures(FILE *file,const ChannelType channel,
135 const char *name,const double scale,const ChannelFeatures *channel_features)
cristy3ed852e2009-09-05 21:47:34 +0000136{
cristybd822072010-01-27 00:30:00 +0000137#define FeaturesFormat " %s:\n" \
cristycdf8e1b2010-01-28 01:52:33 +0000138 " Angular Second Moment:\n" \
cristybd822072010-01-27 00:30:00 +0000139 " %g, %g, %g, %g\n" \
cristycdf8e1b2010-01-28 01:52:33 +0000140 " Contrast:\n" \
141 " %g, %g, %g, %g\n" \
142 " Correlation:\n" \
143 " %g, %g, %g, %g\n" \
cristycf5e6492010-01-28 02:45:28 +0000144 " Sum of Square: Variance:\n" \
145 " %g, %g, %g, %g\n" \
146 " Inverse Difference Moment:\n" \
147 " %g, %g, %g, %g\n"
cristybd822072010-01-27 00:30:00 +0000148
149 int
150 status;
151
152 status=fprintf(file,FeaturesFormat,name,
153 channel_features[channel].angular_second_moment[0],
154 channel_features[channel].angular_second_moment[1],
155 channel_features[channel].angular_second_moment[2],
156 channel_features[channel].angular_second_moment[3],
157 channel_features[channel].contrast[0],
158 channel_features[channel].contrast[1],
159 channel_features[channel].contrast[2],
cristycdf8e1b2010-01-28 01:52:33 +0000160 channel_features[channel].contrast[3],
161 channel_features[channel].correlation[0],
162 channel_features[channel].correlation[1],
163 channel_features[channel].correlation[2],
cristycf5e6492010-01-28 02:45:28 +0000164 channel_features[channel].correlation[3],
165 channel_features[channel].variance_sum_of_squares[0],
166 channel_features[channel].variance_sum_of_squares[1],
167 channel_features[channel].variance_sum_of_squares[2],
168 channel_features[channel].variance_sum_of_squares[3],
169 channel_features[channel].inverse_difference_moment[0],
170 channel_features[channel].inverse_difference_moment[1],
171 channel_features[channel].inverse_difference_moment[2],
172 channel_features[channel].inverse_difference_moment[3]);
cristybd822072010-01-27 00:30:00 +0000173 return(status);
174}
175
176static int PrintChannelStatistics(FILE *file,const ChannelType channel,
177 const char *name,const double scale,
178 const ChannelStatistics *channel_statistics)
179{
180#define StatisticsFormat " %s:\n min: " QuantumFormat \
cristye7f51092010-01-17 00:39:37 +0000181 " (%g)\n max: " QuantumFormat " (%g)\n" \
182 " mean: %g (%g)\n standard deviation: %g (%g)\n" \
183 " kurtosis: %g\n skewness: %g\n"
cristy3ed852e2009-09-05 21:47:34 +0000184
cristybd822072010-01-27 00:30:00 +0000185 double
186 maxima,
187 mean,
188 minima;
189
190 int
191 status;
192
193 minima=channel_statistics[channel].minima;
194 maxima=channel_statistics[channel].maxima;
195 mean=channel_statistics[channel].mean;
196 if (channel == AlphaChannel)
197 {
198 minima=QuantumRange-minima;
199 maxima=QuantumRange-maxima;
200 mean=QuantumRange-mean;
201 }
202 status=fprintf(file,StatisticsFormat,name,(Quantum) (scale*minima),minima/
203 (double) QuantumRange,(Quantum) (maxima/scale),maxima/(double) QuantumRange,
204 scale*mean,mean/(double) QuantumRange,
205 scale*channel_statistics[channel].standard_deviation,
206 channel_statistics[channel].standard_deviation/(double)
207 QuantumRange,channel_statistics[channel].kurtosis,
208 channel_statistics[channel].skewness);
209 return(status);
210}
211
212MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
213 const MagickBooleanType verbose)
214{
cristy3ed852e2009-09-05 21:47:34 +0000215 char
216 color[MaxTextExtent],
217 format[MaxTextExtent],
218 key[MaxTextExtent];
219
cristybd822072010-01-27 00:30:00 +0000220 ChannelFeatures
221 *channel_features;
222
223 ChannelStatistics
224 *channel_statistics;
225
cristy3ed852e2009-09-05 21:47:34 +0000226 ColorspaceType
227 colorspace;
228
229 const char
230 *artifact,
231 *name,
232 *property,
233 *registry,
234 *value;
235
236 const MagickInfo
237 *magick_info;
238
239 const PixelPacket
240 *pixels;
241
242 double
243 elapsed_time,
244 user_time;
245
246 ExceptionInfo
247 *exception;
248
249 ImageType
250 type;
251
252 long
253 y;
254
255 MagickBooleanType
256 ping;
257
258 register long
259 i,
260 x;
261
262 unsigned long
cristybd822072010-01-27 00:30:00 +0000263 distance,
cristy3ed852e2009-09-05 21:47:34 +0000264 scale;
265
266 assert(image != (Image *) NULL);
267 assert(image->signature == MagickSignature);
268 if (image->debug != MagickFalse)
269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
270 if (file == (FILE *) NULL)
271 file=stdout;
272 *format='\0';
273 elapsed_time=GetElapsedTime(&image->timer);
274 user_time=GetUserTime(&image->timer);
275 GetTimerInfo(&image->timer);
276 if (verbose == MagickFalse)
277 {
278 /*
279 Display summary info about the image.
280 */
281 if (*image->magick_filename != '\0')
282 if (LocaleCompare(image->magick_filename,image->filename) != 0)
283 (void) fprintf(file,"%s=>",image->magick_filename);
284 if ((GetPreviousImageInList(image) == (Image *) NULL) &&
285 (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0))
286 (void) fprintf(file,"%s ",image->filename);
287 else
288 (void) fprintf(file,"%s[%lu] ",image->filename,image->scene);
289 (void) fprintf(file,"%s ",image->magick);
290 if ((image->magick_columns != 0) || (image->magick_rows != 0))
291 if ((image->magick_columns != image->columns) ||
292 (image->magick_rows != image->rows))
293 (void) fprintf(file,"%lux%lu=>",image->magick_columns,
294 image->magick_rows);
295 (void) fprintf(file,"%lux%lu ",image->columns,image->rows);
296 if ((image->page.width != 0) || (image->page.height != 0) ||
297 (image->page.x != 0) || (image->page.y != 0))
298 (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width,
299 image->page.height,image->page.x,image->page.y);
300 (void) fprintf(file,"%lu-bit ",image->depth);
301 if (image->type != UndefinedType)
302 (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
303 (long) image->type));
304 if (image->storage_class == DirectClass)
305 {
306 (void) fprintf(file,"DirectClass ");
307 if (image->total_colors != 0)
308 {
cristyb9080c92009-12-01 20:13:26 +0000309 (void) FormatMagickSize(image->total_colors,MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000310 (void) fprintf(file,"%s ",format);
311 }
312 }
313 else
314 if (image->total_colors <= image->colors)
315 (void) fprintf(file,"PseudoClass %luc ",image->colors);
316 else
317 (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors,
318 image->colors);
319 if (image->error.mean_error_per_pixel != 0.0)
320 (void) fprintf(file,"%ld/%f/%fdb ",(long)
321 (image->error.mean_error_per_pixel+0.5),
322 image->error.normalized_mean_error,
323 image->error.normalized_maximum_error);
324 if (GetBlobSize(image) != 0)
325 {
cristyb9080c92009-12-01 20:13:26 +0000326 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000327 (void) fprintf(file,"%s ",format);
328 }
cristy3d231692009-09-29 01:05:22 +0000329 (void) fprintf(file,"%0.3fu %ld:%02ld.%03ld",user_time,(long)
330 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
331 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy3ed852e2009-09-05 21:47:34 +0000332 (void) fprintf(file,"\n");
333 (void) fflush(file);
334 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
335 }
336 /*
337 Display verbose info about the image.
338 */
339 exception=AcquireExceptionInfo();
340 pixels=GetVirtualPixels(image,0,0,1,1,exception);
341 exception=DestroyExceptionInfo(exception);
342 ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
343 type=GetImageType(image,&image->exception);
344 (void) SignatureImage(image);
345 (void) fprintf(file,"Image: %s\n",image->filename);
346 if (*image->magick_filename != '\0')
347 if (LocaleCompare(image->magick_filename,image->filename) != 0)
348 {
349 char
350 filename[MaxTextExtent];
351
352 GetPathComponent(image->magick_filename,TailPath,filename);
353 (void) fprintf(file," Base filename: %s\n",filename);
354 }
355 magick_info=GetMagickInfo(image->magick,&image->exception);
356 if ((magick_info == (const MagickInfo *) NULL) ||
357 (*GetMagickDescription(magick_info) == '\0'))
358 (void) fprintf(file," Format: %s\n",image->magick);
359 else
360 (void) fprintf(file," Format: %s (%s)\n",image->magick,
361 GetMagickDescription(magick_info));
362 (void) fprintf(file," Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
363 (long) image->storage_class));
364 (void) fprintf(file," Geometry: %lux%lu%+ld%+ld\n",image->columns,
365 image->rows,image->tile_offset.x,image->tile_offset.y);
366 if ((image->magick_columns != 0) || (image->magick_rows != 0))
367 if ((image->magick_columns != image->columns) ||
368 (image->magick_rows != image->rows))
369 (void) fprintf(file," Base geometry: %lux%lu\n",image->magick_columns,
370 image->magick_rows);
371 if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
372 {
cristye7f51092010-01-17 00:39:37 +0000373 (void) fprintf(file," Resolution: %gx%g\n",image->x_resolution,
cristy3ed852e2009-09-05 21:47:34 +0000374 image->y_resolution);
cristye7f51092010-01-17 00:39:37 +0000375 (void) fprintf(file," Print size: %gx%g\n",(double) image->columns/
cristy3ed852e2009-09-05 21:47:34 +0000376 image->x_resolution,(double) image->rows/image->y_resolution);
377 }
378 (void) fprintf(file," Units: %s\n",MagickOptionToMnemonic(
379 MagickResolutionOptions,(long) image->units));
380 (void) fprintf(file," Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
381 (long) type));
382 if (image->type != UndefinedType)
383 (void) fprintf(file," Base type: %s\n",MagickOptionToMnemonic(
384 MagickTypeOptions,(long) image->type));
385 (void) fprintf(file," Endianess: %s\n",MagickOptionToMnemonic(
386 MagickEndianOptions,(long) image->endian));
387 /*
388 Detail channel depth and extrema.
389 */
390 (void) fprintf(file," Colorspace: %s\n",MagickOptionToMnemonic(
391 MagickColorspaceOptions,(long) image->colorspace));
cristybd822072010-01-27 00:30:00 +0000392 channel_statistics=(ChannelStatistics *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000393 if (ping == MagickFalse)
cristybd822072010-01-27 00:30:00 +0000394 channel_statistics=GetImageChannelStatistics(image,&image->exception);
395 if (channel_statistics != (ChannelStatistics *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000396 {
cristy3ed852e2009-09-05 21:47:34 +0000397 unsigned long
398 depth;
399
400 depth=GetImageDepth(image,&image->exception);
401 if (image->depth == depth)
402 (void) fprintf(file," Depth: %lu-bit\n",image->depth);
403 else
404 (void) fprintf(file," Depth: %lu/%lu-bit\n",image->depth,depth);
cristy3ed852e2009-09-05 21:47:34 +0000405 (void) fprintf(file," Channel depth:\n");
406 colorspace=image->colorspace;
407 if (IsGrayImage(image,&image->exception) != MagickFalse)
408 colorspace=GRAYColorspace;
409 switch (colorspace)
410 {
411 case RGBColorspace:
412 default:
413 {
414 (void) fprintf(file," red: %lu-bit\n",
415 channel_statistics[RedChannel].depth);
416 (void) fprintf(file," green: %lu-bit\n",
417 channel_statistics[GreenChannel].depth);
418 (void) fprintf(file," blue: %lu-bit\n",
419 channel_statistics[BlueChannel].depth);
420 if (image->matte != MagickFalse)
421 (void) fprintf(file," alpha: %lu-bit\n",
422 channel_statistics[OpacityChannel].depth);
423 break;
424 }
425 case CMYKColorspace:
426 {
427 (void) fprintf(file," cyan: %lu-bit\n",
428 channel_statistics[CyanChannel].depth);
429 (void) fprintf(file," magenta: %lu-bit\n",
430 channel_statistics[MagentaChannel].depth);
431 (void) fprintf(file," yellow: %lu-bit\n",
432 channel_statistics[YellowChannel].depth);
433 (void) fprintf(file," black: %lu-bit\n",
434 channel_statistics[BlackChannel].depth);
435 if (image->matte != MagickFalse)
436 (void) fprintf(file," alpha: %lu-bit\n",
437 channel_statistics[OpacityChannel].depth);
438 break;
439 }
440 case GRAYColorspace:
441 {
442 (void) fprintf(file," gray: %lu-bit\n",
443 channel_statistics[GrayChannel].depth);
444 if (image->matte != MagickFalse)
445 (void) fprintf(file," alpha: %lu-bit\n",
446 channel_statistics[OpacityChannel].depth);
447 break;
448 }
449 }
450 scale=1;
451 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
452 scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long)
453 MAGICKCORE_QUANTUM_DEPTH-image->depth));
454 (void) fprintf(file," Channel statistics:\n");
455 switch (colorspace)
456 {
457 case RGBColorspace:
458 default:
459 {
cristybd822072010-01-27 00:30:00 +0000460 (void) PrintChannelStatistics(file,RedChannel,"Red",1.0/scale,
461 channel_statistics);
462 (void) PrintChannelStatistics(file,GreenChannel,"Green",1.0/scale,
463 channel_statistics);
464 (void) PrintChannelStatistics(file,BlueChannel,"Blue",1.0/scale,
465 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000466 break;
467 }
468 case CMYKColorspace:
469 {
cristybd822072010-01-27 00:30:00 +0000470 (void) PrintChannelStatistics(file,CyanChannel,"Cyan",1.0/scale,
471 channel_statistics);
472 (void) PrintChannelStatistics(file,MagentaChannel,"Magenta",1.0/scale,
473 channel_statistics);
474 (void) PrintChannelStatistics(file,YellowChannel,"Yellow",1.0/scale,
475 channel_statistics);
476 (void) PrintChannelStatistics(file,BlackChannel,"Black",1.0/scale,
477 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000478 break;
479 }
480 case GRAYColorspace:
481 {
cristybd822072010-01-27 00:30:00 +0000482 (void) PrintChannelStatistics(file,GrayChannel,"Gray",1.0/scale,
483 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000484 break;
485 }
486 }
487 if (image->matte != MagickFalse)
cristybd822072010-01-27 00:30:00 +0000488 (void) PrintChannelStatistics(file,AlphaChannel,"Alpha",1.0/scale,
489 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000490 if (colorspace != GRAYColorspace)
491 {
492 (void) fprintf(file," Image statistics:\n");
cristybd822072010-01-27 00:30:00 +0000493 (void) PrintChannelStatistics(file,AllChannels,"Overall",1.0/scale,
494 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000495 }
496 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
497 channel_statistics);
cristybd822072010-01-27 00:30:00 +0000498 }
499 channel_features=(ChannelFeatures *) NULL;
500 artifact=GetImageArtifact(image,"identify:features");
cristybd822072010-01-27 00:30:00 +0000501 if ((ping == MagickFalse) && (artifact != (const char *) NULL))
cristy8c02fa12010-01-27 01:10:17 +0000502 {
503 distance=StringToUnsignedLong(artifact);
504 channel_features=GetImageChannelFeatures(image,distance,
505 &image->exception);
506 }
cristybd822072010-01-27 00:30:00 +0000507 if (channel_features != (ChannelFeatures *) NULL)
508 {
cristy7396d882010-01-27 02:37:56 +0000509 (void) fprintf(file," Channel features (horizontal, vertical, left and right diagonals):\n");
cristybd822072010-01-27 00:30:00 +0000510 switch (colorspace)
511 {
512 case RGBColorspace:
513 default:
cristy549a37e2010-01-26 15:24:15 +0000514 {
cristybd822072010-01-27 00:30:00 +0000515 (void) PrintChannelFeatures(file,RedChannel,"Red",1.0/scale,
516 channel_features);
517 (void) PrintChannelFeatures(file,GreenChannel,"Green",1.0/scale,
518 channel_features);
519 (void) PrintChannelFeatures(file,BlueChannel,"Blue",1.0/scale,
520 channel_features);
521 break;
522 }
523 case CMYKColorspace:
524 {
525 (void) PrintChannelFeatures(file,CyanChannel,"Cyan",1.0/scale,
526 channel_features);
527 (void) PrintChannelFeatures(file,MagentaChannel,"Magenta",1.0/
528 scale,channel_features);
529 (void) PrintChannelFeatures(file,YellowChannel,"Yellow",1.0/scale,
530 channel_features);
531 (void) PrintChannelFeatures(file,BlackChannel,"Black",1.0/scale,
532 channel_features);
533 break;
534 }
535 case GRAYColorspace:
536 {
537 (void) PrintChannelFeatures(file,GrayChannel,"Gray",1.0/scale,
538 channel_features);
539 break;
540 }
541 }
542 if (image->matte != MagickFalse)
543 (void) PrintChannelFeatures(file,AlphaChannel,"Alpha",1.0/scale,
544 channel_features);
545 if (colorspace != GRAYColorspace)
546 {
547 (void) fprintf(file," Image features:\n");
548 (void) PrintChannelFeatures(file,AllChannels,"Overall",1.0/scale,
cristy549a37e2010-01-26 15:24:15 +0000549 channel_features);
550 }
cristybd822072010-01-27 00:30:00 +0000551 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
552 channel_features);
553 }
554 if (ping == MagickFalse)
555 {
cristy3ed852e2009-09-05 21:47:34 +0000556 if (image->colorspace == CMYKColorspace)
557 (void) fprintf(file," Total ink density: %.0f%%\n",100.0*
558 GetImageTotalInkDensity(image)/(double) QuantumRange);
559 x=0;
560 if (image->matte != MagickFalse)
561 {
562 register const IndexPacket
563 *indexes;
564
565 register const PixelPacket
566 *p;
567
568 p=(PixelPacket *) NULL;
569 indexes=(IndexPacket *) NULL;
570 for (y=0; y < (long) image->rows; y++)
571 {
572 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
573 if (p == (const PixelPacket *) NULL)
574 break;
575 indexes=GetVirtualIndexQueue(image);
576 for (x=0; x < (long) image->columns; x++)
577 {
578 if (p->opacity == (Quantum) TransparentOpacity)
579 break;
580 p++;
581 }
582 if (x < (long) image->columns)
583 break;
584 }
585 if ((x < (long) image->columns) || (y < (long) image->rows))
586 {
587 char
588 tuple[MaxTextExtent];
589
590 MagickPixelPacket
591 pixel;
592
593 GetMagickPixelPacket(image,&pixel);
594 SetMagickPixelPacket(image,p,indexes+x,&pixel);
595 (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
596 &image->exception);
597 (void) fprintf(file," Alpha: %s ",tuple);
598 GetColorTuple(&pixel,MagickTrue,tuple);
599 (void) fprintf(file," %s\n",tuple);
600 }
601 }
cristy549a37e2010-01-26 15:24:15 +0000602 artifact=GetImageArtifact(image,"identify:unique");
603 if ((artifact != (const char *) NULL) &&
604 (IsMagickTrue(artifact) != MagickFalse))
605 (void) fprintf(file," Colors: %lu\n",GetNumberColors(image,
606 (FILE *) NULL,&image->exception));
607 if (IsHistogramImage(image,&image->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000608 {
cristy549a37e2010-01-26 15:24:15 +0000609 (void) fprintf(file," Histogram:\n");
610 (void) GetNumberColors(image,file,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +0000611 }
612 }
613 if (image->storage_class == PseudoClass)
614 {
615 (void) fprintf(file," Colormap: %lu\n",image->colors);
616 if (image->colors <= 1024)
617 {
618 char
619 color[MaxTextExtent],
620 hex[MaxTextExtent],
621 tuple[MaxTextExtent];
622
623 MagickPixelPacket
624 pixel;
625
626 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000627 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000628
629 GetMagickPixelPacket(image,&pixel);
630 p=image->colormap;
631 for (i=0; i < (long) image->colors; i++)
632 {
633 SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
634 (void) CopyMagickString(tuple,"(",MaxTextExtent);
635 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
636 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
637 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
638 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
639 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
640 if (pixel.colorspace == CMYKColorspace)
641 {
642 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
643 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
644 tuple);
645 }
646 if (pixel.matte != MagickFalse)
647 {
648 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
649 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,
650 tuple);
651 }
652 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
653 (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
654 &image->exception);
655 GetColorTuple(&pixel,MagickTrue,hex);
656 (void) fprintf(file," %8ld: %s %s %s\n",i,tuple,hex,color);
657 p++;
658 }
659 }
660 }
661 if (image->error.mean_error_per_pixel != 0.0)
cristye7f51092010-01-17 00:39:37 +0000662 (void) fprintf(file," Mean error per pixel: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000663 image->error.mean_error_per_pixel);
664 if (image->error.normalized_mean_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000665 (void) fprintf(file," Normalized mean error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000666 image->error.normalized_mean_error);
667 if (image->error.normalized_maximum_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000668 (void) fprintf(file," Normalized maximum error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000669 image->error.normalized_maximum_error);
670 (void) fprintf(file," Rendering intent: %s\n",MagickOptionToMnemonic(
671 MagickIntentOptions,(long) image->rendering_intent));
672 if (image->gamma != 0.0)
cristye7f51092010-01-17 00:39:37 +0000673 (void) fprintf(file," Gamma: %g\n",image->gamma);
cristy3ed852e2009-09-05 21:47:34 +0000674 if ((image->chromaticity.red_primary.x != 0.0) ||
675 (image->chromaticity.green_primary.x != 0.0) ||
676 (image->chromaticity.blue_primary.x != 0.0) ||
677 (image->chromaticity.white_point.x != 0.0))
678 {
679 /*
680 Display image chromaticity.
681 */
682 (void) fprintf(file," Chromaticity:\n");
cristye7f51092010-01-17 00:39:37 +0000683 (void) fprintf(file," red primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000684 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
cristye7f51092010-01-17 00:39:37 +0000685 (void) fprintf(file," green primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000686 image->chromaticity.green_primary.x,
687 image->chromaticity.green_primary.y);
cristye7f51092010-01-17 00:39:37 +0000688 (void) fprintf(file," blue primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000689 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
cristye7f51092010-01-17 00:39:37 +0000690 (void) fprintf(file," white point: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000691 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
692 }
693 if ((image->extract_info.width*image->extract_info.height) != 0)
694 (void) fprintf(file," Tile geometry: %lux%lu%+ld%+ld\n",
695 image->extract_info.width,image->extract_info.height,
696 image->extract_info.x,image->extract_info.y);
697 (void) fprintf(file," Interlace: %s\n",MagickOptionToMnemonic(
698 MagickInterlaceOptions,(long) image->interlace));
699 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
700 &image->exception);
701 (void) fprintf(file," Background color: %s\n",color);
702 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
703 &image->exception);
704 (void) fprintf(file," Border color: %s\n",color);
705 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
706 &image->exception);
707 (void) fprintf(file," Matte color: %s\n",color);
708 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
709 &image->exception);
710 (void) fprintf(file," Transparent color: %s\n",color);
cristy11a77682009-10-11 21:50:20 +0000711 (void) fprintf(file," Compose: %s\n",MagickOptionToMnemonic(
712 MagickComposeOptions,(long) image->compose));
cristy3ed852e2009-09-05 21:47:34 +0000713 if ((image->page.width != 0) || (image->page.height != 0) ||
714 (image->page.x != 0) || (image->page.y != 0))
715 (void) fprintf(file," Page geometry: %lux%lu%+ld%+ld\n",image->page.width,
716 image->page.height,image->page.x,image->page.y);
717 if ((image->page.x != 0) || (image->page.y != 0))
718 (void) fprintf(file," Origin geometry: %+ld%+ld\n",image->page.x,
719 image->page.y);
720 (void) fprintf(file," Dispose: %s\n",MagickOptionToMnemonic(
721 MagickDisposeOptions,(long) image->dispose));
722 if (image->delay != 0)
723 (void) fprintf(file," Delay: %lux%ld\n",image->delay,
724 image->ticks_per_second);
725 if (image->iterations != 1)
726 (void) fprintf(file," Iterations: %lu\n",image->iterations);
727 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
728 (void) fprintf(file," Scene: %lu of %lu\n",image->scene,
729 GetImageListLength(image));
730 else
731 if (image->scene != 0)
732 (void) fprintf(file," Scene: %lu\n",image->scene);
733 (void) fprintf(file," Compression: %s\n",MagickOptionToMnemonic(
734 MagickCompressOptions,(long) image->compression));
735 if (image->quality != UndefinedCompressionQuality)
736 (void) fprintf(file," Quality: %lu\n",image->quality);
737 (void) fprintf(file," Orientation: %s\n",MagickOptionToMnemonic(
738 MagickOrientationOptions,(long) image->orientation));
739 if (image->montage != (char *) NULL)
740 (void) fprintf(file," Montage: %s\n",image->montage);
741 if (image->directory != (char *) NULL)
742 {
743 Image
744 *tile;
745
746 ImageInfo
747 *image_info;
748
749 register char
750 *p,
751 *q;
752
753 WarningHandler
754 handler;
755
756 /*
757 Display visual image directory.
758 */
759 image_info=AcquireImageInfo();
760 (void) CloneString(&image_info->size,"64x64");
761 (void) fprintf(file," Directory:\n");
762 for (p=image->directory; *p != '\0'; p++)
763 {
764 q=p;
765 while ((*q != '\n') && (*q != '\0'))
766 q++;
767 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
768 p=q;
769 (void) fprintf(file," %s",image_info->filename);
770 handler=SetWarningHandler((WarningHandler) NULL);
771 tile=ReadImage(image_info,&image->exception);
772 (void) SetWarningHandler(handler);
773 if (tile == (Image *) NULL)
774 {
775 (void) fprintf(file,"\n");
776 continue;
777 }
778 (void) fprintf(file," %lux%lu %s\n",tile->magick_columns,
779 tile->magick_rows,tile->magick);
780 (void) SignatureImage(tile);
781 ResetImagePropertyIterator(tile);
782 property=GetNextImageProperty(tile);
783 while (property != (const char *) NULL)
784 {
785 (void) fprintf(file," %s:\n",property);
786 value=GetImageProperty(tile,property);
787 if (value != (const char *) NULL)
788 (void) fprintf(file,"%s\n",value);
789 property=GetNextImageProperty(tile);
790 }
791 tile=DestroyImage(tile);
792 }
793 image_info=DestroyImageInfo(image_info);
794 }
795 (void) GetImageProperty(image,"exif:*");
796 ResetImagePropertyIterator(image);
797 property=GetNextImageProperty(image);
798 if (property != (const char *) NULL)
799 {
800 /*
801 Display image properties.
802 */
803 (void) fprintf(file," Properties:\n");
804 while (property != (const char *) NULL)
805 {
806 (void) fprintf(file," %c",*property);
807 if (strlen(property) > 1)
808 (void) fprintf(file,"%s: ",property+1);
809 if (strlen(property) > 80)
810 (void) fputc('\n',file);
811 value=GetImageProperty(image,property);
812 if (value != (const char *) NULL)
813 (void) fprintf(file,"%s\n",value);
814 property=GetNextImageProperty(image);
815 }
816 }
817 (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
818 value=GetImageProperty(image,key);
819 if (value != (const char *) NULL)
820 {
821 /*
822 Display clipping path.
823 */
824 (void) fprintf(file," Clipping path: ");
825 if (strlen(value) > 80)
826 (void) fputc('\n',file);
827 (void) fprintf(file,"%s\n",value);
828 }
829 ResetImageProfileIterator(image);
830 name=GetNextImageProfile(image);
831 if (name != (char *) NULL)
832 {
833 const StringInfo
834 *profile;
835
836 /*
837 Identify image profiles.
838 */
839 (void) fprintf(file," Profiles:\n");
840 while (name != (char *) NULL)
841 {
842 profile=GetImageProfile(image,name);
843 if (profile == (StringInfo *) NULL)
844 continue;
845 (void) fprintf(file," Profile-%s: %lu bytes\n",name,(unsigned long)
846 GetStringInfoLength(profile));
847#if defined(MAGICKCORE_LCMS_DELEGATE)
848 if ((LocaleCompare(name,"icc") == 0) ||
849 (LocaleCompare(name,"icm") == 0))
850 {
851 cmsHPROFILE
852 icc_profile;
853
854 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
855 (DWORD) GetStringInfoLength(profile));
856 if (icc_profile != (cmsHPROFILE *) NULL)
857 {
858 const char
859 *name;
860
861 name=cmsTakeProductName(icc_profile);
862 if (name != (const char *) NULL)
863 (void) fprintf(file," %s\n",name);
864 (void) cmsCloseProfile(icc_profile);
865 }
866 }
867#endif
868 if (LocaleCompare(name,"iptc") == 0)
869 {
870 char
871 *attribute,
872 **attribute_list;
873
874 const char
875 *tag;
876
877 long
878 dataset,
879 record,
880 sentinel;
881
882 register long
883 j;
884
885 size_t
886 length,
887 profile_length;
888
889 profile_length=GetStringInfoLength(profile);
890 for (i=0; i < (long) profile_length; i+=(long) length)
891 {
892 length=1;
893 sentinel=GetStringInfoDatum(profile)[i++];
894 if (sentinel != 0x1c)
895 continue;
896 dataset=GetStringInfoDatum(profile)[i++];
897 record=GetStringInfoDatum(profile)[i++];
898 switch (record)
899 {
900 case 5: tag="Image Name"; break;
901 case 7: tag="Edit Status"; break;
902 case 10: tag="Priority"; break;
903 case 15: tag="Category"; break;
904 case 20: tag="Supplemental Category"; break;
905 case 22: tag="Fixture Identifier"; break;
906 case 25: tag="Keyword"; break;
907 case 30: tag="Release Date"; break;
908 case 35: tag="Release Time"; break;
909 case 40: tag="Special Instructions"; break;
910 case 45: tag="Reference Service"; break;
911 case 47: tag="Reference Date"; break;
912 case 50: tag="Reference Number"; break;
913 case 55: tag="Created Date"; break;
914 case 60: tag="Created Time"; break;
915 case 65: tag="Originating Program"; break;
916 case 70: tag="Program Version"; break;
917 case 75: tag="Object Cycle"; break;
918 case 80: tag="Byline"; break;
919 case 85: tag="Byline Title"; break;
920 case 90: tag="City"; break;
921 case 95: tag="Province State"; break;
922 case 100: tag="Country Code"; break;
923 case 101: tag="Country"; break;
924 case 103: tag="Original Transmission Reference"; break;
925 case 105: tag="Headline"; break;
926 case 110: tag="Credit"; break;
927 case 115: tag="Src"; break;
928 case 116: tag="Copyright String"; break;
929 case 120: tag="Caption"; break;
930 case 121: tag="Local Caption"; break;
931 case 122: tag="Caption Writer"; break;
932 case 200: tag="Custom Field 1"; break;
933 case 201: tag="Custom Field 2"; break;
934 case 202: tag="Custom Field 3"; break;
935 case 203: tag="Custom Field 4"; break;
936 case 204: tag="Custom Field 5"; break;
937 case 205: tag="Custom Field 6"; break;
938 case 206: tag="Custom Field 7"; break;
939 case 207: tag="Custom Field 8"; break;
940 case 208: tag="Custom Field 9"; break;
941 case 209: tag="Custom Field 10"; break;
942 case 210: tag="Custom Field 11"; break;
943 case 211: tag="Custom Field 12"; break;
944 case 212: tag="Custom Field 13"; break;
945 case 213: tag="Custom Field 14"; break;
946 case 214: tag="Custom Field 15"; break;
947 case 215: tag="Custom Field 16"; break;
948 case 216: tag="Custom Field 17"; break;
949 case 217: tag="Custom Field 18"; break;
950 case 218: tag="Custom Field 19"; break;
951 case 219: tag="Custom Field 20"; break;
952 default: tag="unknown"; break;
953 }
954 (void) fprintf(file," %s[%ld,%ld]: ",tag,dataset,record);
955 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
956 length|=GetStringInfoDatum(profile)[i++];
957 attribute=(char *) NULL;
958 if (~length >= MaxTextExtent)
959 attribute=(char *) AcquireQuantumMemory(length+
960 MaxTextExtent,sizeof(*attribute));
961 if (attribute != (char *) NULL)
962 {
963 (void) CopyMagickString(attribute,(char *)
964 GetStringInfoDatum(profile)+i,length+1);
965 attribute_list=StringToList(attribute);
966 if (attribute_list != (char **) NULL)
967 {
968 for (j=0; attribute_list[j] != (char *) NULL; j++)
969 {
970 (void) fputs(attribute_list[j],file);
971 (void) fputs("\n",file);
972 attribute_list[j]=(char *) RelinquishMagickMemory(
973 attribute_list[j]);
974 }
975 attribute_list=(char **) RelinquishMagickMemory(
976 attribute_list);
977 }
978 attribute=DestroyString(attribute);
979 }
980 }
981 }
982 if (image->debug != MagickFalse)
983 PrintStringInfo(file,name,profile);
984 name=GetNextImageProfile(image);
985 }
986 }
987 ResetImageArtifactIterator(image);
988 artifact=GetNextImageArtifact(image);
989 if (artifact != (const char *) NULL)
990 {
991 /*
992 Display image artifacts.
993 */
994 (void) fprintf(file," Artifacts:\n");
995 while (artifact != (const char *) NULL)
996 {
997 (void) fprintf(file," %c",*artifact);
998 if (strlen(artifact) > 1)
999 (void) fprintf(file,"%s: ",artifact+1);
1000 if (strlen(artifact) > 80)
1001 (void) fputc('\n',file);
1002 value=GetImageArtifact(image,artifact);
1003 if (value != (const char *) NULL)
1004 (void) fprintf(file,"%s\n",value);
1005 artifact=GetNextImageArtifact(image);
1006 }
1007 }
1008 ResetImageRegistryIterator();
1009 registry=GetNextImageRegistry();
1010 if (registry != (const char *) NULL)
1011 {
1012 /*
1013 Display image registry.
1014 */
1015 (void) fprintf(file," Registry:\n");
1016 while (registry != (const char *) NULL)
1017 {
1018 (void) fprintf(file," %c",*registry);
1019 if (strlen(registry) > 1)
1020 (void) fprintf(file,"%s: ",registry+1);
1021 if (strlen(registry) > 80)
1022 (void) fputc('\n',file);
1023 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1024 &image->exception);
1025 if (value != (const char *) NULL)
1026 (void) fprintf(file,"%s\n",value);
1027 registry=GetNextImageRegistry();
1028 }
1029 }
1030 (void) fprintf(file," Tainted: %s\n",MagickOptionToMnemonic(
1031 MagickBooleanOptions,(long) image->taint));
cristyb9080c92009-12-01 20:13:26 +00001032 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001033 (void) fprintf(file," Filesize: %s\n",format);
cristyb9080c92009-12-01 20:13:26 +00001034 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1035 MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001036 (void) fprintf(file," Number pixels: %s\n",format);
cristy3d231692009-09-29 01:05:22 +00001037 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristyb9080c92009-12-01 20:13:26 +00001038 elapsed_time+0.5),MagickFalse,format);
cristy3d231692009-09-29 01:05:22 +00001039 (void) fprintf(file," Pixels per second: %s\n",format);
1040 (void) fprintf(file," User time: %0.3fu\n",user_time);
1041 (void) fprintf(file," Elapsed time: %ld:%02ld.%03ld\n",(long)
1042 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),(long)
1043 (1000.0*(elapsed_time-floor(elapsed_time))));
1044 (void) fprintf(file," Version: %s\n",GetMagickVersion((unsigned long *)
1045 NULL));
cristy3ed852e2009-09-05 21:47:34 +00001046 (void) fflush(file);
1047 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1048}