2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % JJJJJ SSSSS OOO N N %
13 % Write Info About the Image in JSON Format. %
20 % Copyright 1999-2017 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 % https://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 typedef struct _IPTCInfo
98 static MagickBooleanType
99 WriteJSONImage(const ImageInfo *,Image *,ExceptionInfo *);
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 % R e g i s t e r J S O N I m a g e %
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 % RegisterJSONImage() adds attributes for the JSON image format to
113 % the list of supported formats. The attributes include the image format
114 % tag, a method to read and/or write the format, whether the format
115 % supports the saving of more than one frame to the same file or blob,
116 % whether the format supports native in-memory I/O, and a brief
117 % description of the format.
119 % The format of the RegisterJSONImage method is:
121 % size_t RegisterJSONImage(void)
124 ModuleExport size_t RegisterJSONImage(void)
129 entry=AcquireMagickInfo("JSON","JSON","The image format and characteristics");
130 entry->encoder=(EncodeImageHandler *) WriteJSONImage;
131 entry->mime_type=ConstantString("application/json");
132 entry->flags^=CoderBlobSupportFlag;
133 (void) RegisterMagickInfo(entry);
134 return(MagickImageCoderSignature);
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % U n r e g i s t e r J S O N I m a g e %
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % UnregisterJSONImage() removes format registrations made by the
149 % JSON module from the list of supported formats.
151 % The format of the UnregisterJSONImage method is:
153 % UnregisterJSONImage(void)
156 ModuleExport void UnregisterJSONImage(void)
158 (void) UnregisterMagickInfo("JSON");
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 % W r i t e J S O N I m a g e %
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 % WriteJSONImage writes the image attributes in the JSON format.
174 % The format of the WriteJSONImage method is:
176 % MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
177 % Image *image,ExceptionInfo *exception)
179 % A description of each parameter follows.
181 % o image_info: the image info.
183 % o image: The image.
185 % o exception: return any errors or warnings in this structure.
189 static void JSONFormatLocaleFile(FILE *file,const char *format,
204 assert(format != (const char *) NULL);
205 if ((value == (char *) NULL) || (*value == '\0'))
207 (void) FormatLocaleFile(file,format,"null");
210 length=strlen(value)+2;
212 Find all the chars that need escaping and increase the dest length counter.
214 for (p=value; *p != '\0'; p++)
233 if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
239 escaped_json=(char *) NULL;
240 if (~length >= (MagickPathExtent-1))
241 escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent,
242 sizeof(*escaped_json));
243 if (escaped_json == (char *) NULL)
245 (void) FormatLocaleFile(file,format,"null");
250 for (p=value; *p != '\0'; p++)
298 if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
300 (void) FormatLocaleString(q,7,"\\u%04X",(int) *p);
311 (void) FormatLocaleFile(file,format,escaped_json);
312 (void) DestroyString(escaped_json);
315 static ChannelStatistics *GetLocationStatistics(const Image *image,
316 const StatisticType type,ExceptionInfo *exception)
327 assert(image != (Image *) NULL);
328 assert(image->signature == MagickCoreSignature);
329 if (image->debug != MagickFalse)
330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
331 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
332 MaxPixelChannels+1,sizeof(*channel_statistics));
333 if (channel_statistics == (ChannelStatistics *) NULL)
334 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
335 (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
336 sizeof(*channel_statistics));
337 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
341 case MaximumStatistic:
344 channel_statistics[i].maxima=(-MagickMaximumValue);
347 case MinimumStatistic:
349 channel_statistics[i].minima=MagickMaximumValue;
354 for (y=0; y < (ssize_t) image->rows; y++)
356 register const Quantum
362 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
363 if (p == (const Quantum *) NULL)
365 for (x=0; x < (ssize_t) image->columns; x++)
370 if (GetPixelReadMask(image,p) <= (QuantumRange/2))
372 p+=GetPixelChannels(image);
375 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
377 PixelChannel channel = GetPixelChannelChannel(image,i);
378 PixelTrait traits = GetPixelChannelTraits(image,channel);
379 if (traits == UndefinedPixelTrait)
383 case MaximumStatistic:
386 if ((double) p[i] > channel_statistics[channel].maxima)
387 channel_statistics[channel].maxima=(double) p[i];
390 case MinimumStatistic:
392 if ((double) p[i] < channel_statistics[channel].minima)
393 channel_statistics[channel].minima=(double) p[i];
398 p+=GetPixelChannels(image);
401 return(channel_statistics);
404 static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
405 const char *name,const MagickBooleanType separator,
406 const ChannelFeatures *channel_features)
408 #define PrintFeature(feature) \
409 GetMagickPrecision(),(feature)[0], \
410 GetMagickPrecision(),(feature)[1], \
411 GetMagickPrecision(),(feature)[2], \
412 GetMagickPrecision(),(feature)[3], \
413 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
415 #define FeaturesFormat " \"%s\": {\n" \
416 " \"angularSecondMoment\": {\n" \
417 " \"horizontal\": %.*g,\n" \
418 " \"vertical\": %.*g,\n" \
419 " \"leftDiagonal\": %.*g,\n" \
420 " \"rightDiagonal\": %.*g,\n" \
421 " \"average\": %.*g\n" \
423 " \"contrast\": {\n" \
424 " \"horizontal\": %.*g,\n" \
425 " \"vertical\": %.*g,\n" \
426 " \"leftDiagonal\": %.*g,\n" \
427 " \"rightDiagonal\": %.*g,\n" \
428 " \"average\": %.*g\n" \
430 " \"correlation\": {\n" \
431 " \"horizontal\": %.*g,\n" \
432 " \"vertical\": %.*g,\n" \
433 " \"leftDiagonal\": %.*g,\n" \
434 " \"rightDiagonal\": %.*g,\n" \
435 " \"average\": %.*g\n" \
437 " \"sumOfSquaresVariance\": {\n" \
438 " \"horizontal\": %.*g,\n" \
439 " \"vertical\": %.*g,\n" \
440 " \"leftDiagonal\": %.*g,\n" \
441 " \"rightDiagonal\": %.*g,\n" \
442 " \"average\": %.*g\n" \
444 " \"inverseDifferenceMoment\": {\n" \
445 " \"horizontal\": %.*g,\n" \
446 " \"vertical\": %.*g,\n" \
447 " \"leftDiagonal\": %.*g,\n" \
448 " \"rightDiagonal\": %.*g,\n" \
449 " \"average\": %.*g\n" \
451 " \"sumAverage\": {\n" \
452 " \"horizontal\": %.*g,\n" \
453 " \"vertical\": %.*g,\n" \
454 " \"leftDiagonal\": %.*g,\n" \
455 " \"rightDiagonal\": %.*g,\n" \
456 " \"average\": %.*g\n" \
458 " \"sumVariance\": {\n" \
459 " \"horizontal\": %.*g,\n" \
460 " \"vertical\": %.*g,\n" \
461 " \"leftDiagonal\": %.*g,\n" \
462 " \"rightDiagonal\": %.*g,\n" \
463 " \"average\": %.*g\n" \
465 " \"sumEntropy\": {\n" \
466 " \"horizontal\": %.*g,\n" \
467 " \"vertical\": %.*g,\n" \
468 " \"leftDiagonal\": %.*g,\n" \
469 " \"rightDiagonal\": %.*g,\n" \
470 " \"average\": %.*g\n" \
472 " \"entropy\": {\n" \
473 " \"horizontal\": %.*g,\n" \
474 " \"vertical\": %.*g,\n" \
475 " \"leftDiagonal\": %.*g,\n" \
476 " \"rightDiagonal\": %.*g,\n" \
477 " \"average\": %.*g\n" \
479 " \"differenceVariance\": {\n" \
480 " \"horizontal\": %.*g,\n" \
481 " \"vertical\": %.*g,\n" \
482 " \"leftDiagonal\": %.*g,\n" \
483 " \"rightDiagonal\": %.*g,\n" \
484 " \"average\": %.*g\n" \
486 " \"differenceEntropy\": {\n" \
487 " \"horizontal\": %.*g,\n" \
488 " \"vertical\": %.*g,\n" \
489 " \"leftDiagonal\": %.*g,\n" \
490 " \"rightDiagonal\": %.*g,\n" \
491 " \"average\": %.*g\n" \
493 " \"informationMeasureOfCorrelation1\": {\n" \
494 " \"horizontal\": %.*g,\n" \
495 " \"vertical\": %.*g,\n" \
496 " \"leftDiagonal\": %.*g,\n" \
497 " \"rightDiagonal\": %.*g,\n" \
498 " \"average\": %.*g\n" \
500 " \"informationMeasureOfCorrelation2\": {\n" \
501 " \"horizontal\": %.*g,\n" \
502 " \"vertical\": %.*g,\n" \
503 " \"leftDiagonal\": %.*g,\n" \
504 " \"rightDiagonal\": %.*g,\n" \
505 " \"average\": %.*g\n" \
507 " \"maximumCorrelationCoefficient\": {\n" \
508 " \"horizontal\": %.*g,\n" \
509 " \"vertical\": %.*g,\n" \
510 " \"leftDiagonal\": %.*g,\n" \
511 " \"rightDiagonal\": %.*g,\n" \
512 " \"average\": %.*g\n" \
518 n=FormatLocaleFile(file,FeaturesFormat,name,
519 PrintFeature(channel_features[channel].angular_second_moment),
520 PrintFeature(channel_features[channel].contrast),
521 PrintFeature(channel_features[channel].correlation),
522 PrintFeature(channel_features[channel].variance_sum_of_squares),
523 PrintFeature(channel_features[channel].inverse_difference_moment),
524 PrintFeature(channel_features[channel].sum_average),
525 PrintFeature(channel_features[channel].sum_variance),
526 PrintFeature(channel_features[channel].sum_entropy),
527 PrintFeature(channel_features[channel].entropy),
528 PrintFeature(channel_features[channel].difference_variance),
529 PrintFeature(channel_features[channel].difference_entropy),
530 PrintFeature(channel_features[channel].measure_of_correlation_1),
531 PrintFeature(channel_features[channel].measure_of_correlation_2),
532 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
533 (void) FormatLocaleFile(file," }");
534 if (separator != MagickFalse)
535 (void) FormatLocaleFile(file,",");
536 (void) FormatLocaleFile(file,"\n");
540 static ssize_t PrintChannelLocations(FILE *file,const Image *image,
541 const PixelChannel channel,const char *name,const StatisticType type,
542 const size_t max_locations,const MagickBooleanType separator,
543 const ChannelStatistics *channel_statistics)
557 case MaximumStatistic:
560 target=channel_statistics[channel].maxima;
563 case MinimumStatistic:
565 target=channel_statistics[channel].minima;
569 (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": "
570 "%.*g,\n",name,GetMagickPrecision(),QuantumScale*target);
571 exception=AcquireExceptionInfo();
573 for (y=0; y < (ssize_t) image->rows; y++)
575 register const Quantum
582 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
583 if (p == (const Quantum *) NULL)
585 for (x=0; x < (ssize_t) image->columns; x++)
590 PixelTrait traits = GetPixelChannelTraits(image,channel);
591 if (traits == UndefinedPixelTrait)
593 offset=GetPixelChannelOffset(image,channel);
594 match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse;
595 if (match != MagickFalse)
597 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
600 (void) FormatLocaleFile(file,",\n");
601 (void) FormatLocaleFile(file," \"location%.20g\": {\n"
602 " \"x\": %.20g,\n \"y\": %.20g\n"
603 " }",(double) n,(double) x,(double) y);
606 p+=GetPixelChannels(image);
608 if (x < (ssize_t) image->columns)
611 (void) FormatLocaleFile(file,"\n }");
612 if (separator != MagickFalse)
613 (void) FormatLocaleFile(file,",");
614 (void) FormatLocaleFile(file,"\n");
618 static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
619 const char *name,const MagickBooleanType separator,
620 const ChannelMoments *channel_moments)
628 n=FormatLocaleFile(file," \"%s\": {\n",name);
629 n+=FormatLocaleFile(file," \"centroid\": {\n "
631 " \"y\": %.*g\n },\n",
632 GetMagickPrecision(),channel_moments[channel].centroid.x,
633 GetMagickPrecision(),channel_moments[channel].centroid.y);
634 n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n"
636 " \"y\": %.*g\n },\n",
637 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
638 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
639 n+=FormatLocaleFile(file," \"ellipseAngle\": %.*g,\n",
640 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
641 n+=FormatLocaleFile(file," \"ellipseEccentricity\": %.*g,\n",
642 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
643 n+=FormatLocaleFile(file," \"ellipseIntensity\": %.*g,\n",
644 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
645 for (i=0; i < 7; i++)
646 n+=FormatLocaleFile(file," \"I%.20g\": %.*g,\n",i+1.0,
647 GetMagickPrecision(),channel_moments[channel].invariant[i]);
648 n+=FormatLocaleFile(file," \"I%.20g\": %.*g\n",i+1.0,
649 GetMagickPrecision(),channel_moments[channel].invariant[i]);
650 (void) FormatLocaleFile(file," }");
651 if (separator != MagickFalse)
652 (void) FormatLocaleFile(file,",");
653 (void) FormatLocaleFile(file,"\n");
657 static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
658 const ChannelPerceptualHash *channel_phash)
666 (void) FormatLocaleFile(file," \"colorspaces\": [ ");
667 for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
669 (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic(
670 MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
671 if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
672 (void) FormatLocaleFile(file,", ");
674 (void) FormatLocaleFile(file,"],\n");
675 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
680 PixelChannel channel = GetPixelChannelChannel(image,i);
681 PixelTrait traits = GetPixelChannelTraits(image,channel);
682 if (traits == UndefinedPixelTrait)
684 n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel);
685 for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
690 n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1);
691 for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
693 n+=FormatLocaleFile(file,"%.*g",GetMagickPrecision(),
694 channel_phash[channel].phash[k][j]);
695 if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
696 n+=FormatLocaleFile(file,", ");
698 n+=FormatLocaleFile(file,"]");
699 if (j < (MaximumNumberOfPerceptualHashes-1))
700 n+=FormatLocaleFile(file,",\n");
702 if (i < (ssize_t) (GetPixelChannels(image)-1))
703 n+=FormatLocaleFile(file,"\n },\n");
705 n+=FormatLocaleFile(file,"\n }\n");
709 static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
710 const char *name,const double scale,const MagickBooleanType separator,
711 const ChannelStatistics *channel_statistics)
713 #define StatisticsFormat " \"%s\": {\n \"min\": %.*g,\n" \
714 " \"max\": %.*g,\n \"mean\": %.*g,\n " \
715 "\"standardDeviation\": %.*g,\n \"kurtosis\": %.*g,\n "\
716 "\"skewness\": %.*g,\n \"entropy\": %.*g\n }"
721 n=FormatLocaleFile(file,StatisticsFormat,name,GetMagickPrecision(),
722 (double) ClampToQuantum(scale*channel_statistics[channel].minima),
723 GetMagickPrecision(),(double) ClampToQuantum(scale*
724 channel_statistics[channel].maxima),GetMagickPrecision(),scale*
725 channel_statistics[channel].mean,GetMagickPrecision(),scale*
726 channel_statistics[channel].standard_deviation,GetMagickPrecision(),
727 channel_statistics[channel].kurtosis,GetMagickPrecision(),
728 channel_statistics[channel].skewness,GetMagickPrecision(),
729 channel_statistics[channel].entropy);
730 if (separator != MagickFalse)
731 (void) FormatLocaleFile(file,",");
732 (void) FormatLocaleFile(file,"\n");
736 static void EncodeIptcProfile(FILE *file,const StringInfo *profile)
764 values=(IPTCInfo **) NULL;
766 profile_length=GetStringInfoLength(profile);
767 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
770 sentinel=GetStringInfoDatum(profile)[i++];
771 if (sentinel != 0x1c)
773 dataset=GetStringInfoDatum(profile)[i++];
774 record=GetStringInfoDatum(profile)[i++];
775 value=(IPTCInfo *) NULL;
776 for (j=0; j < (ssize_t) count; j++)
778 if ((values[j]->record == record) && (values[j]->dataset == dataset))
781 if (value == (IPTCInfo *) NULL)
783 values=(IPTCInfo **) ResizeQuantumMemory(values,count+1,
785 if (values == (IPTCInfo **) NULL)
787 value=(IPTCInfo *) AcquireMagickMemory(sizeof(*value));
788 if (value == (IPTCInfo *) NULL)
790 /* Check the tag length in IPTCInfo when a new tag is added */
793 case 5: tag="Image Name"; break;
794 case 7: tag="Edit Status"; break;
795 case 10: tag="Priority"; break;
796 case 15: tag="Category"; break;
797 case 20: tag="Supplemental Category"; break;
798 case 22: tag="Fixture Identifier"; break;
799 case 25: tag="Keyword"; break;
800 case 30: tag="Release Date"; break;
801 case 35: tag="Release Time"; break;
802 case 40: tag="Special Instructions"; break;
803 case 45: tag="Reference Service"; break;
804 case 47: tag="Reference Date"; break;
805 case 50: tag="Reference Number"; break;
806 case 55: tag="Created Date"; break;
807 case 60: tag="Created Time"; break;
808 case 65: tag="Originating Program"; break;
809 case 70: tag="Program Version"; break;
810 case 75: tag="Object Cycle"; break;
811 case 80: tag="Byline"; break;
812 case 85: tag="Byline Title"; break;
813 case 90: tag="City"; break;
814 case 92: tag="Sub-Location"; break;
815 case 95: tag="Province State"; break;
816 case 100: tag="Country Code"; break;
817 case 101: tag="Country"; break;
818 case 103: tag="Original Transmission Reference"; break;
819 case 105: tag="Headline"; break;
820 case 110: tag="Credit"; break;
821 case 115: tag="Src"; break;
822 case 116: tag="Copyright String"; break;
823 case 120: tag="Caption"; break;
824 case 121: tag="Local Caption"; break;
825 case 122: tag="Caption Writer"; break;
826 case 200: tag="Custom Field 1"; break;
827 case 201: tag="Custom Field 2"; break;
828 case 202: tag="Custom Field 3"; break;
829 case 203: tag="Custom Field 4"; break;
830 case 204: tag="Custom Field 5"; break;
831 case 205: tag="Custom Field 6"; break;
832 case 206: tag="Custom Field 7"; break;
833 case 207: tag="Custom Field 8"; break;
834 case 208: tag="Custom Field 9"; break;
835 case 209: tag="Custom Field 10"; break;
836 case 210: tag="Custom Field 11"; break;
837 case 211: tag="Custom Field 12"; break;
838 case 212: tag="Custom Field 13"; break;
839 case 213: tag="Custom Field 14"; break;
840 case 214: tag="Custom Field 15"; break;
841 case 215: tag="Custom Field 16"; break;
842 case 216: tag="Custom Field 17"; break;
843 case 217: tag="Custom Field 18"; break;
844 case 218: tag="Custom Field 19"; break;
845 case 219: tag="Custom Field 20"; break;
846 default: tag="Unknown"; break;
848 (void) CopyMagickString(value->tag,tag,strlen(tag)+1);
849 value->record=record;
850 value->dataset=dataset;
851 value->values=(char ***) NULL;
852 value->values_length=0;
853 values[count++]=value;
855 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
856 length|=GetStringInfoDatum(profile)[i++];
857 attribute=(char *) NULL;
858 if (~length >= (MagickPathExtent-1))
859 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
861 if (attribute != (char *) NULL)
863 (void) CopyMagickString(attribute,(char *)
864 GetStringInfoDatum(profile)+i,length+1);
865 attribute_list=StringToList(attribute);
866 if (attribute_list != (char **) NULL)
868 value->values=(char ***) ResizeQuantumMemory(value->values,
869 value->values_length+1,
870 sizeof(*value->values));
871 if (value->values == (char ***) NULL)
873 value->values[value->values_length++]=attribute_list;
875 attribute=DestroyString(attribute);
878 if (values != (IPTCInfo **) NULL)
880 for (i=0; i < (ssize_t) count; i++)
883 (void) FormatLocaleFile(file," \"%s[%.20g,%.20g]\": ",
884 value->tag,(double) value->dataset,(double) value->record);
885 if (value->values_length == 0)
886 (void) FormatLocaleFile(file,"null,");
889 (void) FormatLocaleFile(file,"[");
890 for (j=0; j < (ssize_t) value->values_length; j++)
892 for (k=0; value->values[j][k] != (char *) NULL; k++)
895 (void) FormatLocaleFile(file,",");
896 JSONFormatLocaleFile(file,"%s",value->values[j][k]);
897 value->values[j][k]=(char *) RelinquishMagickMemory(
898 value->values[j][k]);
900 value->values[j]=(char **) RelinquishMagickMemory(
903 value->values=(char ***) RelinquishMagickMemory(value->values);
904 (void) FormatLocaleFile(file,"],\n");
906 values[i]=(IPTCInfo *) RelinquishMagickMemory(values[i]);
908 values=(IPTCInfo **) RelinquishMagickMemory(values);
912 static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
913 ExceptionInfo *exception)
916 color[MagickPathExtent],
917 format[MagickPathExtent],
918 key[MagickPathExtent];
926 ChannelPerceptualHash
960 register const Quantum
975 assert(image != (Image *) NULL);
976 assert(image->signature == MagickCoreSignature);
977 if (image->debug != MagickFalse)
978 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
980 elapsed_time=GetElapsedTime(&image->timer);
981 user_time=GetUserTime(&image->timer);
982 GetTimerInfo(&image->timer);
983 p=GetVirtualPixels(image,0,0,1,1,exception);
984 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
986 (void) SignatureImage(image,exception);
987 JSONFormatLocaleFile(file,"{\n \"image\": {\n \"name\": %s,\n",
989 if (*image->magick_filename != '\0')
990 if (LocaleCompare(image->magick_filename,image->filename) != 0)
993 filename[MagickPathExtent];
995 GetPathComponent(image->magick_filename,TailPath,filename);
996 JSONFormatLocaleFile(file," \"baseName\": %s,\n",filename);
998 JSONFormatLocaleFile(file," \"format\": %s,\n",image->magick);
999 magick_info=GetMagickInfo(image->magick,exception);
1000 if ((magick_info != (const MagickInfo *) NULL) &&
1001 (GetMagickDescription(magick_info) != (const char *) NULL))
1002 JSONFormatLocaleFile(file," \"formatDescription\": %s,\n",
1004 if ((magick_info != (const MagickInfo *) NULL) &&
1005 (GetMagickMimeType(magick_info) != (const char *) NULL))
1006 JSONFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
1008 JSONFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
1009 MagickClassOptions,(ssize_t) image->storage_class));
1010 (void) FormatLocaleFile(file," \"geometry\": {\n"
1011 " \"width\": %g,\n \"height\": %g,\n"
1012 " \"x\": %g,\n \"y\": %g\n },\n",
1013 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
1014 (double) image->tile_offset.y);
1015 if ((image->magick_columns != 0) || (image->magick_rows != 0))
1016 if ((image->magick_columns != image->columns) ||
1017 (image->magick_rows != image->rows))
1018 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
1019 " \"width\": %g,\n \"height\": %g\n },\n",(double)
1020 image->magick_columns,(double) image->magick_rows);
1021 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
1023 (void) FormatLocaleFile(file," \"resolution\": {\n"
1024 " \"x\": %g,\n \"y\": %g\n },\n",image->resolution.x,
1025 image->resolution.y);
1026 (void) FormatLocaleFile(file," \"printSize\": {\n"
1027 " \"x\": %.*g,\n \"y\": %.*g\n },\n",GetMagickPrecision(),
1028 image->columns/image->resolution.x,GetMagickPrecision(),(double)
1029 image->rows/image->resolution.y);
1031 JSONFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
1032 MagickResolutionOptions,(ssize_t) image->units));
1033 colorspace=image->colorspace;
1034 type=IdentifyImageType(image,exception);
1035 if ((type == BilevelType) || (type == GrayscaleType) ||
1036 (type == GrayscaleAlphaType))
1037 colorspace=GRAYColorspace;
1038 JSONFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
1039 MagickTypeOptions,(ssize_t) type));
1040 base_type=GetImageType(image);
1041 if (type != base_type)
1042 JSONFormatLocaleFile(file," \"baseType\": %s,\n",
1043 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) base_type));
1044 JSONFormatLocaleFile(file," \"endianess\": %s,\n",
1045 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
1046 locate=GetImageArtifact(image,"identify:locate");
1047 if (locate == (const char *) NULL)
1048 locate=GetImageArtifact(image,"json:locate");
1049 if (locate != (const char *) NULL)
1061 Display minimum, maximum, or mean pixel locations.
1063 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
1064 MagickFalse,locate);
1065 limit=GetImageArtifact(image,"identify:limit");
1066 if (limit == (const char *) NULL)
1067 limit=GetImageArtifact(image,"json:limit");
1069 if (limit != (const char *) NULL)
1070 max_locations=StringToUnsignedLong(limit);
1071 channel_statistics=GetLocationStatistics(image,type,exception);
1072 if (channel_statistics == (ChannelStatistics *) NULL)
1073 return(MagickFalse);
1074 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
1075 if (image->alpha_trait != UndefinedPixelTrait)
1076 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
1077 type,max_locations,MagickTrue,channel_statistics);
1083 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
1084 type,max_locations,MagickTrue,channel_statistics);
1085 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
1086 type,max_locations,MagickTrue,channel_statistics);
1087 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
1088 type,max_locations,MagickFalse,channel_statistics);
1091 case CMYKColorspace:
1093 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
1094 type,max_locations,MagickTrue,channel_statistics);
1095 (void) PrintChannelLocations(file,image,MagentaPixelChannel,"Magenta",
1096 type,max_locations,MagickTrue,channel_statistics);
1097 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
1098 type,max_locations,MagickTrue,channel_statistics);
1099 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
1100 type,max_locations,MagickFalse,channel_statistics);
1103 case GRAYColorspace:
1105 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
1106 type,max_locations,MagickFalse,channel_statistics);
1110 (void) FormatLocaleFile(file," },\n");
1111 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1112 channel_statistics);
1115 Detail channel depth and extrema.
1117 JSONFormatLocaleFile(file," \"colorspace\": %s,\n",
1118 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
1119 image->colorspace));
1120 channel_statistics=(ChannelStatistics *) NULL;
1121 channel_moments=(ChannelMoments *) NULL;
1122 channel_phash=(ChannelPerceptualHash *) NULL;
1123 channel_features=(ChannelFeatures *) NULL;
1125 channel_statistics=GetImageStatistics(image,exception);
1126 if (channel_statistics == (ChannelStatistics *) NULL)
1127 return(MagickFalse);
1128 artifact=GetImageArtifact(image,"identify:moments");
1129 if (artifact == (const char *) NULL)
1130 artifact=GetImageArtifact(image,"json:moments");
1131 if (artifact != (const char *) NULL)
1133 channel_moments=GetImageMoments(image,exception);
1134 channel_phash=GetImagePerceptualHash(image,exception);
1136 artifact=GetImageArtifact(image,"identify:features");
1137 if (artifact == (const char *) NULL)
1138 artifact=GetImageArtifact(image,"json:features");
1139 if (artifact != (const char *) NULL)
1141 distance=StringToUnsignedLong(artifact);
1142 channel_features=GetImageFeatures(image,distance,exception);
1144 depth=GetImageDepth(image,exception);
1145 (void) FormatLocaleFile(file," \"depth\": %g,\n",(double) depth);
1146 (void) FormatLocaleFile(file," \"baseDepth\": %g,\n",(double)
1148 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
1149 if (image->alpha_trait != UndefinedPixelTrait)
1150 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
1151 channel_statistics[AlphaPixelChannel].depth);
1157 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
1158 channel_statistics[RedChannel].depth);
1159 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
1160 channel_statistics[GreenChannel].depth);
1161 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
1162 channel_statistics[BlueChannel].depth);
1165 case CMYKColorspace:
1167 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
1168 channel_statistics[CyanChannel].depth);
1169 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
1170 channel_statistics[MagentaChannel].depth);
1171 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
1172 channel_statistics[YellowChannel].depth);
1173 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
1174 channel_statistics[BlackChannel].depth);
1177 case GRAYColorspace:
1179 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
1180 channel_statistics[GrayChannel].depth);
1184 (void) FormatLocaleFile(file," },\n");
1186 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
1187 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
1188 MAGICKCORE_QUANTUM_DEPTH-image->depth));
1189 if (channel_statistics != (ChannelStatistics *) NULL)
1191 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
1192 channel_statistics[CompositePixelChannel].area);
1193 if (colorspace != GRAYColorspace)
1195 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
1196 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
1197 "Overall",1.0/scale,MagickFalse,channel_statistics);
1198 (void) FormatLocaleFile(file," },\n");
1200 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
1201 if (image->alpha_trait != UndefinedPixelTrait)
1202 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
1203 MagickTrue,channel_statistics);
1209 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale,
1210 MagickTrue,channel_statistics);
1211 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
1212 scale,MagickTrue,channel_statistics);
1213 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale,
1214 MagickFalse,channel_statistics);
1217 case CMYKColorspace:
1219 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale,
1220 MagickTrue,channel_statistics);
1221 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
1222 scale,MagickTrue,channel_statistics);
1223 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
1224 scale,MagickTrue,channel_statistics);
1225 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
1226 scale,MagickFalse,channel_statistics);
1229 case GRAYColorspace:
1231 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale,
1232 MagickFalse,channel_statistics);
1236 (void) FormatLocaleFile(file," },\n");
1237 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1238 channel_statistics);
1240 if (channel_moments != (ChannelMoments *) NULL)
1242 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
1243 if (image->alpha_trait != UndefinedPixelTrait)
1244 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue,
1251 (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue,
1253 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue,
1255 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse,
1259 case CMYKColorspace:
1261 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue,
1263 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
1264 MagickTrue,channel_moments);
1265 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
1266 MagickTrue,channel_moments);
1267 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
1268 MagickFalse,channel_moments);
1271 case GRAYColorspace:
1273 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse,
1278 (void) FormatLocaleFile(file," },\n");
1279 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1282 if (channel_phash != (ChannelPerceptualHash *) NULL)
1284 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
1285 (void) PrintChannelPerceptualHash(image,file,channel_phash);
1286 (void) FormatLocaleFile(file," },\n");
1287 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1290 if (channel_features != (ChannelFeatures *) NULL)
1292 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1293 if (image->alpha_trait != UndefinedPixelTrait)
1294 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue,
1301 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue,
1303 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
1304 MagickTrue,channel_features);
1305 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse,
1309 case CMYKColorspace:
1311 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue,
1313 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
1314 MagickTrue,channel_features);
1315 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
1316 MagickTrue,channel_features);
1317 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
1318 MagickFalse,channel_features);
1321 case GRAYColorspace:
1323 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse,
1328 (void) FormatLocaleFile(file," },\n");
1329 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1332 if (image->colorspace == CMYKColorspace)
1333 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
1334 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1335 (double) QuantumRange);
1337 if (image->alpha_trait != UndefinedPixelTrait)
1339 register const Quantum
1342 p=(const Quantum *) NULL;
1343 for (y=0; y < (ssize_t) image->rows; y++)
1345 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1346 if (p == (const Quantum *) NULL)
1348 for (x=0; x < (ssize_t) image->columns; x++)
1350 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
1352 p+=GetPixelChannels(image);
1354 if (x < (ssize_t) image->columns)
1357 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1362 GetPixelInfo(image,&pixel);
1363 GetPixelInfoPixel(image,p,&pixel);
1364 GetColorTuple(&pixel,MagickTrue,color);
1365 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1368 if (image->storage_class == PseudoClass)
1373 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1374 (double) image->colors);
1375 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1377 for (i=0; i < (ssize_t) image->colors; i++)
1379 GetColorTuple(p,MagickTrue,color);
1380 (void) FormatLocaleFile(file,"\"%s\"",color);
1381 if (i < (ssize_t) (image->colors-1))
1382 (void) FormatLocaleFile(file,",");
1383 if (((i+1) % 5) == 0)
1384 (void) FormatLocaleFile(file,"\n ");
1387 (void) FormatLocaleFile(file,"\n ],\n");
1389 if (image->error.mean_error_per_pixel != 0.0)
1390 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": %g,\n",
1391 image->error.mean_error_per_pixel);
1392 if (image->error.normalized_mean_error != 0.0)
1393 (void) FormatLocaleFile(file," \"normalizedMeanError\": %g,\n",
1394 image->error.normalized_mean_error);
1395 if (image->error.normalized_maximum_error != 0.0)
1396 (void) FormatLocaleFile(file," \"normalizedMaximumError\": %g,\n",
1397 image->error.normalized_maximum_error);
1398 JSONFormatLocaleFile(file," \"renderingIntent\": %s,\n",
1399 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1400 image->rendering_intent));
1401 if (image->gamma != 0.0)
1402 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
1403 if ((image->chromaticity.red_primary.x != 0.0) ||
1404 (image->chromaticity.green_primary.x != 0.0) ||
1405 (image->chromaticity.blue_primary.x != 0.0) ||
1406 (image->chromaticity.white_point.x != 0.0))
1409 Display image chromaticity.
1411 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1412 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1413 " \"x\": %g,\n \"y\": %g\n },\n",
1414 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
1415 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1416 " \"x\": %g,\n \"y\": %g\n },\n",
1417 image->chromaticity.green_primary.x,
1418 image->chromaticity.green_primary.y);
1419 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1420 " \"x\": %g,\n \"y\": %g\n },\n",
1421 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
1422 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1423 " \"x\": %g,\n \"y\": %g\n }\n",
1424 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
1425 (void) FormatLocaleFile(file," },\n");
1427 if ((image->extract_info.width*image->extract_info.height) != 0)
1428 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1429 " \"width\": %.20g,\n \"height\": %.20g,\n"
1430 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1431 (double) image->extract_info.width,(double) image->extract_info.height,
1432 (double) image->extract_info.x,(double) image->extract_info.y);
1433 GetColorTuple(&image->matte_color,MagickTrue,color);
1434 (void) FormatLocaleFile(file," \"matteColor\": \"%s\",\n",color);
1435 GetColorTuple(&image->background_color,MagickTrue,color);
1436 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1437 GetColorTuple(&image->border_color,MagickTrue,color);
1438 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
1439 GetColorTuple(&image->transparent_color,MagickTrue,color);
1440 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
1441 JSONFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
1442 MagickInterlaceOptions,(ssize_t) image->interlace));
1443 JSONFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
1444 MagickPixelIntensityOptions,(ssize_t) image->intensity));
1445 JSONFormatLocaleFile(file," \"compose\": %s,\n",
1446 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
1447 if ((image->page.width != 0) || (image->page.height != 0) ||
1448 (image->page.x != 0) || (image->page.y != 0))
1449 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1450 " \"width\": %.20g,\n \"height\": %.20g,\n"
1451 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1452 (double) image->page.width,(double) image->page.height,
1453 (double) image->page.x,(double) image->page.y);
1454 if ((image->page.x != 0) || (image->page.y != 0))
1455 (void) FormatLocaleFile(file," \"originGeometry\": %+.20g%+.20g,\n",
1456 (double) image->page.x,(double) image->page.y);
1457 JSONFormatLocaleFile(file," \"dispose\": %s,\n",
1458 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
1459 if (image->delay != 0)
1460 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\",\n",
1461 (double) image->delay,(double) image->ticks_per_second);
1462 if (image->iterations != 1)
1463 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
1465 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
1466 (void) FormatLocaleFile(file," \"scene\": %.20g,\n \"scenes\": "
1467 "%.20g,\n",(double) image->scene,(double) GetImageListLength(image));
1469 if (image->scene != 0)
1470 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1472 JSONFormatLocaleFile(file," \"compression\": %s,\n",
1473 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1474 image->compression));
1475 if (image->quality != UndefinedCompressionQuality)
1476 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1478 JSONFormatLocaleFile(file," \"orientation\": %s,\n",
1479 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1480 image->orientation));
1481 if (image->montage != (char *) NULL)
1482 JSONFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
1483 if (image->directory != (char *) NULL)
1499 Display visual image directory.
1501 image_info=AcquireImageInfo();
1502 (void) CloneString(&image_info->size,"64x64");
1503 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1508 while ((*q != '\n') && (*q != '\0'))
1510 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
1512 JSONFormatLocaleFile(file,"{\n \"name\": %s",
1513 image_info->filename);
1514 handler=SetWarningHandler((WarningHandler) NULL);
1515 tile=ReadImage(image_info,exception);
1516 (void) SetWarningHandler(handler);
1517 if (tile == (Image *) NULL)
1519 (void) FormatLocaleFile(file," }");
1522 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1523 (double) tile->magick_columns,(double) tile->magick_rows,
1525 (void) SignatureImage(tile,exception);
1526 ResetImagePropertyIterator(tile);
1527 property=GetNextImageProperty(tile);
1528 while (property != (const char *) NULL)
1530 JSONFormatLocaleFile(file,",\n %s: ",property);
1531 value=GetImageProperty(tile,property,exception);
1532 JSONFormatLocaleFile(file,"%s",value);
1533 property=GetNextImageProperty(tile);
1535 tile=DestroyImage(tile);
1537 (void) FormatLocaleFile(file,"\n },");
1539 (void) FormatLocaleFile(file,"\n }");
1541 (void) FormatLocaleFile(file,"],\n");
1542 image_info=DestroyImageInfo(image_info);
1544 (void) GetImageProperty(image,"exif:*",exception);
1545 (void) GetImageProperty(image,"icc:*",exception);
1546 (void) GetImageProperty(image,"iptc:*",exception);
1547 (void) GetImageProperty(image,"xmp:*",exception);
1548 ResetImagePropertyIterator(image);
1549 property=GetNextImageProperty(image);
1550 if (property != (const char *) NULL)
1556 Display image properties.
1559 (void) FormatLocaleFile(file," \"properties\": {\n");
1560 while (property != (const char *) NULL)
1563 (void) FormatLocaleFile(file,",\n");
1564 JSONFormatLocaleFile(file," %s: ",property);
1565 value=GetImageProperty(image,property,exception);
1566 JSONFormatLocaleFile(file,"%s",value);
1567 property=GetNextImageProperty(image);
1569 (void) FormatLocaleFile(file,"\n },\n");
1571 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
1572 value=GetImageProperty(image,key,exception);
1573 if (value != (const char *) NULL)
1576 Display clipping path.
1578 JSONFormatLocaleFile(file," \"clipping path\": %s,\n",value);
1580 ResetImageProfileIterator(image);
1581 name=GetNextImageProfile(image);
1582 if (name != (char *) NULL)
1591 Identify image profiles.
1594 (void) FormatLocaleFile(file," \"profiles\": {\n");
1595 while (name != (char *) NULL)
1597 profile=GetImageProfile(image,name);
1598 if (profile == (StringInfo *) NULL)
1601 (void) FormatLocaleFile(file,",\n");
1602 JSONFormatLocaleFile(file," %s: {\n",name);
1603 if (LocaleCompare(name,"iptc") == 0)
1604 EncodeIptcProfile(file,profile);
1605 (void) FormatLocaleFile(file," \"length\": %.20g",(double)
1606 GetStringInfoLength(profile));
1607 (void) FormatLocaleFile(file,"\n }");
1608 name=GetNextImageProfile(image);
1610 (void) FormatLocaleFile(file,"\n },\n");
1612 ResetImageArtifactIterator(image);
1613 artifact=GetNextImageArtifact(image);
1614 if (artifact != (const char *) NULL)
1620 Display image artifacts.
1623 (void) FormatLocaleFile(file," \"artifacts\": {\n");
1624 while (artifact != (const char *) NULL)
1627 (void) FormatLocaleFile(file,",\n");
1628 JSONFormatLocaleFile(file," %s: ",artifact);
1629 value=GetImageArtifact(image,artifact);
1630 JSONFormatLocaleFile(file,"%s",value);
1631 artifact=GetNextImageArtifact(image);
1633 (void) FormatLocaleFile(file,"\n },\n");
1635 ResetImageRegistryIterator();
1636 registry=GetNextImageRegistry();
1637 if (registry != (const char *) NULL)
1643 Display image registry.
1645 (void) FormatLocaleFile(file," \"registry\": {\n");
1647 while (registry != (const char *) NULL)
1650 (void) FormatLocaleFile(file,",\n");
1651 JSONFormatLocaleFile(file," %s: ",registry);
1652 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1654 JSONFormatLocaleFile(file,"%s",value);
1655 registry=GetNextImageRegistry();
1657 (void) FormatLocaleFile(file," },\n");
1659 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1660 image->taint != MagickFalse ? "true" : "false");
1661 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
1663 JSONFormatLocaleFile(file," \"filesize\": %s,\n",format);
1664 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1665 MagickFalse,"B",MagickPathExtent,format);
1666 if (strlen(format) > 1)
1667 format[strlen(format)-1]='\0';
1668 JSONFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
1669 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
1670 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
1671 JSONFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
1672 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1673 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1674 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1675 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1677 url=GetMagickHomeURL();
1678 JSONFormatLocaleFile(file," \"version\": %s\n",url);
1679 url=DestroyString(url);
1680 (void) FormatLocaleFile(file," }\n}\n");
1681 (void) fflush(file);
1682 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1685 static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1686 Image *image,ExceptionInfo *exception)
1698 Open output image file.
1700 assert(image_info != (const ImageInfo *) NULL);
1701 assert(image_info->signature == MagickCoreSignature);
1702 assert(image != (Image *) NULL);
1703 assert(image->signature == MagickCoreSignature);
1704 if (image->debug != MagickFalse)
1705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1706 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1707 if (status == MagickFalse)
1709 file=GetBlobFileHandle(image);
1710 if (file == (FILE *) NULL)
1716 WriteBlobString(image,"[");
1717 image->magick_columns=image->columns;
1718 image->magick_rows=image->rows;
1719 EncodeImageAttributes(image,file,exception);
1720 if (GetNextImageInList(image) == (Image *) NULL)
1722 WriteBlobString(image,"]");
1725 WriteBlobString(image,",\n");
1726 image=SyncNextImageInList(image);
1727 status=SetImageProgress(image,SaveImagesTag,scene++,
1728 GetImageListLength(image));
1729 if (status == MagickFalse)
1731 } while (image_info->adjoin != MagickFalse);
1732 (void) CloseBlob(image);