blob: a064970539a30167b9e3ccbc772f994e179979d4 [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");
dirk08e9a112015-02-22 01:51:41 +0000132 entry->flags^=CoderBlobSupportFlag;
cristy3f07aa32014-01-18 01:16:33 +0000133 (void) RegisterMagickInfo(entry);
134 return(MagickImageCoderSignature);
135}
136
137/*
138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139% %
140% %
141% %
142% U n r e g i s t e r J S O N I m a g e %
143% %
144% %
145% %
146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147%
148% UnregisterJSONImage() removes format registrations made by the
149% JSON module from the list of supported formats.
150%
151% The format of the UnregisterJSONImage method is:
152%
153% UnregisterJSONImage(void)
154%
155*/
156ModuleExport void UnregisterJSONImage(void)
157{
158 (void) UnregisterMagickInfo("JSON");
159}
160
161/*
162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163% %
164% %
165% %
166% W r i t e J S O N I m a g e %
167% %
168% %
169% %
170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171%
172% WriteJSONImage writes the image attributes in the JSON format.
173%
174% The format of the WriteJSONImage method is:
175%
176% MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
177% Image *image,ExceptionInfo *exception)
178%
179% A description of each parameter follows.
180%
181% o image_info: the image info.
182%
183% o image: The image.
184%
185% o exception: return any errors or warnings in this structure.
186%
187*/
cristy9e818982014-01-18 14:54:37 +0000188
Cristydb96d692017-10-29 10:37:57 -0400189static void JSONFormatLocaleFile(FILE *file,const char *format,
190 const char *value)
dirk6c316f22015-06-27 15:44:29 +0000191{
192 char
193 *escaped_json;
194
195 register char
196 *q;
197
198 register const char
199 *p;
200
201 size_t
202 length;
203
204 assert(format != (const char *) NULL);
Cristydb96d692017-10-29 10:37:57 -0400205 if ((value == (char *) NULL) || (*value == '\0'))
206 {
207 (void) FormatLocaleFile(file,format,"null");
208 return;
209 }
dirk6c316f22015-06-27 15:44:29 +0000210 length=strlen(value)+2;
211 /*
Cristydb96d692017-10-29 10:37:57 -0400212 Find all the chars that need escaping and increase the dest length counter.
dirk6c316f22015-06-27 15:44:29 +0000213 */
214 for (p=value; *p != '\0'; p++)
Cristydb96d692017-10-29 10:37:57 -0400215 {
216 switch (*p)
dirk6c316f22015-06-27 15:44:29 +0000217 {
Cristydb96d692017-10-29 10:37:57 -0400218 case '"':
219 case '\b':
220 case '\f':
221 case '\n':
222 case '\r':
223 case '\t':
224 case '\\':
225 {
226 if (~length < 1)
227 return;
228 length++;
229 break;
230 }
231 default:
232 {
233 if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
234 length+=6;
235 break;
236 }
dirk6c316f22015-06-27 15:44:29 +0000237 }
Cristydb96d692017-10-29 10:37:57 -0400238 }
dirk6c316f22015-06-27 15:44:29 +0000239 escaped_json=(char *) NULL;
240 if (~length >= (MagickPathExtent-1))
241 escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent,
242 sizeof(*escaped_json));
243 if (escaped_json == (char *) NULL)
Cristydb96d692017-10-29 10:37:57 -0400244 {
245 (void) FormatLocaleFile(file,format,"null");
246 return;
247 }
dirk6c316f22015-06-27 15:44:29 +0000248 q=escaped_json;
249 *q++='"';
250 for (p=value; *p != '\0'; p++)
Cristydb96d692017-10-29 10:37:57 -0400251 {
252 switch (*p)
dirk6c316f22015-06-27 15:44:29 +0000253 {
Cristydb96d692017-10-29 10:37:57 -0400254 case '"':
255 {
256 *q++='\\';
257 *q++=(*p);
258 break;
259 }
260 case '\b':
261 {
262 *q++='\\';
263 *q++='b';
264 break;
265 }
266 case '\f':
267 {
268 *q++='\\';
269 *q++='f';
270 break;
271 }
272 case '\n':
273 {
274 *q++='\\';
275 *q++='n';
276 break;
277 }
278 case '\r':
279 {
280 *q++='\\';
281 *q++='r';
282 break;
283 }
284 case '\t':
285 {
286 *q++='\\';
287 *q++='t';
288 break;
289 }
290 case '\\':
291 {
292 *q++='\\';
293 *q++='\\';
294 break;
295 }
296 default:
297 {
298 if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
299 {
300 (void) FormatLocaleString(q,7,"\\u%04X",(int) *p);
301 q+=6;
dirk6c316f22015-06-27 15:44:29 +0000302 break;
Cristydb96d692017-10-29 10:37:57 -0400303 }
304 *q++=(*p);
305 break;
306 }
307 }
dirk6c316f22015-06-27 15:44:29 +0000308 }
309 *q++='"';
310 *q='\0';
311 (void) FormatLocaleFile(file,format,escaped_json);
312 (void) DestroyString(escaped_json);
313}
314
cristy9e818982014-01-18 14:54:37 +0000315static ChannelStatistics *GetLocationStatistics(const Image *image,
316 const StatisticType type,ExceptionInfo *exception)
317{
318 ChannelStatistics
319 *channel_statistics;
320
321 register ssize_t
322 i;
323
324 ssize_t
325 y;
326
327 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000328 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000329 if (image->debug != MagickFalse)
330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
331 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
332 MaxPixelChannels+1,sizeof(*channel_statistics));
333 if (channel_statistics == (ChannelStatistics *) NULL)
334 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
Cristy81bfff22018-03-10 07:58:31 -0500335 (void) memset(channel_statistics,0,(MaxPixelChannels+1)*
cristy9e818982014-01-18 14:54:37 +0000336 sizeof(*channel_statistics));
337 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
338 {
339 switch (type)
340 {
341 case MaximumStatistic:
342 default:
343 {
cristyfe181a72014-02-02 21:17:43 +0000344 channel_statistics[i].maxima=(-MagickMaximumValue);
cristy9e818982014-01-18 14:54:37 +0000345 break;
346 }
347 case MinimumStatistic:
348 {
cristyfe181a72014-02-02 21:17:43 +0000349 channel_statistics[i].minima=MagickMaximumValue;
cristy9e818982014-01-18 14:54:37 +0000350 break;
351 }
352 }
353 }
354 for (y=0; y < (ssize_t) image->rows; y++)
355 {
356 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100357 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +0000358
359 register ssize_t
360 x;
361
362 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
363 if (p == (const Quantum *) NULL)
364 break;
365 for (x=0; x < (ssize_t) image->columns; x++)
366 {
367 register ssize_t
368 i;
369
Cristyd05ae9a2017-08-12 07:55:19 -0400370 if (GetPixelReadMask(image,p) <= (QuantumRange/2))
cristy9e818982014-01-18 14:54:37 +0000371 {
372 p+=GetPixelChannels(image);
373 continue;
374 }
375 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
376 {
Cristy3c296d62017-08-19 20:09:26 -0400377 PixelChannel channel = GetPixelChannelChannel(image,i);
378 PixelTrait traits = GetPixelChannelTraits(image,channel);
cristy9e818982014-01-18 14:54:37 +0000379 if (traits == UndefinedPixelTrait)
380 continue;
381 switch (type)
382 {
383 case MaximumStatistic:
384 default:
385 {
386 if ((double) p[i] > channel_statistics[channel].maxima)
387 channel_statistics[channel].maxima=(double) p[i];
388 break;
389 }
390 case MinimumStatistic:
391 {
392 if ((double) p[i] < channel_statistics[channel].minima)
393 channel_statistics[channel].minima=(double) p[i];
394 break;
395 }
396 }
397 }
398 p+=GetPixelChannels(image);
399 }
400 }
401 return(channel_statistics);
402}
403
404static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000405 const char *name,const MagickBooleanType separator,
406 const ChannelFeatures *channel_features)
cristy9e818982014-01-18 14:54:37 +0000407{
408#define PrintFeature(feature) \
409 GetMagickPrecision(),(feature)[0], \
410 GetMagickPrecision(),(feature)[1], \
411 GetMagickPrecision(),(feature)[2], \
412 GetMagickPrecision(),(feature)[3], \
413 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
414
dirk6c316f22015-06-27 15:44:29 +0000415#define FeaturesFormat " \"%s\": {\n" \
416 " \"angularSecondMoment\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400417 " \"horizontal\": %.*g,\n" \
418 " \"vertical\": %.*g,\n" \
419 " \"leftDiagonal\": %.*g,\n" \
420 " \"rightDiagonal\": %.*g,\n" \
421 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000422 " },\n" \
423 " \"contrast\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400424 " \"horizontal\": %.*g,\n" \
425 " \"vertical\": %.*g,\n" \
426 " \"leftDiagonal\": %.*g,\n" \
427 " \"rightDiagonal\": %.*g,\n" \
428 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000429 " },\n" \
430 " \"correlation\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400431 " \"horizontal\": %.*g,\n" \
432 " \"vertical\": %.*g,\n" \
433 " \"leftDiagonal\": %.*g,\n" \
434 " \"rightDiagonal\": %.*g,\n" \
435 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000436 " },\n" \
437 " \"sumOfSquaresVariance\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400438 " \"horizontal\": %.*g,\n" \
439 " \"vertical\": %.*g,\n" \
440 " \"leftDiagonal\": %.*g,\n" \
441 " \"rightDiagonal\": %.*g,\n" \
442 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000443 " },\n" \
444 " \"inverseDifferenceMoment\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400445 " \"horizontal\": %.*g,\n" \
446 " \"vertical\": %.*g,\n" \
447 " \"leftDiagonal\": %.*g,\n" \
448 " \"rightDiagonal\": %.*g,\n" \
449 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000450 " },\n" \
451 " \"sumAverage\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400452 " \"horizontal\": %.*g,\n" \
453 " \"vertical\": %.*g,\n" \
454 " \"leftDiagonal\": %.*g,\n" \
455 " \"rightDiagonal\": %.*g,\n" \
456 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000457 " },\n" \
458 " \"sumVariance\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400459 " \"horizontal\": %.*g,\n" \
460 " \"vertical\": %.*g,\n" \
461 " \"leftDiagonal\": %.*g,\n" \
462 " \"rightDiagonal\": %.*g,\n" \
463 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000464 " },\n" \
465 " \"sumEntropy\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400466 " \"horizontal\": %.*g,\n" \
467 " \"vertical\": %.*g,\n" \
468 " \"leftDiagonal\": %.*g,\n" \
469 " \"rightDiagonal\": %.*g,\n" \
470 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000471 " },\n" \
472 " \"entropy\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400473 " \"horizontal\": %.*g,\n" \
474 " \"vertical\": %.*g,\n" \
475 " \"leftDiagonal\": %.*g,\n" \
476 " \"rightDiagonal\": %.*g,\n" \
477 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000478 " },\n" \
479 " \"differenceVariance\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400480 " \"horizontal\": %.*g,\n" \
481 " \"vertical\": %.*g,\n" \
482 " \"leftDiagonal\": %.*g,\n" \
483 " \"rightDiagonal\": %.*g,\n" \
484 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000485 " },\n" \
486 " \"differenceEntropy\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400487 " \"horizontal\": %.*g,\n" \
488 " \"vertical\": %.*g,\n" \
489 " \"leftDiagonal\": %.*g,\n" \
490 " \"rightDiagonal\": %.*g,\n" \
491 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000492 " },\n" \
493 " \"informationMeasureOfCorrelation1\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400494 " \"horizontal\": %.*g,\n" \
495 " \"vertical\": %.*g,\n" \
496 " \"leftDiagonal\": %.*g,\n" \
497 " \"rightDiagonal\": %.*g,\n" \
498 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000499 " },\n" \
500 " \"informationMeasureOfCorrelation2\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400501 " \"horizontal\": %.*g,\n" \
502 " \"vertical\": %.*g,\n" \
503 " \"leftDiagonal\": %.*g,\n" \
504 " \"rightDiagonal\": %.*g,\n" \
505 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000506 " },\n" \
507 " \"maximumCorrelationCoefficient\": {\n" \
Cristybc978e02017-10-29 13:29:43 -0400508 " \"horizontal\": %.*g,\n" \
509 " \"vertical\": %.*g,\n" \
510 " \"leftDiagonal\": %.*g,\n" \
511 " \"rightDiagonal\": %.*g,\n" \
512 " \"average\": %.*g\n" \
dirk6c316f22015-06-27 15:44:29 +0000513 " }\n"
cristy9e818982014-01-18 14:54:37 +0000514
515 ssize_t
516 n;
517
518 n=FormatLocaleFile(file,FeaturesFormat,name,
519 PrintFeature(channel_features[channel].angular_second_moment),
520 PrintFeature(channel_features[channel].contrast),
521 PrintFeature(channel_features[channel].correlation),
522 PrintFeature(channel_features[channel].variance_sum_of_squares),
523 PrintFeature(channel_features[channel].inverse_difference_moment),
524 PrintFeature(channel_features[channel].sum_average),
525 PrintFeature(channel_features[channel].sum_variance),
526 PrintFeature(channel_features[channel].sum_entropy),
527 PrintFeature(channel_features[channel].entropy),
528 PrintFeature(channel_features[channel].difference_variance),
529 PrintFeature(channel_features[channel].difference_entropy),
530 PrintFeature(channel_features[channel].measure_of_correlation_1),
531 PrintFeature(channel_features[channel].measure_of_correlation_2),
532 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
dirk6c316f22015-06-27 15:44:29 +0000533 (void) FormatLocaleFile(file," }");
534 if (separator != MagickFalse)
535 (void) FormatLocaleFile(file,",");
536 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000537 return(n);
538}
539
540static ssize_t PrintChannelLocations(FILE *file,const Image *image,
541 const PixelChannel channel,const char *name,const StatisticType type,
dirk6c316f22015-06-27 15:44:29 +0000542 const size_t max_locations,const MagickBooleanType separator,
543 const ChannelStatistics *channel_statistics)
cristy9e818982014-01-18 14:54:37 +0000544{
545 double
546 target;
547
548 ExceptionInfo
549 *exception;
550
551 ssize_t
552 n,
553 y;
554
555 switch (type)
556 {
557 case MaximumStatistic:
558 default:
559 {
560 target=channel_statistics[channel].maxima;
561 break;
562 }
563 case MinimumStatistic:
564 {
565 target=channel_statistics[channel].minima;
566 break;
567 }
568 }
dirk6c316f22015-06-27 15:44:29 +0000569 (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": "
Cristybc978e02017-10-29 13:29:43 -0400570 "%.*g,\n",name,GetMagickPrecision(),QuantumScale*target);
cristy9e818982014-01-18 14:54:37 +0000571 exception=AcquireExceptionInfo();
572 n=0;
573 for (y=0; y < (ssize_t) image->rows; y++)
574 {
575 register const Quantum
576 *p;
577
578 ssize_t
579 offset,
580 x;
581
582 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
583 if (p == (const Quantum *) NULL)
584 break;
585 for (x=0; x < (ssize_t) image->columns; x++)
586 {
587 MagickBooleanType
588 match;
589
Cristy3c296d62017-08-19 20:09:26 -0400590 PixelTrait traits = GetPixelChannelTraits(image,channel);
cristy9e818982014-01-18 14:54:37 +0000591 if (traits == UndefinedPixelTrait)
592 continue;
593 offset=GetPixelChannelOffset(image,channel);
cristy3bdd9252014-12-21 20:01:43 +0000594 match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse;
cristy9e818982014-01-18 14:54:37 +0000595 if (match != MagickFalse)
596 {
597 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
598 break;
dirk6c316f22015-06-27 15:44:29 +0000599 if (n != 0)
600 (void) FormatLocaleFile(file,",\n");
601 (void) FormatLocaleFile(file," \"location%.20g\": {\n"
602 " \"x\": %.20g,\n \"y\": %.20g\n"
603 " }",(double) n,(double) x,(double) y);
cristy9e818982014-01-18 14:54:37 +0000604 n++;
605 }
606 p+=GetPixelChannels(image);
607 }
608 if (x < (ssize_t) image->columns)
609 break;
610 }
dirk6c316f22015-06-27 15:44:29 +0000611 (void) FormatLocaleFile(file,"\n }");
612 if (separator != MagickFalse)
613 (void) FormatLocaleFile(file,",");
cristy9e818982014-01-18 14:54:37 +0000614 (void) FormatLocaleFile(file,"\n");
615 return(n);
616}
617
618static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000619 const char *name,const MagickBooleanType separator,
620 const ChannelMoments *channel_moments)
cristy9e818982014-01-18 14:54:37 +0000621{
622 register ssize_t
623 i;
624
625 ssize_t
626 n;
627
dirk6c316f22015-06-27 15:44:29 +0000628 n=FormatLocaleFile(file," \"%s\": {\n",name);
629 n+=FormatLocaleFile(file," \"centroid\": {\n "
Cristybc978e02017-10-29 13:29:43 -0400630 " \"x\": %.*g,\n"
631 " \"y\": %.*g\n },\n",
cristy9e818982014-01-18 14:54:37 +0000632 GetMagickPrecision(),channel_moments[channel].centroid.x,
633 GetMagickPrecision(),channel_moments[channel].centroid.y);
dirk6c316f22015-06-27 15:44:29 +0000634 n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n"
Cristybc978e02017-10-29 13:29:43 -0400635 " \"x\": %.*g,\n"
636 " \"y\": %.*g\n },\n",
cristy9e818982014-01-18 14:54:37 +0000637 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
638 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
Cristybc978e02017-10-29 13:29:43 -0400639 n+=FormatLocaleFile(file," \"ellipseAngle\": %.*g,\n",
cristy9e818982014-01-18 14:54:37 +0000640 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
Cristybc978e02017-10-29 13:29:43 -0400641 n+=FormatLocaleFile(file," \"ellipseEccentricity\": %.*g,\n",
cristy9e818982014-01-18 14:54:37 +0000642 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
Cristybc978e02017-10-29 13:29:43 -0400643 n+=FormatLocaleFile(file," \"ellipseIntensity\": %.*g,\n",
cristy9e818982014-01-18 14:54:37 +0000644 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
dirk6c316f22015-06-27 15:44:29 +0000645 for (i=0; i < 7; i++)
Cristybc978e02017-10-29 13:29:43 -0400646 n+=FormatLocaleFile(file," \"I%.20g\": %.*g,\n",i+1.0,
dirk6c316f22015-06-27 15:44:29 +0000647 GetMagickPrecision(),channel_moments[channel].invariant[i]);
Cristybc978e02017-10-29 13:29:43 -0400648 n+=FormatLocaleFile(file," \"I%.20g\": %.*g\n",i+1.0,
dirk6c316f22015-06-27 15:44:29 +0000649 GetMagickPrecision(),channel_moments[channel].invariant[i]);
650 (void) FormatLocaleFile(file," }");
651 if (separator != MagickFalse)
652 (void) FormatLocaleFile(file,",");
653 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000654 return(n);
655}
656
Cristye6961802016-09-03 11:31:13 -0400657static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
cristydc395172014-02-23 01:33:36 +0000658 const ChannelPerceptualHash *channel_phash)
659{
660 register ssize_t
661 i;
662
663 ssize_t
Cristy69a7c2b2016-12-24 11:22:36 -0500664 n = 0;
cristydc395172014-02-23 01:33:36 +0000665
Cristye6961802016-09-03 11:31:13 -0400666 (void) FormatLocaleFile(file," \"colorspaces\": [ ");
667 for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
668 {
669 (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic(
670 MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
671 if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
672 (void) FormatLocaleFile(file,", ");
673 }
674 (void) FormatLocaleFile(file,"],\n");
675 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
676 {
677 register ssize_t
678 j;
679
Cristy3c296d62017-08-19 20:09:26 -0400680 PixelChannel channel = GetPixelChannelChannel(image,i);
681 PixelTrait traits = GetPixelChannelTraits(image,channel);
Cristye6961802016-09-03 11:31:13 -0400682 if (traits == UndefinedPixelTrait)
683 continue;
684 n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel);
685 for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
686 {
687 register ssize_t
688 k;
689
690 n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1);
691 for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
692 {
Cristybc978e02017-10-29 13:29:43 -0400693 n+=FormatLocaleFile(file,"%.*g",GetMagickPrecision(),
Cristye6961802016-09-03 11:31:13 -0400694 channel_phash[channel].phash[k][j]);
695 if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
696 n+=FormatLocaleFile(file,", ");
697 }
698 n+=FormatLocaleFile(file,"]");
699 if (j < (MaximumNumberOfPerceptualHashes-1))
700 n+=FormatLocaleFile(file,",\n");
701 }
Cristy338f0882016-12-10 12:12:35 -0500702 if (i < (ssize_t) (GetPixelChannels(image)-1))
Cristye6961802016-09-03 11:31:13 -0400703 n+=FormatLocaleFile(file,"\n },\n");
704 }
705 n+=FormatLocaleFile(file,"\n }\n");
cristydc395172014-02-23 01:33:36 +0000706 return(n);
707}
708
cristy9e818982014-01-18 14:54:37 +0000709static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000710 const char *name,const double scale,const MagickBooleanType separator,
cristy9e818982014-01-18 14:54:37 +0000711 const ChannelStatistics *channel_statistics)
712{
Cristybc978e02017-10-29 13:29:43 -0400713#define StatisticsFormat " \"%s\": {\n \"min\": %.*g,\n" \
714 " \"max\": %.*g,\n \"mean\": %.*g,\n " \
715 "\"standardDeviation\": %.*g,\n \"kurtosis\": %.*g,\n "\
716 "\"skewness\": %.*g,\n \"entropy\": %.*g\n }"
cristy9e818982014-01-18 14:54:37 +0000717
718 ssize_t
719 n;
720
Cristybc978e02017-10-29 13:29:43 -0400721 n=FormatLocaleFile(file,StatisticsFormat,name,GetMagickPrecision(),
722 (double) ClampToQuantum(scale*channel_statistics[channel].minima),
723 GetMagickPrecision(),(double) ClampToQuantum(scale*
724 channel_statistics[channel].maxima),GetMagickPrecision(),scale*
725 channel_statistics[channel].mean,GetMagickPrecision(),scale*
Cristy7a4f99c2018-04-28 17:34:11 -0400726 IsNaN(channel_statistics[channel].standard_deviation) != 0 ? MagickEpsilon :
Cristybc978e02017-10-29 13:29:43 -0400727 channel_statistics[channel].standard_deviation,GetMagickPrecision(),
728 channel_statistics[channel].kurtosis,GetMagickPrecision(),
729 channel_statistics[channel].skewness,GetMagickPrecision(),
730 channel_statistics[channel].entropy);
dirk6c316f22015-06-27 15:44:29 +0000731 if (separator != MagickFalse)
cristye1c94d92015-06-28 12:16:33 +0000732 (void) FormatLocaleFile(file,",");
dirk6c316f22015-06-27 15:44:29 +0000733 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000734 return(n);
735}
736
Dirk Lemstra32b15502017-09-21 17:04:36 +0200737static void EncodeIptcProfile(FILE *file,const StringInfo *profile)
738{
739 char
740 *attribute,
741 **attribute_list;
742
743 const char
744 *tag;
745
Cristydb96d692017-10-29 10:37:57 -0400746 IPTCInfo
Dirk Lemstra32b15502017-09-21 17:04:36 +0200747 *value,
748 **values;
749
750 long
751 dataset,
752 record,
753 sentinel;
754
755 register ssize_t
756 i,
757 j,
758 k;
759
760 size_t
761 count,
762 length,
763 profile_length;
764
Cristydb96d692017-10-29 10:37:57 -0400765 values=(IPTCInfo **) NULL;
Dirk Lemstra32b15502017-09-21 17:04:36 +0200766 count=0;
767 profile_length=GetStringInfoLength(profile);
768 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
769 {
770 length=1;
771 sentinel=GetStringInfoDatum(profile)[i++];
772 if (sentinel != 0x1c)
773 continue;
774 dataset=GetStringInfoDatum(profile)[i++];
775 record=GetStringInfoDatum(profile)[i++];
Cristydb96d692017-10-29 10:37:57 -0400776 value=(IPTCInfo *) NULL;
Cristy7c7050a2017-09-30 12:12:21 -0400777 for (j=0; j < (ssize_t) count; j++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200778 {
779 if ((values[j]->record == record) && (values[j]->dataset == dataset))
780 value=values[j];
781 }
Cristydb96d692017-10-29 10:37:57 -0400782 if (value == (IPTCInfo *) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200783 {
Cristydb96d692017-10-29 10:37:57 -0400784 values=(IPTCInfo **) ResizeQuantumMemory(values,count+1,
Dirk Lemstra32b15502017-09-21 17:04:36 +0200785 sizeof(*values));
Cristydb96d692017-10-29 10:37:57 -0400786 if (values == (IPTCInfo **) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200787 break;
Cristydb96d692017-10-29 10:37:57 -0400788 value=(IPTCInfo *) AcquireMagickMemory(sizeof(*value));
789 if (value == (IPTCInfo *) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200790 break;
Cristydb96d692017-10-29 10:37:57 -0400791 /* Check the tag length in IPTCInfo when a new tag is added */
Dirk Lemstra32b15502017-09-21 17:04:36 +0200792 switch (record)
793 {
794 case 5: tag="Image Name"; break;
795 case 7: tag="Edit Status"; break;
796 case 10: tag="Priority"; break;
797 case 15: tag="Category"; break;
798 case 20: tag="Supplemental Category"; break;
799 case 22: tag="Fixture Identifier"; break;
800 case 25: tag="Keyword"; break;
801 case 30: tag="Release Date"; break;
802 case 35: tag="Release Time"; break;
803 case 40: tag="Special Instructions"; break;
804 case 45: tag="Reference Service"; break;
805 case 47: tag="Reference Date"; break;
806 case 50: tag="Reference Number"; break;
807 case 55: tag="Created Date"; break;
808 case 60: tag="Created Time"; break;
809 case 65: tag="Originating Program"; break;
810 case 70: tag="Program Version"; break;
811 case 75: tag="Object Cycle"; break;
812 case 80: tag="Byline"; break;
813 case 85: tag="Byline Title"; break;
814 case 90: tag="City"; break;
815 case 92: tag="Sub-Location"; break;
816 case 95: tag="Province State"; break;
817 case 100: tag="Country Code"; break;
818 case 101: tag="Country"; break;
819 case 103: tag="Original Transmission Reference"; break;
820 case 105: tag="Headline"; break;
821 case 110: tag="Credit"; break;
822 case 115: tag="Src"; break;
823 case 116: tag="Copyright String"; break;
824 case 120: tag="Caption"; break;
825 case 121: tag="Local Caption"; break;
826 case 122: tag="Caption Writer"; break;
827 case 200: tag="Custom Field 1"; break;
828 case 201: tag="Custom Field 2"; break;
829 case 202: tag="Custom Field 3"; break;
830 case 203: tag="Custom Field 4"; break;
831 case 204: tag="Custom Field 5"; break;
832 case 205: tag="Custom Field 6"; break;
833 case 206: tag="Custom Field 7"; break;
834 case 207: tag="Custom Field 8"; break;
835 case 208: tag="Custom Field 9"; break;
836 case 209: tag="Custom Field 10"; break;
837 case 210: tag="Custom Field 11"; break;
838 case 211: tag="Custom Field 12"; break;
839 case 212: tag="Custom Field 13"; break;
840 case 213: tag="Custom Field 14"; break;
841 case 214: tag="Custom Field 15"; break;
842 case 215: tag="Custom Field 16"; break;
843 case 216: tag="Custom Field 17"; break;
844 case 217: tag="Custom Field 18"; break;
845 case 218: tag="Custom Field 19"; break;
846 case 219: tag="Custom Field 20"; break;
847 default: tag="Unknown"; break;
848 }
849 (void) CopyMagickString(value->tag,tag,strlen(tag)+1);
850 value->record=record;
851 value->dataset=dataset;
852 value->values=(char ***) NULL;
853 value->values_length=0;
854 values[count++]=value;
855 }
856 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
857 length|=GetStringInfoDatum(profile)[i++];
858 attribute=(char *) NULL;
859 if (~length >= (MagickPathExtent-1))
860 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
861 sizeof(*attribute));
862 if (attribute != (char *) NULL)
863 {
864 (void) CopyMagickString(attribute,(char *)
865 GetStringInfoDatum(profile)+i,length+1);
866 attribute_list=StringToList(attribute);
867 if (attribute_list != (char **) NULL)
868 {
869 value->values=(char ***) ResizeQuantumMemory(value->values,
870 value->values_length+1,
871 sizeof(*value->values));
872 if (value->values == (char ***) NULL)
873 break;
874 value->values[value->values_length++]=attribute_list;
875 }
876 attribute=DestroyString(attribute);
877 }
878 }
Cristydb96d692017-10-29 10:37:57 -0400879 if (values != (IPTCInfo **) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200880 {
Cristy7c7050a2017-09-30 12:12:21 -0400881 for (i=0; i < (ssize_t) count; i++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200882 {
883 value=values[i];
884 (void) FormatLocaleFile(file," \"%s[%.20g,%.20g]\": ",
885 value->tag,(double) value->dataset,(double) value->record);
886 if (value->values_length == 0)
887 (void) FormatLocaleFile(file,"null,");
888 else
889 {
890 (void) FormatLocaleFile(file,"[");
Cristy7c7050a2017-09-30 12:12:21 -0400891 for (j=0; j < (ssize_t) value->values_length; j++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200892 {
893 for (k=0; value->values[j][k] != (char *) NULL; k++)
894 {
895 if (j > 0 || k > 0)
896 (void) FormatLocaleFile(file,",");
Cristydb96d692017-10-29 10:37:57 -0400897 JSONFormatLocaleFile(file,"%s",value->values[j][k]);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200898 value->values[j][k]=(char *) RelinquishMagickMemory(
899 value->values[j][k]);
900 }
901 value->values[j]=(char **) RelinquishMagickMemory(
902 value->values[j]);
903 }
904 value->values=(char ***) RelinquishMagickMemory(value->values);
905 (void) FormatLocaleFile(file,"],\n");
906 }
Cristydb96d692017-10-29 10:37:57 -0400907 values[i]=(IPTCInfo *) RelinquishMagickMemory(values[i]);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200908 }
Cristydb96d692017-10-29 10:37:57 -0400909 values=(IPTCInfo **) RelinquishMagickMemory(values);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200910 }
911}
912
cristy9e818982014-01-18 14:54:37 +0000913static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
914 ExceptionInfo *exception)
915{
cristy9e818982014-01-18 14:54:37 +0000916 char
cristy151b66d2015-04-15 10:50:31 +0000917 color[MagickPathExtent],
918 format[MagickPathExtent],
919 key[MagickPathExtent];
cristy9e818982014-01-18 14:54:37 +0000920
921 ChannelFeatures
922 *channel_features;
923
924 ChannelMoments
925 *channel_moments;
926
cristydc395172014-02-23 01:33:36 +0000927 ChannelPerceptualHash
928 *channel_phash;
929
cristy9e818982014-01-18 14:54:37 +0000930 ChannelStatistics
931 *channel_statistics;
932
Cristy519e0052016-10-16 15:28:40 -0400933 char
934 *url;
935
cristy9e818982014-01-18 14:54:37 +0000936 const char
937 *artifact,
938 *locate,
939 *name,
940 *property,
941 *registry,
942 *value;
943
944 const MagickInfo
945 *magick_info;
946
947 double
948 elapsed_time,
Cristye7408482020-08-27 20:59:50 -0400949 user_time,
950 version;
cristy9e818982014-01-18 14:54:37 +0000951
952 ImageType
953 type;
954
955 MagickBooleanType
956 ping;
957
958 register const Quantum
959 *p;
960
961 register ssize_t
962 i,
963 x;
964
965 size_t
dirk6c316f22015-06-27 15:44:29 +0000966 depth,
cristy9e818982014-01-18 14:54:37 +0000967 distance,
968 scale;
969
970 ssize_t
971 y;
972
973 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000974 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000975 if (image->debug != MagickFalse)
976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristya10f7442014-01-19 18:32:15 +0000977 *format='\0';
978 elapsed_time=GetElapsedTime(&image->timer);
979 user_time=GetUserTime(&image->timer);
980 GetTimerInfo(&image->timer);
981 p=GetVirtualPixels(image,0,0,1,1,exception);
982 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
cristye1c94d92015-06-28 12:16:33 +0000983 (void) ping;
cristya10f7442014-01-19 18:32:15 +0000984 (void) SignatureImage(image,exception);
Cristye7408482020-08-27 20:59:50 -0400985 (void) FormatLocaleFile(file,"\n{\n");
986 version=1.0;
987 artifact=GetImageArtifact(image,"json:version");
988 if (artifact != (const char *) NULL)
989 version=StringToDouble(artifact,(char **) NULL);
990 if (version >= 1.0)
991 (void) FormatLocaleFile(file," \"version\": \"%.1f\",\n",version);
992 JSONFormatLocaleFile(file," \"image\": {\n \"name\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +0000993 image->filename);
cristya10f7442014-01-19 18:32:15 +0000994 if (*image->magick_filename != '\0')
995 if (LocaleCompare(image->magick_filename,image->filename) != 0)
996 {
997 char
cristy151b66d2015-04-15 10:50:31 +0000998 filename[MagickPathExtent];
cristya10f7442014-01-19 18:32:15 +0000999
1000 GetPathComponent(image->magick_filename,TailPath,filename);
Cristydb96d692017-10-29 10:37:57 -04001001 JSONFormatLocaleFile(file," \"baseName\": %s,\n",filename);
cristya10f7442014-01-19 18:32:15 +00001002 }
Cristydb96d692017-10-29 10:37:57 -04001003 JSONFormatLocaleFile(file," \"format\": %s,\n",image->magick);
cristya10f7442014-01-19 18:32:15 +00001004 magick_info=GetMagickInfo(image->magick,exception);
dirk6c316f22015-06-27 15:44:29 +00001005 if ((magick_info != (const MagickInfo *) NULL) &&
1006 (GetMagickDescription(magick_info) != (const char *) NULL))
Cristydb96d692017-10-29 10:37:57 -04001007 JSONFormatLocaleFile(file," \"formatDescription\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001008 image->magick);
cristy12bcd3d2015-01-28 00:54:23 +00001009 if ((magick_info != (const MagickInfo *) NULL) &&
cristya10f7442014-01-19 18:32:15 +00001010 (GetMagickMimeType(magick_info) != (const char *) NULL))
Cristydb96d692017-10-29 10:37:57 -04001011 JSONFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
cristya10f7442014-01-19 18:32:15 +00001012 magick_info));
Cristydb96d692017-10-29 10:37:57 -04001013 JSONFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001014 MagickClassOptions,(ssize_t) image->storage_class));
dirk6c316f22015-06-27 15:44:29 +00001015 (void) FormatLocaleFile(file," \"geometry\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001016 " \"width\": %g,\n \"height\": %g,\n"
1017 " \"x\": %g,\n \"y\": %g\n },\n",
dirk6c316f22015-06-27 15:44:29 +00001018 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
1019 (double) image->tile_offset.y);
cristya10f7442014-01-19 18:32:15 +00001020 if ((image->magick_columns != 0) || (image->magick_rows != 0))
1021 if ((image->magick_columns != image->columns) ||
1022 (image->magick_rows != image->rows))
dirk6c316f22015-06-27 15:44:29 +00001023 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001024 " \"width\": %g,\n \"height\": %g\n },\n",(double)
1025 image->magick_columns,(double) image->magick_rows);
cristya10f7442014-01-19 18:32:15 +00001026 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
1027 {
dirk6c316f22015-06-27 15:44:29 +00001028 (void) FormatLocaleFile(file," \"resolution\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001029 " \"x\": %g,\n \"y\": %g\n },\n",image->resolution.x,
cristya10f7442014-01-19 18:32:15 +00001030 image->resolution.y);
Cristybc978e02017-10-29 13:29:43 -04001031 (void) FormatLocaleFile(file," \"printSize\": {\n"
1032 " \"x\": %.*g,\n \"y\": %.*g\n },\n",GetMagickPrecision(),
1033 image->columns/image->resolution.x,GetMagickPrecision(),(double)
1034 image->rows/image->resolution.y);
cristya10f7442014-01-19 18:32:15 +00001035 }
Cristydb96d692017-10-29 10:37:57 -04001036 JSONFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001037 MagickResolutionOptions,(ssize_t) image->units));
Cristy95ab3892017-12-24 09:34:52 -05001038 type=IdentifyImageType(image,exception);
Cristydb96d692017-10-29 10:37:57 -04001039 JSONFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001040 MagickTypeOptions,(ssize_t) type));
Cristy4826fb42017-12-17 12:05:09 -05001041 if (image->type != type)
Cristydb96d692017-10-29 10:37:57 -04001042 JSONFormatLocaleFile(file," \"baseType\": %s,\n",
Cristy4826fb42017-12-17 12:05:09 -05001043 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) image->type));
Cristye7408482020-08-27 20:59:50 -04001044 if (version < 1.0)
1045 JSONFormatLocaleFile(file," \"endianess\": %s,\n",
1046 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
1047 else
1048 JSONFormatLocaleFile(file," \"endianness\": %s,\n",
1049 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
cristy9e818982014-01-18 14:54:37 +00001050 locate=GetImageArtifact(image,"identify:locate");
cristy3e583dd2014-01-19 14:11:51 +00001051 if (locate == (const char *) NULL)
1052 locate=GetImageArtifact(image,"json:locate");
cristy9e818982014-01-18 14:54:37 +00001053 if (locate != (const char *) NULL)
1054 {
1055 const char
1056 *limit;
1057
1058 size_t
1059 max_locations;
1060
1061 StatisticType
1062 type;
1063
1064 /*
1065 Display minimum, maximum, or mean pixel locations.
1066 */
1067 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
1068 MagickFalse,locate);
1069 limit=GetImageArtifact(image,"identify:limit");
cristy3e583dd2014-01-19 14:11:51 +00001070 if (limit == (const char *) NULL)
1071 limit=GetImageArtifact(image,"json:limit");
cristy9e818982014-01-18 14:54:37 +00001072 max_locations=0;
1073 if (limit != (const char *) NULL)
1074 max_locations=StringToUnsignedLong(limit);
1075 channel_statistics=GetLocationStatistics(image,type,exception);
1076 if (channel_statistics == (ChannelStatistics *) NULL)
1077 return(MagickFalse);
dirk6c316f22015-06-27 15:44:29 +00001078 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
1079 if (image->alpha_trait != UndefinedPixelTrait)
1080 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
1081 type,max_locations,MagickTrue,channel_statistics);
Cristy3889d152017-12-22 19:42:13 -05001082 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001083 {
1084 case RGBColorspace:
1085 default:
1086 {
1087 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
dirk6c316f22015-06-27 15:44:29 +00001088 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001089 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
dirk6c316f22015-06-27 15:44:29 +00001090 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001091 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
dirk6c316f22015-06-27 15:44:29 +00001092 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001093 break;
1094 }
1095 case CMYKColorspace:
1096 {
1097 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
dirk6c316f22015-06-27 15:44:29 +00001098 type,max_locations,MagickTrue,channel_statistics);
Cristy95ab3892017-12-24 09:34:52 -05001099 (void) PrintChannelLocations(file,image,MagentaPixelChannel,
1100 "Magenta",type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001101 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001102 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001103 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001104 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001105 break;
1106 }
Cristybeb4c2b2017-12-26 19:43:17 -05001107 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001108 case GRAYColorspace:
1109 {
1110 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
dirk6c316f22015-06-27 15:44:29 +00001111 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001112 break;
1113 }
1114 }
dirk6c316f22015-06-27 15:44:29 +00001115 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001116 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1117 channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001118 }
cristy9e818982014-01-18 14:54:37 +00001119 /*
1120 Detail channel depth and extrema.
1121 */
Cristydb96d692017-10-29 10:37:57 -04001122 JSONFormatLocaleFile(file," \"colorspace\": %s,\n",
Cristy3889d152017-12-22 19:42:13 -05001123 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
1124 image->colorspace));
cristy9e818982014-01-18 14:54:37 +00001125 channel_statistics=(ChannelStatistics *) NULL;
1126 channel_moments=(ChannelMoments *) NULL;
cristydc395172014-02-23 01:33:36 +00001127 channel_phash=(ChannelPerceptualHash *) NULL;
cristy9e818982014-01-18 14:54:37 +00001128 channel_features=(ChannelFeatures *) NULL;
cristy9e818982014-01-18 14:54:37 +00001129 scale=1;
dirk6c316f22015-06-27 15:44:29 +00001130 channel_statistics=GetImageStatistics(image,exception);
1131 if (channel_statistics == (ChannelStatistics *) NULL)
1132 return(MagickFalse);
1133 artifact=GetImageArtifact(image,"identify:moments");
1134 if (artifact == (const char *) NULL)
1135 artifact=GetImageArtifact(image,"json:moments");
1136 if (artifact != (const char *) NULL)
cristy9e818982014-01-18 14:54:37 +00001137 {
dirk6c316f22015-06-27 15:44:29 +00001138 channel_moments=GetImageMoments(image,exception);
1139 channel_phash=GetImagePerceptualHash(image,exception);
cristy9e818982014-01-18 14:54:37 +00001140 }
dirk6c316f22015-06-27 15:44:29 +00001141 artifact=GetImageArtifact(image,"identify:features");
1142 if (artifact == (const char *) NULL)
1143 artifact=GetImageArtifact(image,"json:features");
1144 if (artifact != (const char *) NULL)
1145 {
1146 distance=StringToUnsignedLong(artifact);
1147 channel_features=GetImageFeatures(image,distance,exception);
1148 }
1149 depth=GetImageDepth(image,exception);
Cristybc978e02017-10-29 13:29:43 -04001150 (void) FormatLocaleFile(file," \"depth\": %g,\n",(double) depth);
1151 (void) FormatLocaleFile(file," \"baseDepth\": %g,\n",(double)
dirk6c316f22015-06-27 15:44:29 +00001152 image->depth);
1153 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
dirk6c316f22015-06-27 15:44:29 +00001154 if (image->alpha_trait != UndefinedPixelTrait)
1155 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
1156 channel_statistics[AlphaPixelChannel].depth);
Cristy3889d152017-12-22 19:42:13 -05001157 switch (image->colorspace)
dirk6c316f22015-06-27 15:44:29 +00001158 {
1159 case RGBColorspace:
1160 default:
1161 {
1162 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
1163 channel_statistics[RedChannel].depth);
1164 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
1165 channel_statistics[GreenChannel].depth);
1166 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
1167 channel_statistics[BlueChannel].depth);
1168 break;
1169 }
1170 case CMYKColorspace:
1171 {
1172 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
1173 channel_statistics[CyanChannel].depth);
1174 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
1175 channel_statistics[MagentaChannel].depth);
1176 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
1177 channel_statistics[YellowChannel].depth);
1178 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
1179 channel_statistics[BlackChannel].depth);
1180 break;
1181 }
Cristybeb4c2b2017-12-26 19:43:17 -05001182 case LinearGRAYColorspace:
dirk6c316f22015-06-27 15:44:29 +00001183 case GRAYColorspace:
1184 {
1185 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
1186 channel_statistics[GrayChannel].depth);
1187 break;
1188 }
1189 }
1190 (void) FormatLocaleFile(file," },\n");
1191 scale=1;
1192 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
1193 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
1194 MAGICKCORE_QUANTUM_DEPTH-image->depth));
cristy9e818982014-01-18 14:54:37 +00001195 if (channel_statistics != (ChannelStatistics *) NULL)
1196 {
dirk6c316f22015-06-27 15:44:29 +00001197 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
cristy9e818982014-01-18 14:54:37 +00001198 channel_statistics[CompositePixelChannel].area);
Cristybeb4c2b2017-12-26 19:43:17 -05001199 if ((image->colorspace != LinearGRAYColorspace) &&
1200 (image->colorspace != GRAYColorspace))
dirk6c316f22015-06-27 15:44:29 +00001201 {
1202 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
1203 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
1204 "Overall",1.0/scale,MagickFalse,channel_statistics);
1205 (void) FormatLocaleFile(file," },\n");
1206 }
1207 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
1208 if (image->alpha_trait != UndefinedPixelTrait)
1209 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
1210 MagickTrue,channel_statistics);
Cristy3889d152017-12-22 19:42:13 -05001211 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001212 {
1213 case RGBColorspace:
1214 default:
1215 {
dirk6c316f22015-06-27 15:44:29 +00001216 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale,
1217 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001218 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
dirk6c316f22015-06-27 15:44:29 +00001219 scale,MagickTrue,channel_statistics);
1220 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale,
1221 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001222 break;
1223 }
1224 case CMYKColorspace:
1225 {
dirk6c316f22015-06-27 15:44:29 +00001226 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale,
1227 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001228 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
dirk6c316f22015-06-27 15:44:29 +00001229 scale,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001230 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
dirk6c316f22015-06-27 15:44:29 +00001231 scale,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001232 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
dirk6c316f22015-06-27 15:44:29 +00001233 scale,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001234 break;
1235 }
Cristybeb4c2b2017-12-26 19:43:17 -05001236 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001237 case GRAYColorspace:
1238 {
dirk6c316f22015-06-27 15:44:29 +00001239 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale,
1240 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001241 break;
1242 }
1243 }
dirk6c316f22015-06-27 15:44:29 +00001244 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001245 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1246 channel_statistics);
1247 }
1248 if (channel_moments != (ChannelMoments *) NULL)
1249 {
dirk6c316f22015-06-27 15:44:29 +00001250 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
1251 if (image->alpha_trait != UndefinedPixelTrait)
1252 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue,
1253 channel_moments);
Cristy3889d152017-12-22 19:42:13 -05001254 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001255 {
1256 case RGBColorspace:
1257 default:
1258 {
dirk6c316f22015-06-27 15:44:29 +00001259 (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001260 channel_moments);
dirk6c316f22015-06-27 15:44:29 +00001261 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001262 channel_moments);
dirk6c316f22015-06-27 15:44:29 +00001263 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001264 channel_moments);
1265 break;
1266 }
1267 case CMYKColorspace:
1268 {
dirk6c316f22015-06-27 15:44:29 +00001269 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001270 channel_moments);
1271 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +00001272 MagickTrue,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001273 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001274 MagickTrue,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001275 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001276 MagickFalse,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001277 break;
1278 }
Cristybeb4c2b2017-12-26 19:43:17 -05001279 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001280 case GRAYColorspace:
1281 {
dirk6c316f22015-06-27 15:44:29 +00001282 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001283 channel_moments);
1284 break;
1285 }
1286 }
dirk6c316f22015-06-27 15:44:29 +00001287 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001288 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1289 channel_moments);
1290 }
cristydc395172014-02-23 01:33:36 +00001291 if (channel_phash != (ChannelPerceptualHash *) NULL)
1292 {
1293 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
Cristye6961802016-09-03 11:31:13 -04001294 (void) PrintChannelPerceptualHash(image,file,channel_phash);
cristydc395172014-02-23 01:33:36 +00001295 (void) FormatLocaleFile(file," },\n");
1296 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1297 channel_phash);
1298 }
cristy9e818982014-01-18 14:54:37 +00001299 if (channel_features != (ChannelFeatures *) NULL)
1300 {
dirk6c316f22015-06-27 15:44:29 +00001301 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1302 if (image->alpha_trait != UndefinedPixelTrait)
1303 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue,
1304 channel_features);
Cristy3889d152017-12-22 19:42:13 -05001305 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001306 {
1307 case RGBColorspace:
1308 default:
1309 {
dirk6c316f22015-06-27 15:44:29 +00001310 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001311 channel_features);
1312 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
dirk6c316f22015-06-27 15:44:29 +00001313 MagickTrue,channel_features);
1314 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001315 channel_features);
1316 break;
1317 }
1318 case CMYKColorspace:
1319 {
dirk6c316f22015-06-27 15:44:29 +00001320 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001321 channel_features);
1322 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +00001323 MagickTrue,channel_features);
cristy9e818982014-01-18 14:54:37 +00001324 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001325 MagickTrue,channel_features);
cristy9e818982014-01-18 14:54:37 +00001326 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001327 MagickFalse,channel_features);
cristy9e818982014-01-18 14:54:37 +00001328 break;
1329 }
Cristybeb4c2b2017-12-26 19:43:17 -05001330 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001331 case GRAYColorspace:
1332 {
dirk6c316f22015-06-27 15:44:29 +00001333 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001334 channel_features);
1335 break;
1336 }
1337 }
dirk6c316f22015-06-27 15:44:29 +00001338 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001339 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1340 channel_features);
1341 }
dirk6c316f22015-06-27 15:44:29 +00001342 if (image->colorspace == CMYKColorspace)
1343 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
cristye1c94d92015-06-28 12:16:33 +00001344 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1345 (double) QuantumRange);
dirk6c316f22015-06-27 15:44:29 +00001346 x=0;
1347 if (image->alpha_trait != UndefinedPixelTrait)
1348 {
1349 register const Quantum
1350 *p;
1351
1352 p=(const Quantum *) NULL;
1353 for (y=0; y < (ssize_t) image->rows; y++)
cristy9e818982014-01-18 14:54:37 +00001354 {
dirk6c316f22015-06-27 15:44:29 +00001355 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1356 if (p == (const Quantum *) NULL)
1357 break;
1358 for (x=0; x < (ssize_t) image->columns; x++)
cristy9e818982014-01-18 14:54:37 +00001359 {
dirk6c316f22015-06-27 15:44:29 +00001360 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
cristy9e818982014-01-18 14:54:37 +00001361 break;
dirk6c316f22015-06-27 15:44:29 +00001362 p+=GetPixelChannels(image);
cristy9e818982014-01-18 14:54:37 +00001363 }
dirk6c316f22015-06-27 15:44:29 +00001364 if (x < (ssize_t) image->columns)
1365 break;
cristy9e818982014-01-18 14:54:37 +00001366 }
dirk6c316f22015-06-27 15:44:29 +00001367 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1368 {
1369 PixelInfo
1370 pixel;
1371
1372 GetPixelInfo(image,&pixel);
1373 GetPixelInfoPixel(image,p,&pixel);
1374 GetColorTuple(&pixel,MagickTrue,color);
1375 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1376 }
1377 }
cristy9e818982014-01-18 14:54:37 +00001378 if (image->storage_class == PseudoClass)
1379 {
dirk6c316f22015-06-27 15:44:29 +00001380 register PixelInfo
dirk05d2ff72015-11-18 23:13:43 +01001381 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +00001382
dirk6c316f22015-06-27 15:44:29 +00001383 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1384 (double) image->colors);
1385 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1386 p=image->colormap;
1387 for (i=0; i < (ssize_t) image->colors; i++)
1388 {
1389 GetColorTuple(p,MagickTrue,color);
1390 (void) FormatLocaleFile(file,"\"%s\"",color);
1391 if (i < (ssize_t) (image->colors-1))
1392 (void) FormatLocaleFile(file,",");
1393 if (((i+1) % 5) == 0)
1394 (void) FormatLocaleFile(file,"\n ");
1395 p++;
1396 }
1397 (void) FormatLocaleFile(file,"\n ],\n");
cristy9e818982014-01-18 14:54:37 +00001398 }
1399 if (image->error.mean_error_per_pixel != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001400 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001401 image->error.mean_error_per_pixel);
1402 if (image->error.normalized_mean_error != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001403 (void) FormatLocaleFile(file," \"normalizedMeanError\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001404 image->error.normalized_mean_error);
1405 if (image->error.normalized_maximum_error != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001406 (void) FormatLocaleFile(file," \"normalizedMaximumError\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001407 image->error.normalized_maximum_error);
Cristydb96d692017-10-29 10:37:57 -04001408 JSONFormatLocaleFile(file," \"renderingIntent\": %s,\n",
cristy9e818982014-01-18 14:54:37 +00001409 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1410 image->rendering_intent));
1411 if (image->gamma != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001412 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
cristy9e818982014-01-18 14:54:37 +00001413 if ((image->chromaticity.red_primary.x != 0.0) ||
1414 (image->chromaticity.green_primary.x != 0.0) ||
1415 (image->chromaticity.blue_primary.x != 0.0) ||
1416 (image->chromaticity.white_point.x != 0.0))
1417 {
1418 /*
1419 Display image chromaticity.
1420 */
dirk6c316f22015-06-27 15:44:29 +00001421 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1422 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1423 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001424 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001425 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1426 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001427 image->chromaticity.green_primary.x,
1428 image->chromaticity.green_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001429 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1430 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001431 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001432 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1433 " \"x\": %g,\n \"y\": %g\n }\n",
cristy9e818982014-01-18 14:54:37 +00001434 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
dirk6c316f22015-06-27 15:44:29 +00001435 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001436 }
1437 if ((image->extract_info.width*image->extract_info.height) != 0)
dirk6c316f22015-06-27 15:44:29 +00001438 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1439 " \"width\": %.20g,\n \"height\": %.20g,\n"
1440 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001441 (double) image->extract_info.width,(double) image->extract_info.height,
1442 (double) image->extract_info.x,(double) image->extract_info.y);
Cristy18b27502017-02-16 07:29:19 -05001443 GetColorTuple(&image->matte_color,MagickTrue,color);
1444 (void) FormatLocaleFile(file," \"matteColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001445 GetColorTuple(&image->background_color,MagickTrue,color);
1446 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1447 GetColorTuple(&image->border_color,MagickTrue,color);
1448 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001449 GetColorTuple(&image->transparent_color,MagickTrue,color);
1450 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
Cristydb96d692017-10-29 10:37:57 -04001451 JSONFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001452 MagickInterlaceOptions,(ssize_t) image->interlace));
Cristydb96d692017-10-29 10:37:57 -04001453 JSONFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001454 MagickPixelIntensityOptions,(ssize_t) image->intensity));
Cristydb96d692017-10-29 10:37:57 -04001455 JSONFormatLocaleFile(file," \"compose\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001456 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
cristy9e818982014-01-18 14:54:37 +00001457 if ((image->page.width != 0) || (image->page.height != 0) ||
1458 (image->page.x != 0) || (image->page.y != 0))
dirk6c316f22015-06-27 15:44:29 +00001459 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1460 " \"width\": %.20g,\n \"height\": %.20g,\n"
1461 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1462 (double) image->page.width,(double) image->page.height,
1463 (double) image->page.x,(double) image->page.y);
cristy9e818982014-01-18 14:54:37 +00001464 if ((image->page.x != 0) || (image->page.y != 0))
Travis Petticrew6e95e022018-02-09 13:33:20 -06001465 (void) FormatLocaleFile(file," \"originGeometry\": \"%+.20g%+.20g\",\n",
dirk6c316f22015-06-27 15:44:29 +00001466 (double) image->page.x,(double) image->page.y);
Cristydb96d692017-10-29 10:37:57 -04001467 JSONFormatLocaleFile(file," \"dispose\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001468 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
cristy9e818982014-01-18 14:54:37 +00001469 if (image->delay != 0)
Darek Finster76c7e832017-10-13 01:57:47 +02001470 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\",\n",
dirk6c316f22015-06-27 15:44:29 +00001471 (double) image->delay,(double) image->ticks_per_second);
cristy9e818982014-01-18 14:54:37 +00001472 if (image->iterations != 1)
dirk6c316f22015-06-27 15:44:29 +00001473 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
cristy9e818982014-01-18 14:54:37 +00001474 image->iterations);
1475 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
Dirk Lemstra3ea0d282017-09-21 13:31:12 +02001476 (void) FormatLocaleFile(file," \"scene\": %.20g,\n \"scenes\": "
1477 "%.20g,\n",(double) image->scene,(double) GetImageListLength(image));
cristy9e818982014-01-18 14:54:37 +00001478 else
1479 if (image->scene != 0)
dirk6c316f22015-06-27 15:44:29 +00001480 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1481 image->scene);
Cristydb96d692017-10-29 10:37:57 -04001482 JSONFormatLocaleFile(file," \"compression\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001483 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1484 image->compression));
cristy9e818982014-01-18 14:54:37 +00001485 if (image->quality != UndefinedCompressionQuality)
dirk6c316f22015-06-27 15:44:29 +00001486 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1487 image->quality);
Cristydb96d692017-10-29 10:37:57 -04001488 JSONFormatLocaleFile(file," \"orientation\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001489 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1490 image->orientation));
cristy9e818982014-01-18 14:54:37 +00001491 if (image->montage != (char *) NULL)
Cristydb96d692017-10-29 10:37:57 -04001492 JSONFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
cristy9e818982014-01-18 14:54:37 +00001493 if (image->directory != (char *) NULL)
1494 {
1495 Image
1496 *tile;
1497
1498 ImageInfo
1499 *image_info;
1500
1501 register char
1502 *p,
1503 *q;
1504
1505 WarningHandler
1506 handler;
1507
1508 /*
1509 Display visual image directory.
1510 */
1511 image_info=AcquireImageInfo();
1512 (void) CloneString(&image_info->size,"64x64");
dirk6c316f22015-06-27 15:44:29 +00001513 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1514 p=image->directory;
1515 while (*p != '\0')
cristy9e818982014-01-18 14:54:37 +00001516 {
1517 q=p;
Cristy5d293d22018-02-24 12:45:52 -05001518 while ((*q != '\xff') && (*q != '\0'))
cristy9e818982014-01-18 14:54:37 +00001519 q++;
1520 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
dirk6c316f22015-06-27 15:44:29 +00001521 p=q+1;
Cristydb96d692017-10-29 10:37:57 -04001522 JSONFormatLocaleFile(file,"{\n \"name\": %s",
dirk6c316f22015-06-27 15:44:29 +00001523 image_info->filename);
cristy9e818982014-01-18 14:54:37 +00001524 handler=SetWarningHandler((WarningHandler) NULL);
1525 tile=ReadImage(image_info,exception);
1526 (void) SetWarningHandler(handler);
1527 if (tile == (Image *) NULL)
1528 {
dirk6c316f22015-06-27 15:44:29 +00001529 (void) FormatLocaleFile(file," }");
cristy9e818982014-01-18 14:54:37 +00001530 continue;
1531 }
dirk6c316f22015-06-27 15:44:29 +00001532 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1533 (double) tile->magick_columns,(double) tile->magick_rows,
1534 tile->magick);
cristy9e818982014-01-18 14:54:37 +00001535 (void) SignatureImage(tile,exception);
1536 ResetImagePropertyIterator(tile);
1537 property=GetNextImageProperty(tile);
1538 while (property != (const char *) NULL)
1539 {
Cristydb96d692017-10-29 10:37:57 -04001540 JSONFormatLocaleFile(file,",\n %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001541 value=GetImageProperty(tile,property,exception);
Cristydb96d692017-10-29 10:37:57 -04001542 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001543 property=GetNextImageProperty(tile);
1544 }
Cristy4e72d442018-01-11 06:29:53 -05001545 tile=DestroyImageList(tile);
dirk6c316f22015-06-27 15:44:29 +00001546 if (*p != '\0')
1547 (void) FormatLocaleFile(file,"\n },");
1548 else
1549 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001550 }
dirk6c316f22015-06-27 15:44:29 +00001551 (void) FormatLocaleFile(file,"],\n");
cristy9e818982014-01-18 14:54:37 +00001552 image_info=DestroyImageInfo(image_info);
1553 }
cristy9e818982014-01-18 14:54:37 +00001554 ResetImagePropertyIterator(image);
1555 property=GetNextImageProperty(image);
1556 if (property != (const char *) NULL)
1557 {
dirk6c316f22015-06-27 15:44:29 +00001558 size_t
1559 n;
1560
cristy9e818982014-01-18 14:54:37 +00001561 /*
1562 Display image properties.
1563 */
dirk6c316f22015-06-27 15:44:29 +00001564 n=0;
1565 (void) FormatLocaleFile(file," \"properties\": {\n");
cristy9e818982014-01-18 14:54:37 +00001566 while (property != (const char *) NULL)
1567 {
dirk6c316f22015-06-27 15:44:29 +00001568 if (n++ != 0)
1569 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001570 JSONFormatLocaleFile(file," %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001571 value=GetImageProperty(image,property,exception);
Cristydb96d692017-10-29 10:37:57 -04001572 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001573 property=GetNextImageProperty(image);
1574 }
dirk6c316f22015-06-27 15:44:29 +00001575 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001576 }
cristy151b66d2015-04-15 10:50:31 +00001577 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
cristy9e818982014-01-18 14:54:37 +00001578 value=GetImageProperty(image,key,exception);
1579 if (value != (const char *) NULL)
1580 {
1581 /*
1582 Display clipping path.
1583 */
Cristydb96d692017-10-29 10:37:57 -04001584 JSONFormatLocaleFile(file," \"clipping path\": %s,\n",value);
cristy9e818982014-01-18 14:54:37 +00001585 }
1586 ResetImageProfileIterator(image);
1587 name=GetNextImageProfile(image);
1588 if (name != (char *) NULL)
1589 {
1590 const StringInfo
1591 *profile;
1592
dirk6c316f22015-06-27 15:44:29 +00001593 size_t
1594 n;
1595
cristy9e818982014-01-18 14:54:37 +00001596 /*
1597 Identify image profiles.
1598 */
dirk6c316f22015-06-27 15:44:29 +00001599 n=0;
1600 (void) FormatLocaleFile(file," \"profiles\": {\n");
cristy9e818982014-01-18 14:54:37 +00001601 while (name != (char *) NULL)
1602 {
1603 profile=GetImageProfile(image,name);
1604 if (profile == (StringInfo *) NULL)
1605 continue;
dirk6c316f22015-06-27 15:44:29 +00001606 if (n++ != 0)
1607 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001608 JSONFormatLocaleFile(file," %s: {\n",name);
cristy9e818982014-01-18 14:54:37 +00001609 if (LocaleCompare(name,"iptc") == 0)
Dirk Lemstra32b15502017-09-21 17:04:36 +02001610 EncodeIptcProfile(file,profile);
Cristybc978e02017-10-29 13:29:43 -04001611 (void) FormatLocaleFile(file," \"length\": %.20g",(double)
dirk6c316f22015-06-27 15:44:29 +00001612 GetStringInfoLength(profile));
1613 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001614 name=GetNextImageProfile(image);
1615 }
dirk6c316f22015-06-27 15:44:29 +00001616 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001617 }
1618 ResetImageArtifactIterator(image);
1619 artifact=GetNextImageArtifact(image);
1620 if (artifact != (const char *) NULL)
1621 {
dirk6c316f22015-06-27 15:44:29 +00001622 ssize_t
1623 n;
1624
cristy9e818982014-01-18 14:54:37 +00001625 /*
1626 Display image artifacts.
1627 */
dirk6c316f22015-06-27 15:44:29 +00001628 n=0;
1629 (void) FormatLocaleFile(file," \"artifacts\": {\n");
cristy9e818982014-01-18 14:54:37 +00001630 while (artifact != (const char *) NULL)
1631 {
dirk6c316f22015-06-27 15:44:29 +00001632 if (n++ != 0)
1633 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001634 JSONFormatLocaleFile(file," %s: ",artifact);
cristy9e818982014-01-18 14:54:37 +00001635 value=GetImageArtifact(image,artifact);
Cristydb96d692017-10-29 10:37:57 -04001636 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001637 artifact=GetNextImageArtifact(image);
1638 }
dirk6c316f22015-06-27 15:44:29 +00001639 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001640 }
1641 ResetImageRegistryIterator();
1642 registry=GetNextImageRegistry();
1643 if (registry != (const char *) NULL)
1644 {
dirk6c316f22015-06-27 15:44:29 +00001645 ssize_t
1646 n;
1647
cristy9e818982014-01-18 14:54:37 +00001648 /*
1649 Display image registry.
1650 */
dirk6c316f22015-06-27 15:44:29 +00001651 (void) FormatLocaleFile(file," \"registry\": {\n");
1652 n=0;
cristy9e818982014-01-18 14:54:37 +00001653 while (registry != (const char *) NULL)
1654 {
dirk6c316f22015-06-27 15:44:29 +00001655 if (n++ != 0)
1656 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001657 JSONFormatLocaleFile(file," %s: ",registry);
cristy9e818982014-01-18 14:54:37 +00001658 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1659 exception);
Cristydb96d692017-10-29 10:37:57 -04001660 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001661 registry=GetNextImageRegistry();
1662 }
dirk6c316f22015-06-27 15:44:29 +00001663 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001664 }
dirk6c316f22015-06-27 15:44:29 +00001665 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1666 image->taint != MagickFalse ? "true" : "false");
cristy151b66d2015-04-15 10:50:31 +00001667 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
cristyd4618c02015-04-14 23:54:43 +00001668 format);
Cristydb96d692017-10-29 10:37:57 -04001669 JSONFormatLocaleFile(file," \"filesize\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001670 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
cristy151b66d2015-04-15 10:50:31 +00001671 MagickFalse,"B",MagickPathExtent,format);
cristy9e818982014-01-18 14:54:37 +00001672 if (strlen(format) > 1)
1673 format[strlen(format)-1]='\0';
Cristydb96d692017-10-29 10:37:57 -04001674 JSONFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001675 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristy151b66d2015-04-15 10:50:31 +00001676 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
Cristydb96d692017-10-29 10:37:57 -04001677 JSONFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
dirk6c316f22015-06-27 15:44:29 +00001678 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1679 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1680 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1681 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1682 elapsed_time))));
Cristy519e0052016-10-16 15:28:40 -04001683 url=GetMagickHomeURL();
Cristydb96d692017-10-29 10:37:57 -04001684 JSONFormatLocaleFile(file," \"version\": %s\n",url);
Cristy519e0052016-10-16 15:28:40 -04001685 url=DestroyString(url);
dirk6c316f22015-06-27 15:44:29 +00001686 (void) FormatLocaleFile(file," }\n}\n");
cristy9e818982014-01-18 14:54:37 +00001687 (void) fflush(file);
1688 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1689}
1690
cristy3f07aa32014-01-18 01:16:33 +00001691static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1692 Image *image,ExceptionInfo *exception)
1693{
dirk6c316f22015-06-27 15:44:29 +00001694 FILE
1695 *file;
1696
cristy3f07aa32014-01-18 01:16:33 +00001697 MagickBooleanType
1698 status;
1699
1700 MagickOffsetType
1701 scene;
1702
Cristyc45b2bb2018-04-07 12:32:12 -04001703 size_t
1704 imageListLength;
1705
cristy3f07aa32014-01-18 01:16:33 +00001706 /*
1707 Open output image file.
1708 */
1709 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001710 assert(image_info->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001711 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001712 assert(image->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001713 if (image->debug != MagickFalse)
1714 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1715 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1716 if (status == MagickFalse)
1717 return(status);
dirk6c316f22015-06-27 15:44:29 +00001718 file=GetBlobFileHandle(image);
1719 if (file == (FILE *) NULL)
1720 file=stdout;
cristy3f07aa32014-01-18 01:16:33 +00001721 scene=0;
Cristyc45b2bb2018-04-07 12:32:12 -04001722 imageListLength=GetImageListLength(image);
cristy3f07aa32014-01-18 01:16:33 +00001723 do
1724 {
Dirk Lemstrac9105bd2017-09-21 13:39:00 +02001725 if (scene == 0)
Cristy457c4d62017-12-16 07:45:18 -05001726 (void) WriteBlobString(image,"[");
cristy9e818982014-01-18 14:54:37 +00001727 image->magick_columns=image->columns;
1728 image->magick_rows=image->rows;
Cristy457c4d62017-12-16 07:45:18 -05001729 (void) EncodeImageAttributes(image,file,exception);
cristy3f07aa32014-01-18 01:16:33 +00001730 if (GetNextImageInList(image) == (Image *) NULL)
dirk6c316f22015-06-27 15:44:29 +00001731 {
Cristy457c4d62017-12-16 07:45:18 -05001732 (void) WriteBlobString(image,"]");
dirk6c316f22015-06-27 15:44:29 +00001733 break;
1734 }
Cristy457c4d62017-12-16 07:45:18 -05001735 (void) WriteBlobString(image,",\n");
cristy3f07aa32014-01-18 01:16:33 +00001736 image=SyncNextImageInList(image);
Cristyc45b2bb2018-04-07 12:32:12 -04001737 status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength);
cristy3f07aa32014-01-18 01:16:33 +00001738 if (status == MagickFalse)
1739 break;
1740 } while (image_info->adjoin != MagickFalse);
1741 (void) CloseBlob(image);
1742 return(MagickTrue);
1743}