blob: 1dbf9fbc3fdd9cbaf2039fc53c4c4fe404dc7968 [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,
cristye1897792010-01-29 02:05:50 +0000135 const char *name,const ChannelFeatures *channel_features)
cristy3ed852e2009-09-05 21:47:34 +0000136{
cristye1897792010-01-29 02:05:50 +0000137#define PrintFeature(feature) \
138 GetMagickPrecision(),(feature)[0], \
139 GetMagickPrecision(),(feature)[1], \
140 GetMagickPrecision(),(feature)[2], \
141 GetMagickPrecision(),(feature)[3]
142
cristybd822072010-01-27 00:30:00 +0000143#define FeaturesFormat " %s:\n" \
cristycdf8e1b2010-01-28 01:52:33 +0000144 " Angular Second Moment:\n" \
cristye1897792010-01-29 02:05:50 +0000145 " %.*g, %.*g, %.*g, %.*g\n" \
cristycdf8e1b2010-01-28 01:52:33 +0000146 " Contrast:\n" \
cristye1897792010-01-29 02:05:50 +0000147 " %.*g, %.*g, %.*g, %.*g\n" \
cristycdf8e1b2010-01-28 01:52:33 +0000148 " Correlation:\n" \
cristye1897792010-01-29 02:05:50 +0000149 " %.*g, %.*g, %.*g, %.*g\n" \
150 " Sum of Squares: Variance:\n" \
151 " %.*g, %.*g, %.*g, %.*g\n" \
cristycf5e6492010-01-28 02:45:28 +0000152 " Inverse Difference Moment:\n" \
cristye1897792010-01-29 02:05:50 +0000153 " %.*g, %.*g, %.*g, %.*g\n" \
154 " Sum Average:\n" \
155 " %.*g, %.*g, %.*g, %.*g\n" \
156 " Sum Variance:\n" \
157 " %.*g, %.*g, %.*g, %.*g\n" \
158 " Sum Entropy:\n" \
159 " %.*g, %.*g, %.*g, %.*g\n" \
160 " Entropy:\n" \
161 " %.*g, %.*g, %.*g, %.*g\n" \
162 " Difference Variance:\n" \
163 " %.*g, %.*g, %.*g, %.*g\n"
cristybd822072010-01-27 00:30:00 +0000164
165 int
166 status;
167
168 status=fprintf(file,FeaturesFormat,name,
cristye1897792010-01-29 02:05:50 +0000169 PrintFeature(channel_features[channel].angular_second_moment),
170 PrintFeature(channel_features[channel].contrast),
171 PrintFeature(channel_features[channel].correlation),
172 PrintFeature(channel_features[channel].variance_sum_of_squares),
173 PrintFeature(channel_features[channel].inverse_difference_moment),
174 PrintFeature(channel_features[channel].sum_average),
175 PrintFeature(channel_features[channel].sum_variance),
176 PrintFeature(channel_features[channel].sum_entropy),
177 PrintFeature(channel_features[channel].entropy),
178 PrintFeature(channel_features[channel].difference_variance));
cristybd822072010-01-27 00:30:00 +0000179 return(status);
180}
181
182static int PrintChannelStatistics(FILE *file,const ChannelType channel,
183 const char *name,const double scale,
184 const ChannelStatistics *channel_statistics)
185{
186#define StatisticsFormat " %s:\n min: " QuantumFormat \
cristye7f51092010-01-17 00:39:37 +0000187 " (%g)\n max: " QuantumFormat " (%g)\n" \
188 " mean: %g (%g)\n standard deviation: %g (%g)\n" \
189 " kurtosis: %g\n skewness: %g\n"
cristy3ed852e2009-09-05 21:47:34 +0000190
cristybd822072010-01-27 00:30:00 +0000191 double
192 maxima,
193 mean,
194 minima;
195
196 int
197 status;
198
199 minima=channel_statistics[channel].minima;
200 maxima=channel_statistics[channel].maxima;
201 mean=channel_statistics[channel].mean;
202 if (channel == AlphaChannel)
203 {
204 minima=QuantumRange-minima;
205 maxima=QuantumRange-maxima;
206 mean=QuantumRange-mean;
207 }
208 status=fprintf(file,StatisticsFormat,name,(Quantum) (scale*minima),minima/
209 (double) QuantumRange,(Quantum) (maxima/scale),maxima/(double) QuantumRange,
210 scale*mean,mean/(double) QuantumRange,
211 scale*channel_statistics[channel].standard_deviation,
212 channel_statistics[channel].standard_deviation/(double)
213 QuantumRange,channel_statistics[channel].kurtosis,
214 channel_statistics[channel].skewness);
215 return(status);
216}
217
218MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
219 const MagickBooleanType verbose)
220{
cristy3ed852e2009-09-05 21:47:34 +0000221 char
222 color[MaxTextExtent],
223 format[MaxTextExtent],
224 key[MaxTextExtent];
225
cristybd822072010-01-27 00:30:00 +0000226 ChannelFeatures
227 *channel_features;
228
229 ChannelStatistics
230 *channel_statistics;
231
cristy3ed852e2009-09-05 21:47:34 +0000232 ColorspaceType
233 colorspace;
234
235 const char
236 *artifact,
237 *name,
238 *property,
239 *registry,
240 *value;
241
242 const MagickInfo
243 *magick_info;
244
245 const PixelPacket
246 *pixels;
247
248 double
249 elapsed_time,
250 user_time;
251
252 ExceptionInfo
253 *exception;
254
255 ImageType
256 type;
257
258 long
259 y;
260
261 MagickBooleanType
262 ping;
263
264 register long
265 i,
266 x;
267
268 unsigned long
cristybd822072010-01-27 00:30:00 +0000269 distance,
cristy3ed852e2009-09-05 21:47:34 +0000270 scale;
271
272 assert(image != (Image *) NULL);
273 assert(image->signature == MagickSignature);
274 if (image->debug != MagickFalse)
275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
276 if (file == (FILE *) NULL)
277 file=stdout;
278 *format='\0';
279 elapsed_time=GetElapsedTime(&image->timer);
280 user_time=GetUserTime(&image->timer);
281 GetTimerInfo(&image->timer);
282 if (verbose == MagickFalse)
283 {
284 /*
285 Display summary info about the image.
286 */
287 if (*image->magick_filename != '\0')
288 if (LocaleCompare(image->magick_filename,image->filename) != 0)
289 (void) fprintf(file,"%s=>",image->magick_filename);
290 if ((GetPreviousImageInList(image) == (Image *) NULL) &&
291 (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0))
292 (void) fprintf(file,"%s ",image->filename);
293 else
294 (void) fprintf(file,"%s[%lu] ",image->filename,image->scene);
295 (void) fprintf(file,"%s ",image->magick);
296 if ((image->magick_columns != 0) || (image->magick_rows != 0))
297 if ((image->magick_columns != image->columns) ||
298 (image->magick_rows != image->rows))
299 (void) fprintf(file,"%lux%lu=>",image->magick_columns,
300 image->magick_rows);
301 (void) fprintf(file,"%lux%lu ",image->columns,image->rows);
302 if ((image->page.width != 0) || (image->page.height != 0) ||
303 (image->page.x != 0) || (image->page.y != 0))
304 (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width,
305 image->page.height,image->page.x,image->page.y);
306 (void) fprintf(file,"%lu-bit ",image->depth);
307 if (image->type != UndefinedType)
308 (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
309 (long) image->type));
310 if (image->storage_class == DirectClass)
311 {
312 (void) fprintf(file,"DirectClass ");
313 if (image->total_colors != 0)
314 {
cristyb9080c92009-12-01 20:13:26 +0000315 (void) FormatMagickSize(image->total_colors,MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000316 (void) fprintf(file,"%s ",format);
317 }
318 }
319 else
320 if (image->total_colors <= image->colors)
321 (void) fprintf(file,"PseudoClass %luc ",image->colors);
322 else
323 (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors,
324 image->colors);
325 if (image->error.mean_error_per_pixel != 0.0)
326 (void) fprintf(file,"%ld/%f/%fdb ",(long)
327 (image->error.mean_error_per_pixel+0.5),
328 image->error.normalized_mean_error,
329 image->error.normalized_maximum_error);
330 if (GetBlobSize(image) != 0)
331 {
cristyb9080c92009-12-01 20:13:26 +0000332 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000333 (void) fprintf(file,"%s ",format);
334 }
cristy3d231692009-09-29 01:05:22 +0000335 (void) fprintf(file,"%0.3fu %ld:%02ld.%03ld",user_time,(long)
336 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
337 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy3ed852e2009-09-05 21:47:34 +0000338 (void) fprintf(file,"\n");
339 (void) fflush(file);
340 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
341 }
342 /*
343 Display verbose info about the image.
344 */
345 exception=AcquireExceptionInfo();
346 pixels=GetVirtualPixels(image,0,0,1,1,exception);
347 exception=DestroyExceptionInfo(exception);
348 ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
349 type=GetImageType(image,&image->exception);
350 (void) SignatureImage(image);
351 (void) fprintf(file,"Image: %s\n",image->filename);
352 if (*image->magick_filename != '\0')
353 if (LocaleCompare(image->magick_filename,image->filename) != 0)
354 {
355 char
356 filename[MaxTextExtent];
357
358 GetPathComponent(image->magick_filename,TailPath,filename);
359 (void) fprintf(file," Base filename: %s\n",filename);
360 }
361 magick_info=GetMagickInfo(image->magick,&image->exception);
362 if ((magick_info == (const MagickInfo *) NULL) ||
363 (*GetMagickDescription(magick_info) == '\0'))
364 (void) fprintf(file," Format: %s\n",image->magick);
365 else
366 (void) fprintf(file," Format: %s (%s)\n",image->magick,
367 GetMagickDescription(magick_info));
368 (void) fprintf(file," Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
369 (long) image->storage_class));
370 (void) fprintf(file," Geometry: %lux%lu%+ld%+ld\n",image->columns,
371 image->rows,image->tile_offset.x,image->tile_offset.y);
372 if ((image->magick_columns != 0) || (image->magick_rows != 0))
373 if ((image->magick_columns != image->columns) ||
374 (image->magick_rows != image->rows))
375 (void) fprintf(file," Base geometry: %lux%lu\n",image->magick_columns,
376 image->magick_rows);
377 if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
378 {
cristye7f51092010-01-17 00:39:37 +0000379 (void) fprintf(file," Resolution: %gx%g\n",image->x_resolution,
cristy3ed852e2009-09-05 21:47:34 +0000380 image->y_resolution);
cristye7f51092010-01-17 00:39:37 +0000381 (void) fprintf(file," Print size: %gx%g\n",(double) image->columns/
cristy3ed852e2009-09-05 21:47:34 +0000382 image->x_resolution,(double) image->rows/image->y_resolution);
383 }
384 (void) fprintf(file," Units: %s\n",MagickOptionToMnemonic(
385 MagickResolutionOptions,(long) image->units));
386 (void) fprintf(file," Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
387 (long) type));
388 if (image->type != UndefinedType)
389 (void) fprintf(file," Base type: %s\n",MagickOptionToMnemonic(
390 MagickTypeOptions,(long) image->type));
391 (void) fprintf(file," Endianess: %s\n",MagickOptionToMnemonic(
392 MagickEndianOptions,(long) image->endian));
393 /*
394 Detail channel depth and extrema.
395 */
396 (void) fprintf(file," Colorspace: %s\n",MagickOptionToMnemonic(
397 MagickColorspaceOptions,(long) image->colorspace));
cristybd822072010-01-27 00:30:00 +0000398 channel_statistics=(ChannelStatistics *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000399 if (ping == MagickFalse)
cristybd822072010-01-27 00:30:00 +0000400 channel_statistics=GetImageChannelStatistics(image,&image->exception);
401 if (channel_statistics != (ChannelStatistics *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000402 {
cristy3ed852e2009-09-05 21:47:34 +0000403 unsigned long
404 depth;
405
406 depth=GetImageDepth(image,&image->exception);
407 if (image->depth == depth)
408 (void) fprintf(file," Depth: %lu-bit\n",image->depth);
409 else
410 (void) fprintf(file," Depth: %lu/%lu-bit\n",image->depth,depth);
cristy3ed852e2009-09-05 21:47:34 +0000411 (void) fprintf(file," Channel depth:\n");
412 colorspace=image->colorspace;
413 if (IsGrayImage(image,&image->exception) != MagickFalse)
414 colorspace=GRAYColorspace;
415 switch (colorspace)
416 {
417 case RGBColorspace:
418 default:
419 {
420 (void) fprintf(file," red: %lu-bit\n",
421 channel_statistics[RedChannel].depth);
422 (void) fprintf(file," green: %lu-bit\n",
423 channel_statistics[GreenChannel].depth);
424 (void) fprintf(file," blue: %lu-bit\n",
425 channel_statistics[BlueChannel].depth);
426 if (image->matte != MagickFalse)
427 (void) fprintf(file," alpha: %lu-bit\n",
428 channel_statistics[OpacityChannel].depth);
429 break;
430 }
431 case CMYKColorspace:
432 {
433 (void) fprintf(file," cyan: %lu-bit\n",
434 channel_statistics[CyanChannel].depth);
435 (void) fprintf(file," magenta: %lu-bit\n",
436 channel_statistics[MagentaChannel].depth);
437 (void) fprintf(file," yellow: %lu-bit\n",
438 channel_statistics[YellowChannel].depth);
439 (void) fprintf(file," black: %lu-bit\n",
440 channel_statistics[BlackChannel].depth);
441 if (image->matte != MagickFalse)
442 (void) fprintf(file," alpha: %lu-bit\n",
443 channel_statistics[OpacityChannel].depth);
444 break;
445 }
446 case GRAYColorspace:
447 {
448 (void) fprintf(file," gray: %lu-bit\n",
449 channel_statistics[GrayChannel].depth);
450 if (image->matte != MagickFalse)
451 (void) fprintf(file," alpha: %lu-bit\n",
452 channel_statistics[OpacityChannel].depth);
453 break;
454 }
455 }
456 scale=1;
457 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
458 scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long)
459 MAGICKCORE_QUANTUM_DEPTH-image->depth));
460 (void) fprintf(file," Channel statistics:\n");
461 switch (colorspace)
462 {
463 case RGBColorspace:
464 default:
465 {
cristybd822072010-01-27 00:30:00 +0000466 (void) PrintChannelStatistics(file,RedChannel,"Red",1.0/scale,
467 channel_statistics);
468 (void) PrintChannelStatistics(file,GreenChannel,"Green",1.0/scale,
469 channel_statistics);
470 (void) PrintChannelStatistics(file,BlueChannel,"Blue",1.0/scale,
471 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000472 break;
473 }
474 case CMYKColorspace:
475 {
cristybd822072010-01-27 00:30:00 +0000476 (void) PrintChannelStatistics(file,CyanChannel,"Cyan",1.0/scale,
477 channel_statistics);
478 (void) PrintChannelStatistics(file,MagentaChannel,"Magenta",1.0/scale,
479 channel_statistics);
480 (void) PrintChannelStatistics(file,YellowChannel,"Yellow",1.0/scale,
481 channel_statistics);
482 (void) PrintChannelStatistics(file,BlackChannel,"Black",1.0/scale,
483 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000484 break;
485 }
486 case GRAYColorspace:
487 {
cristybd822072010-01-27 00:30:00 +0000488 (void) PrintChannelStatistics(file,GrayChannel,"Gray",1.0/scale,
489 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000490 break;
491 }
492 }
493 if (image->matte != MagickFalse)
cristybd822072010-01-27 00:30:00 +0000494 (void) PrintChannelStatistics(file,AlphaChannel,"Alpha",1.0/scale,
495 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000496 if (colorspace != GRAYColorspace)
497 {
498 (void) fprintf(file," Image statistics:\n");
cristybd822072010-01-27 00:30:00 +0000499 (void) PrintChannelStatistics(file,AllChannels,"Overall",1.0/scale,
500 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000501 }
502 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
503 channel_statistics);
cristybd822072010-01-27 00:30:00 +0000504 }
505 channel_features=(ChannelFeatures *) NULL;
506 artifact=GetImageArtifact(image,"identify:features");
cristybd822072010-01-27 00:30:00 +0000507 if ((ping == MagickFalse) && (artifact != (const char *) NULL))
cristy8c02fa12010-01-27 01:10:17 +0000508 {
509 distance=StringToUnsignedLong(artifact);
510 channel_features=GetImageChannelFeatures(image,distance,
511 &image->exception);
512 }
cristybd822072010-01-27 00:30:00 +0000513 if (channel_features != (ChannelFeatures *) NULL)
514 {
cristy7396d882010-01-27 02:37:56 +0000515 (void) fprintf(file," Channel features (horizontal, vertical, left and right diagonals):\n");
cristybd822072010-01-27 00:30:00 +0000516 switch (colorspace)
517 {
518 case RGBColorspace:
519 default:
cristy549a37e2010-01-26 15:24:15 +0000520 {
cristye1897792010-01-29 02:05:50 +0000521 (void) PrintChannelFeatures(file,RedChannel,"Red",channel_features);
522 (void) PrintChannelFeatures(file,GreenChannel,"Green",
cristybd822072010-01-27 00:30:00 +0000523 channel_features);
cristye1897792010-01-29 02:05:50 +0000524 (void) PrintChannelFeatures(file,BlueChannel,"Blue",channel_features);
cristybd822072010-01-27 00:30:00 +0000525 break;
526 }
527 case CMYKColorspace:
528 {
cristye1897792010-01-29 02:05:50 +0000529 (void) PrintChannelFeatures(file,CyanChannel,"Cyan",channel_features);
530 (void) PrintChannelFeatures(file,MagentaChannel,"Magenta",
cristybd822072010-01-27 00:30:00 +0000531 channel_features);
cristye1897792010-01-29 02:05:50 +0000532 (void) PrintChannelFeatures(file,YellowChannel,"Yellow",
cristybd822072010-01-27 00:30:00 +0000533 channel_features);
cristye1897792010-01-29 02:05:50 +0000534 (void) PrintChannelFeatures(file,BlackChannel,"Black",
cristybd822072010-01-27 00:30:00 +0000535 channel_features);
536 break;
537 }
538 case GRAYColorspace:
539 {
cristye1897792010-01-29 02:05:50 +0000540 (void) PrintChannelFeatures(file,GrayChannel,"Gray",channel_features);
cristybd822072010-01-27 00:30:00 +0000541 break;
542 }
543 }
544 if (image->matte != MagickFalse)
cristye1897792010-01-29 02:05:50 +0000545 (void) PrintChannelFeatures(file,AlphaChannel,"Alpha",channel_features);
cristybd822072010-01-27 00:30:00 +0000546 if (colorspace != GRAYColorspace)
547 {
548 (void) fprintf(file," Image features:\n");
cristye1897792010-01-29 02:05:50 +0000549 (void) PrintChannelFeatures(file,AllChannels,"Overall",
cristy549a37e2010-01-26 15:24:15 +0000550 channel_features);
551 }
cristybd822072010-01-27 00:30:00 +0000552 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
553 channel_features);
554 }
555 if (ping == MagickFalse)
556 {
cristy3ed852e2009-09-05 21:47:34 +0000557 if (image->colorspace == CMYKColorspace)
558 (void) fprintf(file," Total ink density: %.0f%%\n",100.0*
559 GetImageTotalInkDensity(image)/(double) QuantumRange);
560 x=0;
561 if (image->matte != MagickFalse)
562 {
563 register const IndexPacket
564 *indexes;
565
566 register const PixelPacket
567 *p;
568
569 p=(PixelPacket *) NULL;
570 indexes=(IndexPacket *) NULL;
571 for (y=0; y < (long) image->rows; y++)
572 {
573 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
574 if (p == (const PixelPacket *) NULL)
575 break;
576 indexes=GetVirtualIndexQueue(image);
577 for (x=0; x < (long) image->columns; x++)
578 {
579 if (p->opacity == (Quantum) TransparentOpacity)
580 break;
581 p++;
582 }
583 if (x < (long) image->columns)
584 break;
585 }
586 if ((x < (long) image->columns) || (y < (long) image->rows))
587 {
588 char
589 tuple[MaxTextExtent];
590
591 MagickPixelPacket
592 pixel;
593
594 GetMagickPixelPacket(image,&pixel);
595 SetMagickPixelPacket(image,p,indexes+x,&pixel);
596 (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
597 &image->exception);
598 (void) fprintf(file," Alpha: %s ",tuple);
599 GetColorTuple(&pixel,MagickTrue,tuple);
600 (void) fprintf(file," %s\n",tuple);
601 }
602 }
cristy549a37e2010-01-26 15:24:15 +0000603 artifact=GetImageArtifact(image,"identify:unique");
604 if ((artifact != (const char *) NULL) &&
605 (IsMagickTrue(artifact) != MagickFalse))
606 (void) fprintf(file," Colors: %lu\n",GetNumberColors(image,
607 (FILE *) NULL,&image->exception));
608 if (IsHistogramImage(image,&image->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000609 {
cristy549a37e2010-01-26 15:24:15 +0000610 (void) fprintf(file," Histogram:\n");
611 (void) GetNumberColors(image,file,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +0000612 }
613 }
614 if (image->storage_class == PseudoClass)
615 {
616 (void) fprintf(file," Colormap: %lu\n",image->colors);
617 if (image->colors <= 1024)
618 {
619 char
620 color[MaxTextExtent],
621 hex[MaxTextExtent],
622 tuple[MaxTextExtent];
623
624 MagickPixelPacket
625 pixel;
626
627 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000628 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000629
630 GetMagickPixelPacket(image,&pixel);
631 p=image->colormap;
632 for (i=0; i < (long) image->colors; i++)
633 {
634 SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
635 (void) CopyMagickString(tuple,"(",MaxTextExtent);
636 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
637 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
638 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
639 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
640 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
641 if (pixel.colorspace == CMYKColorspace)
642 {
643 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
644 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
645 tuple);
646 }
647 if (pixel.matte != MagickFalse)
648 {
649 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
650 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,
651 tuple);
652 }
653 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
654 (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
655 &image->exception);
656 GetColorTuple(&pixel,MagickTrue,hex);
657 (void) fprintf(file," %8ld: %s %s %s\n",i,tuple,hex,color);
658 p++;
659 }
660 }
661 }
662 if (image->error.mean_error_per_pixel != 0.0)
cristye7f51092010-01-17 00:39:37 +0000663 (void) fprintf(file," Mean error per pixel: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000664 image->error.mean_error_per_pixel);
665 if (image->error.normalized_mean_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000666 (void) fprintf(file," Normalized mean error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000667 image->error.normalized_mean_error);
668 if (image->error.normalized_maximum_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000669 (void) fprintf(file," Normalized maximum error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000670 image->error.normalized_maximum_error);
671 (void) fprintf(file," Rendering intent: %s\n",MagickOptionToMnemonic(
672 MagickIntentOptions,(long) image->rendering_intent));
673 if (image->gamma != 0.0)
cristye7f51092010-01-17 00:39:37 +0000674 (void) fprintf(file," Gamma: %g\n",image->gamma);
cristy3ed852e2009-09-05 21:47:34 +0000675 if ((image->chromaticity.red_primary.x != 0.0) ||
676 (image->chromaticity.green_primary.x != 0.0) ||
677 (image->chromaticity.blue_primary.x != 0.0) ||
678 (image->chromaticity.white_point.x != 0.0))
679 {
680 /*
681 Display image chromaticity.
682 */
683 (void) fprintf(file," Chromaticity:\n");
cristye7f51092010-01-17 00:39:37 +0000684 (void) fprintf(file," red primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000685 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
cristye7f51092010-01-17 00:39:37 +0000686 (void) fprintf(file," green primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000687 image->chromaticity.green_primary.x,
688 image->chromaticity.green_primary.y);
cristye7f51092010-01-17 00:39:37 +0000689 (void) fprintf(file," blue primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000690 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
cristye7f51092010-01-17 00:39:37 +0000691 (void) fprintf(file," white point: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000692 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
693 }
694 if ((image->extract_info.width*image->extract_info.height) != 0)
695 (void) fprintf(file," Tile geometry: %lux%lu%+ld%+ld\n",
696 image->extract_info.width,image->extract_info.height,
697 image->extract_info.x,image->extract_info.y);
698 (void) fprintf(file," Interlace: %s\n",MagickOptionToMnemonic(
699 MagickInterlaceOptions,(long) image->interlace));
700 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
701 &image->exception);
702 (void) fprintf(file," Background color: %s\n",color);
703 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
704 &image->exception);
705 (void) fprintf(file," Border color: %s\n",color);
706 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
707 &image->exception);
708 (void) fprintf(file," Matte color: %s\n",color);
709 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
710 &image->exception);
711 (void) fprintf(file," Transparent color: %s\n",color);
cristy11a77682009-10-11 21:50:20 +0000712 (void) fprintf(file," Compose: %s\n",MagickOptionToMnemonic(
713 MagickComposeOptions,(long) image->compose));
cristy3ed852e2009-09-05 21:47:34 +0000714 if ((image->page.width != 0) || (image->page.height != 0) ||
715 (image->page.x != 0) || (image->page.y != 0))
716 (void) fprintf(file," Page geometry: %lux%lu%+ld%+ld\n",image->page.width,
717 image->page.height,image->page.x,image->page.y);
718 if ((image->page.x != 0) || (image->page.y != 0))
719 (void) fprintf(file," Origin geometry: %+ld%+ld\n",image->page.x,
720 image->page.y);
721 (void) fprintf(file," Dispose: %s\n",MagickOptionToMnemonic(
722 MagickDisposeOptions,(long) image->dispose));
723 if (image->delay != 0)
724 (void) fprintf(file," Delay: %lux%ld\n",image->delay,
725 image->ticks_per_second);
726 if (image->iterations != 1)
727 (void) fprintf(file," Iterations: %lu\n",image->iterations);
728 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
729 (void) fprintf(file," Scene: %lu of %lu\n",image->scene,
730 GetImageListLength(image));
731 else
732 if (image->scene != 0)
733 (void) fprintf(file," Scene: %lu\n",image->scene);
734 (void) fprintf(file," Compression: %s\n",MagickOptionToMnemonic(
735 MagickCompressOptions,(long) image->compression));
736 if (image->quality != UndefinedCompressionQuality)
737 (void) fprintf(file," Quality: %lu\n",image->quality);
738 (void) fprintf(file," Orientation: %s\n",MagickOptionToMnemonic(
739 MagickOrientationOptions,(long) image->orientation));
740 if (image->montage != (char *) NULL)
741 (void) fprintf(file," Montage: %s\n",image->montage);
742 if (image->directory != (char *) NULL)
743 {
744 Image
745 *tile;
746
747 ImageInfo
748 *image_info;
749
750 register char
751 *p,
752 *q;
753
754 WarningHandler
755 handler;
756
757 /*
758 Display visual image directory.
759 */
760 image_info=AcquireImageInfo();
761 (void) CloneString(&image_info->size,"64x64");
762 (void) fprintf(file," Directory:\n");
763 for (p=image->directory; *p != '\0'; p++)
764 {
765 q=p;
766 while ((*q != '\n') && (*q != '\0'))
767 q++;
768 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
769 p=q;
770 (void) fprintf(file," %s",image_info->filename);
771 handler=SetWarningHandler((WarningHandler) NULL);
772 tile=ReadImage(image_info,&image->exception);
773 (void) SetWarningHandler(handler);
774 if (tile == (Image *) NULL)
775 {
776 (void) fprintf(file,"\n");
777 continue;
778 }
779 (void) fprintf(file," %lux%lu %s\n",tile->magick_columns,
780 tile->magick_rows,tile->magick);
781 (void) SignatureImage(tile);
782 ResetImagePropertyIterator(tile);
783 property=GetNextImageProperty(tile);
784 while (property != (const char *) NULL)
785 {
786 (void) fprintf(file," %s:\n",property);
787 value=GetImageProperty(tile,property);
788 if (value != (const char *) NULL)
789 (void) fprintf(file,"%s\n",value);
790 property=GetNextImageProperty(tile);
791 }
792 tile=DestroyImage(tile);
793 }
794 image_info=DestroyImageInfo(image_info);
795 }
796 (void) GetImageProperty(image,"exif:*");
797 ResetImagePropertyIterator(image);
798 property=GetNextImageProperty(image);
799 if (property != (const char *) NULL)
800 {
801 /*
802 Display image properties.
803 */
804 (void) fprintf(file," Properties:\n");
805 while (property != (const char *) NULL)
806 {
807 (void) fprintf(file," %c",*property);
808 if (strlen(property) > 1)
809 (void) fprintf(file,"%s: ",property+1);
810 if (strlen(property) > 80)
811 (void) fputc('\n',file);
812 value=GetImageProperty(image,property);
813 if (value != (const char *) NULL)
814 (void) fprintf(file,"%s\n",value);
815 property=GetNextImageProperty(image);
816 }
817 }
818 (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
819 value=GetImageProperty(image,key);
820 if (value != (const char *) NULL)
821 {
822 /*
823 Display clipping path.
824 */
825 (void) fprintf(file," Clipping path: ");
826 if (strlen(value) > 80)
827 (void) fputc('\n',file);
828 (void) fprintf(file,"%s\n",value);
829 }
830 ResetImageProfileIterator(image);
831 name=GetNextImageProfile(image);
832 if (name != (char *) NULL)
833 {
834 const StringInfo
835 *profile;
836
837 /*
838 Identify image profiles.
839 */
840 (void) fprintf(file," Profiles:\n");
841 while (name != (char *) NULL)
842 {
843 profile=GetImageProfile(image,name);
844 if (profile == (StringInfo *) NULL)
845 continue;
846 (void) fprintf(file," Profile-%s: %lu bytes\n",name,(unsigned long)
847 GetStringInfoLength(profile));
848#if defined(MAGICKCORE_LCMS_DELEGATE)
849 if ((LocaleCompare(name,"icc") == 0) ||
850 (LocaleCompare(name,"icm") == 0))
851 {
852 cmsHPROFILE
853 icc_profile;
854
855 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
856 (DWORD) GetStringInfoLength(profile));
857 if (icc_profile != (cmsHPROFILE *) NULL)
858 {
859 const char
860 *name;
861
862 name=cmsTakeProductName(icc_profile);
863 if (name != (const char *) NULL)
864 (void) fprintf(file," %s\n",name);
865 (void) cmsCloseProfile(icc_profile);
866 }
867 }
868#endif
869 if (LocaleCompare(name,"iptc") == 0)
870 {
871 char
872 *attribute,
873 **attribute_list;
874
875 const char
876 *tag;
877
878 long
879 dataset,
880 record,
881 sentinel;
882
883 register long
884 j;
885
886 size_t
887 length,
888 profile_length;
889
890 profile_length=GetStringInfoLength(profile);
891 for (i=0; i < (long) profile_length; i+=(long) length)
892 {
893 length=1;
894 sentinel=GetStringInfoDatum(profile)[i++];
895 if (sentinel != 0x1c)
896 continue;
897 dataset=GetStringInfoDatum(profile)[i++];
898 record=GetStringInfoDatum(profile)[i++];
899 switch (record)
900 {
901 case 5: tag="Image Name"; break;
902 case 7: tag="Edit Status"; break;
903 case 10: tag="Priority"; break;
904 case 15: tag="Category"; break;
905 case 20: tag="Supplemental Category"; break;
906 case 22: tag="Fixture Identifier"; break;
907 case 25: tag="Keyword"; break;
908 case 30: tag="Release Date"; break;
909 case 35: tag="Release Time"; break;
910 case 40: tag="Special Instructions"; break;
911 case 45: tag="Reference Service"; break;
912 case 47: tag="Reference Date"; break;
913 case 50: tag="Reference Number"; break;
914 case 55: tag="Created Date"; break;
915 case 60: tag="Created Time"; break;
916 case 65: tag="Originating Program"; break;
917 case 70: tag="Program Version"; break;
918 case 75: tag="Object Cycle"; break;
919 case 80: tag="Byline"; break;
920 case 85: tag="Byline Title"; break;
921 case 90: tag="City"; break;
922 case 95: tag="Province State"; break;
923 case 100: tag="Country Code"; break;
924 case 101: tag="Country"; break;
925 case 103: tag="Original Transmission Reference"; break;
926 case 105: tag="Headline"; break;
927 case 110: tag="Credit"; break;
928 case 115: tag="Src"; break;
929 case 116: tag="Copyright String"; break;
930 case 120: tag="Caption"; break;
931 case 121: tag="Local Caption"; break;
932 case 122: tag="Caption Writer"; break;
933 case 200: tag="Custom Field 1"; break;
934 case 201: tag="Custom Field 2"; break;
935 case 202: tag="Custom Field 3"; break;
936 case 203: tag="Custom Field 4"; break;
937 case 204: tag="Custom Field 5"; break;
938 case 205: tag="Custom Field 6"; break;
939 case 206: tag="Custom Field 7"; break;
940 case 207: tag="Custom Field 8"; break;
941 case 208: tag="Custom Field 9"; break;
942 case 209: tag="Custom Field 10"; break;
943 case 210: tag="Custom Field 11"; break;
944 case 211: tag="Custom Field 12"; break;
945 case 212: tag="Custom Field 13"; break;
946 case 213: tag="Custom Field 14"; break;
947 case 214: tag="Custom Field 15"; break;
948 case 215: tag="Custom Field 16"; break;
949 case 216: tag="Custom Field 17"; break;
950 case 217: tag="Custom Field 18"; break;
951 case 218: tag="Custom Field 19"; break;
952 case 219: tag="Custom Field 20"; break;
953 default: tag="unknown"; break;
954 }
955 (void) fprintf(file," %s[%ld,%ld]: ",tag,dataset,record);
956 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
957 length|=GetStringInfoDatum(profile)[i++];
958 attribute=(char *) NULL;
959 if (~length >= MaxTextExtent)
960 attribute=(char *) AcquireQuantumMemory(length+
961 MaxTextExtent,sizeof(*attribute));
962 if (attribute != (char *) NULL)
963 {
964 (void) CopyMagickString(attribute,(char *)
965 GetStringInfoDatum(profile)+i,length+1);
966 attribute_list=StringToList(attribute);
967 if (attribute_list != (char **) NULL)
968 {
969 for (j=0; attribute_list[j] != (char *) NULL; j++)
970 {
971 (void) fputs(attribute_list[j],file);
972 (void) fputs("\n",file);
973 attribute_list[j]=(char *) RelinquishMagickMemory(
974 attribute_list[j]);
975 }
976 attribute_list=(char **) RelinquishMagickMemory(
977 attribute_list);
978 }
979 attribute=DestroyString(attribute);
980 }
981 }
982 }
983 if (image->debug != MagickFalse)
984 PrintStringInfo(file,name,profile);
985 name=GetNextImageProfile(image);
986 }
987 }
988 ResetImageArtifactIterator(image);
989 artifact=GetNextImageArtifact(image);
990 if (artifact != (const char *) NULL)
991 {
992 /*
993 Display image artifacts.
994 */
995 (void) fprintf(file," Artifacts:\n");
996 while (artifact != (const char *) NULL)
997 {
998 (void) fprintf(file," %c",*artifact);
999 if (strlen(artifact) > 1)
1000 (void) fprintf(file,"%s: ",artifact+1);
1001 if (strlen(artifact) > 80)
1002 (void) fputc('\n',file);
1003 value=GetImageArtifact(image,artifact);
1004 if (value != (const char *) NULL)
1005 (void) fprintf(file,"%s\n",value);
1006 artifact=GetNextImageArtifact(image);
1007 }
1008 }
1009 ResetImageRegistryIterator();
1010 registry=GetNextImageRegistry();
1011 if (registry != (const char *) NULL)
1012 {
1013 /*
1014 Display image registry.
1015 */
1016 (void) fprintf(file," Registry:\n");
1017 while (registry != (const char *) NULL)
1018 {
1019 (void) fprintf(file," %c",*registry);
1020 if (strlen(registry) > 1)
1021 (void) fprintf(file,"%s: ",registry+1);
1022 if (strlen(registry) > 80)
1023 (void) fputc('\n',file);
1024 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1025 &image->exception);
1026 if (value != (const char *) NULL)
1027 (void) fprintf(file,"%s\n",value);
1028 registry=GetNextImageRegistry();
1029 }
1030 }
1031 (void) fprintf(file," Tainted: %s\n",MagickOptionToMnemonic(
1032 MagickBooleanOptions,(long) image->taint));
cristyb9080c92009-12-01 20:13:26 +00001033 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001034 (void) fprintf(file," Filesize: %s\n",format);
cristyb9080c92009-12-01 20:13:26 +00001035 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1036 MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001037 (void) fprintf(file," Number pixels: %s\n",format);
cristy3d231692009-09-29 01:05:22 +00001038 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristyb9080c92009-12-01 20:13:26 +00001039 elapsed_time+0.5),MagickFalse,format);
cristy3d231692009-09-29 01:05:22 +00001040 (void) fprintf(file," Pixels per second: %s\n",format);
1041 (void) fprintf(file," User time: %0.3fu\n",user_time);
1042 (void) fprintf(file," Elapsed time: %ld:%02ld.%03ld\n",(long)
1043 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),(long)
1044 (1000.0*(elapsed_time-floor(elapsed_time))));
1045 (void) fprintf(file," Version: %s\n",GetMagickVersion((unsigned long *)
1046 NULL));
cristy3ed852e2009-09-05 21:47:34 +00001047 (void) fflush(file);
1048 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1049}