2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % JJJJJ SSSSS OOO N N %
13 % Write Info About the Image in JSON Format. %
20 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/artifact.h"
44 #include "MagickCore/attribute.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/blob-private.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/colorspace.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/feature.h"
54 #include "MagickCore/image.h"
55 #include "MagickCore/image-private.h"
56 #include "MagickCore/list.h"
57 #include "MagickCore/magick.h"
58 #include "MagickCore/memory_.h"
59 #include "MagickCore/monitor.h"
60 #include "MagickCore/monitor-private.h"
61 #include "MagickCore/option.h"
62 #include "MagickCore/pixel.h"
63 #include "MagickCore/pixel-accessor.h"
64 #include "MagickCore/pixel-private.h"
65 #include "MagickCore/prepress.h"
66 #include "MagickCore/property.h"
67 #include "MagickCore/quantum-private.h"
68 #include "MagickCore/registry.h"
69 #include "MagickCore/signature.h"
70 #include "MagickCore/static.h"
71 #include "MagickCore/statistic.h"
72 #include "MagickCore/string_.h"
73 #include "MagickCore/string-private.h"
74 #include "MagickCore/utility.h"
75 #include "MagickCore/version.h"
76 #include "MagickCore/module.h"
81 static MagickBooleanType
82 WriteJSONImage(const ImageInfo *,Image *,ExceptionInfo *);
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 % R e g i s t e r J S O N I m a g e %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % RegisterJSONImage() adds attributes for the JSON image format to
96 % the list of supported formats. The attributes include the image format
97 % tag, a method to read and/or write the format, whether the format
98 % supports the saving of more than one frame to the same file or blob,
99 % whether the format supports native in-memory I/O, and a brief
100 % description of the format.
102 % The format of the RegisterJSONImage method is:
104 % size_t RegisterJSONImage(void)
107 ModuleExport size_t RegisterJSONImage(void)
112 entry=SetMagickInfo("JSON");
113 entry->encoder=(EncodeImageHandler *) WriteJSONImage;
114 entry->blob_support=MagickFalse;
115 entry->description=ConstantString("The image format and characteristics");
116 entry->module=ConstantString("JSON");
117 (void) RegisterMagickInfo(entry);
118 return(MagickImageCoderSignature);
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 % U n r e g i s t e r J S O N I m a g e %
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 % UnregisterJSONImage() removes format registrations made by the
133 % JSON module from the list of supported formats.
135 % The format of the UnregisterJSONImage method is:
137 % UnregisterJSONImage(void)
140 ModuleExport void UnregisterJSONImage(void)
142 (void) UnregisterMagickInfo("JSON");
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 % W r i t e J S O N I m a g e %
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 % WriteJSONImage writes the image attributes in the JSON format.
158 % The format of the WriteJSONImage method is:
160 % MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
161 % Image *image,ExceptionInfo *exception)
163 % A description of each parameter follows.
165 % o image_info: the image info.
167 % o image: The image.
169 % o exception: return any errors or warnings in this structure.
173 static ChannelStatistics *GetLocationStatistics(const Image *image,
174 const StatisticType type,ExceptionInfo *exception)
185 assert(image != (Image *) NULL);
186 assert(image->signature == MagickSignature);
187 if (image->debug != MagickFalse)
188 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
189 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
190 MaxPixelChannels+1,sizeof(*channel_statistics));
191 if (channel_statistics == (ChannelStatistics *) NULL)
192 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
193 (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
194 sizeof(*channel_statistics));
195 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
199 case MaximumStatistic:
202 channel_statistics[i].maxima=(-MagickMaximumValue);
205 case MinimumStatistic:
207 channel_statistics[i].minima=MagickMaximumValue;
212 for (y=0; y < (ssize_t) image->rows; y++)
214 register const Quantum
220 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
221 if (p == (const Quantum *) NULL)
223 for (x=0; x < (ssize_t) image->columns; x++)
228 if (GetPixelReadMask(image,p) == 0)
230 p+=GetPixelChannels(image);
233 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
235 PixelChannel channel=GetPixelChannelChannel(image,i);
236 PixelTrait traits=GetPixelChannelTraits(image,channel);
237 if (traits == UndefinedPixelTrait)
241 case MaximumStatistic:
244 if ((double) p[i] > channel_statistics[channel].maxima)
245 channel_statistics[channel].maxima=(double) p[i];
248 case MinimumStatistic:
250 if ((double) p[i] < channel_statistics[channel].minima)
251 channel_statistics[channel].minima=(double) p[i];
256 p+=GetPixelChannels(image);
259 return(channel_statistics);
262 static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
263 const char *name,const ChannelFeatures *channel_features)
265 #define PrintFeature(feature) \
266 GetMagickPrecision(),(feature)[0], \
267 GetMagickPrecision(),(feature)[1], \
268 GetMagickPrecision(),(feature)[2], \
269 GetMagickPrecision(),(feature)[3], \
270 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
272 #define FeaturesFormat " %s:\n" \
273 " Angular Second Moment:\n" \
274 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
276 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
278 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
279 " Sum of Squares: Variance:\n" \
280 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
281 " Inverse Difference Moment:\n" \
282 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
284 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
286 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
288 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
290 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
291 " Difference Variance:\n" \
292 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
293 " Difference Entropy:\n" \
294 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
295 " Information Measure of Correlation 1:\n" \
296 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
297 " Information Measure of Correlation 2:\n" \
298 " %.*g, %.*g, %.*g, %.*g, %.*g\n" \
299 " Maximum Correlation Coefficient:\n" \
300 " %.*g, %.*g, %.*g, %.*g, %.*g\n"
305 n=FormatLocaleFile(file,FeaturesFormat,name,
306 PrintFeature(channel_features[channel].angular_second_moment),
307 PrintFeature(channel_features[channel].contrast),
308 PrintFeature(channel_features[channel].correlation),
309 PrintFeature(channel_features[channel].variance_sum_of_squares),
310 PrintFeature(channel_features[channel].inverse_difference_moment),
311 PrintFeature(channel_features[channel].sum_average),
312 PrintFeature(channel_features[channel].sum_variance),
313 PrintFeature(channel_features[channel].sum_entropy),
314 PrintFeature(channel_features[channel].entropy),
315 PrintFeature(channel_features[channel].difference_variance),
316 PrintFeature(channel_features[channel].difference_entropy),
317 PrintFeature(channel_features[channel].measure_of_correlation_1),
318 PrintFeature(channel_features[channel].measure_of_correlation_2),
319 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
323 static ssize_t PrintChannelLocations(FILE *file,const Image *image,
324 const PixelChannel channel,const char *name,const StatisticType type,
325 const size_t max_locations,const ChannelStatistics *channel_statistics)
339 case MaximumStatistic:
342 target=channel_statistics[channel].maxima;
345 case MinimumStatistic:
347 target=channel_statistics[channel].minima;
351 (void) FormatLocaleFile(file," %s: %.*g (%.*g)",name,GetMagickPrecision(),
352 target,GetMagickPrecision(),QuantumScale*target);
353 exception=AcquireExceptionInfo();
355 for (y=0; y < (ssize_t) image->rows; y++)
357 register const Quantum
364 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
365 if (p == (const Quantum *) NULL)
367 for (x=0; x < (ssize_t) image->columns; x++)
372 PixelTrait traits=GetPixelChannelTraits(image,channel);
373 if (traits == UndefinedPixelTrait)
375 offset=GetPixelChannelOffset(image,channel);
376 match=fabs((double) p[offset]-target) < 0.5 ? MagickTrue : MagickFalse;
377 if (match != MagickFalse)
379 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
381 (void) FormatLocaleFile(file," %.20g,%.20g",(double) x,(double) y);
384 p+=GetPixelChannels(image);
386 if (x < (ssize_t) image->columns)
389 (void) FormatLocaleFile(file,"\n");
393 static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
394 const char *name,const ChannelMoments *channel_moments)
402 n=FormatLocaleFile(file," %s:\n",name);
403 n+=FormatLocaleFile(file," Centroid: %.*g,%.*g\n",
404 GetMagickPrecision(),channel_moments[channel].centroid.x,
405 GetMagickPrecision(),channel_moments[channel].centroid.y);
406 n+=FormatLocaleFile(file," Ellipse Semi-Major/Minor axis: %.*g,%.*g\n",
407 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
408 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
409 n+=FormatLocaleFile(file," Ellipse angle: %.*g\n",
410 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
411 n+=FormatLocaleFile(file," Ellipse eccentricity: %.*g\n",
412 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
413 n+=FormatLocaleFile(file," Ellipse intensity: %.*g\n",
414 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
415 for (i=0; i < 8; i++)
416 n+=FormatLocaleFile(file," I%.20g: %.*g\n",i+1.0,GetMagickPrecision(),
417 channel_moments[channel].I[i]);
421 static ssize_t PrintChannelPerceptualHash(FILE *file,const ChannelType channel,
422 const char *name,const MagickBooleanType separator,
423 const ChannelPerceptualHash *channel_phash)
431 n=FormatLocaleFile(file," \"%s\": {\n",name);
432 for (i=0; i < 6; i++)
433 n+=FormatLocaleFile(file,
434 " \"PH%.20g\": [ \"%.*g\", \"%.*g\" ],\n",i+1.0,
435 GetMagickPrecision(),channel_phash[channel].P[i],
436 GetMagickPrecision(),channel_phash[channel].Q[i]);
437 n+=FormatLocaleFile(file,
438 " \"PH%.20g\": [ \"%.*g\", \"%.*g\" ]\n",i+1.0,
439 GetMagickPrecision(),channel_phash[channel].P[i],
440 GetMagickPrecision(),channel_phash[channel].Q[i]);
441 (void) FormatLocaleFile(file," }");
442 if (separator != MagickFalse)
443 (void) FormatLocaleFile(file,",");
444 (void) FormatLocaleFile(file,"\n");
448 static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
449 const char *name,const double scale,
450 const ChannelStatistics *channel_statistics)
452 #define StatisticsFormat " %s:\n min: " QuantumFormat \
453 " (%g)\n max: " QuantumFormat " (%g)\n" \
454 " mean: %g (%g)\n standard deviation: %g (%g)\n" \
455 " kurtosis: %g\n skewness: %g\n"
460 n=FormatLocaleFile(file,StatisticsFormat,name,ClampToQuantum(scale*
461 channel_statistics[channel].minima),channel_statistics[channel].minima/
462 (double) QuantumRange,ClampToQuantum(scale*
463 channel_statistics[channel].maxima),channel_statistics[channel].maxima/
464 (double) QuantumRange,scale*channel_statistics[channel].mean,
465 channel_statistics[channel].mean/(double) QuantumRange,scale*
466 channel_statistics[channel].standard_deviation,
467 channel_statistics[channel].standard_deviation/(double) QuantumRange,
468 channel_statistics[channel].kurtosis,channel_statistics[channel].skewness);
472 static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
473 ExceptionInfo *exception)
476 color[MaxTextExtent],
477 format[MaxTextExtent],
486 ChannelPerceptualHash
516 register const Quantum
530 assert(image != (Image *) NULL);
531 assert(image->signature == MagickSignature);
532 if (image->debug != MagickFalse)
533 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
534 if (file == (FILE *) NULL)
537 elapsed_time=GetElapsedTime(&image->timer);
538 user_time=GetUserTime(&image->timer);
539 GetTimerInfo(&image->timer);
540 p=GetVirtualPixels(image,0,0,1,1,exception);
541 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
542 type=GetImageType(image,exception);
543 (void) SignatureImage(image,exception);
544 (void) FormatLocaleFile(file,"Image: %s\n",image->filename);
545 if (*image->magick_filename != '\0')
546 if (LocaleCompare(image->magick_filename,image->filename) != 0)
549 filename[MaxTextExtent];
551 GetPathComponent(image->magick_filename,TailPath,filename);
552 (void) FormatLocaleFile(file," Base filename: %s\n",filename);
554 magick_info=GetMagickInfo(image->magick,exception);
555 if ((magick_info == (const MagickInfo *) NULL) ||
556 (GetMagickDescription(magick_info) == (const char *) NULL))
557 (void) FormatLocaleFile(file," Format: %s\n",image->magick);
559 (void) FormatLocaleFile(file," Format: %s (%s)\n",image->magick,
560 GetMagickDescription(magick_info));
561 if ((magick_info == (const MagickInfo *) NULL) ||
562 (GetMagickMimeType(magick_info) != (const char *) NULL))
563 (void) FormatLocaleFile(file," Mime type: %s\n",GetMagickMimeType(
565 (void) FormatLocaleFile(file," Class: %s\n",CommandOptionToMnemonic(
566 MagickClassOptions,(ssize_t) image->storage_class));
567 (void) FormatLocaleFile(file," Geometry: %.20gx%.20g%+.20g%+.20g\n",(double)
568 image->columns,(double) image->rows,(double) image->tile_offset.x,(double)
569 image->tile_offset.y);
570 if ((image->magick_columns != 0) || (image->magick_rows != 0))
571 if ((image->magick_columns != image->columns) ||
572 (image->magick_rows != image->rows))
573 (void) FormatLocaleFile(file," Base geometry: %.20gx%.20g\n",(double)
574 image->magick_columns,(double) image->magick_rows);
575 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
577 (void) FormatLocaleFile(file," Resolution: %gx%g\n",image->resolution.x,
578 image->resolution.y);
579 (void) FormatLocaleFile(file," Print size: %gx%g\n",(double)
580 image->columns/image->resolution.x,(double) image->rows/
581 image->resolution.y);
583 (void) FormatLocaleFile(file," Units: %s\n",CommandOptionToMnemonic(
584 MagickResolutionOptions,(ssize_t) image->units));
585 (void) FormatLocaleFile(file," Type: %s\n",CommandOptionToMnemonic(
586 MagickTypeOptions,(ssize_t) type));
587 if (image->type != UndefinedType)
588 (void) FormatLocaleFile(file," Base type: %s\n",CommandOptionToMnemonic(
589 MagickTypeOptions,(ssize_t) image->type));
590 (void) FormatLocaleFile(file," Endianess: %s\n",CommandOptionToMnemonic(
591 MagickEndianOptions,(ssize_t) image->endian));
592 locate=GetImageArtifact(image,"identify:locate");
593 if (locate == (const char *) NULL)
594 locate=GetImageArtifact(image,"json:locate");
595 if (locate != (const char *) NULL)
607 Display minimum, maximum, or mean pixel locations.
609 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
611 limit=GetImageArtifact(image,"identify:limit");
612 if (limit == (const char *) NULL)
613 limit=GetImageArtifact(image,"json:limit");
615 if (limit != (const char *) NULL)
616 max_locations=StringToUnsignedLong(limit);
617 channel_statistics=GetLocationStatistics(image,type,exception);
618 if (channel_statistics == (ChannelStatistics *) NULL)
620 colorspace=image->colorspace;
621 if (IsImageGray(image,exception) != MagickFalse)
622 colorspace=GRAYColorspace;
623 (void) FormatLocaleFile(file,"Channel %s locations:\n",locate);
629 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
630 type,max_locations,channel_statistics);
631 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
632 type,max_locations,channel_statistics);
633 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
634 type,max_locations,channel_statistics);
639 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
640 type,max_locations,channel_statistics);
641 (void) PrintChannelLocations(file,image,MagentaPixelChannel,"Magenta",
642 type,max_locations,channel_statistics);
643 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
644 type,max_locations,channel_statistics);
645 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
646 type,max_locations,channel_statistics);
651 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
652 type,max_locations,channel_statistics);
656 if (image->alpha_trait == BlendPixelTrait)
657 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
658 type,max_locations,channel_statistics);
659 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
663 Detail channel depth and extrema.
665 (void) FormatLocaleFile(file," Colorspace: %s\n",CommandOptionToMnemonic(
666 MagickColorspaceOptions,(ssize_t) image->colorspace));
667 channel_statistics=(ChannelStatistics *) NULL;
668 channel_moments=(ChannelMoments *) NULL;
669 channel_phash=(ChannelPerceptualHash *) NULL;
670 channel_features=(ChannelFeatures *) NULL;
671 colorspace=image->colorspace;
673 if (ping == MagickFalse)
678 channel_statistics=GetImageStatistics(image,exception);
679 if (channel_statistics == (ChannelStatistics *) NULL)
681 artifact=GetImageArtifact(image,"identify:moments");
682 if (artifact == (const char *) NULL)
683 artifact=GetImageArtifact(image,"json:moments");
684 if (artifact != (const char *) NULL)
686 channel_moments=GetImageMoments(image,exception);
687 channel_phash=GetImagePerceptualHash(image,exception);
689 artifact=GetImageArtifact(image,"identify:features");
690 if (artifact == (const char *) NULL)
691 artifact=GetImageArtifact(image,"json:features");
692 if (artifact != (const char *) NULL)
694 distance=StringToUnsignedLong(artifact);
695 channel_features=GetImageFeatures(image,distance,exception);
697 depth=GetImageDepth(image,exception);
698 if (image->depth == depth)
699 (void) FormatLocaleFile(file," Depth: %.20g-bit\n",(double)
702 (void) FormatLocaleFile(file," Depth: %.20g/%.20g-bit\n",(double)
703 image->depth,(double) depth);
704 (void) FormatLocaleFile(file," Channel depth:\n");
705 if (IsImageGray(image,exception) != MagickFalse)
706 colorspace=GRAYColorspace;
712 (void) FormatLocaleFile(file," Red: %.20g-bit\n",(double)
713 channel_statistics[RedPixelChannel].depth);
714 (void) FormatLocaleFile(file," Green: %.20g-bit\n",(double)
715 channel_statistics[GreenPixelChannel].depth);
716 (void) FormatLocaleFile(file," Blue: %.20g-bit\n",(double)
717 channel_statistics[BluePixelChannel].depth);
722 (void) FormatLocaleFile(file," Cyan: %.20g-bit\n",(double)
723 channel_statistics[CyanPixelChannel].depth);
724 (void) FormatLocaleFile(file," Magenta: %.20g-bit\n",(double)
725 channel_statistics[MagentaPixelChannel].depth);
726 (void) FormatLocaleFile(file," Yellow: %.20g-bit\n",(double)
727 channel_statistics[YellowPixelChannel].depth);
728 (void) FormatLocaleFile(file," Black: %.20g-bit\n",(double)
729 channel_statistics[BlackPixelChannel].depth);
734 (void) FormatLocaleFile(file," Gray: %.20g-bit\n",(double)
735 channel_statistics[GrayPixelChannel].depth);
739 if (image->alpha_trait == BlendPixelTrait)
740 (void) FormatLocaleFile(file," alpha: %.20g-bit\n",(double)
741 channel_statistics[AlphaPixelChannel].depth);
743 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
744 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
745 MAGICKCORE_QUANTUM_DEPTH-image->depth));
747 if (channel_statistics != (ChannelStatistics *) NULL)
749 (void) FormatLocaleFile(file," Channel statistics:\n");
750 (void) FormatLocaleFile(file," Pixels: %.20g\n",
751 channel_statistics[CompositePixelChannel].area);
757 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/
758 scale,channel_statistics);
759 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
760 scale,channel_statistics);
761 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/
762 scale,channel_statistics);
767 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/
768 scale,channel_statistics);
769 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
770 scale,channel_statistics);
771 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
772 scale,channel_statistics);
773 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
774 scale,channel_statistics);
779 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/
780 scale,channel_statistics);
784 if (image->alpha_trait == BlendPixelTrait)
785 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/
786 scale,channel_statistics);
787 if (colorspace != GRAYColorspace)
789 (void) FormatLocaleFile(file," Image statistics:\n");
790 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
791 "Overall",1.0/scale,channel_statistics);
793 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
796 if (channel_moments != (ChannelMoments *) NULL)
798 (void) FormatLocaleFile(file," Channel moments:\n");
804 (void) PrintChannelMoments(file,RedPixelChannel,"Red",
806 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",
808 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",
814 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",
816 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
818 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
820 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
826 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",
831 if (image->alpha_trait == BlendPixelTrait)
832 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",
834 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
837 if (channel_phash != (ChannelPerceptualHash *) NULL)
839 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
840 if (image->alpha_trait == BlendPixelTrait)
841 (void) PrintChannelPerceptualHash(file,AlphaChannel,"alphaAlpha",
842 MagickTrue,channel_phash);
843 (void) PrintChannelPerceptualHash(file,RedChannel,"redHue",MagickTrue,
845 (void) PrintChannelPerceptualHash(file,GreenChannel,"greenChroma",
846 MagickTrue,channel_phash);
847 (void) PrintChannelPerceptualHash(file,BlueChannel,"blueLuma",MagickFalse,
849 (void) FormatLocaleFile(file," },\n");
850 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
853 if (channel_features != (ChannelFeatures *) NULL)
855 (void) FormatLocaleFile(file," Channel features (horizontal, vertical, "
856 "left and right diagonals, average):\n");
862 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",
864 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
866 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",
872 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",
874 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
876 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
878 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
884 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",
889 if (image->alpha_trait == BlendPixelTrait)
890 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",
892 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
895 if (ping == MagickFalse)
897 if (image->colorspace == CMYKColorspace)
898 (void) FormatLocaleFile(file," Total ink density: %.0f%%\n",100.0*
899 GetImageTotalInkDensity(image,exception)/(double) QuantumRange);
901 if (image->alpha_trait == BlendPixelTrait)
903 register const Quantum
906 p=(const Quantum *) NULL;
907 for (y=0; y < (ssize_t) image->rows; y++)
909 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
910 if (p == (const Quantum *) NULL)
912 for (x=0; x < (ssize_t) image->columns; x++)
914 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
916 p+=GetPixelChannels(image);
918 if (x < (ssize_t) image->columns)
921 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
924 tuple[MaxTextExtent];
929 GetPixelInfo(image,&pixel);
930 GetPixelInfoPixel(image,p,&pixel);
931 (void) QueryColorname(image,&pixel,SVGCompliance,tuple,
933 (void) FormatLocaleFile(file," Alpha: %s ",tuple);
934 GetColorTuple(&pixel,MagickTrue,tuple);
935 (void) FormatLocaleFile(file," %s\n",tuple);
939 if (image->storage_class == PseudoClass)
941 (void) FormatLocaleFile(file," Colormap entries: %.20g\n",(double)
943 (void) FormatLocaleFile(file," Colormap:\n");
944 if (image->colors <= 1024)
947 color[MaxTextExtent],
949 tuple[MaxTextExtent];
957 GetPixelInfo(image,&pixel);
959 for (i=0; i < (ssize_t) image->colors; i++)
962 (void) CopyMagickString(tuple,"(",MaxTextExtent);
963 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,
965 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
966 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,
968 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
969 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,
971 if (pixel.colorspace == CMYKColorspace)
973 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
974 ConcatenateColorComponent(&pixel,BlackPixelChannel,
975 X11Compliance,tuple);
977 if (pixel.alpha_trait == BlendPixelTrait)
979 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
980 ConcatenateColorComponent(&pixel,AlphaPixelChannel,
981 X11Compliance,tuple);
983 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
984 (void) QueryColorname(image,&pixel,SVGCompliance,color,
986 GetColorTuple(&pixel,MagickTrue,hex);
987 (void) FormatLocaleFile(file," %8ld: %s %s %s\n",(long) i,tuple,
993 if (image->error.mean_error_per_pixel != 0.0)
994 (void) FormatLocaleFile(file," Mean error per pixel: %g\n",
995 image->error.mean_error_per_pixel);
996 if (image->error.normalized_mean_error != 0.0)
997 (void) FormatLocaleFile(file," Normalized mean error: %g\n",
998 image->error.normalized_mean_error);
999 if (image->error.normalized_maximum_error != 0.0)
1000 (void) FormatLocaleFile(file," Normalized maximum error: %g\n",
1001 image->error.normalized_maximum_error);
1002 (void) FormatLocaleFile(file," Rendering intent: %s\n",
1003 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1004 image->rendering_intent));
1005 if (image->gamma != 0.0)
1006 (void) FormatLocaleFile(file," Gamma: %g\n",image->gamma);
1007 if ((image->chromaticity.red_primary.x != 0.0) ||
1008 (image->chromaticity.green_primary.x != 0.0) ||
1009 (image->chromaticity.blue_primary.x != 0.0) ||
1010 (image->chromaticity.white_point.x != 0.0))
1013 Display image chromaticity.
1015 (void) FormatLocaleFile(file," Chromaticity:\n");
1016 (void) FormatLocaleFile(file," red primary: (%g,%g)\n",
1017 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
1018 (void) FormatLocaleFile(file," green primary: (%g,%g)\n",
1019 image->chromaticity.green_primary.x,
1020 image->chromaticity.green_primary.y);
1021 (void) FormatLocaleFile(file," blue primary: (%g,%g)\n",
1022 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
1023 (void) FormatLocaleFile(file," white point: (%g,%g)\n",
1024 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
1026 if ((image->extract_info.width*image->extract_info.height) != 0)
1027 (void) FormatLocaleFile(file," Tile geometry: %.20gx%.20g%+.20g%+.20g\n",
1028 (double) image->extract_info.width,(double) image->extract_info.height,
1029 (double) image->extract_info.x,(double) image->extract_info.y);
1030 (void) QueryColorname(image,&image->background_color,SVGCompliance,color,
1032 (void) FormatLocaleFile(file," Background color: %s\n",color);
1033 (void) QueryColorname(image,&image->border_color,SVGCompliance,color,
1035 (void) FormatLocaleFile(file," Border color: %s\n",color);
1036 (void) QueryColorname(image,&image->matte_color,SVGCompliance,color,
1038 (void) FormatLocaleFile(file," Matte color: %s\n",color);
1039 (void) QueryColorname(image,&image->transparent_color,SVGCompliance,color,
1041 (void) FormatLocaleFile(file," Transparent color: %s\n",color);
1042 (void) FormatLocaleFile(file," Interlace: %s\n",CommandOptionToMnemonic(
1043 MagickInterlaceOptions,(ssize_t) image->interlace));
1044 (void) FormatLocaleFile(file," Intensity: %s\n",CommandOptionToMnemonic(
1045 MagickPixelIntensityOptions,(ssize_t) image->intensity));
1046 (void) FormatLocaleFile(file," Compose: %s\n",CommandOptionToMnemonic(
1047 MagickComposeOptions,(ssize_t) image->compose));
1048 if ((image->page.width != 0) || (image->page.height != 0) ||
1049 (image->page.x != 0) || (image->page.y != 0))
1050 (void) FormatLocaleFile(file," Page geometry: %.20gx%.20g%+.20g%+.20g\n",
1051 (double) image->page.width,(double) image->page.height,(double)
1052 image->page.x,(double) image->page.y);
1053 if ((image->page.x != 0) || (image->page.y != 0))
1054 (void) FormatLocaleFile(file," Origin geometry: %+.20g%+.20g\n",(double)
1055 image->page.x,(double) image->page.y);
1056 (void) FormatLocaleFile(file," Dispose: %s\n",CommandOptionToMnemonic(
1057 MagickDisposeOptions,(ssize_t) image->dispose));
1058 if (image->delay != 0)
1059 (void) FormatLocaleFile(file," Delay: %.20gx%.20g\n",(double) image->delay,
1060 (double) image->ticks_per_second);
1061 if (image->iterations != 1)
1062 (void) FormatLocaleFile(file," Iterations: %.20g\n",(double)
1064 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
1065 (void) FormatLocaleFile(file," Scene: %.20g of %.20g\n",(double)
1066 image->scene,(double) GetImageListLength(image));
1068 if (image->scene != 0)
1069 (void) FormatLocaleFile(file," Scene: %.20g\n",(double) image->scene);
1070 (void) FormatLocaleFile(file," Compression: %s\n",CommandOptionToMnemonic(
1071 MagickCompressOptions,(ssize_t) image->compression));
1072 if (image->quality != UndefinedCompressionQuality)
1073 (void) FormatLocaleFile(file," Quality: %.20g\n",(double) image->quality);
1074 (void) FormatLocaleFile(file," Orientation: %s\n",CommandOptionToMnemonic(
1075 MagickOrientationOptions,(ssize_t) image->orientation));
1076 if (image->montage != (char *) NULL)
1077 (void) FormatLocaleFile(file," Montage: %s\n",image->montage);
1078 if (image->directory != (char *) NULL)
1094 Display visual image directory.
1096 image_info=AcquireImageInfo();
1097 (void) CloneString(&image_info->size,"64x64");
1098 (void) FormatLocaleFile(file," Directory:\n");
1099 for (p=image->directory; *p != '\0'; p++)
1102 while ((*q != '\n') && (*q != '\0'))
1104 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
1106 (void) FormatLocaleFile(file," %s",image_info->filename);
1107 handler=SetWarningHandler((WarningHandler) NULL);
1108 tile=ReadImage(image_info,exception);
1109 (void) SetWarningHandler(handler);
1110 if (tile == (Image *) NULL)
1112 (void) FormatLocaleFile(file,"\n");
1115 (void) FormatLocaleFile(file," %.20gx%.20g %s\n",(double)
1116 tile->magick_columns,(double) tile->magick_rows,tile->magick);
1117 (void) SignatureImage(tile,exception);
1118 ResetImagePropertyIterator(tile);
1119 property=GetNextImageProperty(tile);
1120 while (property != (const char *) NULL)
1122 (void) FormatLocaleFile(file," %s:\n",property);
1123 value=GetImageProperty(tile,property,exception);
1124 if (value != (const char *) NULL)
1125 (void) FormatLocaleFile(file,"%s\n",value);
1126 property=GetNextImageProperty(tile);
1128 tile=DestroyImage(tile);
1130 image_info=DestroyImageInfo(image_info);
1132 (void) GetImageProperty(image,"exif:*",exception);
1133 (void) GetImageProperty(image,"icc:*",exception);
1134 (void) GetImageProperty(image,"iptc:*",exception);
1135 (void) GetImageProperty(image,"xmp:*",exception);
1136 ResetImagePropertyIterator(image);
1137 property=GetNextImageProperty(image);
1138 if (property != (const char *) NULL)
1141 Display image properties.
1143 (void) FormatLocaleFile(file," Properties:\n");
1144 while (property != (const char *) NULL)
1146 (void) FormatLocaleFile(file," %s: ",property);
1147 value=GetImageProperty(image,property,exception);
1148 if (value != (const char *) NULL)
1149 (void) FormatLocaleFile(file,"%s\n",value);
1150 property=GetNextImageProperty(image);
1153 (void) FormatLocaleString(key,MaxTextExtent,"8BIM:1999,2998:#1");
1154 value=GetImageProperty(image,key,exception);
1155 if (value != (const char *) NULL)
1158 Display clipping path.
1160 (void) FormatLocaleFile(file," Clipping path: ");
1161 if (strlen(value) > 80)
1162 (void) fputc('\n',file);
1163 (void) FormatLocaleFile(file,"%s\n",value);
1165 ResetImageProfileIterator(image);
1166 name=GetNextImageProfile(image);
1167 if (name != (char *) NULL)
1173 Identify image profiles.
1175 (void) FormatLocaleFile(file," Profiles:\n");
1176 while (name != (char *) NULL)
1178 profile=GetImageProfile(image,name);
1179 if (profile == (StringInfo *) NULL)
1181 (void) FormatLocaleFile(file," Profile-%s: %.20g bytes\n",name,
1182 (double) GetStringInfoLength(profile));
1183 if (LocaleCompare(name,"iptc") == 0)
1204 profile_length=GetStringInfoLength(profile);
1205 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
1208 sentinel=GetStringInfoDatum(profile)[i++];
1209 if (sentinel != 0x1c)
1211 dataset=GetStringInfoDatum(profile)[i++];
1212 record=GetStringInfoDatum(profile)[i++];
1215 case 5: tag="Image Name"; break;
1216 case 7: tag="Edit Status"; break;
1217 case 10: tag="Priority"; break;
1218 case 15: tag="Category"; break;
1219 case 20: tag="Supplemental Category"; break;
1220 case 22: tag="Fixture Identifier"; break;
1221 case 25: tag="Keyword"; break;
1222 case 30: tag="Release Date"; break;
1223 case 35: tag="Release Time"; break;
1224 case 40: tag="Special Instructions"; break;
1225 case 45: tag="Reference Service"; break;
1226 case 47: tag="Reference Date"; break;
1227 case 50: tag="Reference Number"; break;
1228 case 55: tag="Created Date"; break;
1229 case 60: tag="Created Time"; break;
1230 case 65: tag="Originating Program"; break;
1231 case 70: tag="Program Version"; break;
1232 case 75: tag="Object Cycle"; break;
1233 case 80: tag="Byline"; break;
1234 case 85: tag="Byline Title"; break;
1235 case 90: tag="City"; break;
1236 case 95: tag="Province State"; break;
1237 case 100: tag="Country Code"; break;
1238 case 101: tag="Country"; break;
1239 case 103: tag="Original Transmission Reference"; break;
1240 case 105: tag="Headline"; break;
1241 case 110: tag="Credit"; break;
1242 case 115: tag="Src"; break;
1243 case 116: tag="Copyright String"; break;
1244 case 120: tag="Caption"; break;
1245 case 121: tag="Local Caption"; break;
1246 case 122: tag="Caption Writer"; break;
1247 case 200: tag="Custom Field 1"; break;
1248 case 201: tag="Custom Field 2"; break;
1249 case 202: tag="Custom Field 3"; break;
1250 case 203: tag="Custom Field 4"; break;
1251 case 204: tag="Custom Field 5"; break;
1252 case 205: tag="Custom Field 6"; break;
1253 case 206: tag="Custom Field 7"; break;
1254 case 207: tag="Custom Field 8"; break;
1255 case 208: tag="Custom Field 9"; break;
1256 case 209: tag="Custom Field 10"; break;
1257 case 210: tag="Custom Field 11"; break;
1258 case 211: tag="Custom Field 12"; break;
1259 case 212: tag="Custom Field 13"; break;
1260 case 213: tag="Custom Field 14"; break;
1261 case 214: tag="Custom Field 15"; break;
1262 case 215: tag="Custom Field 16"; break;
1263 case 216: tag="Custom Field 17"; break;
1264 case 217: tag="Custom Field 18"; break;
1265 case 218: tag="Custom Field 19"; break;
1266 case 219: tag="Custom Field 20"; break;
1267 default: tag="unknown"; break;
1269 (void) FormatLocaleFile(file," %s[%.20g,%.20g]: ",tag,
1270 (double) dataset,(double) record);
1271 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
1272 length|=GetStringInfoDatum(profile)[i++];
1273 attribute=(char *) NULL;
1274 if (~length >= (MaxTextExtent-1))
1275 attribute=(char *) AcquireQuantumMemory(length+MaxTextExtent,
1276 sizeof(*attribute));
1277 if (attribute != (char *) NULL)
1279 (void) CopyMagickString(attribute,(char *)
1280 GetStringInfoDatum(profile)+i,length+1);
1281 attribute_list=StringToList(attribute);
1282 if (attribute_list != (char **) NULL)
1284 for (j=0; attribute_list[j] != (char *) NULL; j++)
1286 (void) fputs(attribute_list[j],file);
1287 (void) fputs("\n",file);
1288 attribute_list[j]=(char *) RelinquishMagickMemory(
1291 attribute_list=(char **) RelinquishMagickMemory(
1294 attribute=DestroyString(attribute);
1298 if (image->debug != MagickFalse)
1299 PrintStringInfo(file,name,profile);
1300 name=GetNextImageProfile(image);
1303 ResetImageArtifactIterator(image);
1304 artifact=GetNextImageArtifact(image);
1305 if (artifact != (const char *) NULL)
1308 Display image artifacts.
1310 (void) FormatLocaleFile(file," Artifacts:\n");
1311 while (artifact != (const char *) NULL)
1313 (void) FormatLocaleFile(file," %s: ",artifact);
1314 value=GetImageArtifact(image,artifact);
1315 if (value != (const char *) NULL)
1316 (void) FormatLocaleFile(file,"%s\n",value);
1317 artifact=GetNextImageArtifact(image);
1320 ResetImageRegistryIterator();
1321 registry=GetNextImageRegistry();
1322 if (registry != (const char *) NULL)
1325 Display image registry.
1327 (void) FormatLocaleFile(file," Registry:\n");
1328 while (registry != (const char *) NULL)
1330 (void) FormatLocaleFile(file," %s: ",registry);
1331 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1333 if (value != (const char *) NULL)
1334 (void) FormatLocaleFile(file,"%s\n",value);
1335 registry=GetNextImageRegistry();
1338 (void) FormatLocaleFile(file," Tainted: %s\n",CommandOptionToMnemonic(
1339 MagickBooleanOptions,(ssize_t) image->taint));
1340 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
1341 (void) FormatLocaleFile(file," Filesize: %s\n",format);
1342 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1343 MagickFalse,format);
1344 if (strlen(format) > 1)
1345 format[strlen(format)-1]='\0';
1346 (void) FormatLocaleFile(file," Number pixels: %s\n",format);
1347 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
1348 elapsed_time+0.5),MagickFalse,format);
1349 (void) FormatLocaleFile(file," Pixels per second: %s\n",format);
1350 (void) FormatLocaleFile(file," User time: %0.3fu\n",user_time);
1351 (void) FormatLocaleFile(file," Elapsed time: %lu:%02lu.%03lu\n",
1352 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(elapsed_time,
1353 60.0)),(unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))));
1354 (void) FormatLocaleFile(file," Version: %s\n",GetMagickVersion((size_t *)
1356 (void) fflush(file);
1357 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1360 static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1361 Image *image,ExceptionInfo *exception)
1370 Open output image file.
1372 assert(image_info != (const ImageInfo *) NULL);
1373 assert(image_info->signature == MagickSignature);
1374 assert(image != (Image *) NULL);
1375 assert(image->signature == MagickSignature);
1376 if (image->debug != MagickFalse)
1377 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1378 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1379 if (status == MagickFalse)
1384 (void) CopyMagickString(image->filename,image->magick_filename,
1386 image->magick_columns=image->columns;
1387 image->magick_rows=image->rows;
1388 (void) EncodeImageAttributes(image,GetBlobFileHandle(image),exception);
1389 if (GetNextImageInList(image) == (Image *) NULL)
1391 image=SyncNextImageInList(image);
1392 status=SetImageProgress(image,SaveImagesTag,scene++,
1393 GetImageListLength(image));
1394 if (status == MagickFalse)
1396 } while (image_info->adjoin != MagickFalse);
1397 (void) CloseBlob(image);