blob: d324948c4112693aa2b219b32002b18591ea72ea [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" \
138 " angular second moment:\n" \
139 " %g, %g, %g, %g\n" \
140 " contrast:\n" \
141 " %g, %g, %g, %g\n"
142
143 int
144 status;
145
146 status=fprintf(file,FeaturesFormat,name,
147 channel_features[channel].angular_second_moment[0],
148 channel_features[channel].angular_second_moment[1],
149 channel_features[channel].angular_second_moment[2],
150 channel_features[channel].angular_second_moment[3],
151 channel_features[channel].contrast[0],
152 channel_features[channel].contrast[1],
153 channel_features[channel].contrast[2],
154 channel_features[channel].contrast[3]);
155 return(status);
156}
157
158static int PrintChannelStatistics(FILE *file,const ChannelType channel,
159 const char *name,const double scale,
160 const ChannelStatistics *channel_statistics)
161{
162#define StatisticsFormat " %s:\n min: " QuantumFormat \
cristye7f51092010-01-17 00:39:37 +0000163 " (%g)\n max: " QuantumFormat " (%g)\n" \
164 " mean: %g (%g)\n standard deviation: %g (%g)\n" \
165 " kurtosis: %g\n skewness: %g\n"
cristy3ed852e2009-09-05 21:47:34 +0000166
cristybd822072010-01-27 00:30:00 +0000167 double
168 maxima,
169 mean,
170 minima;
171
172 int
173 status;
174
175 minima=channel_statistics[channel].minima;
176 maxima=channel_statistics[channel].maxima;
177 mean=channel_statistics[channel].mean;
178 if (channel == AlphaChannel)
179 {
180 minima=QuantumRange-minima;
181 maxima=QuantumRange-maxima;
182 mean=QuantumRange-mean;
183 }
184 status=fprintf(file,StatisticsFormat,name,(Quantum) (scale*minima),minima/
185 (double) QuantumRange,(Quantum) (maxima/scale),maxima/(double) QuantumRange,
186 scale*mean,mean/(double) QuantumRange,
187 scale*channel_statistics[channel].standard_deviation,
188 channel_statistics[channel].standard_deviation/(double)
189 QuantumRange,channel_statistics[channel].kurtosis,
190 channel_statistics[channel].skewness);
191 return(status);
192}
193
194MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
195 const MagickBooleanType verbose)
196{
cristy3ed852e2009-09-05 21:47:34 +0000197 char
198 color[MaxTextExtent],
199 format[MaxTextExtent],
200 key[MaxTextExtent];
201
cristybd822072010-01-27 00:30:00 +0000202 ChannelFeatures
203 *channel_features;
204
205 ChannelStatistics
206 *channel_statistics;
207
cristy3ed852e2009-09-05 21:47:34 +0000208 ColorspaceType
209 colorspace;
210
211 const char
212 *artifact,
213 *name,
214 *property,
215 *registry,
216 *value;
217
218 const MagickInfo
219 *magick_info;
220
221 const PixelPacket
222 *pixels;
223
224 double
225 elapsed_time,
226 user_time;
227
228 ExceptionInfo
229 *exception;
230
231 ImageType
232 type;
233
234 long
235 y;
236
237 MagickBooleanType
238 ping;
239
240 register long
241 i,
242 x;
243
244 unsigned long
cristybd822072010-01-27 00:30:00 +0000245 distance,
cristy3ed852e2009-09-05 21:47:34 +0000246 scale;
247
248 assert(image != (Image *) NULL);
249 assert(image->signature == MagickSignature);
250 if (image->debug != MagickFalse)
251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
252 if (file == (FILE *) NULL)
253 file=stdout;
254 *format='\0';
255 elapsed_time=GetElapsedTime(&image->timer);
256 user_time=GetUserTime(&image->timer);
257 GetTimerInfo(&image->timer);
258 if (verbose == MagickFalse)
259 {
260 /*
261 Display summary info about the image.
262 */
263 if (*image->magick_filename != '\0')
264 if (LocaleCompare(image->magick_filename,image->filename) != 0)
265 (void) fprintf(file,"%s=>",image->magick_filename);
266 if ((GetPreviousImageInList(image) == (Image *) NULL) &&
267 (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0))
268 (void) fprintf(file,"%s ",image->filename);
269 else
270 (void) fprintf(file,"%s[%lu] ",image->filename,image->scene);
271 (void) fprintf(file,"%s ",image->magick);
272 if ((image->magick_columns != 0) || (image->magick_rows != 0))
273 if ((image->magick_columns != image->columns) ||
274 (image->magick_rows != image->rows))
275 (void) fprintf(file,"%lux%lu=>",image->magick_columns,
276 image->magick_rows);
277 (void) fprintf(file,"%lux%lu ",image->columns,image->rows);
278 if ((image->page.width != 0) || (image->page.height != 0) ||
279 (image->page.x != 0) || (image->page.y != 0))
280 (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width,
281 image->page.height,image->page.x,image->page.y);
282 (void) fprintf(file,"%lu-bit ",image->depth);
283 if (image->type != UndefinedType)
284 (void) fprintf(file,"%s ",MagickOptionToMnemonic(MagickTypeOptions,
285 (long) image->type));
286 if (image->storage_class == DirectClass)
287 {
288 (void) fprintf(file,"DirectClass ");
289 if (image->total_colors != 0)
290 {
cristyb9080c92009-12-01 20:13:26 +0000291 (void) FormatMagickSize(image->total_colors,MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000292 (void) fprintf(file,"%s ",format);
293 }
294 }
295 else
296 if (image->total_colors <= image->colors)
297 (void) fprintf(file,"PseudoClass %luc ",image->colors);
298 else
299 (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors,
300 image->colors);
301 if (image->error.mean_error_per_pixel != 0.0)
302 (void) fprintf(file,"%ld/%f/%fdb ",(long)
303 (image->error.mean_error_per_pixel+0.5),
304 image->error.normalized_mean_error,
305 image->error.normalized_maximum_error);
306 if (GetBlobSize(image) != 0)
307 {
cristyb9080c92009-12-01 20:13:26 +0000308 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +0000309 (void) fprintf(file,"%s ",format);
310 }
cristy3d231692009-09-29 01:05:22 +0000311 (void) fprintf(file,"%0.3fu %ld:%02ld.%03ld",user_time,(long)
312 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
313 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy3ed852e2009-09-05 21:47:34 +0000314 (void) fprintf(file,"\n");
315 (void) fflush(file);
316 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
317 }
318 /*
319 Display verbose info about the image.
320 */
321 exception=AcquireExceptionInfo();
322 pixels=GetVirtualPixels(image,0,0,1,1,exception);
323 exception=DestroyExceptionInfo(exception);
324 ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse;
325 type=GetImageType(image,&image->exception);
326 (void) SignatureImage(image);
327 (void) fprintf(file,"Image: %s\n",image->filename);
328 if (*image->magick_filename != '\0')
329 if (LocaleCompare(image->magick_filename,image->filename) != 0)
330 {
331 char
332 filename[MaxTextExtent];
333
334 GetPathComponent(image->magick_filename,TailPath,filename);
335 (void) fprintf(file," Base filename: %s\n",filename);
336 }
337 magick_info=GetMagickInfo(image->magick,&image->exception);
338 if ((magick_info == (const MagickInfo *) NULL) ||
339 (*GetMagickDescription(magick_info) == '\0'))
340 (void) fprintf(file," Format: %s\n",image->magick);
341 else
342 (void) fprintf(file," Format: %s (%s)\n",image->magick,
343 GetMagickDescription(magick_info));
344 (void) fprintf(file," Class: %s\n",MagickOptionToMnemonic(MagickClassOptions,
345 (long) image->storage_class));
346 (void) fprintf(file," Geometry: %lux%lu%+ld%+ld\n",image->columns,
347 image->rows,image->tile_offset.x,image->tile_offset.y);
348 if ((image->magick_columns != 0) || (image->magick_rows != 0))
349 if ((image->magick_columns != image->columns) ||
350 (image->magick_rows != image->rows))
351 (void) fprintf(file," Base geometry: %lux%lu\n",image->magick_columns,
352 image->magick_rows);
353 if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
354 {
cristye7f51092010-01-17 00:39:37 +0000355 (void) fprintf(file," Resolution: %gx%g\n",image->x_resolution,
cristy3ed852e2009-09-05 21:47:34 +0000356 image->y_resolution);
cristye7f51092010-01-17 00:39:37 +0000357 (void) fprintf(file," Print size: %gx%g\n",(double) image->columns/
cristy3ed852e2009-09-05 21:47:34 +0000358 image->x_resolution,(double) image->rows/image->y_resolution);
359 }
360 (void) fprintf(file," Units: %s\n",MagickOptionToMnemonic(
361 MagickResolutionOptions,(long) image->units));
362 (void) fprintf(file," Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions,
363 (long) type));
364 if (image->type != UndefinedType)
365 (void) fprintf(file," Base type: %s\n",MagickOptionToMnemonic(
366 MagickTypeOptions,(long) image->type));
367 (void) fprintf(file," Endianess: %s\n",MagickOptionToMnemonic(
368 MagickEndianOptions,(long) image->endian));
369 /*
370 Detail channel depth and extrema.
371 */
372 (void) fprintf(file," Colorspace: %s\n",MagickOptionToMnemonic(
373 MagickColorspaceOptions,(long) image->colorspace));
cristybd822072010-01-27 00:30:00 +0000374 channel_statistics=(ChannelStatistics *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000375 if (ping == MagickFalse)
cristybd822072010-01-27 00:30:00 +0000376 channel_statistics=GetImageChannelStatistics(image,&image->exception);
377 if (channel_statistics != (ChannelStatistics *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000378 {
cristy3ed852e2009-09-05 21:47:34 +0000379 unsigned long
380 depth;
381
382 depth=GetImageDepth(image,&image->exception);
383 if (image->depth == depth)
384 (void) fprintf(file," Depth: %lu-bit\n",image->depth);
385 else
386 (void) fprintf(file," Depth: %lu/%lu-bit\n",image->depth,depth);
cristy3ed852e2009-09-05 21:47:34 +0000387 (void) fprintf(file," Channel depth:\n");
388 colorspace=image->colorspace;
389 if (IsGrayImage(image,&image->exception) != MagickFalse)
390 colorspace=GRAYColorspace;
391 switch (colorspace)
392 {
393 case RGBColorspace:
394 default:
395 {
396 (void) fprintf(file," red: %lu-bit\n",
397 channel_statistics[RedChannel].depth);
398 (void) fprintf(file," green: %lu-bit\n",
399 channel_statistics[GreenChannel].depth);
400 (void) fprintf(file," blue: %lu-bit\n",
401 channel_statistics[BlueChannel].depth);
402 if (image->matte != MagickFalse)
403 (void) fprintf(file," alpha: %lu-bit\n",
404 channel_statistics[OpacityChannel].depth);
405 break;
406 }
407 case CMYKColorspace:
408 {
409 (void) fprintf(file," cyan: %lu-bit\n",
410 channel_statistics[CyanChannel].depth);
411 (void) fprintf(file," magenta: %lu-bit\n",
412 channel_statistics[MagentaChannel].depth);
413 (void) fprintf(file," yellow: %lu-bit\n",
414 channel_statistics[YellowChannel].depth);
415 (void) fprintf(file," black: %lu-bit\n",
416 channel_statistics[BlackChannel].depth);
417 if (image->matte != MagickFalse)
418 (void) fprintf(file," alpha: %lu-bit\n",
419 channel_statistics[OpacityChannel].depth);
420 break;
421 }
422 case GRAYColorspace:
423 {
424 (void) fprintf(file," gray: %lu-bit\n",
425 channel_statistics[GrayChannel].depth);
426 if (image->matte != MagickFalse)
427 (void) fprintf(file," alpha: %lu-bit\n",
428 channel_statistics[OpacityChannel].depth);
429 break;
430 }
431 }
432 scale=1;
433 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
434 scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long)
435 MAGICKCORE_QUANTUM_DEPTH-image->depth));
436 (void) fprintf(file," Channel statistics:\n");
437 switch (colorspace)
438 {
439 case RGBColorspace:
440 default:
441 {
cristybd822072010-01-27 00:30:00 +0000442 (void) PrintChannelStatistics(file,RedChannel,"Red",1.0/scale,
443 channel_statistics);
444 (void) PrintChannelStatistics(file,GreenChannel,"Green",1.0/scale,
445 channel_statistics);
446 (void) PrintChannelStatistics(file,BlueChannel,"Blue",1.0/scale,
447 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000448 break;
449 }
450 case CMYKColorspace:
451 {
cristybd822072010-01-27 00:30:00 +0000452 (void) PrintChannelStatistics(file,CyanChannel,"Cyan",1.0/scale,
453 channel_statistics);
454 (void) PrintChannelStatistics(file,MagentaChannel,"Magenta",1.0/scale,
455 channel_statistics);
456 (void) PrintChannelStatistics(file,YellowChannel,"Yellow",1.0/scale,
457 channel_statistics);
458 (void) PrintChannelStatistics(file,BlackChannel,"Black",1.0/scale,
459 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000460 break;
461 }
462 case GRAYColorspace:
463 {
cristybd822072010-01-27 00:30:00 +0000464 (void) PrintChannelStatistics(file,GrayChannel,"Gray",1.0/scale,
465 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000466 break;
467 }
468 }
469 if (image->matte != MagickFalse)
cristybd822072010-01-27 00:30:00 +0000470 (void) PrintChannelStatistics(file,AlphaChannel,"Alpha",1.0/scale,
471 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000472 if (colorspace != GRAYColorspace)
473 {
474 (void) fprintf(file," Image statistics:\n");
cristybd822072010-01-27 00:30:00 +0000475 (void) PrintChannelStatistics(file,AllChannels,"Overall",1.0/scale,
476 channel_statistics);
cristy3ed852e2009-09-05 21:47:34 +0000477 }
478 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
479 channel_statistics);
cristybd822072010-01-27 00:30:00 +0000480 }
481 channel_features=(ChannelFeatures *) NULL;
482 artifact=GetImageArtifact(image,"identify:features");
cristybd822072010-01-27 00:30:00 +0000483 if ((ping == MagickFalse) && (artifact != (const char *) NULL))
cristy8c02fa12010-01-27 01:10:17 +0000484 {
485 distance=StringToUnsignedLong(artifact);
486 channel_features=GetImageChannelFeatures(image,distance,
487 &image->exception);
488 }
cristybd822072010-01-27 00:30:00 +0000489 if (channel_features != (ChannelFeatures *) NULL)
490 {
cristy7396d882010-01-27 02:37:56 +0000491 (void) fprintf(file," Channel features (horizontal, vertical, left and right diagonals):\n");
cristybd822072010-01-27 00:30:00 +0000492 switch (colorspace)
493 {
494 case RGBColorspace:
495 default:
cristy549a37e2010-01-26 15:24:15 +0000496 {
cristybd822072010-01-27 00:30:00 +0000497 (void) PrintChannelFeatures(file,RedChannel,"Red",1.0/scale,
498 channel_features);
499 (void) PrintChannelFeatures(file,GreenChannel,"Green",1.0/scale,
500 channel_features);
501 (void) PrintChannelFeatures(file,BlueChannel,"Blue",1.0/scale,
502 channel_features);
503 break;
504 }
505 case CMYKColorspace:
506 {
507 (void) PrintChannelFeatures(file,CyanChannel,"Cyan",1.0/scale,
508 channel_features);
509 (void) PrintChannelFeatures(file,MagentaChannel,"Magenta",1.0/
510 scale,channel_features);
511 (void) PrintChannelFeatures(file,YellowChannel,"Yellow",1.0/scale,
512 channel_features);
513 (void) PrintChannelFeatures(file,BlackChannel,"Black",1.0/scale,
514 channel_features);
515 break;
516 }
517 case GRAYColorspace:
518 {
519 (void) PrintChannelFeatures(file,GrayChannel,"Gray",1.0/scale,
520 channel_features);
521 break;
522 }
523 }
524 if (image->matte != MagickFalse)
525 (void) PrintChannelFeatures(file,AlphaChannel,"Alpha",1.0/scale,
526 channel_features);
527 if (colorspace != GRAYColorspace)
528 {
529 (void) fprintf(file," Image features:\n");
530 (void) PrintChannelFeatures(file,AllChannels,"Overall",1.0/scale,
cristy549a37e2010-01-26 15:24:15 +0000531 channel_features);
532 }
cristybd822072010-01-27 00:30:00 +0000533 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
534 channel_features);
535 }
536 if (ping == MagickFalse)
537 {
cristy3ed852e2009-09-05 21:47:34 +0000538 if (image->colorspace == CMYKColorspace)
539 (void) fprintf(file," Total ink density: %.0f%%\n",100.0*
540 GetImageTotalInkDensity(image)/(double) QuantumRange);
541 x=0;
542 if (image->matte != MagickFalse)
543 {
544 register const IndexPacket
545 *indexes;
546
547 register const PixelPacket
548 *p;
549
550 p=(PixelPacket *) NULL;
551 indexes=(IndexPacket *) NULL;
552 for (y=0; y < (long) image->rows; y++)
553 {
554 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
555 if (p == (const PixelPacket *) NULL)
556 break;
557 indexes=GetVirtualIndexQueue(image);
558 for (x=0; x < (long) image->columns; x++)
559 {
560 if (p->opacity == (Quantum) TransparentOpacity)
561 break;
562 p++;
563 }
564 if (x < (long) image->columns)
565 break;
566 }
567 if ((x < (long) image->columns) || (y < (long) image->rows))
568 {
569 char
570 tuple[MaxTextExtent];
571
572 MagickPixelPacket
573 pixel;
574
575 GetMagickPixelPacket(image,&pixel);
576 SetMagickPixelPacket(image,p,indexes+x,&pixel);
577 (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
578 &image->exception);
579 (void) fprintf(file," Alpha: %s ",tuple);
580 GetColorTuple(&pixel,MagickTrue,tuple);
581 (void) fprintf(file," %s\n",tuple);
582 }
583 }
cristy549a37e2010-01-26 15:24:15 +0000584 artifact=GetImageArtifact(image,"identify:unique");
585 if ((artifact != (const char *) NULL) &&
586 (IsMagickTrue(artifact) != MagickFalse))
587 (void) fprintf(file," Colors: %lu\n",GetNumberColors(image,
588 (FILE *) NULL,&image->exception));
589 if (IsHistogramImage(image,&image->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000590 {
cristy549a37e2010-01-26 15:24:15 +0000591 (void) fprintf(file," Histogram:\n");
592 (void) GetNumberColors(image,file,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +0000593 }
594 }
595 if (image->storage_class == PseudoClass)
596 {
597 (void) fprintf(file," Colormap: %lu\n",image->colors);
598 if (image->colors <= 1024)
599 {
600 char
601 color[MaxTextExtent],
602 hex[MaxTextExtent],
603 tuple[MaxTextExtent];
604
605 MagickPixelPacket
606 pixel;
607
608 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000609 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000610
611 GetMagickPixelPacket(image,&pixel);
612 p=image->colormap;
613 for (i=0; i < (long) image->colors; i++)
614 {
615 SetMagickPixelPacket(image,p,(IndexPacket *) NULL,&pixel);
616 (void) CopyMagickString(tuple,"(",MaxTextExtent);
617 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
618 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
619 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
620 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
621 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
622 if (pixel.colorspace == CMYKColorspace)
623 {
624 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
625 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,
626 tuple);
627 }
628 if (pixel.matte != MagickFalse)
629 {
630 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
631 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,
632 tuple);
633 }
634 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
635 (void) QueryMagickColorname(image,&pixel,SVGCompliance,color,
636 &image->exception);
637 GetColorTuple(&pixel,MagickTrue,hex);
638 (void) fprintf(file," %8ld: %s %s %s\n",i,tuple,hex,color);
639 p++;
640 }
641 }
642 }
643 if (image->error.mean_error_per_pixel != 0.0)
cristye7f51092010-01-17 00:39:37 +0000644 (void) fprintf(file," Mean error per pixel: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000645 image->error.mean_error_per_pixel);
646 if (image->error.normalized_mean_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000647 (void) fprintf(file," Normalized mean error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000648 image->error.normalized_mean_error);
649 if (image->error.normalized_maximum_error != 0.0)
cristye7f51092010-01-17 00:39:37 +0000650 (void) fprintf(file," Normalized maximum error: %g\n",
cristy3ed852e2009-09-05 21:47:34 +0000651 image->error.normalized_maximum_error);
652 (void) fprintf(file," Rendering intent: %s\n",MagickOptionToMnemonic(
653 MagickIntentOptions,(long) image->rendering_intent));
654 if (image->gamma != 0.0)
cristye7f51092010-01-17 00:39:37 +0000655 (void) fprintf(file," Gamma: %g\n",image->gamma);
cristy3ed852e2009-09-05 21:47:34 +0000656 if ((image->chromaticity.red_primary.x != 0.0) ||
657 (image->chromaticity.green_primary.x != 0.0) ||
658 (image->chromaticity.blue_primary.x != 0.0) ||
659 (image->chromaticity.white_point.x != 0.0))
660 {
661 /*
662 Display image chromaticity.
663 */
664 (void) fprintf(file," Chromaticity:\n");
cristye7f51092010-01-17 00:39:37 +0000665 (void) fprintf(file," red primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000666 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
cristye7f51092010-01-17 00:39:37 +0000667 (void) fprintf(file," green primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000668 image->chromaticity.green_primary.x,
669 image->chromaticity.green_primary.y);
cristye7f51092010-01-17 00:39:37 +0000670 (void) fprintf(file," blue primary: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000671 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
cristye7f51092010-01-17 00:39:37 +0000672 (void) fprintf(file," white point: (%g,%g)\n",
cristy3ed852e2009-09-05 21:47:34 +0000673 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
674 }
675 if ((image->extract_info.width*image->extract_info.height) != 0)
676 (void) fprintf(file," Tile geometry: %lux%lu%+ld%+ld\n",
677 image->extract_info.width,image->extract_info.height,
678 image->extract_info.x,image->extract_info.y);
679 (void) fprintf(file," Interlace: %s\n",MagickOptionToMnemonic(
680 MagickInterlaceOptions,(long) image->interlace));
681 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
682 &image->exception);
683 (void) fprintf(file," Background color: %s\n",color);
684 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
685 &image->exception);
686 (void) fprintf(file," Border color: %s\n",color);
687 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
688 &image->exception);
689 (void) fprintf(file," Matte color: %s\n",color);
690 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
691 &image->exception);
692 (void) fprintf(file," Transparent color: %s\n",color);
cristy11a77682009-10-11 21:50:20 +0000693 (void) fprintf(file," Compose: %s\n",MagickOptionToMnemonic(
694 MagickComposeOptions,(long) image->compose));
cristy3ed852e2009-09-05 21:47:34 +0000695 if ((image->page.width != 0) || (image->page.height != 0) ||
696 (image->page.x != 0) || (image->page.y != 0))
697 (void) fprintf(file," Page geometry: %lux%lu%+ld%+ld\n",image->page.width,
698 image->page.height,image->page.x,image->page.y);
699 if ((image->page.x != 0) || (image->page.y != 0))
700 (void) fprintf(file," Origin geometry: %+ld%+ld\n",image->page.x,
701 image->page.y);
702 (void) fprintf(file," Dispose: %s\n",MagickOptionToMnemonic(
703 MagickDisposeOptions,(long) image->dispose));
704 if (image->delay != 0)
705 (void) fprintf(file," Delay: %lux%ld\n",image->delay,
706 image->ticks_per_second);
707 if (image->iterations != 1)
708 (void) fprintf(file," Iterations: %lu\n",image->iterations);
709 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
710 (void) fprintf(file," Scene: %lu of %lu\n",image->scene,
711 GetImageListLength(image));
712 else
713 if (image->scene != 0)
714 (void) fprintf(file," Scene: %lu\n",image->scene);
715 (void) fprintf(file," Compression: %s\n",MagickOptionToMnemonic(
716 MagickCompressOptions,(long) image->compression));
717 if (image->quality != UndefinedCompressionQuality)
718 (void) fprintf(file," Quality: %lu\n",image->quality);
719 (void) fprintf(file," Orientation: %s\n",MagickOptionToMnemonic(
720 MagickOrientationOptions,(long) image->orientation));
721 if (image->montage != (char *) NULL)
722 (void) fprintf(file," Montage: %s\n",image->montage);
723 if (image->directory != (char *) NULL)
724 {
725 Image
726 *tile;
727
728 ImageInfo
729 *image_info;
730
731 register char
732 *p,
733 *q;
734
735 WarningHandler
736 handler;
737
738 /*
739 Display visual image directory.
740 */
741 image_info=AcquireImageInfo();
742 (void) CloneString(&image_info->size,"64x64");
743 (void) fprintf(file," Directory:\n");
744 for (p=image->directory; *p != '\0'; p++)
745 {
746 q=p;
747 while ((*q != '\n') && (*q != '\0'))
748 q++;
749 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
750 p=q;
751 (void) fprintf(file," %s",image_info->filename);
752 handler=SetWarningHandler((WarningHandler) NULL);
753 tile=ReadImage(image_info,&image->exception);
754 (void) SetWarningHandler(handler);
755 if (tile == (Image *) NULL)
756 {
757 (void) fprintf(file,"\n");
758 continue;
759 }
760 (void) fprintf(file," %lux%lu %s\n",tile->magick_columns,
761 tile->magick_rows,tile->magick);
762 (void) SignatureImage(tile);
763 ResetImagePropertyIterator(tile);
764 property=GetNextImageProperty(tile);
765 while (property != (const char *) NULL)
766 {
767 (void) fprintf(file," %s:\n",property);
768 value=GetImageProperty(tile,property);
769 if (value != (const char *) NULL)
770 (void) fprintf(file,"%s\n",value);
771 property=GetNextImageProperty(tile);
772 }
773 tile=DestroyImage(tile);
774 }
775 image_info=DestroyImageInfo(image_info);
776 }
777 (void) GetImageProperty(image,"exif:*");
778 ResetImagePropertyIterator(image);
779 property=GetNextImageProperty(image);
780 if (property != (const char *) NULL)
781 {
782 /*
783 Display image properties.
784 */
785 (void) fprintf(file," Properties:\n");
786 while (property != (const char *) NULL)
787 {
788 (void) fprintf(file," %c",*property);
789 if (strlen(property) > 1)
790 (void) fprintf(file,"%s: ",property+1);
791 if (strlen(property) > 80)
792 (void) fputc('\n',file);
793 value=GetImageProperty(image,property);
794 if (value != (const char *) NULL)
795 (void) fprintf(file,"%s\n",value);
796 property=GetNextImageProperty(image);
797 }
798 }
799 (void) FormatMagickString(key,MaxTextExtent,"8BIM:1999,2998:#1");
800 value=GetImageProperty(image,key);
801 if (value != (const char *) NULL)
802 {
803 /*
804 Display clipping path.
805 */
806 (void) fprintf(file," Clipping path: ");
807 if (strlen(value) > 80)
808 (void) fputc('\n',file);
809 (void) fprintf(file,"%s\n",value);
810 }
811 ResetImageProfileIterator(image);
812 name=GetNextImageProfile(image);
813 if (name != (char *) NULL)
814 {
815 const StringInfo
816 *profile;
817
818 /*
819 Identify image profiles.
820 */
821 (void) fprintf(file," Profiles:\n");
822 while (name != (char *) NULL)
823 {
824 profile=GetImageProfile(image,name);
825 if (profile == (StringInfo *) NULL)
826 continue;
827 (void) fprintf(file," Profile-%s: %lu bytes\n",name,(unsigned long)
828 GetStringInfoLength(profile));
829#if defined(MAGICKCORE_LCMS_DELEGATE)
830 if ((LocaleCompare(name,"icc") == 0) ||
831 (LocaleCompare(name,"icm") == 0))
832 {
833 cmsHPROFILE
834 icc_profile;
835
836 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
837 (DWORD) GetStringInfoLength(profile));
838 if (icc_profile != (cmsHPROFILE *) NULL)
839 {
840 const char
841 *name;
842
843 name=cmsTakeProductName(icc_profile);
844 if (name != (const char *) NULL)
845 (void) fprintf(file," %s\n",name);
846 (void) cmsCloseProfile(icc_profile);
847 }
848 }
849#endif
850 if (LocaleCompare(name,"iptc") == 0)
851 {
852 char
853 *attribute,
854 **attribute_list;
855
856 const char
857 *tag;
858
859 long
860 dataset,
861 record,
862 sentinel;
863
864 register long
865 j;
866
867 size_t
868 length,
869 profile_length;
870
871 profile_length=GetStringInfoLength(profile);
872 for (i=0; i < (long) profile_length; i+=(long) length)
873 {
874 length=1;
875 sentinel=GetStringInfoDatum(profile)[i++];
876 if (sentinel != 0x1c)
877 continue;
878 dataset=GetStringInfoDatum(profile)[i++];
879 record=GetStringInfoDatum(profile)[i++];
880 switch (record)
881 {
882 case 5: tag="Image Name"; break;
883 case 7: tag="Edit Status"; break;
884 case 10: tag="Priority"; break;
885 case 15: tag="Category"; break;
886 case 20: tag="Supplemental Category"; break;
887 case 22: tag="Fixture Identifier"; break;
888 case 25: tag="Keyword"; break;
889 case 30: tag="Release Date"; break;
890 case 35: tag="Release Time"; break;
891 case 40: tag="Special Instructions"; break;
892 case 45: tag="Reference Service"; break;
893 case 47: tag="Reference Date"; break;
894 case 50: tag="Reference Number"; break;
895 case 55: tag="Created Date"; break;
896 case 60: tag="Created Time"; break;
897 case 65: tag="Originating Program"; break;
898 case 70: tag="Program Version"; break;
899 case 75: tag="Object Cycle"; break;
900 case 80: tag="Byline"; break;
901 case 85: tag="Byline Title"; break;
902 case 90: tag="City"; break;
903 case 95: tag="Province State"; break;
904 case 100: tag="Country Code"; break;
905 case 101: tag="Country"; break;
906 case 103: tag="Original Transmission Reference"; break;
907 case 105: tag="Headline"; break;
908 case 110: tag="Credit"; break;
909 case 115: tag="Src"; break;
910 case 116: tag="Copyright String"; break;
911 case 120: tag="Caption"; break;
912 case 121: tag="Local Caption"; break;
913 case 122: tag="Caption Writer"; break;
914 case 200: tag="Custom Field 1"; break;
915 case 201: tag="Custom Field 2"; break;
916 case 202: tag="Custom Field 3"; break;
917 case 203: tag="Custom Field 4"; break;
918 case 204: tag="Custom Field 5"; break;
919 case 205: tag="Custom Field 6"; break;
920 case 206: tag="Custom Field 7"; break;
921 case 207: tag="Custom Field 8"; break;
922 case 208: tag="Custom Field 9"; break;
923 case 209: tag="Custom Field 10"; break;
924 case 210: tag="Custom Field 11"; break;
925 case 211: tag="Custom Field 12"; break;
926 case 212: tag="Custom Field 13"; break;
927 case 213: tag="Custom Field 14"; break;
928 case 214: tag="Custom Field 15"; break;
929 case 215: tag="Custom Field 16"; break;
930 case 216: tag="Custom Field 17"; break;
931 case 217: tag="Custom Field 18"; break;
932 case 218: tag="Custom Field 19"; break;
933 case 219: tag="Custom Field 20"; break;
934 default: tag="unknown"; break;
935 }
936 (void) fprintf(file," %s[%ld,%ld]: ",tag,dataset,record);
937 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
938 length|=GetStringInfoDatum(profile)[i++];
939 attribute=(char *) NULL;
940 if (~length >= MaxTextExtent)
941 attribute=(char *) AcquireQuantumMemory(length+
942 MaxTextExtent,sizeof(*attribute));
943 if (attribute != (char *) NULL)
944 {
945 (void) CopyMagickString(attribute,(char *)
946 GetStringInfoDatum(profile)+i,length+1);
947 attribute_list=StringToList(attribute);
948 if (attribute_list != (char **) NULL)
949 {
950 for (j=0; attribute_list[j] != (char *) NULL; j++)
951 {
952 (void) fputs(attribute_list[j],file);
953 (void) fputs("\n",file);
954 attribute_list[j]=(char *) RelinquishMagickMemory(
955 attribute_list[j]);
956 }
957 attribute_list=(char **) RelinquishMagickMemory(
958 attribute_list);
959 }
960 attribute=DestroyString(attribute);
961 }
962 }
963 }
964 if (image->debug != MagickFalse)
965 PrintStringInfo(file,name,profile);
966 name=GetNextImageProfile(image);
967 }
968 }
969 ResetImageArtifactIterator(image);
970 artifact=GetNextImageArtifact(image);
971 if (artifact != (const char *) NULL)
972 {
973 /*
974 Display image artifacts.
975 */
976 (void) fprintf(file," Artifacts:\n");
977 while (artifact != (const char *) NULL)
978 {
979 (void) fprintf(file," %c",*artifact);
980 if (strlen(artifact) > 1)
981 (void) fprintf(file,"%s: ",artifact+1);
982 if (strlen(artifact) > 80)
983 (void) fputc('\n',file);
984 value=GetImageArtifact(image,artifact);
985 if (value != (const char *) NULL)
986 (void) fprintf(file,"%s\n",value);
987 artifact=GetNextImageArtifact(image);
988 }
989 }
990 ResetImageRegistryIterator();
991 registry=GetNextImageRegistry();
992 if (registry != (const char *) NULL)
993 {
994 /*
995 Display image registry.
996 */
997 (void) fprintf(file," Registry:\n");
998 while (registry != (const char *) NULL)
999 {
1000 (void) fprintf(file," %c",*registry);
1001 if (strlen(registry) > 1)
1002 (void) fprintf(file,"%s: ",registry+1);
1003 if (strlen(registry) > 80)
1004 (void) fputc('\n',file);
1005 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1006 &image->exception);
1007 if (value != (const char *) NULL)
1008 (void) fprintf(file,"%s\n",value);
1009 registry=GetNextImageRegistry();
1010 }
1011 }
1012 (void) fprintf(file," Tainted: %s\n",MagickOptionToMnemonic(
1013 MagickBooleanOptions,(long) image->taint));
cristyb9080c92009-12-01 20:13:26 +00001014 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001015 (void) fprintf(file," Filesize: %s\n",format);
cristyb9080c92009-12-01 20:13:26 +00001016 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1017 MagickFalse,format);
cristy3ed852e2009-09-05 21:47:34 +00001018 (void) fprintf(file," Number pixels: %s\n",format);
cristy3d231692009-09-29 01:05:22 +00001019 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristyb9080c92009-12-01 20:13:26 +00001020 elapsed_time+0.5),MagickFalse,format);
cristy3d231692009-09-29 01:05:22 +00001021 (void) fprintf(file," Pixels per second: %s\n",format);
1022 (void) fprintf(file," User time: %0.3fu\n",user_time);
1023 (void) fprintf(file," Elapsed time: %ld:%02ld.%03ld\n",(long)
1024 (elapsed_time/60.0),(long) ceil(fmod(elapsed_time,60.0)),(long)
1025 (1000.0*(elapsed_time-floor(elapsed_time))));
1026 (void) fprintf(file," Version: %s\n",GetMagickVersion((unsigned long *)
1027 NULL));
cristy3ed852e2009-09-05 21:47:34 +00001028 (void) fflush(file);
1029 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1030}