2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % JJJJJ SSSSS OOO N N %
13 % Write Info About the Image in JSON Format. %
20 % Copyright 1999-2015 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->flags^=CoderBlobSupportFlag;
115 (void) RegisterMagickInfo(entry);
116 return(MagickImageCoderSignature);
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 % U n r e g i s t e r J S O N I m a g e %
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % UnregisterJSONImage() removes format registrations made by the
131 % JSON module from the list of supported formats.
133 % The format of the UnregisterJSONImage method is:
135 % UnregisterJSONImage(void)
138 ModuleExport void UnregisterJSONImage(void)
140 (void) UnregisterMagickInfo("JSON");
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % W r i t e J S O N I m a g e %
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 % WriteJSONImage writes the image attributes in the JSON format.
156 % The format of the WriteJSONImage method is:
158 % MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
159 % Image *image,ExceptionInfo *exception)
161 % A description of each parameter follows.
163 % o image_info: the image info.
165 % o image: The image.
167 % o exception: return any errors or warnings in this structure.
171 static void JsonFormatLocaleFile(FILE *file,const char *format,const char *value)
185 assert(format != (const char *) NULL);
186 if (value == (char *) NULL || *value == '\0')
188 (void) FormatLocaleFile(file,format,"null");
191 length=strlen(value)+2;
193 Find all the chars that need escaping and increase the dest length counter
195 for (p=value; *p != '\0'; p++)
214 escaped_json=(char *) NULL;
215 if (~length >= (MagickPathExtent-1))
216 escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent,
217 sizeof(*escaped_json));
218 if (escaped_json == (char *) NULL)
220 (void) FormatLocaleFile(file,format,"null");
225 for (p=value; *p != '\0'; p++)
264 (void) FormatLocaleFile(file,format,escaped_json);
265 (void) DestroyString(escaped_json);
268 static ChannelStatistics *GetLocationStatistics(const Image *image,
269 const StatisticType type,ExceptionInfo *exception)
280 assert(image != (Image *) NULL);
281 assert(image->signature == MagickCoreSignature);
282 if (image->debug != MagickFalse)
283 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
284 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
285 MaxPixelChannels+1,sizeof(*channel_statistics));
286 if (channel_statistics == (ChannelStatistics *) NULL)
287 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
288 (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
289 sizeof(*channel_statistics));
290 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
294 case MaximumStatistic:
297 channel_statistics[i].maxima=(-MagickMaximumValue);
300 case MinimumStatistic:
302 channel_statistics[i].minima=MagickMaximumValue;
307 for (y=0; y < (ssize_t) image->rows; y++)
309 register const Quantum
315 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
316 if (p == (const Quantum *) NULL)
318 for (x=0; x < (ssize_t) image->columns; x++)
323 if (GetPixelReadMask(image,p) == 0)
325 p+=GetPixelChannels(image);
328 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
330 PixelChannel channel=GetPixelChannelChannel(image,i);
331 PixelTrait traits=GetPixelChannelTraits(image,channel);
332 if (traits == UndefinedPixelTrait)
336 case MaximumStatistic:
339 if ((double) p[i] > channel_statistics[channel].maxima)
340 channel_statistics[channel].maxima=(double) p[i];
343 case MinimumStatistic:
345 if ((double) p[i] < channel_statistics[channel].minima)
346 channel_statistics[channel].minima=(double) p[i];
351 p+=GetPixelChannels(image);
354 return(channel_statistics);
357 static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
358 const char *name,const MagickBooleanType separator,
359 const ChannelFeatures *channel_features)
361 #define PrintFeature(feature) \
362 GetMagickPrecision(),(feature)[0], \
363 GetMagickPrecision(),(feature)[1], \
364 GetMagickPrecision(),(feature)[2], \
365 GetMagickPrecision(),(feature)[3], \
366 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
368 #define FeaturesFormat " \"%s\": {\n" \
369 " \"angularSecondMoment\": {\n" \
370 " \"horizontal\": \"%.*g\",\n" \
371 " \"vertical\": \"%.*g\",\n" \
372 " \"leftDiagonal\": \"%.*g\",\n" \
373 " \"rightDiagonal\": \"%.*g\",\n" \
374 " \"average\": \"%.*g\"\n" \
376 " \"contrast\": {\n" \
377 " \"horizontal\": \"%.*g\",\n" \
378 " \"vertical\": \"%.*g\",\n" \
379 " \"leftDiagonal\": \"%.*g\",\n" \
380 " \"rightDiagonal\": \"%.*g\",\n" \
381 " \"average\": \"%.*g\"\n" \
383 " \"correlation\": {\n" \
384 " \"horizontal\": \"%.*g\",\n" \
385 " \"vertical\": \"%.*g\",\n" \
386 " \"leftDiagonal\": \"%.*g\",\n" \
387 " \"rightDiagonal\": \"%.*g\",\n" \
388 " \"average\": \"%.*g\"\n" \
390 " \"sumOfSquaresVariance\": {\n" \
391 " \"horizontal\": \"%.*g\",\n" \
392 " \"vertical\": \"%.*g\",\n" \
393 " \"leftDiagonal\": \"%.*g\",\n" \
394 " \"rightDiagonal\": \"%.*g\",\n" \
395 " \"average\": \"%.*g\"\n" \
397 " \"inverseDifferenceMoment\": {\n" \
398 " \"horizontal\": \"%.*g\",\n" \
399 " \"vertical\": \"%.*g\",\n" \
400 " \"leftDiagonal\": \"%.*g\",\n" \
401 " \"rightDiagonal\": \"%.*g\",\n" \
402 " \"average\": \"%.*g\"\n" \
404 " \"sumAverage\": {\n" \
405 " \"horizontal\": \"%.*g\",\n" \
406 " \"vertical\": \"%.*g\",\n" \
407 " \"leftDiagonal\": \"%.*g\",\n" \
408 " \"rightDiagonal\": \"%.*g\",\n" \
409 " \"average\": \"%.*g\"\n" \
411 " \"sumVariance\": {\n" \
412 " \"horizontal\": \"%.*g\",\n" \
413 " \"vertical\": \"%.*g\",\n" \
414 " \"leftDiagonal\": \"%.*g\",\n" \
415 " \"rightDiagonal\": \"%.*g\",\n" \
416 " \"average\": \"%.*g\"\n" \
418 " \"sumEntropy\": {\n" \
419 " \"horizontal\": \"%.*g\",\n" \
420 " \"vertical\": \"%.*g\",\n" \
421 " \"leftDiagonal\": \"%.*g\",\n" \
422 " \"rightDiagonal\": \"%.*g\",\n" \
423 " \"average\": \"%.*g\"\n" \
425 " \"entropy\": {\n" \
426 " \"horizontal\": \"%.*g\",\n" \
427 " \"vertical\": \"%.*g\",\n" \
428 " \"leftDiagonal\": \"%.*g\",\n" \
429 " \"rightDiagonal\": \"%.*g\",\n" \
430 " \"average\": \"%.*g\"\n" \
432 " \"differenceVariance\": {\n" \
433 " \"horizontal\": \"%.*g\",\n" \
434 " \"vertical\": \"%.*g\",\n" \
435 " \"leftDiagonal\": \"%.*g\",\n" \
436 " \"rightDiagonal\": \"%.*g\",\n" \
437 " \"average\": \"%.*g\"\n" \
439 " \"differenceEntropy\": {\n" \
440 " \"horizontal\": \"%.*g\",\n" \
441 " \"vertical\": \"%.*g\",\n" \
442 " \"leftDiagonal\": \"%.*g\",\n" \
443 " \"rightDiagonal\": \"%.*g\",\n" \
444 " \"average\": \"%.*g\"\n" \
446 " \"informationMeasureOfCorrelation1\": {\n" \
447 " \"horizontal\": \"%.*g\",\n" \
448 " \"vertical\": \"%.*g\",\n" \
449 " \"leftDiagonal\": \"%.*g\",\n" \
450 " \"rightDiagonal\": \"%.*g\",\n" \
451 " \"average\": \"%.*g\"\n" \
453 " \"informationMeasureOfCorrelation2\": {\n" \
454 " \"horizontal\": \"%.*g\",\n" \
455 " \"vertical\": \"%.*g\",\n" \
456 " \"leftDiagonal\": \"%.*g\",\n" \
457 " \"rightDiagonal\": \"%.*g\",\n" \
458 " \"average\": \"%.*g\"\n" \
460 " \"maximumCorrelationCoefficient\": {\n" \
461 " \"horizontal\": \"%.*g\",\n" \
462 " \"vertical\": \"%.*g\",\n" \
463 " \"leftDiagonal\": \"%.*g\",\n" \
464 " \"rightDiagonal\": \"%.*g\",\n" \
465 " \"average\": \"%.*g\"\n" \
471 n=FormatLocaleFile(file,FeaturesFormat,name,
472 PrintFeature(channel_features[channel].angular_second_moment),
473 PrintFeature(channel_features[channel].contrast),
474 PrintFeature(channel_features[channel].correlation),
475 PrintFeature(channel_features[channel].variance_sum_of_squares),
476 PrintFeature(channel_features[channel].inverse_difference_moment),
477 PrintFeature(channel_features[channel].sum_average),
478 PrintFeature(channel_features[channel].sum_variance),
479 PrintFeature(channel_features[channel].sum_entropy),
480 PrintFeature(channel_features[channel].entropy),
481 PrintFeature(channel_features[channel].difference_variance),
482 PrintFeature(channel_features[channel].difference_entropy),
483 PrintFeature(channel_features[channel].measure_of_correlation_1),
484 PrintFeature(channel_features[channel].measure_of_correlation_2),
485 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
486 (void) FormatLocaleFile(file," }");
487 if (separator != MagickFalse)
488 (void) FormatLocaleFile(file,",");
489 (void) FormatLocaleFile(file,"\n");
493 static ssize_t PrintChannelLocations(FILE *file,const Image *image,
494 const PixelChannel channel,const char *name,const StatisticType type,
495 const size_t max_locations,const MagickBooleanType separator,
496 const ChannelStatistics *channel_statistics)
510 case MaximumStatistic:
513 target=channel_statistics[channel].maxima;
516 case MinimumStatistic:
518 target=channel_statistics[channel].minima;
522 (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": "
523 "\"%.*g\",\n",name,GetMagickPrecision(),QuantumScale*target);
524 exception=AcquireExceptionInfo();
526 for (y=0; y < (ssize_t) image->rows; y++)
528 register const Quantum
535 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
536 if (p == (const Quantum *) NULL)
538 for (x=0; x < (ssize_t) image->columns; x++)
543 PixelTrait traits=GetPixelChannelTraits(image,channel);
544 if (traits == UndefinedPixelTrait)
546 offset=GetPixelChannelOffset(image,channel);
547 match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse;
548 if (match != MagickFalse)
550 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
553 (void) FormatLocaleFile(file,",\n");
554 (void) FormatLocaleFile(file," \"location%.20g\": {\n"
555 " \"x\": %.20g,\n \"y\": %.20g\n"
556 " }",(double) n,(double) x,(double) y);
559 p+=GetPixelChannels(image);
561 if (x < (ssize_t) image->columns)
564 (void) FormatLocaleFile(file,"\n }");
565 if (separator != MagickFalse)
566 (void) FormatLocaleFile(file,",");
567 (void) FormatLocaleFile(file,"\n");
571 static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
572 const char *name,const MagickBooleanType separator,
573 const ChannelMoments *channel_moments)
581 n=FormatLocaleFile(file," \"%s\": {\n",name);
582 n+=FormatLocaleFile(file," \"centroid\": {\n "
583 " \"x\": \"%.*g\",\n"
584 " \"y\": \"%.*g\"\n },\n",
585 GetMagickPrecision(),channel_moments[channel].centroid.x,
586 GetMagickPrecision(),channel_moments[channel].centroid.y);
587 n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n"
588 " \"x\": \"%.*g\",\n"
589 " \"y\": \"%.*g\"\n },\n",
590 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
591 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
592 n+=FormatLocaleFile(file," \"ellipseAngle\": \"%.*g\",\n",
593 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
594 n+=FormatLocaleFile(file," \"ellipseEccentricity\": \"%.*g\",\n",
595 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
596 n+=FormatLocaleFile(file," \"ellipseIntensity\": \"%.*g\",\n",
597 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
598 for (i=0; i < 7; i++)
599 n+=FormatLocaleFile(file," \"I%.20g\": \"%.*g\",\n",i+1.0,
600 GetMagickPrecision(),channel_moments[channel].invariant[i]);
601 n+=FormatLocaleFile(file," \"I%.20g\": \"%.*g\"\n",i+1.0,
602 GetMagickPrecision(),channel_moments[channel].invariant[i]);
603 (void) FormatLocaleFile(file," }");
604 if (separator != MagickFalse)
605 (void) FormatLocaleFile(file,",");
606 (void) FormatLocaleFile(file,"\n");
610 static ssize_t PrintChannelPerceptualHash(FILE *file,const ChannelType channel,
611 const char *name,const MagickBooleanType separator,
612 const ChannelPerceptualHash *channel_phash)
620 n=FormatLocaleFile(file," \"%s\": {\n",name);
621 for (i=0; i < 6; i++)
622 n+=FormatLocaleFile(file,
623 " \"PH%.20g\": [ \"%.*g\", \"%.*g\" ],\n",i+1.0,
624 GetMagickPrecision(),channel_phash[channel].srgb_hu_phash[i],
625 GetMagickPrecision(),channel_phash[channel].hclp_hu_phash[i]);
626 n+=FormatLocaleFile(file,
627 " \"PH%.20g\": [ \"%.*g\", \"%.*g\" ]\n",i+1.0,
628 GetMagickPrecision(),channel_phash[channel].srgb_hu_phash[i],
629 GetMagickPrecision(),channel_phash[channel].hclp_hu_phash[i]);
630 (void) FormatLocaleFile(file," }");
631 if (separator != MagickFalse)
632 (void) FormatLocaleFile(file,",");
633 (void) FormatLocaleFile(file,"\n");
637 static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
638 const char *name,const double scale,const MagickBooleanType separator,
639 const ChannelStatistics *channel_statistics)
641 #define StatisticsFormat " \"%s\": {\n \"min\": \"" QuantumFormat \
642 "\",\n \"max\": \"" QuantumFormat "\",\n" \
643 " \"mean\": \"%g\",\n \"standardDeviation\": " \
644 "\"%g\",\n \"kurtosis\": \"%g\",\n \"skewness\": " \
650 n=FormatLocaleFile(file,StatisticsFormat,name,ClampToQuantum(scale*
651 channel_statistics[channel].minima),ClampToQuantum(scale*
652 channel_statistics[channel].maxima),scale*channel_statistics[channel].mean,
653 scale*channel_statistics[channel].standard_deviation,
654 channel_statistics[channel].kurtosis,channel_statistics[channel].skewness);
655 if (separator != MagickFalse)
656 (void) FormatLocaleFile(file,",");
657 (void) FormatLocaleFile(file,"\n");
661 static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
662 ExceptionInfo *exception)
665 color[MagickPathExtent],
666 format[MagickPathExtent],
667 key[MagickPathExtent];
675 ChannelPerceptualHash
705 register const Quantum
720 assert(image != (Image *) NULL);
721 assert(image->signature == MagickCoreSignature);
722 if (image->debug != MagickFalse)
723 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
725 elapsed_time=GetElapsedTime(&image->timer);
726 user_time=GetUserTime(&image->timer);
727 GetTimerInfo(&image->timer);
728 p=GetVirtualPixels(image,0,0,1,1,exception);
729 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
731 type=GetImageType(image,exception);
732 (void) SignatureImage(image,exception);
733 JsonFormatLocaleFile(file,"{\n \"image\": {\n \"name\": %s,\n",
735 if (*image->magick_filename != '\0')
736 if (LocaleCompare(image->magick_filename,image->filename) != 0)
739 filename[MagickPathExtent];
741 GetPathComponent(image->magick_filename,TailPath,filename);
742 JsonFormatLocaleFile(file," \"baseName\": %s,\n",filename);
744 JsonFormatLocaleFile(file," \"format\": %s,\n",image->magick);
745 magick_info=GetMagickInfo(image->magick,exception);
746 if ((magick_info != (const MagickInfo *) NULL) &&
747 (GetMagickDescription(magick_info) != (const char *) NULL))
748 JsonFormatLocaleFile(file," \"formatDescription\": %s,\n",
750 if ((magick_info != (const MagickInfo *) NULL) &&
751 (GetMagickMimeType(magick_info) != (const char *) NULL))
752 JsonFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
754 JsonFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
755 MagickClassOptions,(ssize_t) image->storage_class));
756 (void) FormatLocaleFile(file," \"geometry\": {\n"
757 " \"width\": %.20g,\n \"height\": %.20g,\n"
758 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
759 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
760 (double) image->tile_offset.y);
761 if ((image->magick_columns != 0) || (image->magick_rows != 0))
762 if ((image->magick_columns != image->columns) ||
763 (image->magick_rows != image->rows))
764 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
765 " \"width\": %.20g,\n \"height\": %.20g\n },\n",
766 (double) image->magick_columns,(double) image->magick_rows);
767 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
769 (void) FormatLocaleFile(file," \"resolution\": {\n"
770 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
771 image->resolution.x,image->resolution.y);
772 (void) FormatLocaleFile(file," \"printSize\": {\n"
773 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
774 image->columns/image->resolution.x,(double) image->rows/
775 image->resolution.y);
777 JsonFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
778 MagickResolutionOptions,(ssize_t) image->units));
779 JsonFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
780 MagickTypeOptions,(ssize_t) type));
781 if (image->type != UndefinedType)
782 JsonFormatLocaleFile(file," \"baseType\": %s,\n",
783 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) image->type));
784 JsonFormatLocaleFile(file," \"endianess\": %s,\n",
785 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
786 locate=GetImageArtifact(image,"identify:locate");
787 if (locate == (const char *) NULL)
788 locate=GetImageArtifact(image,"json:locate");
789 if (locate != (const char *) NULL)
801 Display minimum, maximum, or mean pixel locations.
803 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
805 limit=GetImageArtifact(image,"identify:limit");
806 if (limit == (const char *) NULL)
807 limit=GetImageArtifact(image,"json:limit");
809 if (limit != (const char *) NULL)
810 max_locations=StringToUnsignedLong(limit);
811 channel_statistics=GetLocationStatistics(image,type,exception);
812 if (channel_statistics == (ChannelStatistics *) NULL)
814 colorspace=image->colorspace;
815 if (SetImageGray(image,exception) != MagickFalse)
816 colorspace=GRAYColorspace;
817 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
818 if (image->alpha_trait != UndefinedPixelTrait)
819 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
820 type,max_locations,MagickTrue,channel_statistics);
826 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
827 type,max_locations,MagickTrue,channel_statistics);
828 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
829 type,max_locations,MagickTrue,channel_statistics);
830 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
831 type,max_locations,MagickFalse,channel_statistics);
836 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
837 type,max_locations,MagickTrue,channel_statistics);
838 (void) PrintChannelLocations(file,image,MagentaPixelChannel,"Magenta",
839 type,max_locations,MagickTrue,channel_statistics);
840 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
841 type,max_locations,MagickTrue,channel_statistics);
842 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
843 type,max_locations,MagickFalse,channel_statistics);
848 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
849 type,max_locations,MagickFalse,channel_statistics);
853 (void) FormatLocaleFile(file," },\n");
854 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
858 Detail channel depth and extrema.
860 JsonFormatLocaleFile(file," \"colorspace\": %s,\n",
861 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
863 channel_statistics=(ChannelStatistics *) NULL;
864 channel_moments=(ChannelMoments *) NULL;
865 channel_phash=(ChannelPerceptualHash *) NULL;
866 channel_features=(ChannelFeatures *) NULL;
867 colorspace=image->colorspace;
869 channel_statistics=GetImageStatistics(image,exception);
870 if (channel_statistics == (ChannelStatistics *) NULL)
872 artifact=GetImageArtifact(image,"identify:moments");
873 if (artifact == (const char *) NULL)
874 artifact=GetImageArtifact(image,"json:moments");
875 if (artifact != (const char *) NULL)
877 channel_moments=GetImageMoments(image,exception);
878 channel_phash=GetImagePerceptualHash(image,exception);
880 artifact=GetImageArtifact(image,"identify:features");
881 if (artifact == (const char *) NULL)
882 artifact=GetImageArtifact(image,"json:features");
883 if (artifact != (const char *) NULL)
885 distance=StringToUnsignedLong(artifact);
886 channel_features=GetImageFeatures(image,distance,exception);
888 depth=GetImageDepth(image,exception);
889 (void) FormatLocaleFile(file," \"depth\": %.20g,\n",(double) depth);
890 (void) FormatLocaleFile(file," \"baseDepth\": %.20g,\n",(double)
892 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
893 if (SetImageGray(image,exception) != MagickFalse)
894 colorspace=GRAYColorspace;
895 if (image->alpha_trait != UndefinedPixelTrait)
896 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
897 channel_statistics[AlphaPixelChannel].depth);
903 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
904 channel_statistics[RedChannel].depth);
905 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
906 channel_statistics[GreenChannel].depth);
907 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
908 channel_statistics[BlueChannel].depth);
913 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
914 channel_statistics[CyanChannel].depth);
915 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
916 channel_statistics[MagentaChannel].depth);
917 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
918 channel_statistics[YellowChannel].depth);
919 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
920 channel_statistics[BlackChannel].depth);
925 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
926 channel_statistics[GrayChannel].depth);
930 (void) FormatLocaleFile(file," },\n");
932 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
933 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
934 MAGICKCORE_QUANTUM_DEPTH-image->depth));
935 if (channel_statistics != (ChannelStatistics *) NULL)
937 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
938 channel_statistics[CompositePixelChannel].area);
939 if (colorspace != GRAYColorspace)
941 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
942 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
943 "Overall",1.0/scale,MagickFalse,channel_statistics);
944 (void) FormatLocaleFile(file," },\n");
946 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
947 if (image->alpha_trait != UndefinedPixelTrait)
948 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
949 MagickTrue,channel_statistics);
955 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale,
956 MagickTrue,channel_statistics);
957 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
958 scale,MagickTrue,channel_statistics);
959 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale,
960 MagickFalse,channel_statistics);
965 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale,
966 MagickTrue,channel_statistics);
967 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
968 scale,MagickTrue,channel_statistics);
969 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
970 scale,MagickTrue,channel_statistics);
971 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
972 scale,MagickFalse,channel_statistics);
977 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale,
978 MagickFalse,channel_statistics);
982 (void) FormatLocaleFile(file," },\n");
983 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
986 if (channel_moments != (ChannelMoments *) NULL)
988 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
989 if (image->alpha_trait != UndefinedPixelTrait)
990 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue,
997 (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue,
999 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue,
1001 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse,
1005 case CMYKColorspace:
1007 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue,
1009 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
1010 MagickTrue,channel_moments);
1011 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
1012 MagickTrue,channel_moments);
1013 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
1014 MagickFalse,channel_moments);
1017 case GRAYColorspace:
1019 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse,
1024 (void) FormatLocaleFile(file," },\n");
1025 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1028 if (channel_phash != (ChannelPerceptualHash *) NULL)
1030 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
1031 if (image->alpha_trait != UndefinedPixelTrait)
1032 (void) PrintChannelPerceptualHash(file,AlphaChannel,"alphaAlpha",
1033 MagickTrue,channel_phash);
1034 (void) PrintChannelPerceptualHash(file,RedChannel,"redHue",MagickTrue,
1036 (void) PrintChannelPerceptualHash(file,GreenChannel,"greenChroma",
1037 MagickTrue,channel_phash);
1038 (void) PrintChannelPerceptualHash(file,BlueChannel,"blueLuma",MagickFalse,
1040 (void) FormatLocaleFile(file," },\n");
1041 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1044 if (channel_features != (ChannelFeatures *) NULL)
1046 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1047 if (image->alpha_trait != UndefinedPixelTrait)
1048 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue,
1055 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue,
1057 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
1058 MagickTrue,channel_features);
1059 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse,
1063 case CMYKColorspace:
1065 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue,
1067 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
1068 MagickTrue,channel_features);
1069 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
1070 MagickTrue,channel_features);
1071 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
1072 MagickFalse,channel_features);
1075 case GRAYColorspace:
1077 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse,
1082 (void) FormatLocaleFile(file," },\n");
1083 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1086 if (image->colorspace == CMYKColorspace)
1087 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
1088 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1089 (double) QuantumRange);
1091 if (image->alpha_trait != UndefinedPixelTrait)
1093 register const Quantum
1096 p=(const Quantum *) NULL;
1097 for (y=0; y < (ssize_t) image->rows; y++)
1099 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1100 if (p == (const Quantum *) NULL)
1102 for (x=0; x < (ssize_t) image->columns; x++)
1104 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
1106 p+=GetPixelChannels(image);
1108 if (x < (ssize_t) image->columns)
1111 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1116 GetPixelInfo(image,&pixel);
1117 GetPixelInfoPixel(image,p,&pixel);
1118 GetColorTuple(&pixel,MagickTrue,color);
1119 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1122 if (image->storage_class == PseudoClass)
1127 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1128 (double) image->colors);
1129 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1131 for (i=0; i < (ssize_t) image->colors; i++)
1133 GetColorTuple(p,MagickTrue,color);
1134 (void) FormatLocaleFile(file,"\"%s\"",color);
1135 if (i < (ssize_t) (image->colors-1))
1136 (void) FormatLocaleFile(file,",");
1137 if (((i+1) % 5) == 0)
1138 (void) FormatLocaleFile(file,"\n ");
1141 (void) FormatLocaleFile(file,"\n ],\n");
1143 if (image->error.mean_error_per_pixel != 0.0)
1144 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": \"%g\",\n",
1145 image->error.mean_error_per_pixel);
1146 if (image->error.normalized_mean_error != 0.0)
1147 (void) FormatLocaleFile(file," \"normalizedMeanError\": \"%g\",\n",
1148 image->error.normalized_mean_error);
1149 if (image->error.normalized_maximum_error != 0.0)
1150 (void) FormatLocaleFile(file," \"normalizedMaximumError\": \"%g\",\n",
1151 image->error.normalized_maximum_error);
1152 JsonFormatLocaleFile(file," \"renderingIntent\": %s,\n",
1153 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1154 image->rendering_intent));
1155 if (image->gamma != 0.0)
1156 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
1157 if ((image->chromaticity.red_primary.x != 0.0) ||
1158 (image->chromaticity.green_primary.x != 0.0) ||
1159 (image->chromaticity.blue_primary.x != 0.0) ||
1160 (image->chromaticity.white_point.x != 0.0))
1163 Display image chromaticity.
1165 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1166 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1167 " \"x\": %g,\n \"y\": %g\n },\n",
1168 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
1169 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1170 " \"x\": %g,\n \"y\": %g\n },\n",
1171 image->chromaticity.green_primary.x,
1172 image->chromaticity.green_primary.y);
1173 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1174 " \"x\": %g,\n \"y\": %g\n },\n",
1175 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
1176 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1177 " \"x\": %g,\n \"y\": %g\n }\n",
1178 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
1179 (void) FormatLocaleFile(file," },\n");
1181 if ((image->extract_info.width*image->extract_info.height) != 0)
1182 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1183 " \"width\": %.20g,\n \"height\": %.20g,\n"
1184 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1185 (double) image->extract_info.width,(double) image->extract_info.height,
1186 (double) image->extract_info.x,(double) image->extract_info.y);
1187 GetColorTuple(&image->background_color,MagickTrue,color);
1188 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1189 GetColorTuple(&image->border_color,MagickTrue,color);
1190 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
1191 GetColorTuple(&image->matte_color,MagickTrue,color);
1192 (void) FormatLocaleFile(file," \"matteColor\": \"%s\",\n",color);
1193 GetColorTuple(&image->transparent_color,MagickTrue,color);
1194 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
1195 JsonFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
1196 MagickInterlaceOptions,(ssize_t) image->interlace));
1197 JsonFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
1198 MagickPixelIntensityOptions,(ssize_t) image->intensity));
1199 JsonFormatLocaleFile(file," \"compose\": %s,\n",
1200 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
1201 if ((image->page.width != 0) || (image->page.height != 0) ||
1202 (image->page.x != 0) || (image->page.y != 0))
1203 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1204 " \"width\": %.20g,\n \"height\": %.20g,\n"
1205 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1206 (double) image->page.width,(double) image->page.height,
1207 (double) image->page.x,(double) image->page.y);
1208 if ((image->page.x != 0) || (image->page.y != 0))
1209 (void) FormatLocaleFile(file," \"originGeometry\": %+.20g%+.20g\n",
1210 (double) image->page.x,(double) image->page.y);
1211 JsonFormatLocaleFile(file," \"dispose\": %s,\n",
1212 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
1213 if (image->delay != 0)
1214 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\"\n",
1215 (double) image->delay,(double) image->ticks_per_second);
1216 if (image->iterations != 1)
1217 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
1219 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
1220 (void) FormatLocaleFile(file," \"scene\": %.20g\n \"scenes\": "
1221 "%.20g\n",(double) image->scene,(double) GetImageListLength(image));
1223 if (image->scene != 0)
1224 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1226 JsonFormatLocaleFile(file," \"compression\": %s,\n",
1227 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1228 image->compression));
1229 if (image->quality != UndefinedCompressionQuality)
1230 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1232 JsonFormatLocaleFile(file," \"orientation\": %s,\n",
1233 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1234 image->orientation));
1235 if (image->montage != (char *) NULL)
1236 JsonFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
1237 if (image->directory != (char *) NULL)
1253 Display visual image directory.
1255 image_info=AcquireImageInfo();
1256 (void) CloneString(&image_info->size,"64x64");
1257 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1262 while ((*q != '\n') && (*q != '\0'))
1264 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
1266 JsonFormatLocaleFile(file,"{\n \"name\": %s",
1267 image_info->filename);
1268 handler=SetWarningHandler((WarningHandler) NULL);
1269 tile=ReadImage(image_info,exception);
1270 (void) SetWarningHandler(handler);
1271 if (tile == (Image *) NULL)
1273 (void) FormatLocaleFile(file," }");
1276 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1277 (double) tile->magick_columns,(double) tile->magick_rows,
1279 (void) SignatureImage(tile,exception);
1280 ResetImagePropertyIterator(tile);
1281 property=GetNextImageProperty(tile);
1282 while (property != (const char *) NULL)
1284 JsonFormatLocaleFile(file,",\n %s: ",property);
1285 value=GetImageProperty(tile,property,exception);
1286 JsonFormatLocaleFile(file,"%s",value);
1287 property=GetNextImageProperty(tile);
1289 tile=DestroyImage(tile);
1291 (void) FormatLocaleFile(file,"\n },");
1293 (void) FormatLocaleFile(file,"\n }");
1295 (void) FormatLocaleFile(file,"],\n");
1296 image_info=DestroyImageInfo(image_info);
1298 (void) GetImageProperty(image,"exif:*",exception);
1299 (void) GetImageProperty(image,"icc:*",exception);
1300 (void) GetImageProperty(image,"iptc:*",exception);
1301 (void) GetImageProperty(image,"xmp:*",exception);
1302 ResetImagePropertyIterator(image);
1303 property=GetNextImageProperty(image);
1304 if (property != (const char *) NULL)
1310 Display image properties.
1313 (void) FormatLocaleFile(file," \"properties\": {\n");
1314 while (property != (const char *) NULL)
1317 (void) FormatLocaleFile(file,",\n");
1318 JsonFormatLocaleFile(file," %s: ",property);
1319 value=GetImageProperty(image,property,exception);
1320 JsonFormatLocaleFile(file,"%s",value);
1321 property=GetNextImageProperty(image);
1323 (void) FormatLocaleFile(file,"\n },\n");
1325 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
1326 value=GetImageProperty(image,key,exception);
1327 if (value != (const char *) NULL)
1330 Display clipping path.
1332 (void) FormatLocaleFile(file," \"clipping path\": {\n");
1333 JsonFormatLocaleFile(file,"%s\n",value);
1334 (void) FormatLocaleFile(file," },\n");
1336 ResetImageProfileIterator(image);
1337 name=GetNextImageProfile(image);
1338 if (name != (char *) NULL)
1347 Identify image profiles.
1350 (void) FormatLocaleFile(file," \"profiles\": {\n");
1351 while (name != (char *) NULL)
1353 profile=GetImageProfile(image,name);
1354 if (profile == (StringInfo *) NULL)
1357 (void) FormatLocaleFile(file,",\n");
1358 JsonFormatLocaleFile(file," %s: {\n",name);
1359 if (LocaleCompare(name,"iptc") == 0)
1380 profile_length=GetStringInfoLength(profile);
1381 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
1384 sentinel=GetStringInfoDatum(profile)[i++];
1385 if (sentinel != 0x1c)
1387 dataset=GetStringInfoDatum(profile)[i++];
1388 record=GetStringInfoDatum(profile)[i++];
1391 case 5: tag="Image Name"; break;
1392 case 7: tag="Edit Status"; break;
1393 case 10: tag="Priority"; break;
1394 case 15: tag="Category"; break;
1395 case 20: tag="Supplemental Category"; break;
1396 case 22: tag="Fixture Identifier"; break;
1397 case 25: tag="Keyword"; break;
1398 case 30: tag="Release Date"; break;
1399 case 35: tag="Release Time"; break;
1400 case 40: tag="Special Instructions"; break;
1401 case 45: tag="Reference Service"; break;
1402 case 47: tag="Reference Date"; break;
1403 case 50: tag="Reference Number"; break;
1404 case 55: tag="Created Date"; break;
1405 case 60: tag="Created Time"; break;
1406 case 65: tag="Originating Program"; break;
1407 case 70: tag="Program Version"; break;
1408 case 75: tag="Object Cycle"; break;
1409 case 80: tag="Byline"; break;
1410 case 85: tag="Byline Title"; break;
1411 case 90: tag="City"; break;
1412 case 92: tag="Sub-Location"; break;
1413 case 95: tag="Province State"; break;
1414 case 100: tag="Country Code"; break;
1415 case 101: tag="Country"; break;
1416 case 103: tag="Original Transmission Reference"; break;
1417 case 105: tag="Headline"; break;
1418 case 110: tag="Credit"; break;
1419 case 115: tag="Src"; break;
1420 case 116: tag="Copyright String"; break;
1421 case 120: tag="Caption"; break;
1422 case 121: tag="Local Caption"; break;
1423 case 122: tag="Caption Writer"; break;
1424 case 200: tag="Custom Field 1"; break;
1425 case 201: tag="Custom Field 2"; break;
1426 case 202: tag="Custom Field 3"; break;
1427 case 203: tag="Custom Field 4"; break;
1428 case 204: tag="Custom Field 5"; break;
1429 case 205: tag="Custom Field 6"; break;
1430 case 206: tag="Custom Field 7"; break;
1431 case 207: tag="Custom Field 8"; break;
1432 case 208: tag="Custom Field 9"; break;
1433 case 209: tag="Custom Field 10"; break;
1434 case 210: tag="Custom Field 11"; break;
1435 case 211: tag="Custom Field 12"; break;
1436 case 212: tag="Custom Field 13"; break;
1437 case 213: tag="Custom Field 14"; break;
1438 case 214: tag="Custom Field 15"; break;
1439 case 215: tag="Custom Field 16"; break;
1440 case 216: tag="Custom Field 17"; break;
1441 case 217: tag="Custom Field 18"; break;
1442 case 218: tag="Custom Field 19"; break;
1443 case 219: tag="Custom Field 20"; break;
1444 default: tag="unknown"; break;
1446 (void) FormatLocaleFile(file," %s[%.20g,%.20g]: ",tag,
1447 (double) dataset,(double) record);
1448 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
1449 length|=GetStringInfoDatum(profile)[i++];
1450 attribute=(char *) NULL;
1451 if (~length >= (MagickPathExtent-1))
1452 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1453 sizeof(*attribute));
1454 if (attribute != (char *) NULL)
1456 (void) CopyMagickString(attribute,(char *)
1457 GetStringInfoDatum(profile)+i,length+1);
1458 attribute_list=StringToList(attribute);
1459 if (attribute_list != (char **) NULL)
1461 (void) FormatLocaleFile(file,"[");
1462 for (j=0; attribute_list[j] != (char *) NULL; j++)
1465 (void) FormatLocaleFile(file,",");
1466 JsonFormatLocaleFile(file,"%s",attribute_list[j]);
1467 attribute_list[j]=(char *) RelinquishMagickMemory(
1470 (void) FormatLocaleFile(file,"],");
1471 attribute_list=(char **) RelinquishMagickMemory(
1475 (void) FormatLocaleFile(file,"null,");
1476 attribute=DestroyString(attribute);
1479 (void) FormatLocaleFile(file,"null,");
1482 (void) FormatLocaleFile(file," \"length\": \"%.20g\"",(double)
1483 GetStringInfoLength(profile));
1484 (void) FormatLocaleFile(file,"\n }");
1485 name=GetNextImageProfile(image);
1487 (void) FormatLocaleFile(file,"\n },\n");
1489 ResetImageArtifactIterator(image);
1490 artifact=GetNextImageArtifact(image);
1491 if (artifact != (const char *) NULL)
1497 Display image artifacts.
1500 (void) FormatLocaleFile(file," \"artifacts\": {\n");
1501 while (artifact != (const char *) NULL)
1504 (void) FormatLocaleFile(file,",\n");
1505 JsonFormatLocaleFile(file," %s: ",artifact);
1506 value=GetImageArtifact(image,artifact);
1507 JsonFormatLocaleFile(file,"%s",value);
1508 artifact=GetNextImageArtifact(image);
1510 (void) FormatLocaleFile(file,"\n },\n");
1512 ResetImageRegistryIterator();
1513 registry=GetNextImageRegistry();
1514 if (registry != (const char *) NULL)
1520 Display image registry.
1522 (void) FormatLocaleFile(file," \"registry\": {\n");
1524 while (registry != (const char *) NULL)
1527 (void) FormatLocaleFile(file,",\n");
1528 JsonFormatLocaleFile(file," %s: ",registry);
1529 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1531 JsonFormatLocaleFile(file,"%s",value);
1532 registry=GetNextImageRegistry();
1534 (void) FormatLocaleFile(file," },\n");
1536 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1537 image->taint != MagickFalse ? "true" : "false");
1538 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
1540 JsonFormatLocaleFile(file," \"filesize\": %s,\n",format);
1541 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
1542 MagickFalse,"B",MagickPathExtent,format);
1543 if (strlen(format) > 1)
1544 format[strlen(format)-1]='\0';
1545 JsonFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
1546 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
1547 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
1548 JsonFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
1549 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1550 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1551 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1552 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1554 JsonFormatLocaleFile(file," \"version\": %s\n",
1555 GetMagickVersion((size_t *) NULL));
1556 (void) FormatLocaleFile(file," }\n}\n");
1557 (void) fflush(file);
1558 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1561 static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1562 Image *image,ExceptionInfo *exception)
1574 Open output image file.
1576 assert(image_info != (const ImageInfo *) NULL);
1577 assert(image_info->signature == MagickCoreSignature);
1578 assert(image != (Image *) NULL);
1579 assert(image->signature == MagickCoreSignature);
1580 if (image->debug != MagickFalse)
1581 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1582 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1583 if (status == MagickFalse)
1585 file=GetBlobFileHandle(image);
1586 if (file == (FILE *) NULL)
1591 WriteBlobString(image,"[");
1592 image->magick_columns=image->columns;
1593 image->magick_rows=image->rows;
1594 EncodeImageAttributes(image,file,exception);
1595 if (GetNextImageInList(image) == (Image *) NULL)
1597 WriteBlobString(image,"]");
1600 WriteBlobString(image,",\n");
1601 image=SyncNextImageInList(image);
1602 status=SetImageProgress(image,SaveImagesTag,scene++,
1603 GetImageListLength(image));
1604 if (status == MagickFalse)
1606 } while (image_info->adjoin != MagickFalse);
1607 (void) CloseBlob(image);