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