blob: a50bf613a64ee868855c08469786db6ef163a281 [file] [log] [blame]
cristy3f07aa32014-01-18 01:16:33 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% JJJJJ SSSSS OOO N N %
7% J SS O O NN N %
8% J SSS O O N N N %
9% J J SS O O N NN %
10% JJJ SSSSS OOO N N %
11% %
12% %
13% Write Info About the Image in JSON Format. %
14% %
15% Software Design %
16% Cristy %
17% January 2014 %
18% %
19% %
Cristyf775a5c2019-11-26 14:27:47 -050020% Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization %
cristy3f07aa32014-01-18 01:16:33 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
Cristy83d74de2018-10-13 10:17:25 -040026% https://imagemagick.org/script/license.php %
cristy3f07aa32014-01-18 01:16:33 +000027% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
42#include "MagickCore/studio.h"
43#include "MagickCore/artifact.h"
cristy9e818982014-01-18 14:54:37 +000044#include "MagickCore/attribute.h"
cristy3f07aa32014-01-18 01:16:33 +000045#include "MagickCore/blob.h"
46#include "MagickCore/blob-private.h"
cristy9e818982014-01-18 14:54:37 +000047#include "MagickCore/cache.h"
cristy43602772014-01-29 14:07:29 +000048#include "MagickCore/colorspace.h"
49#include "MagickCore/colorspace-private.h"
cristy9e818982014-01-18 14:54:37 +000050#include "MagickCore/constitute.h"
cristy3f07aa32014-01-18 01:16:33 +000051#include "MagickCore/exception.h"
52#include "MagickCore/exception-private.h"
cristy9e818982014-01-18 14:54:37 +000053#include "MagickCore/feature.h"
cristy3f07aa32014-01-18 01:16:33 +000054#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"
cristy43602772014-01-29 14:07:29 +000062#include "MagickCore/pixel.h"
cristy9e818982014-01-18 14:54:37 +000063#include "MagickCore/pixel-accessor.h"
cristy43602772014-01-29 14:07:29 +000064#include "MagickCore/pixel-private.h"
cristy9e818982014-01-18 14:54:37 +000065#include "MagickCore/prepress.h"
cristy3f07aa32014-01-18 01:16:33 +000066#include "MagickCore/property.h"
cristy43602772014-01-29 14:07:29 +000067#include "MagickCore/quantum-private.h"
cristy9e818982014-01-18 14:54:37 +000068#include "MagickCore/registry.h"
cristy9e818982014-01-18 14:54:37 +000069#include "MagickCore/signature.h"
cristy43602772014-01-29 14:07:29 +000070#include "MagickCore/static.h"
cristy9e818982014-01-18 14:54:37 +000071#include "MagickCore/statistic.h"
cristy3f07aa32014-01-18 01:16:33 +000072#include "MagickCore/string_.h"
cristy9e818982014-01-18 14:54:37 +000073#include "MagickCore/string-private.h"
cristy3f07aa32014-01-18 01:16:33 +000074#include "MagickCore/utility.h"
cristy9e818982014-01-18 14:54:37 +000075#include "MagickCore/version.h"
cristy43602772014-01-29 14:07:29 +000076#include "MagickCore/module.h"
Dirk Lemstra32b15502017-09-21 17:04:36 +020077
78/*
79 Typedef declarations.
80*/
Cristydb96d692017-10-29 10:37:57 -040081typedef struct _IPTCInfo
Dirk Lemstra32b15502017-09-21 17:04:36 +020082{
83 long
84 dataset,
85 record;
86
87 size_t
88 values_length;
89
90 char
91 tag[32],
92 ***values;
Cristydb96d692017-10-29 10:37:57 -040093} IPTCInfo;
cristy3f07aa32014-01-18 01:16:33 +000094
95/*
96 Forward declarations.
97*/
98static MagickBooleanType
99 WriteJSONImage(const ImageInfo *,Image *,ExceptionInfo *);
100
101/*
102%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103% %
104% %
105% %
106% R e g i s t e r J S O N I m a g e %
107% %
108% %
109% %
110%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111%
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.
118%
119% The format of the RegisterJSONImage method is:
120%
121% size_t RegisterJSONImage(void)
122%
123*/
124ModuleExport size_t RegisterJSONImage(void)
125{
126 MagickInfo
127 *entry;
128
cristye1c94d92015-06-28 12:16:33 +0000129 entry=AcquireMagickInfo("JSON","JSON","The image format and characteristics");
cristy3f07aa32014-01-18 01:16:33 +0000130 entry->encoder=(EncodeImageHandler *) WriteJSONImage;
dirk2aa15e62015-09-14 21:33:54 +0200131 entry->mime_type=ConstantString("application/json");
Cristye47c01b2020-09-07 16:37:38 -0400132 entry->flags|=CoderEndianSupportFlag;
dirk08e9a112015-02-22 01:51:41 +0000133 entry->flags^=CoderBlobSupportFlag;
cristy3f07aa32014-01-18 01:16:33 +0000134 (void) RegisterMagickInfo(entry);
135 return(MagickImageCoderSignature);
136}
137
138/*
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140% %
141% %
142% %
143% U n r e g i s t e r J S O N I m a g e %
144% %
145% %
146% %
147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148%
149% UnregisterJSONImage() removes format registrations made by the
150% JSON module from the list of supported formats.
151%
152% The format of the UnregisterJSONImage method is:
153%
154% UnregisterJSONImage(void)
155%
156*/
157ModuleExport void UnregisterJSONImage(void)
158{
159 (void) UnregisterMagickInfo("JSON");
160}
161
162/*
163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164% %
165% %
166% %
167% W r i t e J S O N I m a g e %
168% %
169% %
170% %
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172%
173% WriteJSONImage writes the image attributes in the JSON format.
174%
175% The format of the WriteJSONImage method is:
176%
177% MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
178% Image *image,ExceptionInfo *exception)
179%
180% A description of each parameter follows.
181%
182% o image_info: the image info.
183%
184% o image: The image.
185%
186% o exception: return any errors or warnings in this structure.
187%
188*/
cristy9e818982014-01-18 14:54:37 +0000189
Cristydb96d692017-10-29 10:37:57 -0400190static void JSONFormatLocaleFile(FILE *file,const char *format,
191 const char *value)
dirk6c316f22015-06-27 15:44:29 +0000192{
193 char
194 *escaped_json;
195
Cristyf2dc1dd2020-12-28 13:59:26 -0500196 char
dirk6c316f22015-06-27 15:44:29 +0000197 *q;
198
Cristyf2dc1dd2020-12-28 13:59:26 -0500199 const char
dirk6c316f22015-06-27 15:44:29 +0000200 *p;
201
202 size_t
203 length;
204
205 assert(format != (const char *) NULL);
Cristydb96d692017-10-29 10:37:57 -0400206 if ((value == (char *) NULL) || (*value == '\0'))
207 {
208 (void) FormatLocaleFile(file,format,"null");
209 return;
210 }
dirk6c316f22015-06-27 15:44:29 +0000211 length=strlen(value)+2;
212 /*
Cristydb96d692017-10-29 10:37:57 -0400213 Find all the chars that need escaping and increase the dest length counter.
dirk6c316f22015-06-27 15:44:29 +0000214 */
215 for (p=value; *p != '\0'; p++)
Cristydb96d692017-10-29 10:37:57 -0400216 {
217 switch (*p)
dirk6c316f22015-06-27 15:44:29 +0000218 {
Cristydb96d692017-10-29 10:37:57 -0400219 case '"':
220 case '\b':
221 case '\f':
222 case '\n':
223 case '\r':
224 case '\t':
225 case '\\':
226 {
227 if (~length < 1)
228 return;
229 length++;
230 break;
231 }
232 default:
233 {
234 if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
235 length+=6;
236 break;
237 }
dirk6c316f22015-06-27 15:44:29 +0000238 }
Cristydb96d692017-10-29 10:37:57 -0400239 }
dirk6c316f22015-06-27 15:44:29 +0000240 escaped_json=(char *) NULL;
241 if (~length >= (MagickPathExtent-1))
242 escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent,
243 sizeof(*escaped_json));
244 if (escaped_json == (char *) NULL)
Cristydb96d692017-10-29 10:37:57 -0400245 {
246 (void) FormatLocaleFile(file,format,"null");
247 return;
248 }
dirk6c316f22015-06-27 15:44:29 +0000249 q=escaped_json;
250 *q++='"';
251 for (p=value; *p != '\0'; p++)
Cristydb96d692017-10-29 10:37:57 -0400252 {
253 switch (*p)
dirk6c316f22015-06-27 15:44:29 +0000254 {
Cristydb96d692017-10-29 10:37:57 -0400255 case '"':
256 {
257 *q++='\\';
258 *q++=(*p);
259 break;
260 }
261 case '\b':
262 {
263 *q++='\\';
264 *q++='b';
265 break;
266 }
267 case '\f':
268 {
269 *q++='\\';
270 *q++='f';
271 break;
272 }
273 case '\n':
274 {
275 *q++='\\';
276 *q++='n';
277 break;
278 }
279 case '\r':
280 {
281 *q++='\\';
282 *q++='r';
283 break;
284 }
285 case '\t':
286 {
287 *q++='\\';
288 *q++='t';
289 break;
290 }
291 case '\\':
292 {
293 *q++='\\';
294 *q++='\\';
295 break;
296 }
297 default:
298 {
299 if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
300 {
301 (void) FormatLocaleString(q,7,"\\u%04X",(int) *p);
302 q+=6;
dirk6c316f22015-06-27 15:44:29 +0000303 break;
Cristydb96d692017-10-29 10:37:57 -0400304 }
305 *q++=(*p);
306 break;
307 }
308 }
dirk6c316f22015-06-27 15:44:29 +0000309 }
310 *q++='"';
311 *q='\0';
312 (void) FormatLocaleFile(file,format,escaped_json);
313 (void) DestroyString(escaped_json);
314}
315
cristy9e818982014-01-18 14:54:37 +0000316static ChannelStatistics *GetLocationStatistics(const Image *image,
317 const StatisticType type,ExceptionInfo *exception)
318{
319 ChannelStatistics
320 *channel_statistics;
321
Cristyf2dc1dd2020-12-28 13:59:26 -0500322 ssize_t
cristy9e818982014-01-18 14:54:37 +0000323 i;
324
325 ssize_t
326 y;
327
328 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000329 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000330 if (image->debug != MagickFalse)
331 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
332 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
333 MaxPixelChannels+1,sizeof(*channel_statistics));
334 if (channel_statistics == (ChannelStatistics *) NULL)
335 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
Cristy81bfff22018-03-10 07:58:31 -0500336 (void) memset(channel_statistics,0,(MaxPixelChannels+1)*
cristy9e818982014-01-18 14:54:37 +0000337 sizeof(*channel_statistics));
338 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
339 {
340 switch (type)
341 {
342 case MaximumStatistic:
343 default:
344 {
cristyfe181a72014-02-02 21:17:43 +0000345 channel_statistics[i].maxima=(-MagickMaximumValue);
cristy9e818982014-01-18 14:54:37 +0000346 break;
347 }
348 case MinimumStatistic:
349 {
cristyfe181a72014-02-02 21:17:43 +0000350 channel_statistics[i].minima=MagickMaximumValue;
cristy9e818982014-01-18 14:54:37 +0000351 break;
352 }
353 }
354 }
355 for (y=0; y < (ssize_t) image->rows; y++)
356 {
Cristyf2dc1dd2020-12-28 13:59:26 -0500357 const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100358 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +0000359
Cristyf2dc1dd2020-12-28 13:59:26 -0500360 ssize_t
cristy9e818982014-01-18 14:54:37 +0000361 x;
362
363 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
364 if (p == (const Quantum *) NULL)
365 break;
366 for (x=0; x < (ssize_t) image->columns; x++)
367 {
Cristyf2dc1dd2020-12-28 13:59:26 -0500368 ssize_t
cristy9e818982014-01-18 14:54:37 +0000369 i;
370
Cristyd05ae9a2017-08-12 07:55:19 -0400371 if (GetPixelReadMask(image,p) <= (QuantumRange/2))
cristy9e818982014-01-18 14:54:37 +0000372 {
373 p+=GetPixelChannels(image);
374 continue;
375 }
376 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
377 {
Cristy3c296d62017-08-19 20:09:26 -0400378 PixelChannel channel = GetPixelChannelChannel(image,i);
379 PixelTrait traits = GetPixelChannelTraits(image,channel);
cristy9e818982014-01-18 14:54:37 +0000380 if (traits == UndefinedPixelTrait)
381 continue;
382 switch (type)
383 {
384 case MaximumStatistic:
385 default:
386 {
387 if ((double) p[i] > channel_statistics[channel].maxima)
388 channel_statistics[channel].maxima=(double) p[i];
389 break;
390 }
391 case MinimumStatistic:
392 {
393 if ((double) p[i] < channel_statistics[channel].minima)
394 channel_statistics[channel].minima=(double) p[i];
395 break;
396 }
397 }
398 }
399 p+=GetPixelChannels(image);
400 }
401 }
402 return(channel_statistics);
403}
404
405static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000406 const char *name,const MagickBooleanType separator,
407 const ChannelFeatures *channel_features)
cristy9e818982014-01-18 14:54:37 +0000408{
409#define PrintFeature(feature) \
410 GetMagickPrecision(),(feature)[0], \
411 GetMagickPrecision(),(feature)[1], \
412 GetMagickPrecision(),(feature)[2], \
413 GetMagickPrecision(),(feature)[3], \
414 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
415
dirk6c316f22015-06-27 15:44:29 +0000416#define FeaturesFormat " \"%s\": {\n" \
417 " \"angularSecondMoment\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400418 " \"horizontal\": %.*g,\n" \
419 " \"vertical\": %.*g,\n" \
420 " \"leftDiagonal\": %.*g,\n" \
421 " \"rightDiagonal\": %.*g,\n" \
422 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000423 " },\n" \
424 " \"contrast\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400425 " \"horizontal\": %.*g,\n" \
426 " \"vertical\": %.*g,\n" \
427 " \"leftDiagonal\": %.*g,\n" \
428 " \"rightDiagonal\": %.*g,\n" \
429 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000430 " },\n" \
431 " \"correlation\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400432 " \"horizontal\": %.*g,\n" \
433 " \"vertical\": %.*g,\n" \
434 " \"leftDiagonal\": %.*g,\n" \
435 " \"rightDiagonal\": %.*g,\n" \
436 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000437 " },\n" \
438 " \"sumOfSquaresVariance\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400439 " \"horizontal\": %.*g,\n" \
440 " \"vertical\": %.*g,\n" \
441 " \"leftDiagonal\": %.*g,\n" \
442 " \"rightDiagonal\": %.*g,\n" \
443 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000444 " },\n" \
445 " \"inverseDifferenceMoment\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400446 " \"horizontal\": %.*g,\n" \
447 " \"vertical\": %.*g,\n" \
448 " \"leftDiagonal\": %.*g,\n" \
449 " \"rightDiagonal\": %.*g,\n" \
450 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000451 " },\n" \
452 " \"sumAverage\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400453 " \"horizontal\": %.*g,\n" \
454 " \"vertical\": %.*g,\n" \
455 " \"leftDiagonal\": %.*g,\n" \
456 " \"rightDiagonal\": %.*g,\n" \
457 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000458 " },\n" \
459 " \"sumVariance\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400460 " \"horizontal\": %.*g,\n" \
461 " \"vertical\": %.*g,\n" \
462 " \"leftDiagonal\": %.*g,\n" \
463 " \"rightDiagonal\": %.*g,\n" \
464 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000465 " },\n" \
466 " \"sumEntropy\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400467 " \"horizontal\": %.*g,\n" \
468 " \"vertical\": %.*g,\n" \
469 " \"leftDiagonal\": %.*g,\n" \
470 " \"rightDiagonal\": %.*g,\n" \
471 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000472 " },\n" \
473 " \"entropy\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400474 " \"horizontal\": %.*g,\n" \
475 " \"vertical\": %.*g,\n" \
476 " \"leftDiagonal\": %.*g,\n" \
477 " \"rightDiagonal\": %.*g,\n" \
478 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000479 " },\n" \
480 " \"differenceVariance\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400481 " \"horizontal\": %.*g,\n" \
482 " \"vertical\": %.*g,\n" \
483 " \"leftDiagonal\": %.*g,\n" \
484 " \"rightDiagonal\": %.*g,\n" \
485 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000486 " },\n" \
487 " \"differenceEntropy\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400488 " \"horizontal\": %.*g,\n" \
489 " \"vertical\": %.*g,\n" \
490 " \"leftDiagonal\": %.*g,\n" \
491 " \"rightDiagonal\": %.*g,\n" \
492 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000493 " },\n" \
494 " \"informationMeasureOfCorrelation1\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400495 " \"horizontal\": %.*g,\n" \
496 " \"vertical\": %.*g,\n" \
497 " \"leftDiagonal\": %.*g,\n" \
498 " \"rightDiagonal\": %.*g,\n" \
499 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000500 " },\n" \
501 " \"informationMeasureOfCorrelation2\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400502 " \"horizontal\": %.*g,\n" \
503 " \"vertical\": %.*g,\n" \
504 " \"leftDiagonal\": %.*g,\n" \
505 " \"rightDiagonal\": %.*g,\n" \
506 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000507 " },\n" \
508 " \"maximumCorrelationCoefficient\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400509 " \"horizontal\": %.*g,\n" \
510 " \"vertical\": %.*g,\n" \
511 " \"leftDiagonal\": %.*g,\n" \
512 " \"rightDiagonal\": %.*g,\n" \
513 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000514 " }\n"
cristy9e818982014-01-18 14:54:37 +0000515
516 ssize_t
517 n;
518
519 n=FormatLocaleFile(file,FeaturesFormat,name,
520 PrintFeature(channel_features[channel].angular_second_moment),
521 PrintFeature(channel_features[channel].contrast),
522 PrintFeature(channel_features[channel].correlation),
523 PrintFeature(channel_features[channel].variance_sum_of_squares),
524 PrintFeature(channel_features[channel].inverse_difference_moment),
525 PrintFeature(channel_features[channel].sum_average),
526 PrintFeature(channel_features[channel].sum_variance),
527 PrintFeature(channel_features[channel].sum_entropy),
528 PrintFeature(channel_features[channel].entropy),
529 PrintFeature(channel_features[channel].difference_variance),
530 PrintFeature(channel_features[channel].difference_entropy),
531 PrintFeature(channel_features[channel].measure_of_correlation_1),
532 PrintFeature(channel_features[channel].measure_of_correlation_2),
533 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
dirk6c316f22015-06-27 15:44:29 +0000534 (void) FormatLocaleFile(file," }");
535 if (separator != MagickFalse)
536 (void) FormatLocaleFile(file,",");
537 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000538 return(n);
539}
540
541static ssize_t PrintChannelLocations(FILE *file,const Image *image,
542 const PixelChannel channel,const char *name,const StatisticType type,
dirk6c316f22015-06-27 15:44:29 +0000543 const size_t max_locations,const MagickBooleanType separator,
544 const ChannelStatistics *channel_statistics)
cristy9e818982014-01-18 14:54:37 +0000545{
546 double
547 target;
548
549 ExceptionInfo
550 *exception;
551
552 ssize_t
553 n,
554 y;
555
556 switch (type)
557 {
558 case MaximumStatistic:
559 default:
560 {
561 target=channel_statistics[channel].maxima;
562 break;
563 }
564 case MinimumStatistic:
565 {
566 target=channel_statistics[channel].minima;
567 break;
568 }
569 }
dirk6c316f22015-06-27 15:44:29 +0000570 (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": "
Cristybc978e02017-10-29 13:29:43 -0400571 "%.*g,\n",name,GetMagickPrecision(),QuantumScale*target);
cristy9e818982014-01-18 14:54:37 +0000572 exception=AcquireExceptionInfo();
573 n=0;
574 for (y=0; y < (ssize_t) image->rows; y++)
575 {
Cristyf2dc1dd2020-12-28 13:59:26 -0500576 const Quantum
cristy9e818982014-01-18 14:54:37 +0000577 *p;
578
579 ssize_t
580 offset,
581 x;
582
583 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
584 if (p == (const Quantum *) NULL)
585 break;
586 for (x=0; x < (ssize_t) image->columns; x++)
587 {
588 MagickBooleanType
589 match;
590
Cristy3c296d62017-08-19 20:09:26 -0400591 PixelTrait traits = GetPixelChannelTraits(image,channel);
cristy9e818982014-01-18 14:54:37 +0000592 if (traits == UndefinedPixelTrait)
593 continue;
594 offset=GetPixelChannelOffset(image,channel);
cristy3bdd9252014-12-21 20:01:43 +0000595 match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse;
cristy9e818982014-01-18 14:54:37 +0000596 if (match != MagickFalse)
597 {
598 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
599 break;
dirk6c316f22015-06-27 15:44:29 +0000600 if (n != 0)
601 (void) FormatLocaleFile(file,",\n");
602 (void) FormatLocaleFile(file," \"location%.20g\": {\n"
603 " \"x\": %.20g,\n \"y\": %.20g\n"
604 " }",(double) n,(double) x,(double) y);
cristy9e818982014-01-18 14:54:37 +0000605 n++;
606 }
607 p+=GetPixelChannels(image);
608 }
609 if (x < (ssize_t) image->columns)
610 break;
611 }
dirk6c316f22015-06-27 15:44:29 +0000612 (void) FormatLocaleFile(file,"\n }");
613 if (separator != MagickFalse)
614 (void) FormatLocaleFile(file,",");
cristy9e818982014-01-18 14:54:37 +0000615 (void) FormatLocaleFile(file,"\n");
616 return(n);
617}
618
619static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000620 const char *name,const MagickBooleanType separator,
621 const ChannelMoments *channel_moments)
cristy9e818982014-01-18 14:54:37 +0000622{
Cristyf2dc1dd2020-12-28 13:59:26 -0500623 ssize_t
cristy9e818982014-01-18 14:54:37 +0000624 i;
625
626 ssize_t
627 n;
628
dirk6c316f22015-06-27 15:44:29 +0000629 n=FormatLocaleFile(file," \"%s\": {\n",name);
630 n+=FormatLocaleFile(file," \"centroid\": {\n "
Cristybc978e02017-10-29 13:29:43 -0400631 " \"x\": %.*g,\n"
632 " \"y\": %.*g\n },\n",
cristy9e818982014-01-18 14:54:37 +0000633 GetMagickPrecision(),channel_moments[channel].centroid.x,
634 GetMagickPrecision(),channel_moments[channel].centroid.y);
dirk6c316f22015-06-27 15:44:29 +0000635 n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n"
Cristybc978e02017-10-29 13:29:43 -0400636 " \"x\": %.*g,\n"
637 " \"y\": %.*g\n },\n",
cristy9e818982014-01-18 14:54:37 +0000638 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
639 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
Cristybc978e02017-10-29 13:29:43 -0400640 n+=FormatLocaleFile(file," \"ellipseAngle\": %.*g,\n",
cristy9e818982014-01-18 14:54:37 +0000641 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
Cristybc978e02017-10-29 13:29:43 -0400642 n+=FormatLocaleFile(file," \"ellipseEccentricity\": %.*g,\n",
cristy9e818982014-01-18 14:54:37 +0000643 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
Cristybc978e02017-10-29 13:29:43 -0400644 n+=FormatLocaleFile(file," \"ellipseIntensity\": %.*g,\n",
cristy9e818982014-01-18 14:54:37 +0000645 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
dirk6c316f22015-06-27 15:44:29 +0000646 for (i=0; i < 7; i++)
Cristybc978e02017-10-29 13:29:43 -0400647 n+=FormatLocaleFile(file," \"I%.20g\": %.*g,\n",i+1.0,
dirk6c316f22015-06-27 15:44:29 +0000648 GetMagickPrecision(),channel_moments[channel].invariant[i]);
Cristybc978e02017-10-29 13:29:43 -0400649 n+=FormatLocaleFile(file," \"I%.20g\": %.*g\n",i+1.0,
dirk6c316f22015-06-27 15:44:29 +0000650 GetMagickPrecision(),channel_moments[channel].invariant[i]);
651 (void) FormatLocaleFile(file," }");
652 if (separator != MagickFalse)
653 (void) FormatLocaleFile(file,",");
654 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000655 return(n);
656}
657
Cristye6961802016-09-03 11:31:13 -0400658static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
cristydc395172014-02-23 01:33:36 +0000659 const ChannelPerceptualHash *channel_phash)
660{
Cristyf2dc1dd2020-12-28 13:59:26 -0500661 ssize_t
cristydc395172014-02-23 01:33:36 +0000662 i;
663
664 ssize_t
Cristy69a7c2b2016-12-24 11:22:36 -0500665 n = 0;
cristydc395172014-02-23 01:33:36 +0000666
Cristye6961802016-09-03 11:31:13 -0400667 (void) FormatLocaleFile(file," \"colorspaces\": [ ");
668 for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
669 {
670 (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic(
671 MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
672 if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
673 (void) FormatLocaleFile(file,", ");
674 }
675 (void) FormatLocaleFile(file,"],\n");
676 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
677 {
Cristyf2dc1dd2020-12-28 13:59:26 -0500678 ssize_t
Cristye6961802016-09-03 11:31:13 -0400679 j;
680
Cristy3c296d62017-08-19 20:09:26 -0400681 PixelChannel channel = GetPixelChannelChannel(image,i);
682 PixelTrait traits = GetPixelChannelTraits(image,channel);
Cristye6961802016-09-03 11:31:13 -0400683 if (traits == UndefinedPixelTrait)
684 continue;
685 n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel);
686 for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
687 {
Cristyf2dc1dd2020-12-28 13:59:26 -0500688 ssize_t
Cristye6961802016-09-03 11:31:13 -0400689 k;
690
691 n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1);
692 for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
693 {
Cristybc978e02017-10-29 13:29:43 -0400694 n+=FormatLocaleFile(file,"%.*g",GetMagickPrecision(),
Cristye6961802016-09-03 11:31:13 -0400695 channel_phash[channel].phash[k][j]);
696 if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
697 n+=FormatLocaleFile(file,", ");
698 }
699 n+=FormatLocaleFile(file,"]");
700 if (j < (MaximumNumberOfPerceptualHashes-1))
701 n+=FormatLocaleFile(file,",\n");
702 }
Cristy338f0882016-12-10 12:12:35 -0500703 if (i < (ssize_t) (GetPixelChannels(image)-1))
Cristye6961802016-09-03 11:31:13 -0400704 n+=FormatLocaleFile(file,"\n },\n");
705 }
706 n+=FormatLocaleFile(file,"\n }\n");
cristydc395172014-02-23 01:33:36 +0000707 return(n);
708}
709
cristy9e818982014-01-18 14:54:37 +0000710static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000711 const char *name,const double scale,const MagickBooleanType separator,
cristy9e818982014-01-18 14:54:37 +0000712 const ChannelStatistics *channel_statistics)
713{
Cristybc978e02017-10-29 13:29:43 -0400714#define StatisticsFormat " \"%s\": {\n \"min\": %.*g,\n" \
Cristy437efd02020-10-20 21:52:30 -0400715 " \"max\": %.*g,\n \"mean\": %.*g,\n \"median\": %.*g,\n " \
Cristybc978e02017-10-29 13:29:43 -0400716 "\"standardDeviation\": %.*g,\n \"kurtosis\": %.*g,\n "\
717 "\"skewness\": %.*g,\n \"entropy\": %.*g\n }"
cristy9e818982014-01-18 14:54:37 +0000718
719 ssize_t
720 n;
721
Cristybc978e02017-10-29 13:29:43 -0400722 n=FormatLocaleFile(file,StatisticsFormat,name,GetMagickPrecision(),
723 (double) ClampToQuantum(scale*channel_statistics[channel].minima),
724 GetMagickPrecision(),(double) ClampToQuantum(scale*
Cristy437efd02020-10-20 21:52:30 -0400725 channel_statistics[channel].maxima),GetMagickPrecision(),
726 scale*channel_statistics[channel].mean,GetMagickPrecision(),
727 scale*channel_statistics[channel].median,GetMagickPrecision(),scale*
Cristy7a4f99c2018-04-28 17:34:11 -0400728 IsNaN(channel_statistics[channel].standard_deviation) != 0 ? MagickEpsilon :
Cristybc978e02017-10-29 13:29:43 -0400729 channel_statistics[channel].standard_deviation,GetMagickPrecision(),
730 channel_statistics[channel].kurtosis,GetMagickPrecision(),
731 channel_statistics[channel].skewness,GetMagickPrecision(),
732 channel_statistics[channel].entropy);
dirk6c316f22015-06-27 15:44:29 +0000733 if (separator != MagickFalse)
cristye1c94d92015-06-28 12:16:33 +0000734 (void) FormatLocaleFile(file,",");
dirk6c316f22015-06-27 15:44:29 +0000735 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000736 return(n);
737}
738
Dirk Lemstra32b15502017-09-21 17:04:36 +0200739static void EncodeIptcProfile(FILE *file,const StringInfo *profile)
740{
741 char
742 *attribute,
743 **attribute_list;
744
745 const char
746 *tag;
747
Cristydb96d692017-10-29 10:37:57 -0400748 IPTCInfo
Dirk Lemstra32b15502017-09-21 17:04:36 +0200749 *value,
750 **values;
751
752 long
753 dataset,
754 record,
755 sentinel;
756
Cristyf2dc1dd2020-12-28 13:59:26 -0500757 ssize_t
Dirk Lemstra32b15502017-09-21 17:04:36 +0200758 i,
759 j,
760 k;
761
762 size_t
763 count,
764 length,
765 profile_length;
766
Cristydb96d692017-10-29 10:37:57 -0400767 values=(IPTCInfo **) NULL;
Dirk Lemstra32b15502017-09-21 17:04:36 +0200768 count=0;
769 profile_length=GetStringInfoLength(profile);
770 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
771 {
772 length=1;
773 sentinel=GetStringInfoDatum(profile)[i++];
774 if (sentinel != 0x1c)
775 continue;
776 dataset=GetStringInfoDatum(profile)[i++];
777 record=GetStringInfoDatum(profile)[i++];
Cristydb96d692017-10-29 10:37:57 -0400778 value=(IPTCInfo *) NULL;
Cristy7c7050a2017-09-30 12:12:21 -0400779 for (j=0; j < (ssize_t) count; j++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200780 {
781 if ((values[j]->record == record) && (values[j]->dataset == dataset))
782 value=values[j];
783 }
Cristydb96d692017-10-29 10:37:57 -0400784 if (value == (IPTCInfo *) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200785 {
Cristydb96d692017-10-29 10:37:57 -0400786 values=(IPTCInfo **) ResizeQuantumMemory(values,count+1,
Dirk Lemstra32b15502017-09-21 17:04:36 +0200787 sizeof(*values));
Cristydb96d692017-10-29 10:37:57 -0400788 if (values == (IPTCInfo **) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200789 break;
Cristy8357b5d2020-11-22 12:39:10 +0000790 value=(IPTCInfo *) AcquireMagickMemory(sizeof(*value));
Cristydb96d692017-10-29 10:37:57 -0400791 if (value == (IPTCInfo *) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200792 break;
Cristydb96d692017-10-29 10:37:57 -0400793 /* Check the tag length in IPTCInfo when a new tag is added */
Dirk Lemstra32b15502017-09-21 17:04:36 +0200794 switch (record)
795 {
796 case 5: tag="Image Name"; break;
797 case 7: tag="Edit Status"; break;
798 case 10: tag="Priority"; break;
799 case 15: tag="Category"; break;
800 case 20: tag="Supplemental Category"; break;
801 case 22: tag="Fixture Identifier"; break;
802 case 25: tag="Keyword"; break;
803 case 30: tag="Release Date"; break;
804 case 35: tag="Release Time"; break;
805 case 40: tag="Special Instructions"; break;
806 case 45: tag="Reference Service"; break;
807 case 47: tag="Reference Date"; break;
808 case 50: tag="Reference Number"; break;
809 case 55: tag="Created Date"; break;
810 case 60: tag="Created Time"; break;
811 case 65: tag="Originating Program"; break;
812 case 70: tag="Program Version"; break;
813 case 75: tag="Object Cycle"; break;
814 case 80: tag="Byline"; break;
815 case 85: tag="Byline Title"; break;
816 case 90: tag="City"; break;
817 case 92: tag="Sub-Location"; break;
818 case 95: tag="Province State"; break;
819 case 100: tag="Country Code"; break;
820 case 101: tag="Country"; break;
821 case 103: tag="Original Transmission Reference"; break;
822 case 105: tag="Headline"; break;
823 case 110: tag="Credit"; break;
824 case 115: tag="Src"; break;
825 case 116: tag="Copyright String"; break;
826 case 120: tag="Caption"; break;
827 case 121: tag="Local Caption"; break;
828 case 122: tag="Caption Writer"; break;
829 case 200: tag="Custom Field 1"; break;
830 case 201: tag="Custom Field 2"; break;
831 case 202: tag="Custom Field 3"; break;
832 case 203: tag="Custom Field 4"; break;
833 case 204: tag="Custom Field 5"; break;
834 case 205: tag="Custom Field 6"; break;
835 case 206: tag="Custom Field 7"; break;
836 case 207: tag="Custom Field 8"; break;
837 case 208: tag="Custom Field 9"; break;
838 case 209: tag="Custom Field 10"; break;
839 case 210: tag="Custom Field 11"; break;
840 case 211: tag="Custom Field 12"; break;
841 case 212: tag="Custom Field 13"; break;
842 case 213: tag="Custom Field 14"; break;
843 case 214: tag="Custom Field 15"; break;
844 case 215: tag="Custom Field 16"; break;
845 case 216: tag="Custom Field 17"; break;
846 case 217: tag="Custom Field 18"; break;
847 case 218: tag="Custom Field 19"; break;
848 case 219: tag="Custom Field 20"; break;
849 default: tag="Unknown"; break;
850 }
851 (void) CopyMagickString(value->tag,tag,strlen(tag)+1);
852 value->record=record;
853 value->dataset=dataset;
854 value->values=(char ***) NULL;
855 value->values_length=0;
856 values[count++]=value;
857 }
858 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
859 length|=GetStringInfoDatum(profile)[i++];
860 attribute=(char *) NULL;
861 if (~length >= (MagickPathExtent-1))
862 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
863 sizeof(*attribute));
864 if (attribute != (char *) NULL)
865 {
866 (void) CopyMagickString(attribute,(char *)
867 GetStringInfoDatum(profile)+i,length+1);
868 attribute_list=StringToList(attribute);
869 if (attribute_list != (char **) NULL)
870 {
871 value->values=(char ***) ResizeQuantumMemory(value->values,
872 value->values_length+1,
873 sizeof(*value->values));
874 if (value->values == (char ***) NULL)
875 break;
876 value->values[value->values_length++]=attribute_list;
877 }
878 attribute=DestroyString(attribute);
879 }
880 }
Cristydb96d692017-10-29 10:37:57 -0400881 if (values != (IPTCInfo **) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200882 {
Cristy7c7050a2017-09-30 12:12:21 -0400883 for (i=0; i < (ssize_t) count; i++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200884 {
885 value=values[i];
886 (void) FormatLocaleFile(file," \"%s[%.20g,%.20g]\": ",
887 value->tag,(double) value->dataset,(double) value->record);
888 if (value->values_length == 0)
889 (void) FormatLocaleFile(file,"null,");
890 else
891 {
892 (void) FormatLocaleFile(file,"[");
Cristy7c7050a2017-09-30 12:12:21 -0400893 for (j=0; j < (ssize_t) value->values_length; j++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200894 {
895 for (k=0; value->values[j][k] != (char *) NULL; k++)
896 {
897 if (j > 0 || k > 0)
898 (void) FormatLocaleFile(file,",");
Cristydb96d692017-10-29 10:37:57 -0400899 JSONFormatLocaleFile(file,"%s",value->values[j][k]);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200900 value->values[j][k]=(char *) RelinquishMagickMemory(
901 value->values[j][k]);
902 }
903 value->values[j]=(char **) RelinquishMagickMemory(
904 value->values[j]);
905 }
906 value->values=(char ***) RelinquishMagickMemory(value->values);
907 (void) FormatLocaleFile(file,"],\n");
908 }
Cristydb96d692017-10-29 10:37:57 -0400909 values[i]=(IPTCInfo *) RelinquishMagickMemory(values[i]);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200910 }
Cristydb96d692017-10-29 10:37:57 -0400911 values=(IPTCInfo **) RelinquishMagickMemory(values);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200912 }
913}
914
cristy9e818982014-01-18 14:54:37 +0000915static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
916 ExceptionInfo *exception)
917{
cristy9e818982014-01-18 14:54:37 +0000918 char
cristy151b66d2015-04-15 10:50:31 +0000919 color[MagickPathExtent],
920 format[MagickPathExtent],
921 key[MagickPathExtent];
cristy9e818982014-01-18 14:54:37 +0000922
923 ChannelFeatures
924 *channel_features;
925
926 ChannelMoments
927 *channel_moments;
928
cristydc395172014-02-23 01:33:36 +0000929 ChannelPerceptualHash
930 *channel_phash;
931
cristy9e818982014-01-18 14:54:37 +0000932 ChannelStatistics
933 *channel_statistics;
934
cristy9e818982014-01-18 14:54:37 +0000935 const char
936 *artifact,
937 *locate,
938 *name,
939 *property,
940 *registry,
941 *value;
942
943 const MagickInfo
944 *magick_info;
945
946 double
947 elapsed_time,
Cristye7408482020-08-27 20:59:50 -0400948 user_time,
949 version;
cristy9e818982014-01-18 14:54:37 +0000950
951 ImageType
952 type;
953
954 MagickBooleanType
955 ping;
956
Cristyf2dc1dd2020-12-28 13:59:26 -0500957 const Quantum
cristy9e818982014-01-18 14:54:37 +0000958 *p;
959
Cristyf2dc1dd2020-12-28 13:59:26 -0500960 ssize_t
cristy9e818982014-01-18 14:54:37 +0000961 i,
962 x;
963
964 size_t
dirk6c316f22015-06-27 15:44:29 +0000965 depth,
cristy9e818982014-01-18 14:54:37 +0000966 distance,
967 scale;
968
969 ssize_t
970 y;
971
972 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000973 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000974 if (image->debug != MagickFalse)
975 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristya10f7442014-01-19 18:32:15 +0000976 *format='\0';
977 elapsed_time=GetElapsedTime(&image->timer);
978 user_time=GetUserTime(&image->timer);
979 GetTimerInfo(&image->timer);
980 p=GetVirtualPixels(image,0,0,1,1,exception);
981 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
cristye1c94d92015-06-28 12:16:33 +0000982 (void) ping;
cristya10f7442014-01-19 18:32:15 +0000983 (void) SignatureImage(image,exception);
Cristy437efd02020-10-20 21:52:30 -0400984 (void) FormatLocaleFile(file,"{\n");
Cristye7408482020-08-27 20:59:50 -0400985 version=1.0;
986 artifact=GetImageArtifact(image,"json:version");
987 if (artifact != (const char *) NULL)
988 version=StringToDouble(artifact,(char **) NULL);
989 if (version >= 1.0)
990 (void) FormatLocaleFile(file," \"version\": \"%.1f\",\n",version);
Cristy437efd02020-10-20 21:52:30 -0400991 if (*image->magick_filename == '\0')
992 JSONFormatLocaleFile(file," \"image\": {\n \"name\": %s,\n",
993 image->filename);
994 else
995 {
996 JSONFormatLocaleFile(file," \"image\": {\n \"name\": %s,\n",
997 image->magick_filename);
998 if (LocaleCompare(image->magick_filename,image->filename) != 0)
999 {
1000 char
1001 filename[MaxTextExtent];
1002
1003 GetPathComponent(image->magick_filename,TailPath,filename);
1004 JSONFormatLocaleFile(file," \"baseName\": %s,\n",filename);
1005 }
1006 }
Cristydb96d692017-10-29 10:37:57 -04001007 JSONFormatLocaleFile(file," \"format\": %s,\n",image->magick);
cristya10f7442014-01-19 18:32:15 +00001008 magick_info=GetMagickInfo(image->magick,exception);
dirk6c316f22015-06-27 15:44:29 +00001009 if ((magick_info != (const MagickInfo *) NULL) &&
1010 (GetMagickDescription(magick_info) != (const char *) NULL))
Cristydb96d692017-10-29 10:37:57 -04001011 JSONFormatLocaleFile(file," \"formatDescription\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001012 image->magick);
cristy12bcd3d2015-01-28 00:54:23 +00001013 if ((magick_info != (const MagickInfo *) NULL) &&
cristya10f7442014-01-19 18:32:15 +00001014 (GetMagickMimeType(magick_info) != (const char *) NULL))
Cristydb96d692017-10-29 10:37:57 -04001015 JSONFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
cristya10f7442014-01-19 18:32:15 +00001016 magick_info));
Cristydb96d692017-10-29 10:37:57 -04001017 JSONFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001018 MagickClassOptions,(ssize_t) image->storage_class));
dirk6c316f22015-06-27 15:44:29 +00001019 (void) FormatLocaleFile(file," \"geometry\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001020 " \"width\": %g,\n \"height\": %g,\n"
1021 " \"x\": %g,\n \"y\": %g\n },\n",
dirk6c316f22015-06-27 15:44:29 +00001022 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
1023 (double) image->tile_offset.y);
cristya10f7442014-01-19 18:32:15 +00001024 if ((image->magick_columns != 0) || (image->magick_rows != 0))
1025 if ((image->magick_columns != image->columns) ||
1026 (image->magick_rows != image->rows))
dirk6c316f22015-06-27 15:44:29 +00001027 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001028 " \"width\": %g,\n \"height\": %g\n },\n",(double)
1029 image->magick_columns,(double) image->magick_rows);
cristya10f7442014-01-19 18:32:15 +00001030 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
1031 {
dirk6c316f22015-06-27 15:44:29 +00001032 (void) FormatLocaleFile(file," \"resolution\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001033 " \"x\": %g,\n \"y\": %g\n },\n",image->resolution.x,
cristya10f7442014-01-19 18:32:15 +00001034 image->resolution.y);
Cristybc978e02017-10-29 13:29:43 -04001035 (void) FormatLocaleFile(file," \"printSize\": {\n"
1036 " \"x\": %.*g,\n \"y\": %.*g\n },\n",GetMagickPrecision(),
1037 image->columns/image->resolution.x,GetMagickPrecision(),(double)
1038 image->rows/image->resolution.y);
cristya10f7442014-01-19 18:32:15 +00001039 }
Cristydb96d692017-10-29 10:37:57 -04001040 JSONFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001041 MagickResolutionOptions,(ssize_t) image->units));
Cristy95ab3892017-12-24 09:34:52 -05001042 type=IdentifyImageType(image,exception);
Cristydb96d692017-10-29 10:37:57 -04001043 JSONFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001044 MagickTypeOptions,(ssize_t) type));
Cristy4826fb42017-12-17 12:05:09 -05001045 if (image->type != type)
Cristydb96d692017-10-29 10:37:57 -04001046 JSONFormatLocaleFile(file," \"baseType\": %s,\n",
Cristy4826fb42017-12-17 12:05:09 -05001047 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) image->type));
Cristye7408482020-08-27 20:59:50 -04001048 if (version < 1.0)
1049 JSONFormatLocaleFile(file," \"endianess\": %s,\n",
1050 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
1051 else
1052 JSONFormatLocaleFile(file," \"endianness\": %s,\n",
1053 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
cristy9e818982014-01-18 14:54:37 +00001054 locate=GetImageArtifact(image,"identify:locate");
cristy3e583dd2014-01-19 14:11:51 +00001055 if (locate == (const char *) NULL)
1056 locate=GetImageArtifact(image,"json:locate");
cristy9e818982014-01-18 14:54:37 +00001057 if (locate != (const char *) NULL)
1058 {
1059 const char
1060 *limit;
1061
1062 size_t
1063 max_locations;
1064
1065 StatisticType
1066 type;
1067
1068 /*
1069 Display minimum, maximum, or mean pixel locations.
1070 */
1071 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
1072 MagickFalse,locate);
1073 limit=GetImageArtifact(image,"identify:limit");
cristy3e583dd2014-01-19 14:11:51 +00001074 if (limit == (const char *) NULL)
1075 limit=GetImageArtifact(image,"json:limit");
cristy9e818982014-01-18 14:54:37 +00001076 max_locations=0;
1077 if (limit != (const char *) NULL)
1078 max_locations=StringToUnsignedLong(limit);
1079 channel_statistics=GetLocationStatistics(image,type,exception);
1080 if (channel_statistics == (ChannelStatistics *) NULL)
1081 return(MagickFalse);
dirk6c316f22015-06-27 15:44:29 +00001082 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
1083 if (image->alpha_trait != UndefinedPixelTrait)
Cristybee97b82020-12-07 18:46:20 -05001084 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"alpha",
dirk6c316f22015-06-27 15:44:29 +00001085 type,max_locations,MagickTrue,channel_statistics);
Cristy3889d152017-12-22 19:42:13 -05001086 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001087 {
1088 case RGBColorspace:
1089 default:
1090 {
Cristybee97b82020-12-07 18:46:20 -05001091 (void) PrintChannelLocations(file,image,RedPixelChannel,"red",
dirk6c316f22015-06-27 15:44:29 +00001092 type,max_locations,MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001093 (void) PrintChannelLocations(file,image,GreenPixelChannel,"green",
dirk6c316f22015-06-27 15:44:29 +00001094 type,max_locations,MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001095 (void) PrintChannelLocations(file,image,BluePixelChannel,"blue",
dirk6c316f22015-06-27 15:44:29 +00001096 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001097 break;
1098 }
1099 case CMYKColorspace:
1100 {
Cristybee97b82020-12-07 18:46:20 -05001101 (void) PrintChannelLocations(file,image,CyanPixelChannel,"cyan",
dirk6c316f22015-06-27 15:44:29 +00001102 type,max_locations,MagickTrue,channel_statistics);
Cristy95ab3892017-12-24 09:34:52 -05001103 (void) PrintChannelLocations(file,image,MagentaPixelChannel,
Cristybee97b82020-12-07 18:46:20 -05001104 "magenta",type,max_locations,MagickTrue,channel_statistics);
1105 (void) PrintChannelLocations(file,image,YellowPixelChannel,"yellow",
dirk6c316f22015-06-27 15:44:29 +00001106 type,max_locations,MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001107 (void) PrintChannelLocations(file,image,BlackPixelChannel,"black",
dirk6c316f22015-06-27 15:44:29 +00001108 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001109 break;
1110 }
Cristybeb4c2b2017-12-26 19:43:17 -05001111 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001112 case GRAYColorspace:
1113 {
Cristybee97b82020-12-07 18:46:20 -05001114 (void) PrintChannelLocations(file,image,GrayPixelChannel,"gray",
dirk6c316f22015-06-27 15:44:29 +00001115 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001116 break;
1117 }
1118 }
dirk6c316f22015-06-27 15:44:29 +00001119 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001120 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1121 channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001122 }
cristy9e818982014-01-18 14:54:37 +00001123 /*
1124 Detail channel depth and extrema.
1125 */
Cristydb96d692017-10-29 10:37:57 -04001126 JSONFormatLocaleFile(file," \"colorspace\": %s,\n",
Cristy3889d152017-12-22 19:42:13 -05001127 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
1128 image->colorspace));
cristy9e818982014-01-18 14:54:37 +00001129 channel_statistics=(ChannelStatistics *) NULL;
1130 channel_moments=(ChannelMoments *) NULL;
cristydc395172014-02-23 01:33:36 +00001131 channel_phash=(ChannelPerceptualHash *) NULL;
cristy9e818982014-01-18 14:54:37 +00001132 channel_features=(ChannelFeatures *) NULL;
cristy9e818982014-01-18 14:54:37 +00001133 scale=1;
dirk6c316f22015-06-27 15:44:29 +00001134 channel_statistics=GetImageStatistics(image,exception);
1135 if (channel_statistics == (ChannelStatistics *) NULL)
1136 return(MagickFalse);
1137 artifact=GetImageArtifact(image,"identify:moments");
1138 if (artifact == (const char *) NULL)
1139 artifact=GetImageArtifact(image,"json:moments");
1140 if (artifact != (const char *) NULL)
cristy9e818982014-01-18 14:54:37 +00001141 {
dirk6c316f22015-06-27 15:44:29 +00001142 channel_moments=GetImageMoments(image,exception);
1143 channel_phash=GetImagePerceptualHash(image,exception);
cristy9e818982014-01-18 14:54:37 +00001144 }
dirk6c316f22015-06-27 15:44:29 +00001145 artifact=GetImageArtifact(image,"identify:features");
1146 if (artifact == (const char *) NULL)
1147 artifact=GetImageArtifact(image,"json:features");
1148 if (artifact != (const char *) NULL)
1149 {
1150 distance=StringToUnsignedLong(artifact);
1151 channel_features=GetImageFeatures(image,distance,exception);
1152 }
1153 depth=GetImageDepth(image,exception);
Cristybc978e02017-10-29 13:29:43 -04001154 (void) FormatLocaleFile(file," \"depth\": %g,\n",(double) depth);
1155 (void) FormatLocaleFile(file," \"baseDepth\": %g,\n",(double)
dirk6c316f22015-06-27 15:44:29 +00001156 image->depth);
1157 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
dirk6c316f22015-06-27 15:44:29 +00001158 if (image->alpha_trait != UndefinedPixelTrait)
1159 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
1160 channel_statistics[AlphaPixelChannel].depth);
Cristy3889d152017-12-22 19:42:13 -05001161 switch (image->colorspace)
dirk6c316f22015-06-27 15:44:29 +00001162 {
1163 case RGBColorspace:
1164 default:
1165 {
1166 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
1167 channel_statistics[RedChannel].depth);
1168 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
1169 channel_statistics[GreenChannel].depth);
1170 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
1171 channel_statistics[BlueChannel].depth);
1172 break;
1173 }
1174 case CMYKColorspace:
1175 {
1176 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
1177 channel_statistics[CyanChannel].depth);
1178 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
1179 channel_statistics[MagentaChannel].depth);
1180 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
1181 channel_statistics[YellowChannel].depth);
1182 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
1183 channel_statistics[BlackChannel].depth);
1184 break;
1185 }
Cristybeb4c2b2017-12-26 19:43:17 -05001186 case LinearGRAYColorspace:
dirk6c316f22015-06-27 15:44:29 +00001187 case GRAYColorspace:
1188 {
1189 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
1190 channel_statistics[GrayChannel].depth);
1191 break;
1192 }
1193 }
1194 (void) FormatLocaleFile(file," },\n");
1195 scale=1;
1196 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
1197 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
1198 MAGICKCORE_QUANTUM_DEPTH-image->depth));
cristy9e818982014-01-18 14:54:37 +00001199 if (channel_statistics != (ChannelStatistics *) NULL)
1200 {
dirk6c316f22015-06-27 15:44:29 +00001201 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
cristy9e818982014-01-18 14:54:37 +00001202 channel_statistics[CompositePixelChannel].area);
Cristybeb4c2b2017-12-26 19:43:17 -05001203 if ((image->colorspace != LinearGRAYColorspace) &&
1204 (image->colorspace != GRAYColorspace))
dirk6c316f22015-06-27 15:44:29 +00001205 {
1206 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
1207 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
1208 "Overall",1.0/scale,MagickFalse,channel_statistics);
1209 (void) FormatLocaleFile(file," },\n");
1210 }
1211 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
1212 if (image->alpha_trait != UndefinedPixelTrait)
Cristybee97b82020-12-07 18:46:20 -05001213 (void) PrintChannelStatistics(file,AlphaPixelChannel,"alpha",1.0/scale,
dirk6c316f22015-06-27 15:44:29 +00001214 MagickTrue,channel_statistics);
Cristy3889d152017-12-22 19:42:13 -05001215 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001216 {
1217 case RGBColorspace:
1218 default:
1219 {
Cristybee97b82020-12-07 18:46:20 -05001220 (void) PrintChannelStatistics(file,RedPixelChannel,"red",1.0/scale,
dirk6c316f22015-06-27 15:44:29 +00001221 MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001222 (void) PrintChannelStatistics(file,GreenPixelChannel,"green",1.0/
dirk6c316f22015-06-27 15:44:29 +00001223 scale,MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001224 (void) PrintChannelStatistics(file,BluePixelChannel,"blue",1.0/scale,
dirk6c316f22015-06-27 15:44:29 +00001225 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001226 break;
1227 }
1228 case CMYKColorspace:
1229 {
Cristybee97b82020-12-07 18:46:20 -05001230 (void) PrintChannelStatistics(file,CyanPixelChannel,"cyan",1.0/scale,
dirk6c316f22015-06-27 15:44:29 +00001231 MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001232 (void) PrintChannelStatistics(file,MagentaPixelChannel,"magenta",1.0/
dirk6c316f22015-06-27 15:44:29 +00001233 scale,MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001234 (void) PrintChannelStatistics(file,YellowPixelChannel,"yellow",1.0/
dirk6c316f22015-06-27 15:44:29 +00001235 scale,MagickTrue,channel_statistics);
Cristybee97b82020-12-07 18:46:20 -05001236 (void) PrintChannelStatistics(file,BlackPixelChannel,"black",1.0/
dirk6c316f22015-06-27 15:44:29 +00001237 scale,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001238 break;
1239 }
Cristybeb4c2b2017-12-26 19:43:17 -05001240 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001241 case GRAYColorspace:
1242 {
Cristybee97b82020-12-07 18:46:20 -05001243 (void) PrintChannelStatistics(file,GrayPixelChannel,"gray",1.0/scale,
dirk6c316f22015-06-27 15:44:29 +00001244 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001245 break;
1246 }
1247 }
dirk6c316f22015-06-27 15:44:29 +00001248 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001249 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1250 channel_statistics);
1251 }
1252 if (channel_moments != (ChannelMoments *) NULL)
1253 {
dirk6c316f22015-06-27 15:44:29 +00001254 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
1255 if (image->alpha_trait != UndefinedPixelTrait)
Cristybee97b82020-12-07 18:46:20 -05001256 (void) PrintChannelMoments(file,AlphaPixelChannel,"alpha",MagickTrue,
dirk6c316f22015-06-27 15:44:29 +00001257 channel_moments);
Cristy3889d152017-12-22 19:42:13 -05001258 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001259 {
1260 case RGBColorspace:
1261 default:
1262 {
Cristybee97b82020-12-07 18:46:20 -05001263 (void) PrintChannelMoments(file,RedPixelChannel,"red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001264 channel_moments);
Cristybee97b82020-12-07 18:46:20 -05001265 (void) PrintChannelMoments(file,GreenPixelChannel,"green",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001266 channel_moments);
Cristybee97b82020-12-07 18:46:20 -05001267 (void) PrintChannelMoments(file,BluePixelChannel,"blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001268 channel_moments);
1269 break;
1270 }
1271 case CMYKColorspace:
1272 {
Cristybee97b82020-12-07 18:46:20 -05001273 (void) PrintChannelMoments(file,CyanPixelChannel,"cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001274 channel_moments);
Cristybee97b82020-12-07 18:46:20 -05001275 (void) PrintChannelMoments(file,MagentaPixelChannel,"magenta",
dirk6c316f22015-06-27 15:44:29 +00001276 MagickTrue,channel_moments);
Cristybee97b82020-12-07 18:46:20 -05001277 (void) PrintChannelMoments(file,YellowPixelChannel,"yellow",
dirk6c316f22015-06-27 15:44:29 +00001278 MagickTrue,channel_moments);
Cristybee97b82020-12-07 18:46:20 -05001279 (void) PrintChannelMoments(file,BlackPixelChannel,"black",
dirk6c316f22015-06-27 15:44:29 +00001280 MagickFalse,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001281 break;
1282 }
Cristybeb4c2b2017-12-26 19:43:17 -05001283 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001284 case GRAYColorspace:
1285 {
Cristybee97b82020-12-07 18:46:20 -05001286 (void) PrintChannelMoments(file,GrayPixelChannel,"gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001287 channel_moments);
1288 break;
1289 }
1290 }
dirk6c316f22015-06-27 15:44:29 +00001291 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001292 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1293 channel_moments);
1294 }
cristydc395172014-02-23 01:33:36 +00001295 if (channel_phash != (ChannelPerceptualHash *) NULL)
1296 {
1297 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
Cristye6961802016-09-03 11:31:13 -04001298 (void) PrintChannelPerceptualHash(image,file,channel_phash);
cristydc395172014-02-23 01:33:36 +00001299 (void) FormatLocaleFile(file," },\n");
1300 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1301 channel_phash);
1302 }
cristy9e818982014-01-18 14:54:37 +00001303 if (channel_features != (ChannelFeatures *) NULL)
1304 {
dirk6c316f22015-06-27 15:44:29 +00001305 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1306 if (image->alpha_trait != UndefinedPixelTrait)
Cristybee97b82020-12-07 18:46:20 -05001307 (void) PrintChannelFeatures(file,AlphaPixelChannel,"alpha",MagickTrue,
dirk6c316f22015-06-27 15:44:29 +00001308 channel_features);
Cristy3889d152017-12-22 19:42:13 -05001309 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001310 {
1311 case RGBColorspace:
1312 default:
1313 {
Cristybee97b82020-12-07 18:46:20 -05001314 (void) PrintChannelFeatures(file,RedPixelChannel,"red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001315 channel_features);
Cristybee97b82020-12-07 18:46:20 -05001316 (void) PrintChannelFeatures(file,GreenPixelChannel,"green",
dirk6c316f22015-06-27 15:44:29 +00001317 MagickTrue,channel_features);
Cristybee97b82020-12-07 18:46:20 -05001318 (void) PrintChannelFeatures(file,BluePixelChannel,"blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001319 channel_features);
1320 break;
1321 }
1322 case CMYKColorspace:
1323 {
Cristybee97b82020-12-07 18:46:20 -05001324 (void) PrintChannelFeatures(file,CyanPixelChannel,"cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001325 channel_features);
Cristybee97b82020-12-07 18:46:20 -05001326 (void) PrintChannelFeatures(file,MagentaPixelChannel,"magenta",
dirk6c316f22015-06-27 15:44:29 +00001327 MagickTrue,channel_features);
Cristybee97b82020-12-07 18:46:20 -05001328 (void) PrintChannelFeatures(file,YellowPixelChannel,"yellow",
dirk6c316f22015-06-27 15:44:29 +00001329 MagickTrue,channel_features);
Cristybee97b82020-12-07 18:46:20 -05001330 (void) PrintChannelFeatures(file,BlackPixelChannel,"black",
dirk6c316f22015-06-27 15:44:29 +00001331 MagickFalse,channel_features);
cristy9e818982014-01-18 14:54:37 +00001332 break;
1333 }
Cristybeb4c2b2017-12-26 19:43:17 -05001334 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001335 case GRAYColorspace:
1336 {
Cristybee97b82020-12-07 18:46:20 -05001337 (void) PrintChannelFeatures(file,GrayPixelChannel,"gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001338 channel_features);
1339 break;
1340 }
1341 }
dirk6c316f22015-06-27 15:44:29 +00001342 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001343 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1344 channel_features);
1345 }
dirk6c316f22015-06-27 15:44:29 +00001346 if (image->colorspace == CMYKColorspace)
1347 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
cristye1c94d92015-06-28 12:16:33 +00001348 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1349 (double) QuantumRange);
dirk6c316f22015-06-27 15:44:29 +00001350 x=0;
1351 if (image->alpha_trait != UndefinedPixelTrait)
1352 {
Cristyf2dc1dd2020-12-28 13:59:26 -05001353 const Quantum
dirk6c316f22015-06-27 15:44:29 +00001354 *p;
1355
1356 p=(const Quantum *) NULL;
1357 for (y=0; y < (ssize_t) image->rows; y++)
cristy9e818982014-01-18 14:54:37 +00001358 {
dirk6c316f22015-06-27 15:44:29 +00001359 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1360 if (p == (const Quantum *) NULL)
1361 break;
1362 for (x=0; x < (ssize_t) image->columns; x++)
cristy9e818982014-01-18 14:54:37 +00001363 {
dirk6c316f22015-06-27 15:44:29 +00001364 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
cristy9e818982014-01-18 14:54:37 +00001365 break;
dirk6c316f22015-06-27 15:44:29 +00001366 p+=GetPixelChannels(image);
cristy9e818982014-01-18 14:54:37 +00001367 }
dirk6c316f22015-06-27 15:44:29 +00001368 if (x < (ssize_t) image->columns)
1369 break;
cristy9e818982014-01-18 14:54:37 +00001370 }
dirk6c316f22015-06-27 15:44:29 +00001371 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1372 {
1373 PixelInfo
1374 pixel;
1375
1376 GetPixelInfo(image,&pixel);
1377 GetPixelInfoPixel(image,p,&pixel);
1378 GetColorTuple(&pixel,MagickTrue,color);
1379 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1380 }
1381 }
cristy9e818982014-01-18 14:54:37 +00001382 if (image->storage_class == PseudoClass)
1383 {
Cristyf2dc1dd2020-12-28 13:59:26 -05001384 PixelInfo
dirk05d2ff72015-11-18 23:13:43 +01001385 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +00001386
dirk6c316f22015-06-27 15:44:29 +00001387 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1388 (double) image->colors);
1389 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1390 p=image->colormap;
1391 for (i=0; i < (ssize_t) image->colors; i++)
1392 {
1393 GetColorTuple(p,MagickTrue,color);
1394 (void) FormatLocaleFile(file,"\"%s\"",color);
1395 if (i < (ssize_t) (image->colors-1))
1396 (void) FormatLocaleFile(file,",");
1397 if (((i+1) % 5) == 0)
1398 (void) FormatLocaleFile(file,"\n ");
1399 p++;
1400 }
1401 (void) FormatLocaleFile(file,"\n ],\n");
cristy9e818982014-01-18 14:54:37 +00001402 }
1403 if (image->error.mean_error_per_pixel != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001404 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001405 image->error.mean_error_per_pixel);
1406 if (image->error.normalized_mean_error != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001407 (void) FormatLocaleFile(file," \"normalizedMeanError\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001408 image->error.normalized_mean_error);
1409 if (image->error.normalized_maximum_error != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001410 (void) FormatLocaleFile(file," \"normalizedMaximumError\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001411 image->error.normalized_maximum_error);
Cristydb96d692017-10-29 10:37:57 -04001412 JSONFormatLocaleFile(file," \"renderingIntent\": %s,\n",
cristy9e818982014-01-18 14:54:37 +00001413 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1414 image->rendering_intent));
1415 if (image->gamma != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001416 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
cristy9e818982014-01-18 14:54:37 +00001417 if ((image->chromaticity.red_primary.x != 0.0) ||
1418 (image->chromaticity.green_primary.x != 0.0) ||
1419 (image->chromaticity.blue_primary.x != 0.0) ||
1420 (image->chromaticity.white_point.x != 0.0))
1421 {
1422 /*
1423 Display image chromaticity.
1424 */
dirk6c316f22015-06-27 15:44:29 +00001425 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1426 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1427 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001428 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001429 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1430 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001431 image->chromaticity.green_primary.x,
1432 image->chromaticity.green_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001433 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1434 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001435 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001436 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1437 " \"x\": %g,\n \"y\": %g\n }\n",
cristy9e818982014-01-18 14:54:37 +00001438 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
dirk6c316f22015-06-27 15:44:29 +00001439 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001440 }
1441 if ((image->extract_info.width*image->extract_info.height) != 0)
dirk6c316f22015-06-27 15:44:29 +00001442 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1443 " \"width\": %.20g,\n \"height\": %.20g,\n"
1444 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001445 (double) image->extract_info.width,(double) image->extract_info.height,
1446 (double) image->extract_info.x,(double) image->extract_info.y);
Cristy18b27502017-02-16 07:29:19 -05001447 GetColorTuple(&image->matte_color,MagickTrue,color);
1448 (void) FormatLocaleFile(file," \"matteColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001449 GetColorTuple(&image->background_color,MagickTrue,color);
1450 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1451 GetColorTuple(&image->border_color,MagickTrue,color);
1452 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001453 GetColorTuple(&image->transparent_color,MagickTrue,color);
1454 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
Cristydb96d692017-10-29 10:37:57 -04001455 JSONFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001456 MagickInterlaceOptions,(ssize_t) image->interlace));
Cristydb96d692017-10-29 10:37:57 -04001457 JSONFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001458 MagickPixelIntensityOptions,(ssize_t) image->intensity));
Cristydb96d692017-10-29 10:37:57 -04001459 JSONFormatLocaleFile(file," \"compose\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001460 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
cristy9e818982014-01-18 14:54:37 +00001461 if ((image->page.width != 0) || (image->page.height != 0) ||
1462 (image->page.x != 0) || (image->page.y != 0))
dirk6c316f22015-06-27 15:44:29 +00001463 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1464 " \"width\": %.20g,\n \"height\": %.20g,\n"
1465 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1466 (double) image->page.width,(double) image->page.height,
1467 (double) image->page.x,(double) image->page.y);
cristy9e818982014-01-18 14:54:37 +00001468 if ((image->page.x != 0) || (image->page.y != 0))
Travis Petticrew6e95e022018-02-09 13:33:20 -06001469 (void) FormatLocaleFile(file," \"originGeometry\": \"%+.20g%+.20g\",\n",
dirk6c316f22015-06-27 15:44:29 +00001470 (double) image->page.x,(double) image->page.y);
Cristydb96d692017-10-29 10:37:57 -04001471 JSONFormatLocaleFile(file," \"dispose\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001472 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
cristy9e818982014-01-18 14:54:37 +00001473 if (image->delay != 0)
Darek Finster76c7e832017-10-13 01:57:47 +02001474 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\",\n",
dirk6c316f22015-06-27 15:44:29 +00001475 (double) image->delay,(double) image->ticks_per_second);
cristy9e818982014-01-18 14:54:37 +00001476 if (image->iterations != 1)
dirk6c316f22015-06-27 15:44:29 +00001477 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
cristy9e818982014-01-18 14:54:37 +00001478 image->iterations);
1479 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
Dirk Lemstra3ea0d282017-09-21 13:31:12 +02001480 (void) FormatLocaleFile(file," \"scene\": %.20g,\n \"scenes\": "
1481 "%.20g,\n",(double) image->scene,(double) GetImageListLength(image));
cristy9e818982014-01-18 14:54:37 +00001482 else
1483 if (image->scene != 0)
dirk6c316f22015-06-27 15:44:29 +00001484 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1485 image->scene);
Cristydb96d692017-10-29 10:37:57 -04001486 JSONFormatLocaleFile(file," \"compression\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001487 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1488 image->compression));
cristy9e818982014-01-18 14:54:37 +00001489 if (image->quality != UndefinedCompressionQuality)
dirk6c316f22015-06-27 15:44:29 +00001490 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1491 image->quality);
Cristydb96d692017-10-29 10:37:57 -04001492 JSONFormatLocaleFile(file," \"orientation\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001493 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1494 image->orientation));
cristy9e818982014-01-18 14:54:37 +00001495 if (image->montage != (char *) NULL)
Cristydb96d692017-10-29 10:37:57 -04001496 JSONFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
cristy9e818982014-01-18 14:54:37 +00001497 if (image->directory != (char *) NULL)
1498 {
1499 Image
1500 *tile;
1501
1502 ImageInfo
1503 *image_info;
1504
Cristyf2dc1dd2020-12-28 13:59:26 -05001505 char
cristy9e818982014-01-18 14:54:37 +00001506 *p,
1507 *q;
1508
1509 WarningHandler
1510 handler;
1511
1512 /*
1513 Display visual image directory.
1514 */
1515 image_info=AcquireImageInfo();
1516 (void) CloneString(&image_info->size,"64x64");
dirk6c316f22015-06-27 15:44:29 +00001517 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1518 p=image->directory;
1519 while (*p != '\0')
cristy9e818982014-01-18 14:54:37 +00001520 {
1521 q=p;
Cristy5d293d22018-02-24 12:45:52 -05001522 while ((*q != '\xff') && (*q != '\0'))
cristy9e818982014-01-18 14:54:37 +00001523 q++;
1524 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
dirk6c316f22015-06-27 15:44:29 +00001525 p=q+1;
Cristydb96d692017-10-29 10:37:57 -04001526 JSONFormatLocaleFile(file,"{\n \"name\": %s",
dirk6c316f22015-06-27 15:44:29 +00001527 image_info->filename);
cristy9e818982014-01-18 14:54:37 +00001528 handler=SetWarningHandler((WarningHandler) NULL);
1529 tile=ReadImage(image_info,exception);
1530 (void) SetWarningHandler(handler);
1531 if (tile == (Image *) NULL)
1532 {
dirk6c316f22015-06-27 15:44:29 +00001533 (void) FormatLocaleFile(file," }");
cristy9e818982014-01-18 14:54:37 +00001534 continue;
1535 }
dirk6c316f22015-06-27 15:44:29 +00001536 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1537 (double) tile->magick_columns,(double) tile->magick_rows,
1538 tile->magick);
cristy9e818982014-01-18 14:54:37 +00001539 (void) SignatureImage(tile,exception);
1540 ResetImagePropertyIterator(tile);
1541 property=GetNextImageProperty(tile);
1542 while (property != (const char *) NULL)
1543 {
Cristydb96d692017-10-29 10:37:57 -04001544 JSONFormatLocaleFile(file,",\n %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001545 value=GetImageProperty(tile,property,exception);
Cristydb96d692017-10-29 10:37:57 -04001546 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001547 property=GetNextImageProperty(tile);
1548 }
Cristy4e72d442018-01-11 06:29:53 -05001549 tile=DestroyImageList(tile);
dirk6c316f22015-06-27 15:44:29 +00001550 if (*p != '\0')
1551 (void) FormatLocaleFile(file,"\n },");
1552 else
1553 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001554 }
dirk6c316f22015-06-27 15:44:29 +00001555 (void) FormatLocaleFile(file,"],\n");
cristy9e818982014-01-18 14:54:37 +00001556 image_info=DestroyImageInfo(image_info);
1557 }
cristy9e818982014-01-18 14:54:37 +00001558 ResetImagePropertyIterator(image);
1559 property=GetNextImageProperty(image);
1560 if (property != (const char *) NULL)
1561 {
dirk6c316f22015-06-27 15:44:29 +00001562 size_t
1563 n;
1564
cristy9e818982014-01-18 14:54:37 +00001565 /*
1566 Display image properties.
1567 */
dirk6c316f22015-06-27 15:44:29 +00001568 n=0;
1569 (void) FormatLocaleFile(file," \"properties\": {\n");
cristy9e818982014-01-18 14:54:37 +00001570 while (property != (const char *) NULL)
1571 {
dirk6c316f22015-06-27 15:44:29 +00001572 if (n++ != 0)
1573 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001574 JSONFormatLocaleFile(file," %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001575 value=GetImageProperty(image,property,exception);
Cristydb96d692017-10-29 10:37:57 -04001576 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001577 property=GetNextImageProperty(image);
1578 }
dirk6c316f22015-06-27 15:44:29 +00001579 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001580 }
cristy151b66d2015-04-15 10:50:31 +00001581 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
cristy9e818982014-01-18 14:54:37 +00001582 value=GetImageProperty(image,key,exception);
1583 if (value != (const char *) NULL)
1584 {
1585 /*
1586 Display clipping path.
1587 */
Cristydb96d692017-10-29 10:37:57 -04001588 JSONFormatLocaleFile(file," \"clipping path\": %s,\n",value);
cristy9e818982014-01-18 14:54:37 +00001589 }
1590 ResetImageProfileIterator(image);
1591 name=GetNextImageProfile(image);
1592 if (name != (char *) NULL)
1593 {
1594 const StringInfo
1595 *profile;
1596
dirk6c316f22015-06-27 15:44:29 +00001597 size_t
1598 n;
1599
cristy9e818982014-01-18 14:54:37 +00001600 /*
1601 Identify image profiles.
1602 */
dirk6c316f22015-06-27 15:44:29 +00001603 n=0;
1604 (void) FormatLocaleFile(file," \"profiles\": {\n");
cristy9e818982014-01-18 14:54:37 +00001605 while (name != (char *) NULL)
1606 {
1607 profile=GetImageProfile(image,name);
1608 if (profile == (StringInfo *) NULL)
1609 continue;
dirk6c316f22015-06-27 15:44:29 +00001610 if (n++ != 0)
1611 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001612 JSONFormatLocaleFile(file," %s: {\n",name);
cristy9e818982014-01-18 14:54:37 +00001613 if (LocaleCompare(name,"iptc") == 0)
Dirk Lemstra32b15502017-09-21 17:04:36 +02001614 EncodeIptcProfile(file,profile);
Cristybc978e02017-10-29 13:29:43 -04001615 (void) FormatLocaleFile(file," \"length\": %.20g",(double)
dirk6c316f22015-06-27 15:44:29 +00001616 GetStringInfoLength(profile));
1617 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001618 name=GetNextImageProfile(image);
1619 }
dirk6c316f22015-06-27 15:44:29 +00001620 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001621 }
1622 ResetImageArtifactIterator(image);
1623 artifact=GetNextImageArtifact(image);
1624 if (artifact != (const char *) NULL)
1625 {
dirk6c316f22015-06-27 15:44:29 +00001626 ssize_t
1627 n;
1628
cristy9e818982014-01-18 14:54:37 +00001629 /*
1630 Display image artifacts.
1631 */
dirk6c316f22015-06-27 15:44:29 +00001632 n=0;
1633 (void) FormatLocaleFile(file," \"artifacts\": {\n");
cristy9e818982014-01-18 14:54:37 +00001634 while (artifact != (const char *) NULL)
1635 {
dirk6c316f22015-06-27 15:44:29 +00001636 if (n++ != 0)
1637 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001638 JSONFormatLocaleFile(file," %s: ",artifact);
cristy9e818982014-01-18 14:54:37 +00001639 value=GetImageArtifact(image,artifact);
Cristydb96d692017-10-29 10:37:57 -04001640 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001641 artifact=GetNextImageArtifact(image);
1642 }
dirk6c316f22015-06-27 15:44:29 +00001643 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001644 }
1645 ResetImageRegistryIterator();
1646 registry=GetNextImageRegistry();
1647 if (registry != (const char *) NULL)
1648 {
dirk6c316f22015-06-27 15:44:29 +00001649 ssize_t
1650 n;
1651
cristy9e818982014-01-18 14:54:37 +00001652 /*
1653 Display image registry.
1654 */
dirk6c316f22015-06-27 15:44:29 +00001655 (void) FormatLocaleFile(file," \"registry\": {\n");
1656 n=0;
cristy9e818982014-01-18 14:54:37 +00001657 while (registry != (const char *) NULL)
1658 {
dirk6c316f22015-06-27 15:44:29 +00001659 if (n++ != 0)
1660 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001661 JSONFormatLocaleFile(file," %s: ",registry);
cristy9e818982014-01-18 14:54:37 +00001662 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1663 exception);
Cristydb96d692017-10-29 10:37:57 -04001664 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001665 registry=GetNextImageRegistry();
1666 }
dirk6c316f22015-06-27 15:44:29 +00001667 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001668 }
dirk6c316f22015-06-27 15:44:29 +00001669 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1670 image->taint != MagickFalse ? "true" : "false");
Cristy3ea0f812020-10-21 14:06:31 -04001671 (void) FormatMagickSize(image->extent,MagickFalse,"B",MagickPathExtent,
cristyd4618c02015-04-14 23:54:43 +00001672 format);
Cristydb96d692017-10-29 10:37:57 -04001673 JSONFormatLocaleFile(file," \"filesize\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001674 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
cristy151b66d2015-04-15 10:50:31 +00001675 MagickFalse,"B",MagickPathExtent,format);
cristy9e818982014-01-18 14:54:37 +00001676 if (strlen(format) > 1)
1677 format[strlen(format)-1]='\0';
Cristydb96d692017-10-29 10:37:57 -04001678 JSONFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001679 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristy151b66d2015-04-15 10:50:31 +00001680 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
Cristydb96d692017-10-29 10:37:57 -04001681 JSONFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
dirk6c316f22015-06-27 15:44:29 +00001682 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1683 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1684 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1685 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1686 elapsed_time))));
Cristy437efd02020-10-20 21:52:30 -04001687 JSONFormatLocaleFile(file," \"version\": %s\n",GetMagickVersion(
1688 (size_t *) NULL));
1689 (void) FormatLocaleFile(file," }\n}");
cristy9e818982014-01-18 14:54:37 +00001690 (void) fflush(file);
1691 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1692}
1693
cristy3f07aa32014-01-18 01:16:33 +00001694static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1695 Image *image,ExceptionInfo *exception)
1696{
dirk6c316f22015-06-27 15:44:29 +00001697 FILE
1698 *file;
1699
cristy3f07aa32014-01-18 01:16:33 +00001700 MagickBooleanType
1701 status;
1702
1703 MagickOffsetType
1704 scene;
1705
Cristyc45b2bb2018-04-07 12:32:12 -04001706 size_t
Cristybee97b82020-12-07 18:46:20 -05001707 number_scenes;
Cristyc45b2bb2018-04-07 12:32:12 -04001708
cristy3f07aa32014-01-18 01:16:33 +00001709 /*
1710 Open output image file.
1711 */
1712 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001713 assert(image_info->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001714 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001715 assert(image->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001716 if (image->debug != MagickFalse)
1717 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1718 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1719 if (status == MagickFalse)
1720 return(status);
dirk6c316f22015-06-27 15:44:29 +00001721 file=GetBlobFileHandle(image);
1722 if (file == (FILE *) NULL)
1723 file=stdout;
cristy3f07aa32014-01-18 01:16:33 +00001724 scene=0;
Cristybee97b82020-12-07 18:46:20 -05001725 number_scenes=GetImageListLength(image);
cristy3f07aa32014-01-18 01:16:33 +00001726 do
1727 {
Dirk Lemstrac9105bd2017-09-21 13:39:00 +02001728 if (scene == 0)
Cristy457c4d62017-12-16 07:45:18 -05001729 (void) WriteBlobString(image,"[");
cristy9e818982014-01-18 14:54:37 +00001730 image->magick_columns=image->columns;
1731 image->magick_rows=image->rows;
Cristy457c4d62017-12-16 07:45:18 -05001732 (void) EncodeImageAttributes(image,file,exception);
cristy3f07aa32014-01-18 01:16:33 +00001733 if (GetNextImageInList(image) == (Image *) NULL)
dirk6c316f22015-06-27 15:44:29 +00001734 {
Cristy457c4d62017-12-16 07:45:18 -05001735 (void) WriteBlobString(image,"]");
dirk6c316f22015-06-27 15:44:29 +00001736 break;
1737 }
Cristy457c4d62017-12-16 07:45:18 -05001738 (void) WriteBlobString(image,",\n");
cristy3f07aa32014-01-18 01:16:33 +00001739 image=SyncNextImageInList(image);
Cristybee97b82020-12-07 18:46:20 -05001740 status=SetImageProgress(image,SaveImagesTag,scene++,number_scenes);
cristy3f07aa32014-01-18 01:16:33 +00001741 if (status == MagickFalse)
1742 break;
1743 } while (image_info->adjoin != MagickFalse);
1744 (void) CloseBlob(image);
1745 return(MagickTrue);
1746}