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 % 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=AcquireMagickInfo("JSON","JSON","The image format and characteristics");
113 entry->encoder=(EncodeImageHandler *) WriteJSONImage;
114 entry->mime_type=ConstantString("application/json");
115 entry->flags^=CoderBlobSupportFlag;
116 (void) RegisterMagickInfo(entry);
117 return(MagickImageCoderSignature);
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 % U n r e g i s t e r J S O N I m a g e %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % UnregisterJSONImage() removes format registrations made by the
132 % JSON module from the list of supported formats.
134 % The format of the UnregisterJSONImage method is:
136 % UnregisterJSONImage(void)
139 ModuleExport void UnregisterJSONImage(void)
141 (void) UnregisterMagickInfo("JSON");
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % W r i t e J S O N I m a g e %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % WriteJSONImage writes the image attributes in the JSON format.
157 % The format of the WriteJSONImage method is:
159 % MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
160 % Image *image,ExceptionInfo *exception)
162 % A description of each parameter follows.
164 % o image_info: the image info.
166 % o image: The image.
168 % o exception: return any errors or warnings in this structure.
172 static void JsonFormatLocaleFile(FILE *file,const char *format,const char *value)
186 assert(format != (const char *) NULL);
187 if (value == (char *) NULL || *value == '\0')
189 (void) FormatLocaleFile(file,format,"null");
192 length=strlen(value)+2;
194 Find all the chars that need escaping and increase the dest length counter
196 for (p=value; *p != '\0'; p++)
215 escaped_json=(char *) NULL;
216 if (~length >= (MagickPathExtent-1))
217 escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent,
218 sizeof(*escaped_json));
219 if (escaped_json == (char *) NULL)
221 (void) FormatLocaleFile(file,format,"null");
226 for (p=value; *p != '\0'; p++)
265 (void) FormatLocaleFile(file,format,escaped_json);
266 (void) DestroyString(escaped_json);
269 static ChannelStatistics *GetLocationStatistics(const Image *image,
270 const StatisticType type,ExceptionInfo *exception)
281 assert(image != (Image *) NULL);
282 assert(image->signature == MagickCoreSignature);
283 if (image->debug != MagickFalse)
284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
285 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
286 MaxPixelChannels+1,sizeof(*channel_statistics));
287 if (channel_statistics == (ChannelStatistics *) NULL)
288 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
289 (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
290 sizeof(*channel_statistics));
291 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
295 case MaximumStatistic:
298 channel_statistics[i].maxima=(-MagickMaximumValue);
301 case MinimumStatistic:
303 channel_statistics[i].minima=MagickMaximumValue;
308 for (y=0; y < (ssize_t) image->rows; y++)
310 register const Quantum
316 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
317 if (p == (const Quantum *) NULL)
319 for (x=0; x < (ssize_t) image->columns; x++)
324 if (GetPixelReadMask(image,p) == 0)
326 p+=GetPixelChannels(image);
329 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
331 PixelChannel channel=GetPixelChannelChannel(image,i);
332 PixelTrait traits=GetPixelChannelTraits(image,channel);
333 if (traits == UndefinedPixelTrait)
337 case MaximumStatistic:
340 if ((double) p[i] > channel_statistics[channel].maxima)
341 channel_statistics[channel].maxima=(double) p[i];
344 case MinimumStatistic:
346 if ((double) p[i] < channel_statistics[channel].minima)
347 channel_statistics[channel].minima=(double) p[i];
352 p+=GetPixelChannels(image);
355 return(channel_statistics);
358 static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
359 const char *name,const MagickBooleanType separator,
360 const ChannelFeatures *channel_features)
362 #define PrintFeature(feature) \
363 GetMagickPrecision(),(feature)[0], \
364 GetMagickPrecision(),(feature)[1], \
365 GetMagickPrecision(),(feature)[2], \
366 GetMagickPrecision(),(feature)[3], \
367 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
369 #define FeaturesFormat " \"%s\": {\n" \
370 " \"angularSecondMoment\": {\n" \
371 " \"horizontal\": \"%.*g\",\n" \
372 " \"vertical\": \"%.*g\",\n" \
373 " \"leftDiagonal\": \"%.*g\",\n" \
374 " \"rightDiagonal\": \"%.*g\",\n" \
375 " \"average\": \"%.*g\"\n" \
377 " \"contrast\": {\n" \
378 " \"horizontal\": \"%.*g\",\n" \
379 " \"vertical\": \"%.*g\",\n" \
380 " \"leftDiagonal\": \"%.*g\",\n" \
381 " \"rightDiagonal\": \"%.*g\",\n" \
382 " \"average\": \"%.*g\"\n" \
384 " \"correlation\": {\n" \
385 " \"horizontal\": \"%.*g\",\n" \
386 " \"vertical\": \"%.*g\",\n" \
387 " \"leftDiagonal\": \"%.*g\",\n" \
388 " \"rightDiagonal\": \"%.*g\",\n" \
389 " \"average\": \"%.*g\"\n" \
391 " \"sumOfSquaresVariance\": {\n" \
392 " \"horizontal\": \"%.*g\",\n" \
393 " \"vertical\": \"%.*g\",\n" \
394 " \"leftDiagonal\": \"%.*g\",\n" \
395 " \"rightDiagonal\": \"%.*g\",\n" \
396 " \"average\": \"%.*g\"\n" \
398 " \"inverseDifferenceMoment\": {\n" \
399 " \"horizontal\": \"%.*g\",\n" \
400 " \"vertical\": \"%.*g\",\n" \
401 " \"leftDiagonal\": \"%.*g\",\n" \
402 " \"rightDiagonal\": \"%.*g\",\n" \
403 " \"average\": \"%.*g\"\n" \
405 " \"sumAverage\": {\n" \
406 " \"horizontal\": \"%.*g\",\n" \
407 " \"vertical\": \"%.*g\",\n" \
408 " \"leftDiagonal\": \"%.*g\",\n" \
409 " \"rightDiagonal\": \"%.*g\",\n" \
410 " \"average\": \"%.*g\"\n" \
412 " \"sumVariance\": {\n" \
413 " \"horizontal\": \"%.*g\",\n" \
414 " \"vertical\": \"%.*g\",\n" \
415 " \"leftDiagonal\": \"%.*g\",\n" \
416 " \"rightDiagonal\": \"%.*g\",\n" \
417 " \"average\": \"%.*g\"\n" \
419 " \"sumEntropy\": {\n" \
420 " \"horizontal\": \"%.*g\",\n" \
421 " \"vertical\": \"%.*g\",\n" \
422 " \"leftDiagonal\": \"%.*g\",\n" \
423 " \"rightDiagonal\": \"%.*g\",\n" \
424 " \"average\": \"%.*g\"\n" \
426 " \"entropy\": {\n" \
427 " \"horizontal\": \"%.*g\",\n" \
428 " \"vertical\": \"%.*g\",\n" \
429 " \"leftDiagonal\": \"%.*g\",\n" \
430 " \"rightDiagonal\": \"%.*g\",\n" \
431 " \"average\": \"%.*g\"\n" \
433 " \"differenceVariance\": {\n" \
434 " \"horizontal\": \"%.*g\",\n" \
435 " \"vertical\": \"%.*g\",\n" \
436 " \"leftDiagonal\": \"%.*g\",\n" \
437 " \"rightDiagonal\": \"%.*g\",\n" \
438 " \"average\": \"%.*g\"\n" \
440 " \"differenceEntropy\": {\n" \
441 " \"horizontal\": \"%.*g\",\n" \
442 " \"vertical\": \"%.*g\",\n" \
443 " \"leftDiagonal\": \"%.*g\",\n" \
444 " \"rightDiagonal\": \"%.*g\",\n" \
445 " \"average\": \"%.*g\"\n" \
447 " \"informationMeasureOfCorrelation1\": {\n" \
448 " \"horizontal\": \"%.*g\",\n" \
449 " \"vertical\": \"%.*g\",\n" \
450 " \"leftDiagonal\": \"%.*g\",\n" \
451 " \"rightDiagonal\": \"%.*g\",\n" \
452 " \"average\": \"%.*g\"\n" \
454 " \"informationMeasureOfCorrelation2\": {\n" \
455 " \"horizontal\": \"%.*g\",\n" \
456 " \"vertical\": \"%.*g\",\n" \
457 " \"leftDiagonal\": \"%.*g\",\n" \
458 " \"rightDiagonal\": \"%.*g\",\n" \
459 " \"average\": \"%.*g\"\n" \
461 " \"maximumCorrelationCoefficient\": {\n" \
462 " \"horizontal\": \"%.*g\",\n" \
463 " \"vertical\": \"%.*g\",\n" \
464 " \"leftDiagonal\": \"%.*g\",\n" \
465 " \"rightDiagonal\": \"%.*g\",\n" \
466 " \"average\": \"%.*g\"\n" \
472 n=FormatLocaleFile(file,FeaturesFormat,name,
473 PrintFeature(channel_features[channel].angular_second_moment),
474 PrintFeature(channel_features[channel].contrast),
475 PrintFeature(channel_features[channel].correlation),
476 PrintFeature(channel_features[channel].variance_sum_of_squares),
477 PrintFeature(channel_features[channel].inverse_difference_moment),
478 PrintFeature(channel_features[channel].sum_average),
479 PrintFeature(channel_features[channel].sum_variance),
480 PrintFeature(channel_features[channel].sum_entropy),
481 PrintFeature(channel_features[channel].entropy),
482 PrintFeature(channel_features[channel].difference_variance),
483 PrintFeature(channel_features[channel].difference_entropy),
484 PrintFeature(channel_features[channel].measure_of_correlation_1),
485 PrintFeature(channel_features[channel].measure_of_correlation_2),
486 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
487 (void) FormatLocaleFile(file," }");
488 if (separator != MagickFalse)
489 (void) FormatLocaleFile(file,",");
490 (void) FormatLocaleFile(file,"\n");
494 static ssize_t PrintChannelLocations(FILE *file,const Image *image,
495 const PixelChannel channel,const char *name,const StatisticType type,
496 const size_t max_locations,const MagickBooleanType separator,
497 const ChannelStatistics *channel_statistics)
511 case MaximumStatistic:
514 target=channel_statistics[channel].maxima;
517 case MinimumStatistic:
519 target=channel_statistics[channel].minima;
523 (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": "
524 "\"%.*g\",\n",name,GetMagickPrecision(),QuantumScale*target);
525 exception=AcquireExceptionInfo();
527 for (y=0; y < (ssize_t) image->rows; y++)
529 register const Quantum
536 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
537 if (p == (const Quantum *) NULL)
539 for (x=0; x < (ssize_t) image->columns; x++)
544 PixelTrait traits=GetPixelChannelTraits(image,channel);
545 if (traits == UndefinedPixelTrait)
547 offset=GetPixelChannelOffset(image,channel);
548 match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse;
549 if (match != MagickFalse)
551 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
554 (void) FormatLocaleFile(file,",\n");
555 (void) FormatLocaleFile(file," \"location%.20g\": {\n"
556 " \"x\": %.20g,\n \"y\": %.20g\n"
557 " }",(double) n,(double) x,(double) y);
560 p+=GetPixelChannels(image);
562 if (x < (ssize_t) image->columns)
565 (void) FormatLocaleFile(file,"\n }");
566 if (separator != MagickFalse)
567 (void) FormatLocaleFile(file,",");
568 (void) FormatLocaleFile(file,"\n");
572 static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
573 const char *name,const MagickBooleanType separator,
574 const ChannelMoments *channel_moments)
582 n=FormatLocaleFile(file," \"%s\": {\n",name);
583 n+=FormatLocaleFile(file," \"centroid\": {\n "
584 " \"x\": \"%.*g\",\n"
585 " \"y\": \"%.*g\"\n },\n",
586 GetMagickPrecision(),channel_moments[channel].centroid.x,
587 GetMagickPrecision(),channel_moments[channel].centroid.y);
588 n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n"
589 " \"x\": \"%.*g\",\n"
590 " \"y\": \"%.*g\"\n },\n",
591 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
592 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
593 n+=FormatLocaleFile(file," \"ellipseAngle\": \"%.*g\",\n",
594 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
595 n+=FormatLocaleFile(file," \"ellipseEccentricity\": \"%.*g\",\n",
596 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
597 n+=FormatLocaleFile(file," \"ellipseIntensity\": \"%.*g\",\n",
598 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
599 for (i=0; i < 7; i++)
600 n+=FormatLocaleFile(file," \"I%.20g\": \"%.*g\",\n",i+1.0,
601 GetMagickPrecision(),channel_moments[channel].invariant[i]);
602 n+=FormatLocaleFile(file," \"I%.20g\": \"%.*g\"\n",i+1.0,
603 GetMagickPrecision(),channel_moments[channel].invariant[i]);
604 (void) FormatLocaleFile(file," }");
605 if (separator != MagickFalse)
606 (void) FormatLocaleFile(file,",");
607 (void) FormatLocaleFile(file,"\n");
611 static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
612 const ChannelPerceptualHash *channel_phash)
620 (void) FormatLocaleFile(file," \"colorspaces\": [ ");
621 for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
623 (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic(
624 MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
625 if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
626 (void) FormatLocaleFile(file,", ");
628 (void) FormatLocaleFile(file,"],\n");
629 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
634 PixelChannel channel=GetPixelChannelChannel(image,i);
635 PixelTrait traits=GetPixelChannelTraits(image,channel);
636 if (traits == UndefinedPixelTrait)
638 n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel);
639 for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
644 n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1);
645 for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
647 n+=FormatLocaleFile(file,"\"%.*g\"",GetMagickPrecision(),
648 channel_phash[channel].phash[k][j]);
649 if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
650 n+=FormatLocaleFile(file,", ");
652 n+=FormatLocaleFile(file,"]");
653 if (j < (MaximumNumberOfPerceptualHashes-1))
654 n+=FormatLocaleFile(file,",\n");
656 if (i < (ssize_t) (GetPixelChannels(image)-1))
657 n+=FormatLocaleFile(file,"\n },\n");
659 n+=FormatLocaleFile(file,"\n }\n");
663 static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
664 const char *name,const double scale,const MagickBooleanType separator,
665 const ChannelStatistics *channel_statistics)
667 #define StatisticsFormat " \"%s\": {\n \"min\": \"" QuantumFormat \
668 "\",\n \"max\": \"" QuantumFormat "\",\n" \
669 " \"mean\": \"%g\",\n \"standardDeviation\": " \
670 "\"%g\",\n \"kurtosis\": \"%g\",\n \"skewness\": " \
676 n=FormatLocaleFile(file,StatisticsFormat,name,ClampToQuantum(scale*
677 channel_statistics[channel].minima),ClampToQuantum(scale*
678 channel_statistics[channel].maxima),scale*channel_statistics[channel].mean,
679 scale*channel_statistics[channel].standard_deviation,
680 channel_statistics[channel].kurtosis,channel_statistics[channel].skewness);
681 if (separator != MagickFalse)
682 (void) FormatLocaleFile(file,",");
683 (void) FormatLocaleFile(file,"\n");
687 static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
688 ExceptionInfo *exception)
691 color[MagickPathExtent],
692 format[MagickPathExtent],
693 key[MagickPathExtent];
701 ChannelPerceptualHash
735 register const Quantum
750 assert(image != (Image *) NULL);
751 assert(image->signature == MagickCoreSignature);
752 if (image->debug != MagickFalse)
753 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
755 elapsed_time=GetElapsedTime(&image->timer);
756 user_time=GetUserTime(&image->timer);
757 GetTimerInfo(&image->timer);
758 p=GetVirtualPixels(image,0,0,1,1,exception);
759 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
761 (void) SignatureImage(image,exception);
762 JsonFormatLocaleFile(file,"{\n \"image\": {\n \"name\": %s,\n",
764 if (*image->magick_filename != '\0')
765 if (LocaleCompare(image->magick_filename,image->filename) != 0)
768 filename[MagickPathExtent];
770 GetPathComponent(image->magick_filename,TailPath,filename);
771 JsonFormatLocaleFile(file," \"baseName\": %s,\n",filename);
773 JsonFormatLocaleFile(file," \"format\": %s,\n",image->magick);
774 magick_info=GetMagickInfo(image->magick,exception);
775 if ((magick_info != (const MagickInfo *) NULL) &&
776 (GetMagickDescription(magick_info) != (const char *) NULL))
777 JsonFormatLocaleFile(file," \"formatDescription\": %s,\n",
779 if ((magick_info != (const MagickInfo *) NULL) &&
780 (GetMagickMimeType(magick_info) != (const char *) NULL))
781 JsonFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
783 JsonFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
784 MagickClassOptions,(ssize_t) image->storage_class));
785 (void) FormatLocaleFile(file," \"geometry\": {\n"
786 " \"width\": %.20g,\n \"height\": %.20g,\n"
787 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
788 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
789 (double) image->tile_offset.y);
790 if ((image->magick_columns != 0) || (image->magick_rows != 0))
791 if ((image->magick_columns != image->columns) ||
792 (image->magick_rows != image->rows))
793 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
794 " \"width\": %.20g,\n \"height\": %.20g\n },\n",
795 (double) image->magick_columns,(double) image->magick_rows);
796 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
798 (void) FormatLocaleFile(file," \"resolution\": {\n"
799 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
800 image->resolution.x,image->resolution.y);
801 (void) FormatLocaleFile(file," \"printSize\": {\n"
802 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
803 image->columns/image->resolution.x,(double) image->rows/
804 image->resolution.y);
806 JsonFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
807 MagickResolutionOptions,(ssize_t) image->units));
808 colorspace=image->colorspace;
809 type=IdentifyImageType(image,exception);
810 if ((type == BilevelType) || (type == GrayscaleType) ||
811 (type == GrayscaleAlphaType))
812 colorspace=GRAYColorspace;
813 JsonFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
814 MagickTypeOptions,(ssize_t) type));
815 base_type=GetImageType(image);
816 if (type != base_type)
817 JsonFormatLocaleFile(file," \"baseType\": %s,\n",
818 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) base_type));
819 JsonFormatLocaleFile(file," \"endianess\": %s,\n",
820 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
821 locate=GetImageArtifact(image,"identify:locate");
822 if (locate == (const char *) NULL)
823 locate=GetImageArtifact(image,"json:locate");
824 if (locate != (const char *) NULL)
836 Display minimum, maximum, or mean pixel locations.
838 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
840 limit=GetImageArtifact(image,"identify:limit");
841 if (limit == (const char *) NULL)
842 limit=GetImageArtifact(image,"json:limit");
844 if (limit != (const char *) NULL)
845 max_locations=StringToUnsignedLong(limit);
846 channel_statistics=GetLocationStatistics(image,type,exception);
847 if (channel_statistics == (ChannelStatistics *) NULL)
849 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
850 if (image->alpha_trait != UndefinedPixelTrait)
851 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
852 type,max_locations,MagickTrue,channel_statistics);
858 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
859 type,max_locations,MagickTrue,channel_statistics);
860 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
861 type,max_locations,MagickTrue,channel_statistics);
862 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
863 type,max_locations,MagickFalse,channel_statistics);
868 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
869 type,max_locations,MagickTrue,channel_statistics);
870 (void) PrintChannelLocations(file,image,MagentaPixelChannel,"Magenta",
871 type,max_locations,MagickTrue,channel_statistics);
872 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
873 type,max_locations,MagickTrue,channel_statistics);
874 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
875 type,max_locations,MagickFalse,channel_statistics);
880 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
881 type,max_locations,MagickFalse,channel_statistics);
885 (void) FormatLocaleFile(file," },\n");
886 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
890 Detail channel depth and extrema.
892 JsonFormatLocaleFile(file," \"colorspace\": %s,\n",
893 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
895 channel_statistics=(ChannelStatistics *) NULL;
896 channel_moments=(ChannelMoments *) NULL;
897 channel_phash=(ChannelPerceptualHash *) NULL;
898 channel_features=(ChannelFeatures *) NULL;
900 channel_statistics=GetImageStatistics(image,exception);
901 if (channel_statistics == (ChannelStatistics *) NULL)
903 artifact=GetImageArtifact(image,"identify:moments");
904 if (artifact == (const char *) NULL)
905 artifact=GetImageArtifact(image,"json:moments");
906 if (artifact != (const char *) NULL)
908 channel_moments=GetImageMoments(image,exception);
909 channel_phash=GetImagePerceptualHash(image,exception);
911 artifact=GetImageArtifact(image,"identify:features");
912 if (artifact == (const char *) NULL)
913 artifact=GetImageArtifact(image,"json:features");
914 if (artifact != (const char *) NULL)
916 distance=StringToUnsignedLong(artifact);
917 channel_features=GetImageFeatures(image,distance,exception);
919 depth=GetImageDepth(image,exception);
920 (void) FormatLocaleFile(file," \"depth\": %.20g,\n",(double) depth);
921 (void) FormatLocaleFile(file," \"baseDepth\": %.20g,\n",(double)
923 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
924 if (image->alpha_trait != UndefinedPixelTrait)
925 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
926 channel_statistics[AlphaPixelChannel].depth);
932 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
933 channel_statistics[RedChannel].depth);
934 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
935 channel_statistics[GreenChannel].depth);
936 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
937 channel_statistics[BlueChannel].depth);
942 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
943 channel_statistics[CyanChannel].depth);
944 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
945 channel_statistics[MagentaChannel].depth);
946 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
947 channel_statistics[YellowChannel].depth);
948 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
949 channel_statistics[BlackChannel].depth);
954 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
955 channel_statistics[GrayChannel].depth);
959 (void) FormatLocaleFile(file," },\n");
961 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
962 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
963 MAGICKCORE_QUANTUM_DEPTH-image->depth));
964 if (channel_statistics != (ChannelStatistics *) NULL)
966 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
967 channel_statistics[CompositePixelChannel].area);
968 if (colorspace != GRAYColorspace)
970 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
971 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
972 "Overall",1.0/scale,MagickFalse,channel_statistics);
973 (void) FormatLocaleFile(file," },\n");
975 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
976 if (image->alpha_trait != UndefinedPixelTrait)
977 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
978 MagickTrue,channel_statistics);
984 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale,
985 MagickTrue,channel_statistics);
986 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
987 scale,MagickTrue,channel_statistics);
988 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale,
989 MagickFalse,channel_statistics);
994 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale,
995 MagickTrue,channel_statistics);
996 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
997 scale,MagickTrue,channel_statistics);
998 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
999 scale,MagickTrue,channel_statistics);
1000 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
1001 scale,MagickFalse,channel_statistics);
1004 case GRAYColorspace:
1006 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale,
1007 MagickFalse,channel_statistics);
1011 (void) FormatLocaleFile(file," },\n");
1012 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1013 channel_statistics);
1015 if (channel_moments != (ChannelMoments *) NULL)
1017 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
1018 if (image->alpha_trait != UndefinedPixelTrait)
1019 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue,
1026 (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue,
1028 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue,
1030 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse,
1034 case CMYKColorspace:
1036 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue,
1038 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
1039 MagickTrue,channel_moments);
1040 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
1041 MagickTrue,channel_moments);
1042 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
1043 MagickFalse,channel_moments);
1046 case GRAYColorspace:
1048 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse,
1053 (void) FormatLocaleFile(file," },\n");
1054 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1057 if (channel_phash != (ChannelPerceptualHash *) NULL)
1059 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
1060 (void) PrintChannelPerceptualHash(image,file,channel_phash);
1061 (void) FormatLocaleFile(file," },\n");
1062 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1065 if (channel_features != (ChannelFeatures *) NULL)
1067 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1068 if (image->alpha_trait != UndefinedPixelTrait)
1069 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue,
1076 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue,
1078 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
1079 MagickTrue,channel_features);
1080 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse,
1084 case CMYKColorspace:
1086 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue,
1088 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
1089 MagickTrue,channel_features);
1090 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
1091 MagickTrue,channel_features);
1092 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
1093 MagickFalse,channel_features);
1096 case GRAYColorspace:
1098 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse,
1103 (void) FormatLocaleFile(file," },\n");
1104 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1107 if (image->colorspace == CMYKColorspace)
1108 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
1109 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1110 (double) QuantumRange);
1112 if (image->alpha_trait != UndefinedPixelTrait)
1114 register const Quantum
1117 p=(const Quantum *) NULL;
1118 for (y=0; y < (ssize_t) image->rows; y++)
1120 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1121 if (p == (const Quantum *) NULL)
1123 for (x=0; x < (ssize_t) image->columns; x++)
1125 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
1127 p+=GetPixelChannels(image);
1129 if (x < (ssize_t) image->columns)
1132 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1137 GetPixelInfo(image,&pixel);
1138 GetPixelInfoPixel(image,p,&pixel);
1139 GetColorTuple(&pixel,MagickTrue,color);
1140 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1143 if (image->storage_class == PseudoClass)
1148 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1149 (double) image->colors);
1150 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1152 for (i=0; i < (ssize_t) image->colors; i++)
1154 GetColorTuple(p,MagickTrue,color);
1155 (void) FormatLocaleFile(file,"\"%s\"",color);
1156 if (i < (ssize_t) (image->colors-1))
1157 (void) FormatLocaleFile(file,",");
1158 if (((i+1) % 5) == 0)
1159 (void) FormatLocaleFile(file,"\n ");
1162 (void) FormatLocaleFile(file,"\n ],\n");
1164 if (image->error.mean_error_per_pixel != 0.0)
1165 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": \"%g\",\n",
1166 image->error.mean_error_per_pixel);
1167 if (image->error.normalized_mean_error != 0.0)
1168 (void) FormatLocaleFile(file," \"normalizedMeanError\": \"%g\",\n",
1169 image->error.normalized_mean_error);
1170 if (image->error.normalized_maximum_error != 0.0)
1171 (void) FormatLocaleFile(file," \"normalizedMaximumError\": \"%g\",\n",
1172 image->error.normalized_maximum_error);
1173 JsonFormatLocaleFile(file," \"renderingIntent\": %s,\n",
1174 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1175 image->rendering_intent));
1176 if (image->gamma != 0.0)
1177 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
1178 if ((image->chromaticity.red_primary.x != 0.0) ||
1179 (image->chromaticity.green_primary.x != 0.0) ||
1180 (image->chromaticity.blue_primary.x != 0.0) ||
1181 (image->chromaticity.white_point.x != 0.0))
1184 Display image chromaticity.
1186 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1187 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1188 " \"x\": %g,\n \"y\": %g\n },\n",
1189 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
1190 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1191 " \"x\": %g,\n \"y\": %g\n },\n",
1192 image->chromaticity.green_primary.x,
1193 image->chromaticity.green_primary.y);
1194 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1195 " \"x\": %g,\n \"y\": %g\n },\n",
1196 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
1197 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1198 " \"x\": %g,\n \"y\": %g\n }\n",
1199 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
1200 (void) FormatLocaleFile(file," },\n");
1202 if ((image->extract_info.width*image->extract_info.height) != 0)
1203 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1204 " \"width\": %.20g,\n \"height\": %.20g,\n"
1205 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1206 (double) image->extract_info.width,(double) image->extract_info.height,
1207 (double) image->extract_info.x,(double) image->extract_info.y);
1208 GetColorTuple(&image->alpha_color,MagickTrue,color);
1209 (void) FormatLocaleFile(file," \"alphaColor\": \"%s\",\n",color);
1210 GetColorTuple(&image->background_color,MagickTrue,color);
1211 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1212 GetColorTuple(&image->border_color,MagickTrue,color);
1213 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
1214 GetColorTuple(&image->transparent_color,MagickTrue,color);
1215 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
1216 JsonFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
1217 MagickInterlaceOptions,(ssize_t) image->interlace));
1218 JsonFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
1219 MagickPixelIntensityOptions,(ssize_t) image->intensity));
1220 JsonFormatLocaleFile(file," \"compose\": %s,\n",
1221 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
1222 if ((image->page.width != 0) || (image->page.height != 0) ||
1223 (image->page.x != 0) || (image->page.y != 0))
1224 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1225 " \"width\": %.20g,\n \"height\": %.20g,\n"
1226 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1227 (double) image->page.width,(double) image->page.height,
1228 (double) image->page.x,(double) image->page.y);
1229 if ((image->page.x != 0) || (image->page.y != 0))
1230 (void) FormatLocaleFile(file," \"originGeometry\": %+.20g%+.20g\n",
1231 (double) image->page.x,(double) image->page.y);
1232 JsonFormatLocaleFile(file," \"dispose\": %s,\n",
1233 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
1234 if (image->delay != 0)
1235 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\"\n",
1236 (double) image->delay,(double) image->ticks_per_second);
1237 if (image->iterations != 1)
1238 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
1240 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
1241 (void) FormatLocaleFile(file," \"scene\": %.20g\n \"scenes\": "
1242 "%.20g\n",(double) image->scene,(double) GetImageListLength(image));
1244 if (image->scene != 0)
1245 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1247 JsonFormatLocaleFile(file," \"compression\": %s,\n",
1248 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1249 image->compression));
1250 if (image->quality != UndefinedCompressionQuality)
1251 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1253 JsonFormatLocaleFile(file," \"orientation\": %s,\n",
1254 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1255 image->orientation));
1256 if (image->montage != (char *) NULL)
1257 JsonFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
1258 if (image->directory != (char *) NULL)
1274 Display visual image directory.
1276 image_info=AcquireImageInfo();
1277 (void) CloneString(&image_info->size,"64x64");
1278 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1283 while ((*q != '\n') && (*q != '\0'))
1285 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
1287 JsonFormatLocaleFile(file,"{\n \"name\": %s",
1288 image_info->filename);
1289 handler=SetWarningHandler((WarningHandler) NULL);
1290 tile=ReadImage(image_info,exception);
1291 (void) SetWarningHandler(handler);
1292 if (tile == (Image *) NULL)
1294 (void) FormatLocaleFile(file," }");
1297 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1298 (double) tile->magick_columns,(double) tile->magick_rows,
1300 (void) SignatureImage(tile,exception);
1301 ResetImagePropertyIterator(tile);
1302 property=GetNextImageProperty(tile);
1303 while (property != (const char *) NULL)
1305 JsonFormatLocaleFile(file,",\n %s: ",property);
1306 value=GetImageProperty(tile,property,exception);
1307 JsonFormatLocaleFile(file,"%s",value);
1308 property=GetNextImageProperty(tile);
1310 tile=DestroyImage(tile);
1312 (void) FormatLocaleFile(file,"\n },");
1314 (void) FormatLocaleFile(file,"\n }");
1316 (void) FormatLocaleFile(file,"],\n");
1317 image_info=DestroyImageInfo(image_info);
1319 (void) GetImageProperty(image,"exif:*",exception);
1320 (void) GetImageProperty(image,"icc:*",exception);
1321 (void) GetImageProperty(image,"iptc:*",exception);
1322 (void) GetImageProperty(image,"xmp:*",exception);
1323 ResetImagePropertyIterator(image);
1324 property=GetNextImageProperty(image);
1325 if (property != (const char *) NULL)
1331 Display image properties.
1334 (void) FormatLocaleFile(file," \"properties\": {\n");
1335 while (property != (const char *) NULL)
1338 (void) FormatLocaleFile(file,",\n");
1339 JsonFormatLocaleFile(file," %s: ",property);
1340 value=GetImageProperty(image,property,exception);
1341 JsonFormatLocaleFile(file,"%s",value);
1342 property=GetNextImageProperty(image);
1344 (void) FormatLocaleFile(file,"\n },\n");
1346 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
1347 value=GetImageProperty(image,key,exception);
1348 if (value != (const char *) NULL)
1351 Display clipping path.
1353 (void) FormatLocaleFile(file," \"clipping path\": {\n");
1354 JsonFormatLocaleFile(file,"%s\n",value);
1355 (void) FormatLocaleFile(file," },\n");
1357 ResetImageProfileIterator(image);
1358 name=GetNextImageProfile(image);
1359 if (name != (char *) NULL)
1368 Identify image profiles.
1371 (void) FormatLocaleFile(file," \"profiles\": {\n");
1372 while (name != (char *) NULL)
1374 profile=GetImageProfile(image,name);
1375 if (profile == (StringInfo *) NULL)
1378 (void) FormatLocaleFile(file,",\n");
1379 JsonFormatLocaleFile(file," %s: {\n",name);
1380 if (LocaleCompare(name,"iptc") == 0)
1401 profile_length=GetStringInfoLength(profile);
1402 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
1405 sentinel=GetStringInfoDatum(profile)[i++];
1406 if (sentinel != 0x1c)
1408 dataset=GetStringInfoDatum(profile)[i++];
1409 record=GetStringInfoDatum(profile)[i++];
1412 case 5: tag="Image Name"; break;
1413 case 7: tag="Edit Status"; break;
1414 case 10: tag="Priority"; break;
1415 case 15: tag="Category"; break;
1416 case 20: tag="Supplemental Category"; break;
1417 case 22: tag="Fixture Identifier"; break;
1418 case 25: tag="Keyword"; break;
1419 case 30: tag="Release Date"; break;
1420 case 35: tag="Release Time"; break;
1421 case 40: tag="Special Instructions"; break;
1422 case 45: tag="Reference Service"; break;
1423 case 47: tag="Reference Date"; break;
1424 case 50: tag="Reference Number"; break;
1425 case 55: tag="Created Date"; break;
1426 case 60: tag="Created Time"; break;
1427 case 65: tag="Originating Program"; break;
1428 case 70: tag="Program Version"; break;
1429 case 75: tag="Object Cycle"; break;
1430 case 80: tag="Byline"; break;
1431 case 85: tag="Byline Title"; break;
1432 case 90: tag="City"; break;
1433 case 92: tag="Sub-Location"; break;
1434 case 95: tag="Province State"; break;
1435 case 100: tag="Country Code"; break;
1436 case 101: tag="Country"; break;
1437 case 103: tag="Original Transmission Reference"; break;
1438 case 105: tag="Headline"; break;
1439 case 110: tag="Credit"; break;
1440 case 115: tag="Src"; break;
1441 case 116: tag="Copyright String"; break;
1442 case 120: tag="Caption"; break;
1443 case 121: tag="Local Caption"; break;
1444 case 122: tag="Caption Writer"; break;
1445 case 200: tag="Custom Field 1"; break;
1446 case 201: tag="Custom Field 2"; break;
1447 case 202: tag="Custom Field 3"; break;
1448 case 203: tag="Custom Field 4"; break;
1449 case 204: tag="Custom Field 5"; break;
1450 case 205: tag="Custom Field 6"; break;
1451 case 206: tag="Custom Field 7"; break;
1452 case 207: tag="Custom Field 8"; break;
1453 case 208: tag="Custom Field 9"; break;
1454 case 209: tag="Custom Field 10"; break;
1455 case 210: tag="Custom Field 11"; break;
1456 case 211: tag="Custom Field 12"; break;
1457 case 212: tag="Custom Field 13"; break;
1458 case 213: tag="Custom Field 14"; break;
1459 case 214: tag="Custom Field 15"; break;
1460 case 215: tag="Custom Field 16"; break;
1461 case 216: tag="Custom Field 17"; break;
1462 case 217: tag="Custom Field 18"; break;
1463 case 218: tag="Custom Field 19"; break;
1464 case 219: tag="Custom Field 20"; break;
1465 default: tag="unknown"; break;
1467 (void) FormatLocaleFile(file," %s[%.20g,%.20g]: ",tag,
1468 (double) dataset,(double) record);
1469 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
1470 length|=GetStringInfoDatum(profile)[i++];
1471 attribute=(char *) NULL;
1472 if (~length >= (MagickPathExtent-1))
1473 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1474 sizeof(*attribute));
1475 if (attribute != (char *) NULL)
1477 (void) CopyMagickString(attribute,(char *)
1478 GetStringInfoDatum(profile)+i,length+1);
1479 attribute_list=StringToList(attribute);
1480 if (attribute_list != (char **) NULL)
1482 (void) FormatLocaleFile(file,"[");
1483 for (j=0; attribute_list[j] != (char *) NULL; j++)
1486 (void) FormatLocaleFile(file,",");
1487 JsonFormatLocaleFile(file,"%s",attribute_list[j]);
1488 attribute_list[j]=(char *) RelinquishMagickMemory(
1491 (void) FormatLocaleFile(file,"],");
1492 attribute_list=(char **) RelinquishMagickMemory(
1496 (void) FormatLocaleFile(file,"null,");
1497 attribute=DestroyString(attribute);
1500 (void) FormatLocaleFile(file,"null,");
1503 (void) FormatLocaleFile(file," \"length\": \"%.20g\"",(double)
1504 GetStringInfoLength(profile));
1505 (void) FormatLocaleFile(file,"\n }");
1506 name=GetNextImageProfile(image);
1508 (void) FormatLocaleFile(file,"\n },\n");
1510 ResetImageArtifactIterator(image);
1511 artifact=GetNextImageArtifact(image);
1512 if (artifact != (const char *) NULL)
1518 Display image artifacts.
1521 (void) FormatLocaleFile(file," \"artifacts\": {\n");
1522 while (artifact != (const char *) NULL)
1525 (void) FormatLocaleFile(file,",\n");
1526 JsonFormatLocaleFile(file," %s: ",artifact);
1527 value=GetImageArtifact(image,artifact);
1528 JsonFormatLocaleFile(file,"%s",value);
1529 artifact=GetNextImageArtifact(image);
1531 (void) FormatLocaleFile(file,"\n },\n");
1533 ResetImageRegistryIterator();
1534 registry=GetNextImageRegistry();
1535 if (registry != (const char *) NULL)
1541 Display image registry.
1543 (void) FormatLocaleFile(file," \"registry\": {\n");
1545 while (registry != (const char *) NULL)
1548 (void) FormatLocaleFile(file,",\n");
1549 JsonFormatLocaleFile(file," %s: ",registry);
1550 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1552 JsonFormatLocaleFile(file,"%s",value);
1553 registry=GetNextImageRegistry();
1555 (void) FormatLocaleFile(file," },\n");
1557 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1558 image->taint != MagickFalse ? "true" : "false");
1559 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
1561 JsonFormatLocaleFile(file," \"filesize\": %s,\n",format);
1562 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1563 MagickFalse,"B",MagickPathExtent,format);
1564 if (strlen(format) > 1)
1565 format[strlen(format)-1]='\0';
1566 JsonFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
1567 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
1568 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
1569 JsonFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
1570 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1571 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1572 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1573 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1575 url=GetMagickHomeURL();
1576 JsonFormatLocaleFile(file," \"version\": %s\n",url);
1577 url=DestroyString(url);
1578 (void) FormatLocaleFile(file," }\n}\n");
1579 (void) fflush(file);
1580 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1583 static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1584 Image *image,ExceptionInfo *exception)
1596 Open output image file.
1598 assert(image_info != (const ImageInfo *) NULL);
1599 assert(image_info->signature == MagickCoreSignature);
1600 assert(image != (Image *) NULL);
1601 assert(image->signature == MagickCoreSignature);
1602 if (image->debug != MagickFalse)
1603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1604 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1605 if (status == MagickFalse)
1607 file=GetBlobFileHandle(image);
1608 if (file == (FILE *) NULL)
1613 WriteBlobString(image,"[");
1614 image->magick_columns=image->columns;
1615 image->magick_rows=image->rows;
1616 EncodeImageAttributes(image,file,exception);
1617 if (GetNextImageInList(image) == (Image *) NULL)
1619 WriteBlobString(image,"]");
1622 WriteBlobString(image,",\n");
1623 image=SyncNextImageInList(image);
1624 status=SetImageProgress(image,SaveImagesTag,scene++,
1625 GetImageListLength(image));
1626 if (status == MagickFalse)
1628 } while (image_info->adjoin != MagickFalse);
1629 (void) CloseBlob(image);