blob: 14abd8fd394e9108ca1f86bc8263640158de588d [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" \
cristye0e19dc2010-01-29 02:13:08 +0000163 " %.*g, %.*g, %.*g, %.*g\n" \
164 " Difference Entropy:\n" \
165 " %.*g, %.*g, %.*g, %.*g\n" \
166 " Information Measure of Correlation 1:\n" \
167 " %.*g, %.*g, %.*g, %.*g\n" \
168 " Information Measure of Correlation 2:\n" \
169 " %.*g, %.*g, %.*g, %.*g\n" \
170 " Maximum Correlation Coefficient:\n" \
171 " %.*g, %.*g, %.*g, %.*g\n"
cristybd822072010-01-27 00:30:00 +0000172
173 int
174 status;
175
176 status=fprintf(file,FeaturesFormat,name,
cristye1897792010-01-29 02:05:50 +0000177 PrintFeature(channel_features[channel].angular_second_moment),
178 PrintFeature(channel_features[channel].contrast),
179 PrintFeature(channel_features[channel].correlation),
180 PrintFeature(channel_features[channel].variance_sum_of_squares),
181 PrintFeature(channel_features[channel].inverse_difference_moment),
182 PrintFeature(channel_features[channel].sum_average),
183 PrintFeature(channel_features[channel].sum_variance),
184 PrintFeature(channel_features[channel].sum_entropy),
185 PrintFeature(channel_features[channel].entropy),
cristye0e19dc2010-01-29 02:13:08 +0000186 PrintFeature(channel_features[channel].difference_variance),
187 PrintFeature(channel_features[channel].difference_entropy),
188 PrintFeature(channel_features[channel].measure_of_correlation_1),
189 PrintFeature(channel_features[channel].measure_of_correlation_2),
190 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
cristybd822072010-01-27 00:30:00 +0000191 return(status);
192}
193
194static int PrintChannelStatistics(FILE *file,const ChannelType channel,
195 const char *name,const double scale,
196 const ChannelStatistics *channel_statistics)
197{
198#define StatisticsFormat " %s:\n min: " QuantumFormat \
cristye7f51092010-01-17 00:39:37 +0000199 " (%g)\n max: " QuantumFormat " (%g)\n" \
200 " mean: %g (%g)\n standard deviation: %g (%g)\n" \
201 " kurtosis: %g\n skewness: %g\n"
cristy3ed852e2009-09-05 21:47:34 +0000202
cristybd822072010-01-27 00:30:00 +0000203 double
204 maxima,
205 mean,
206 minima;
207
208 int
209 status;
210
211 minima=channel_statistics[channel].minima;
212 maxima=channel_statistics[channel].maxima;
213 mean=channel_statistics[channel].mean;
214 if (channel == AlphaChannel)
215 {
216 minima=QuantumRange-minima;
217 maxima=QuantumRange-maxima;
218 mean=QuantumRange-mean;
219 }
220 status=fprintf(file,StatisticsFormat,name,(Quantum) (scale*minima),minima/
221 (double) QuantumRange,(Quantum) (maxima/scale),maxima/(double) QuantumRange,
222 scale*mean,mean/(double) QuantumRange,
223 scale*channel_statistics[channel].standard_deviation,
224 channel_statistics[channel].standard_deviation/(double)
225 QuantumRange,channel_statistics[channel].kurtosis,
226 channel_statistics[channel].skewness);
227 return(status);
228}
229
230MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
231 const MagickBooleanType verbose)
232{
cristy3ed852e2009-09-05 21:47:34 +0000233 char
234 color[MaxTextExtent],
235 format[MaxTextExtent],
236 key[MaxTextExtent];
237
cristybd822072010-01-27 00:30:00 +0000238 ChannelFeatures
239 *channel_features;
240
241 ChannelStatistics
242 *channel_statistics;
243
cristy3ed852e2009-09-05 21:47:34 +0000244 ColorspaceType
245 colorspace;
246
247 const char
248 *artifact,
249 *name,
250 *property,
251 *registry,
252 *value;
253
254 const MagickInfo
255 *magick_info;
256
257 const PixelPacket
258 *pixels;
259
260 double
261 elapsed_time,
262 user_time;
263
264 ExceptionInfo
265 *exception;
266
267 ImageType
268 type;
269
270 long
271 y;
272
273 MagickBooleanType
274 ping;
275
276 register long
277 i,
278 x;
279
280 unsigned long
cristybd822072010-01-27 00:30:00 +0000281 distance,
cristy3ed852e2009-09-05 21:47:34 +0000282 scale;
283
284 assert(image != (Image *) NULL);
285 assert(image->signature == MagickSignature);
286 if (image->debug != MagickFalse)
287 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
288 if (file == (FILE *) NULL)
289 file=stdout;
290 *format='\0';
291 elapsed_time=GetElapsedTime(&image->timer);
292 user_time=GetUserTime(&image->timer);
293 GetTimerInfo(&image->timer);
294 if (verbose == MagickFalse)
295 {
296 /*
297 Display summary info about the image.
298 */
299 if (*image->magick_filename != '\0')
300 if (LocaleCompare(image->magick_filename,image->filename) != 0)
301 (void) fprintf(file,"%s=>",image->magick_filename);
302 if ((GetPreviousImageInList(image) == (Image *) NULL) &&
303 (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0))
304 (void) fprintf(file,"%s ",image->filename);
305 else
306 (void) fprintf(file,"%s[%lu] ",image->filename,image->scene);
307 (void) fprintf(file,"%s ",image->magick);
308 if ((image->magick_columns != 0) || (image->magick_rows != 0))
309 if ((image->magick_columns != image->columns) ||
310 (image->magick_rows != image->rows))
311 (void) fprintf(file,"%lux%lu=>",image->magick_columns,
312 image->magick_rows);
313 (void) fprintf(file,"%lux%lu ",image->columns,image->rows);
314 if ((image->page.width != 0) || (image->page.height != 0) ||
315 (image->page.x != 0) || (image->page.y != 0))
316 (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width,
317 image->page.height,image->page.x,image->page.y);
318 (void) fprintf(file,"%lu-bit ",image->depth);
319 if (image->type != UndefinedType)
320 (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
321 (long) image->type));
322 if (image->storage_class == DirectClass)
323 {
324 (void) fprintf(file,"DirectClass ");
325 if (image->total_colors != 0)
326 {
cristyb9080c92009-12-01 20:13:26 +0000327 (void) FormatMagickSize(image->total_colors,MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000328 (void) fprintf(file,"%s ",format);
329 }
330 }
331 else
332 if (image->total_colors <= image->colors)
333 (void) fprintf(file,"PseudoClass %luc ",image->colors);
334 else
335 (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors,
336 image->colors);
337 if (image->error.mean_error_per_pixel != 0.0)
338 (void) fprintf(file,"%ld/%f/%fdb ",(long)
339 (image->error.mean_error_per_pixel+0.5),
340 image->error.normalized_mean_error,
341 image->error.normalized_maximum_error);
342 if (GetBlobSize(image) != 0)
343 {
cristyb9080c92009-12-01 20:13:26 +0000344 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000345 (void) fprintf(file,"%s ",format);
346 }
cristy3d231692009-09-29 01:05:22 +0000347 (void) fprintf(file,"%0.3fu %ld:%02ld.%03ld",user_time,(long)
348 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
349 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy3ed852e2009-09-05 21:47:34 +0000350 (void) fprintf(file,"\n");
351 (void) fflush(file);
352 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
353 }
354 /*
355 Display verbose info about the image.
356 */
357 exception=AcquireExceptionInfo();
358 pixels=GetVirtualPixels(image,0,0,1,1,exception);
359 exception=DestroyExceptionInfo(exception);
360 ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
361 type=GetImageType(image,&image->exception);
362 (void) SignatureImage(image);
363 (void) fprintf(file,"Image: %s\n",image->filename);
364 if (*image->magick_filename != '\0')
365 if (LocaleCompare(image->magick_filename,image->filename) != 0)
366 {
367 char
368 filename[MaxTextExtent];
369
370 GetPathComponent(image->magick_filename,TailPath,filename);
371 (void) fprintf(file," Base filename: %s\n",filename);
372 }
373 magick_info=GetMagickInfo(image->magick,&image->exception);
374 if ((magick_info == (const MagickInfo *) NULL) ||
375 (*GetMagickDescription(magick_info) == '\0'))
376 (void) fprintf(file," Format: %s\n",image->magick);
377 else
378 (void) fprintf(file," Format: %s (%s)\n",image->magick,
379 GetMagickDescription(magick_info));
380 (void) fprintf(file," Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
381 (long) image->storage_class));
382 (void) fprintf(file," Geometry: %lux%lu%+ld%+ld\n",image->columns,
383 image->rows,image->tile_offset.x,image->tile_offset.y);
384 if ((image->magick_columns != 0) || (image->magick_rows != 0))
385 if ((image->magick_columns != image->columns) ||
386 (image->magick_rows != image->rows))
387 (void) fprintf(file," Base geometry: %lux%lu\n",image->magick_columns,
388 image->magick_rows);
389 if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
390 {
cristye7f51092010-01-17 00:39:37 +0000391 (void) fprintf(file," Resolution: %gx%g\n",image->x_resolution,
cristy3ed852e2009-09-05 21:47:34 +0000392 image->y_resolution);
cristye7f51092010-01-17 00:39:37 +0000393 (void) fprintf(file," Print size: %gx%g\n",(double) image->columns/
cristy3ed852e2009-09-05 21:47:34 +0000394 image->x_resolution,(double) image->rows/image->y_resolution);
395 }
396 (void) fprintf(file," Units: %s\n",MagickOptionToMnemonic(
397 MagickResolutionOptions,(long) image->units));
398 (void) fprintf(file," Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
399 (long) type));
400 if (image->type != UndefinedType)
401 (void) fprintf(file," Base type: %s\n",MagickOptionToMnemonic(
402 MagickTypeOptions,(long) image->type));
403 (void) fprintf(file," Endianess: %s\n",MagickOptionToMnemonic(
404 MagickEndianOptions,(long) image->endian));
405 /*
406 Detail channel depth and extrema.
407 */
408 (void) fprintf(file," Colorspace: %s\n",MagickOptionToMnemonic(
409 MagickColorspaceOptions,(long) image->colorspace));
cristybd822072010-01-27 00:30:00 +0000410 channel_statistics=(ChannelStatistics *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000411 if (ping == MagickFalse)
cristybd822072010-01-27 00:30:00 +0000412 channel_statistics=GetImageChannelStatistics(image,&image->exception);
413 if (channel_statistics != (ChannelStatistics *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000414 {
cristy3ed852e2009-09-05 21:47:34 +0000415 unsigned long
416 depth;
417
418 depth=GetImageDepth(image,&image->exception);
419 if (image->depth == depth)
420 (void) fprintf(file," Depth: %lu-bit\n",image->depth);
421 else
422 (void) fprintf(file," Depth: %lu/%lu-bit\n",image->depth,depth);
cristy3ed852e2009-09-05 21:47:34 +0000423 (void) fprintf(file," Channel depth:\n");
424 colorspace=image->colorspace;
425 if (IsGrayImage(image,&image->exception) != MagickFalse)
426 colorspace=GRAYColorspace;
427 switch (colorspace)
428 {
429 case RGBColorspace:
430 default:
431 {
432 (void) fprintf(file," red: %lu-bit\n",
433 channel_statistics[RedChannel].depth);
434 (void) fprintf(file," green: %lu-bit\n",
435 channel_statistics[GreenChannel].depth);
436 (void) fprintf(file," blue: %lu-bit\n",
437 channel_statistics[BlueChannel].depth);
438 if (image->matte != MagickFalse)
439 (void) fprintf(file," alpha: %lu-bit\n",
440 channel_statistics[OpacityChannel].depth);
441 break;
442 }
443 case CMYKColorspace:
444 {
445 (void) fprintf(file," cyan: %lu-bit\n",
446 channel_statistics[CyanChannel].depth);
447 (void) fprintf(file," magenta: %lu-bit\n",
448 channel_statistics[MagentaChannel].depth);
449 (void) fprintf(file," yellow: %lu-bit\n",
450 channel_statistics[YellowChannel].depth);
451 (void) fprintf(file," black: %lu-bit\n",
452 channel_statistics[BlackChannel].depth);
453 if (image->matte != MagickFalse)
454 (void) fprintf(file," alpha: %lu-bit\n",
455 channel_statistics[OpacityChannel].depth);
456 break;
457 }
458 case GRAYColorspace:
459 {
460 (void) fprintf(file," gray: %lu-bit\n",
461 channel_statistics[GrayChannel].depth);
462 if (image->matte != MagickFalse)
463 (void) fprintf(file," alpha: %lu-bit\n",
464 channel_statistics[OpacityChannel].depth);
465 break;
466 }
467 }
468 scale=1;
469 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
470 scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long)
471 MAGICKCORE_QUANTUM_DEPTH-image->depth));
472 (void) fprintf(file," Channel statistics:\n");
473 switch (colorspace)
474 {
475 case RGBColorspace:
476 default:
477 {
cristybd822072010-01-27 00:30:00 +0000478 (void) PrintChannelStatistics(file,RedChannel,"Red",1.0/scale,
479 channel_statistics);
480 (void) PrintChannelStatistics(file,GreenChannel,"Green",1.0/scale,
481 channel_statistics);
482 (void) PrintChannelStatistics(file,BlueChannel,"Blue",1.0/scale,
483 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000484 break;
485 }
486 case CMYKColorspace:
487 {
cristybd822072010-01-27 00:30:00 +0000488 (void) PrintChannelStatistics(file,CyanChannel,"Cyan",1.0/scale,
489 channel_statistics);
490 (void) PrintChannelStatistics(file,MagentaChannel,"Magenta",1.0/scale,
491 channel_statistics);
492 (void) PrintChannelStatistics(file,YellowChannel,"Yellow",1.0/scale,
493 channel_statistics);
494 (void) PrintChannelStatistics(file,BlackChannel,"Black",1.0/scale,
495 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000496 break;
497 }
498 case GRAYColorspace:
499 {
cristybd822072010-01-27 00:30:00 +0000500 (void) PrintChannelStatistics(file,GrayChannel,"Gray",1.0/scale,
501 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000502 break;
503 }
504 }
505 if (image->matte != MagickFalse)
cristybd822072010-01-27 00:30:00 +0000506 (void) PrintChannelStatistics(file,AlphaChannel,"Alpha",1.0/scale,
507 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000508 if (colorspace != GRAYColorspace)
509 {
510 (void) fprintf(file," Image statistics:\n");
cristybd822072010-01-27 00:30:00 +0000511 (void) PrintChannelStatistics(file,AllChannels,"Overall",1.0/scale,
512 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000513 }
514 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
515 channel_statistics);
cristybd822072010-01-27 00:30:00 +0000516 }
517 channel_features=(ChannelFeatures *) NULL;
518 artifact=GetImageArtifact(image,"identify:features");
cristybd822072010-01-27 00:30:00 +0000519 if ((ping == MagickFalse) && (artifact != (const char *) NULL))
cristy8c02fa12010-01-27 01:10:17 +0000520 {
521 distance=StringToUnsignedLong(artifact);
522 channel_features=GetImageChannelFeatures(image,distance,
523 &image->exception);
524 }
cristybd822072010-01-27 00:30:00 +0000525 if (channel_features != (ChannelFeatures *) NULL)
526 {
cristy7396d882010-01-27 02:37:56 +0000527 (void) fprintf(file," Channel features (horizontal, vertical, left and right diagonals):\n");
cristybd822072010-01-27 00:30:00 +0000528 switch (colorspace)
529 {
530 case RGBColorspace:
531 default:
cristy549a37e2010-01-26 15:24:15 +0000532 {
cristye1897792010-01-29 02:05:50 +0000533 (void) PrintChannelFeatures(file,RedChannel,"Red",channel_features);
534 (void) PrintChannelFeatures(file,GreenChannel,"Green",
cristybd822072010-01-27 00:30:00 +0000535 channel_features);
cristye1897792010-01-29 02:05:50 +0000536 (void) PrintChannelFeatures(file,BlueChannel,"Blue",channel_features);
cristybd822072010-01-27 00:30:00 +0000537 break;
538 }
539 case CMYKColorspace:
540 {
cristye1897792010-01-29 02:05:50 +0000541 (void) PrintChannelFeatures(file,CyanChannel,"Cyan",channel_features);
542 (void) PrintChannelFeatures(file,MagentaChannel,"Magenta",
cristybd822072010-01-27 00:30:00 +0000543 channel_features);
cristye1897792010-01-29 02:05:50 +0000544 (void) PrintChannelFeatures(file,YellowChannel,"Yellow",
cristybd822072010-01-27 00:30:00 +0000545 channel_features);
cristye1897792010-01-29 02:05:50 +0000546 (void) PrintChannelFeatures(file,BlackChannel,"Black",
cristybd822072010-01-27 00:30:00 +0000547 channel_features);
548 break;
549 }
550 case GRAYColorspace:
551 {
cristye1897792010-01-29 02:05:50 +0000552 (void) PrintChannelFeatures(file,GrayChannel,"Gray",channel_features);
cristybd822072010-01-27 00:30:00 +0000553 break;
554 }
555 }
556 if (image->matte != MagickFalse)
cristye1897792010-01-29 02:05:50 +0000557 (void) PrintChannelFeatures(file,AlphaChannel,"Alpha",channel_features);
cristybd822072010-01-27 00:30:00 +0000558 if (colorspace != GRAYColorspace)
559 {
560 (void) fprintf(file," Image features:\n");
cristye1897792010-01-29 02:05:50 +0000561 (void) PrintChannelFeatures(file,AllChannels,"Overall",
cristy549a37e2010-01-26 15:24:15 +0000562 channel_features);
563 }
cristybd822072010-01-27 00:30:00 +0000564 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
565 channel_features);
566 }
567 if (ping == MagickFalse)
568 {
cristy3ed852e2009-09-05 21:47:34 +0000569 if (image->colorspace == CMYKColorspace)
570 (void) fprintf(file," Total ink density: %.0f%%\n",100.0*
571 GetImageTotalInkDensity(image)/(double) QuantumRange);
572 x=0;
573 if (image->matte != MagickFalse)
574 {
575 register const IndexPacket
576 *indexes;
577
578 register const PixelPacket
579 *p;
580
581 p=(PixelPacket *) NULL;
582 indexes=(IndexPacket *) NULL;
583 for (y=0; y < (long) image->rows; y++)
584 {
585 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
586 if (p == (const PixelPacket *) NULL)
587 break;
588 indexes=GetVirtualIndexQueue(image);
589 for (x=0; x < (long) image->columns; x++)
590 {
591 if (p->opacity == (Quantum) TransparentOpacity)
592 break;
593 p++;
594 }
595 if (x < (long) image->columns)
596 break;
597 }
598 if ((x < (long) image->columns) || (y < (long) image->rows))
599 {
600 char
601 tuple[MaxTextExtent];
602
603 MagickPixelPacket
604 pixel;
605
606 GetMagickPixelPacket(image,&pixel);
607 SetMagickPixelPacket(image,p,indexes+x,&pixel);
608 (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
609 &image->exception);
610 (void) fprintf(file," Alpha: %s ",tuple);
611 GetColorTuple(&pixel,MagickTrue,tuple);
612 (void) fprintf(file," %s\n",tuple);
613 }
614 }
cristy549a37e2010-01-26 15:24:15 +0000615 artifact=GetImageArtifact(image,"identify:unique");
616 if ((artifact != (const char *) NULL) &&
617 (IsMagickTrue(artifact) != MagickFalse))
618 (void) fprintf(file," Colors: %lu\n",GetNumberColors(image,
619 (FILE *) NULL,&image->exception));
620 if (IsHistogramImage(image,&image->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000621 {
cristy549a37e2010-01-26 15:24:15 +0000622 (void) fprintf(file," Histogram:\n");
623 (void) GetNumberColors(image,file,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +0000624 }
625 }
626 if (image->storage_class == PseudoClass)
627 {
628 (void) fprintf(file," Colormap: %lu\n",image->colors);
629 if (image->colors <= 1024)
630 {
631 char
632 color[MaxTextExtent],
633 hex[MaxTextExtent],
634 tuple[MaxTextExtent];
635
636 MagickPixelPacket
637 pixel;
638
639 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000640 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000641
642 GetMagickPixelPacket(image,&pixel);
643 p=image->colormap;
644 for (i=0; i < (long) image->colors; i++)
645 {
646 SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
647 (void) CopyMagickString(tuple,"(",MaxTextExtent);
648 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
649 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
650 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
651 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
652 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
653 if (pixel.colorspace == CMYKColorspace)
654 {
655 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
656 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
657 tuple);
658 }
659 if (pixel.matte != MagickFalse)
660 {
661 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
662 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,
663 tuple);
664 }
665 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
666 (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
667 &image->exception);
668 GetColorTuple(&pixel,MagickTrue,hex);
669 (void) fprintf(file," %8ld: %s %s %s\n",i,tuple,hex,color);
670 p++;
671 }
672 }
673 }
674 if (image->error.mean_error_per_pixel != 0.0)
cristye7f51092010-01-17 00:39:37 +0000675 (void) fprintf(file," Mean error per pixel: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000676 image->error.mean_error_per_pixel);
677 if (image->error.normalized_mean_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000678 (void) fprintf(file," Normalized mean error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000679 image->error.normalized_mean_error);
680 if (image->error.normalized_maximum_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000681 (void) fprintf(file," Normalized maximum error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000682 image->error.normalized_maximum_error);
683 (void) fprintf(file," Rendering intent: %s\n",MagickOptionToMnemonic(
684 MagickIntentOptions,(long) image->rendering_intent));
685 if (image->gamma != 0.0)
cristye7f51092010-01-17 00:39:37 +0000686 (void) fprintf(file," Gamma: %g\n",image->gamma);
cristy3ed852e2009-09-05 21:47:34 +0000687 if ((image->chromaticity.red_primary.x != 0.0) ||
688 (image->chromaticity.green_primary.x != 0.0) ||
689 (image->chromaticity.blue_primary.x != 0.0) ||
690 (image->chromaticity.white_point.x != 0.0))
691 {
692 /*
693 Display image chromaticity.
694 */
695 (void) fprintf(file," Chromaticity:\n");
cristye7f51092010-01-17 00:39:37 +0000696 (void) fprintf(file," red primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000697 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
cristye7f51092010-01-17 00:39:37 +0000698 (void) fprintf(file," green primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000699 image->chromaticity.green_primary.x,
700 image->chromaticity.green_primary.y);
cristye7f51092010-01-17 00:39:37 +0000701 (void) fprintf(file," blue primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000702 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
cristye7f51092010-01-17 00:39:37 +0000703 (void) fprintf(file," white point: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000704 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
705 }
706 if ((image->extract_info.width*image->extract_info.height) != 0)
707 (void) fprintf(file," Tile geometry: %lux%lu%+ld%+ld\n",
708 image->extract_info.width,image->extract_info.height,
709 image->extract_info.x,image->extract_info.y);
710 (void) fprintf(file," Interlace: %s\n",MagickOptionToMnemonic(
711 MagickInterlaceOptions,(long) image->interlace));
712 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
713 &image->exception);
714 (void) fprintf(file," Background color: %s\n",color);
715 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
716 &image->exception);
717 (void) fprintf(file," Border color: %s\n",color);
718 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
719 &image->exception);
720 (void) fprintf(file," Matte color: %s\n",color);
721 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
722 &image->exception);
723 (void) fprintf(file," Transparent color: %s\n",color);
cristy11a77682009-10-11 21:50:20 +0000724 (void) fprintf(file," Compose: %s\n",MagickOptionToMnemonic(
725 MagickComposeOptions,(long) image->compose));
cristy3ed852e2009-09-05 21:47:34 +0000726 if ((image->page.width != 0) || (image->page.height != 0) ||
727 (image->page.x != 0) || (image->page.y != 0))
728 (void) fprintf(file," Page geometry: %lux%lu%+ld%+ld\n",image->page.width,
729 image->page.height,image->page.x,image->page.y);
730 if ((image->page.x != 0) || (image->page.y != 0))
731 (void) fprintf(file," Origin geometry: %+ld%+ld\n",image->page.x,
732 image->page.y);
733 (void) fprintf(file," Dispose: %s\n",MagickOptionToMnemonic(
734 MagickDisposeOptions,(long) image->dispose));
735 if (image->delay != 0)
736 (void) fprintf(file," Delay: %lux%ld\n",image->delay,
737 image->ticks_per_second);
738 if (image->iterations != 1)
739 (void) fprintf(file," Iterations: %lu\n",image->iterations);
740 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
741 (void) fprintf(file," Scene: %lu of %lu\n",image->scene,
742 GetImageListLength(image));
743 else
744 if (image->scene != 0)
745 (void) fprintf(file," Scene: %lu\n",image->scene);
746 (void) fprintf(file," Compression: %s\n",MagickOptionToMnemonic(
747 MagickCompressOptions,(long) image->compression));
748 if (image->quality != UndefinedCompressionQuality)
749 (void) fprintf(file," Quality: %lu\n",image->quality);
750 (void) fprintf(file," Orientation: %s\n",MagickOptionToMnemonic(
751 MagickOrientationOptions,(long) image->orientation));
752 if (image->montage != (char *) NULL)
753 (void) fprintf(file," Montage: %s\n",image->montage);
754 if (image->directory != (char *) NULL)
755 {
756 Image
757 *tile;
758
759 ImageInfo
760 *image_info;
761
762 register char
763 *p,
764 *q;
765
766 WarningHandler
767 handler;
768
769 /*
770 Display visual image directory.
771 */
772 image_info=AcquireImageInfo();
773 (void) CloneString(&image_info->size,"64x64");
774 (void) fprintf(file," Directory:\n");
775 for (p=image->directory; *p != '\0'; p++)
776 {
777 q=p;
778 while ((*q != '\n') && (*q != '\0'))
779 q++;
780 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
781 p=q;
782 (void) fprintf(file," %s",image_info->filename);
783 handler=SetWarningHandler((WarningHandler) NULL);
784 tile=ReadImage(image_info,&image->exception);
785 (void) SetWarningHandler(handler);
786 if (tile == (Image *) NULL)
787 {
788 (void) fprintf(file,"\n");
789 continue;
790 }
791 (void) fprintf(file," %lux%lu %s\n",tile->magick_columns,
792 tile->magick_rows,tile->magick);
793 (void) SignatureImage(tile);
794 ResetImagePropertyIterator(tile);
795 property=GetNextImageProperty(tile);
796 while (property != (const char *) NULL)
797 {
798 (void) fprintf(file," %s:\n",property);
799 value=GetImageProperty(tile,property);
800 if (value != (const char *) NULL)
801 (void) fprintf(file,"%s\n",value);
802 property=GetNextImageProperty(tile);
803 }
804 tile=DestroyImage(tile);
805 }
806 image_info=DestroyImageInfo(image_info);
807 }
808 (void) GetImageProperty(image,"exif:*");
809 ResetImagePropertyIterator(image);
810 property=GetNextImageProperty(image);
811 if (property != (const char *) NULL)
812 {
813 /*
814 Display image properties.
815 */
816 (void) fprintf(file," Properties:\n");
817 while (property != (const char *) NULL)
818 {
819 (void) fprintf(file," %c",*property);
820 if (strlen(property) > 1)
821 (void) fprintf(file,"%s: ",property+1);
822 if (strlen(property) > 80)
823 (void) fputc('\n',file);
824 value=GetImageProperty(image,property);
825 if (value != (const char *) NULL)
826 (void) fprintf(file,"%s\n",value);
827 property=GetNextImageProperty(image);
828 }
829 }
830 (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
831 value=GetImageProperty(image,key);
832 if (value != (const char *) NULL)
833 {
834 /*
835 Display clipping path.
836 */
837 (void) fprintf(file," Clipping path: ");
838 if (strlen(value) > 80)
839 (void) fputc('\n',file);
840 (void) fprintf(file,"%s\n",value);
841 }
842 ResetImageProfileIterator(image);
843 name=GetNextImageProfile(image);
844 if (name != (char *) NULL)
845 {
846 const StringInfo
847 *profile;
848
849 /*
850 Identify image profiles.
851 */
852 (void) fprintf(file," Profiles:\n");
853 while (name != (char *) NULL)
854 {
855 profile=GetImageProfile(image,name);
856 if (profile == (StringInfo *) NULL)
857 continue;
858 (void) fprintf(file," Profile-%s: %lu bytes\n",name,(unsigned long)
859 GetStringInfoLength(profile));
860#if defined(MAGICKCORE_LCMS_DELEGATE)
861 if ((LocaleCompare(name,"icc") == 0) ||
862 (LocaleCompare(name,"icm") == 0))
863 {
864 cmsHPROFILE
865 icc_profile;
866
867 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
868 (DWORD) GetStringInfoLength(profile));
869 if (icc_profile != (cmsHPROFILE *) NULL)
870 {
871 const char
872 *name;
873
874 name=cmsTakeProductName(icc_profile);
875 if (name != (const char *) NULL)
876 (void) fprintf(file," %s\n",name);
877 (void) cmsCloseProfile(icc_profile);
878 }
879 }
880#endif
881 if (LocaleCompare(name,"iptc") == 0)
882 {
883 char
884 *attribute,
885 **attribute_list;
886
887 const char
888 *tag;
889
890 long
891 dataset,
892 record,
893 sentinel;
894
895 register long
896 j;
897
898 size_t
899 length,
900 profile_length;
901
902 profile_length=GetStringInfoLength(profile);
903 for (i=0; i < (long) profile_length; i+=(long) length)
904 {
905 length=1;
906 sentinel=GetStringInfoDatum(profile)[i++];
907 if (sentinel != 0x1c)
908 continue;
909 dataset=GetStringInfoDatum(profile)[i++];
910 record=GetStringInfoDatum(profile)[i++];
911 switch (record)
912 {
913 case 5: tag="Image Name"; break;
914 case 7: tag="Edit Status"; break;
915 case 10: tag="Priority"; break;
916 case 15: tag="Category"; break;
917 case 20: tag="Supplemental Category"; break;
918 case 22: tag="Fixture Identifier"; break;
919 case 25: tag="Keyword"; break;
920 case 30: tag="Release Date"; break;
921 case 35: tag="Release Time"; break;
922 case 40: tag="Special Instructions"; break;
923 case 45: tag="Reference Service"; break;
924 case 47: tag="Reference Date"; break;
925 case 50: tag="Reference Number"; break;
926 case 55: tag="Created Date"; break;
927 case 60: tag="Created Time"; break;
928 case 65: tag="Originating Program"; break;
929 case 70: tag="Program Version"; break;
930 case 75: tag="Object Cycle"; break;
931 case 80: tag="Byline"; break;
932 case 85: tag="Byline Title"; break;
933 case 90: tag="City"; break;
934 case 95: tag="Province State"; break;
935 case 100: tag="Country Code"; break;
936 case 101: tag="Country"; break;
937 case 103: tag="Original Transmission Reference"; break;
938 case 105: tag="Headline"; break;
939 case 110: tag="Credit"; break;
940 case 115: tag="Src"; break;
941 case 116: tag="Copyright String"; break;
942 case 120: tag="Caption"; break;
943 case 121: tag="Local Caption"; break;
944 case 122: tag="Caption Writer"; break;
945 case 200: tag="Custom Field 1"; break;
946 case 201: tag="Custom Field 2"; break;
947 case 202: tag="Custom Field 3"; break;
948 case 203: tag="Custom Field 4"; break;
949 case 204: tag="Custom Field 5"; break;
950 case 205: tag="Custom Field 6"; break;
951 case 206: tag="Custom Field 7"; break;
952 case 207: tag="Custom Field 8"; break;
953 case 208: tag="Custom Field 9"; break;
954 case 209: tag="Custom Field 10"; break;
955 case 210: tag="Custom Field 11"; break;
956 case 211: tag="Custom Field 12"; break;
957 case 212: tag="Custom Field 13"; break;
958 case 213: tag="Custom Field 14"; break;
959 case 214: tag="Custom Field 15"; break;
960 case 215: tag="Custom Field 16"; break;
961 case 216: tag="Custom Field 17"; break;
962 case 217: tag="Custom Field 18"; break;
963 case 218: tag="Custom Field 19"; break;
964 case 219: tag="Custom Field 20"; break;
965 default: tag="unknown"; break;
966 }
967 (void) fprintf(file," %s[%ld,%ld]: ",tag,dataset,record);
968 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
969 length|=GetStringInfoDatum(profile)[i++];
970 attribute=(char *) NULL;
971 if (~length >= MaxTextExtent)
972 attribute=(char *) AcquireQuantumMemory(length+
973 MaxTextExtent,sizeof(*attribute));
974 if (attribute != (char *) NULL)
975 {
976 (void) CopyMagickString(attribute,(char *)
977 GetStringInfoDatum(profile)+i,length+1);
978 attribute_list=StringToList(attribute);
979 if (attribute_list != (char **) NULL)
980 {
981 for (j=0; attribute_list[j] != (char *) NULL; j++)
982 {
983 (void) fputs(attribute_list[j],file);
984 (void) fputs("\n",file);
985 attribute_list[j]=(char *) RelinquishMagickMemory(
986 attribute_list[j]);
987 }
988 attribute_list=(char **) RelinquishMagickMemory(
989 attribute_list);
990 }
991 attribute=DestroyString(attribute);
992 }
993 }
994 }
995 if (image->debug != MagickFalse)
996 PrintStringInfo(file,name,profile);
997 name=GetNextImageProfile(image);
998 }
999 }
1000 ResetImageArtifactIterator(image);
1001 artifact=GetNextImageArtifact(image);
1002 if (artifact != (const char *) NULL)
1003 {
1004 /*
1005 Display image artifacts.
1006 */
1007 (void) fprintf(file," Artifacts:\n");
1008 while (artifact != (const char *) NULL)
1009 {
1010 (void) fprintf(file," %c",*artifact);
1011 if (strlen(artifact) > 1)
1012 (void) fprintf(file,"%s: ",artifact+1);
1013 if (strlen(artifact) > 80)
1014 (void) fputc('\n',file);
1015 value=GetImageArtifact(image,artifact);
1016 if (value != (const char *) NULL)
1017 (void) fprintf(file,"%s\n",value);
1018 artifact=GetNextImageArtifact(image);
1019 }
1020 }
1021 ResetImageRegistryIterator();
1022 registry=GetNextImageRegistry();
1023 if (registry != (const char *) NULL)
1024 {
1025 /*
1026 Display image registry.
1027 */
1028 (void) fprintf(file," Registry:\n");
1029 while (registry != (const char *) NULL)
1030 {
1031 (void) fprintf(file," %c",*registry);
1032 if (strlen(registry) > 1)
1033 (void) fprintf(file,"%s: ",registry+1);
1034 if (strlen(registry) > 80)
1035 (void) fputc('\n',file);
1036 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1037 &image->exception);
1038 if (value != (const char *) NULL)
1039 (void) fprintf(file,"%s\n",value);
1040 registry=GetNextImageRegistry();
1041 }
1042 }
1043 (void) fprintf(file," Tainted: %s\n",MagickOptionToMnemonic(
1044 MagickBooleanOptions,(long) image->taint));
cristyb9080c92009-12-01 20:13:26 +00001045 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001046 (void) fprintf(file," Filesize: %s\n",format);
cristyb9080c92009-12-01 20:13:26 +00001047 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1048 MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001049 (void) fprintf(file," Number pixels: %s\n",format);
cristy3d231692009-09-29 01:05:22 +00001050 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristyb9080c92009-12-01 20:13:26 +00001051 elapsed_time+0.5),MagickFalse,format);
cristy3d231692009-09-29 01:05:22 +00001052 (void) fprintf(file," Pixels per second: %s\n",format);
1053 (void) fprintf(file," User time: %0.3fu\n",user_time);
1054 (void) fprintf(file," Elapsed time: %ld:%02ld.%03ld\n",(long)
1055 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),(long)
1056 (1000.0*(elapsed_time-floor(elapsed_time))));
1057 (void) fprintf(file," Version: %s\n",GetMagickVersion((unsigned long *)
1058 NULL));
cristy3ed852e2009-09-05 21:47:34 +00001059 (void) fflush(file);
1060 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1061}