blob: 24d8cdc32525d6b72e80cafe429c661090192796 [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
196 register char
197 *q;
198
199 register const char
200 *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
322 register ssize_t
323 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 {
357 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100358 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +0000359
360 register ssize_t
361 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 {
368 register ssize_t
369 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 {
576 register const Quantum
577 *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{
623 register ssize_t
624 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{
661 register ssize_t
662 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 {
678 register ssize_t
679 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 {
688 register ssize_t
689 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" \
715 " \"max\": %.*g,\n \"mean\": %.*g,\n " \
716 "\"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*
725 channel_statistics[channel].maxima),GetMagickPrecision(),scale*
726 channel_statistics[channel].mean,GetMagickPrecision(),scale*
Cristy7a4f99c2018-04-28 17:34:11 -0400727 IsNaN(channel_statistics[channel].standard_deviation) != 0 ? MagickEpsilon :
Cristybc978e02017-10-29 13:29:43 -0400728 channel_statistics[channel].standard_deviation,GetMagickPrecision(),
729 channel_statistics[channel].kurtosis,GetMagickPrecision(),
730 channel_statistics[channel].skewness,GetMagickPrecision(),
731 channel_statistics[channel].entropy);
dirk6c316f22015-06-27 15:44:29 +0000732 if (separator != MagickFalse)
cristye1c94d92015-06-28 12:16:33 +0000733 (void) FormatLocaleFile(file,",");
dirk6c316f22015-06-27 15:44:29 +0000734 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000735 return(n);
736}
737
Dirk Lemstra32b15502017-09-21 17:04:36 +0200738static void EncodeIptcProfile(FILE *file,const StringInfo *profile)
739{
740 char
741 *attribute,
742 **attribute_list;
743
744 const char
745 *tag;
746
Cristydb96d692017-10-29 10:37:57 -0400747 IPTCInfo
Dirk Lemstra32b15502017-09-21 17:04:36 +0200748 *value,
749 **values;
750
751 long
752 dataset,
753 record,
754 sentinel;
755
756 register ssize_t
757 i,
758 j,
759 k;
760
761 size_t
762 count,
763 length,
764 profile_length;
765
Cristydb96d692017-10-29 10:37:57 -0400766 values=(IPTCInfo **) NULL;
Dirk Lemstra32b15502017-09-21 17:04:36 +0200767 count=0;
768 profile_length=GetStringInfoLength(profile);
769 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
770 {
771 length=1;
772 sentinel=GetStringInfoDatum(profile)[i++];
773 if (sentinel != 0x1c)
774 continue;
775 dataset=GetStringInfoDatum(profile)[i++];
776 record=GetStringInfoDatum(profile)[i++];
Cristydb96d692017-10-29 10:37:57 -0400777 value=(IPTCInfo *) NULL;
Cristy7c7050a2017-09-30 12:12:21 -0400778 for (j=0; j < (ssize_t) count; j++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200779 {
780 if ((values[j]->record == record) && (values[j]->dataset == dataset))
781 value=values[j];
782 }
Cristydb96d692017-10-29 10:37:57 -0400783 if (value == (IPTCInfo *) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200784 {
Cristydb96d692017-10-29 10:37:57 -0400785 values=(IPTCInfo **) ResizeQuantumMemory(values,count+1,
Dirk Lemstra32b15502017-09-21 17:04:36 +0200786 sizeof(*values));
Cristydb96d692017-10-29 10:37:57 -0400787 if (values == (IPTCInfo **) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200788 break;
Cristydb96d692017-10-29 10:37:57 -0400789 value=(IPTCInfo *) AcquireMagickMemory(sizeof(*value));
790 if (value == (IPTCInfo *) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200791 break;
Cristydb96d692017-10-29 10:37:57 -0400792 /* Check the tag length in IPTCInfo when a new tag is added */
Dirk Lemstra32b15502017-09-21 17:04:36 +0200793 switch (record)
794 {
795 case 5: tag="Image Name"; break;
796 case 7: tag="Edit Status"; break;
797 case 10: tag="Priority"; break;
798 case 15: tag="Category"; break;
799 case 20: tag="Supplemental Category"; break;
800 case 22: tag="Fixture Identifier"; break;
801 case 25: tag="Keyword"; break;
802 case 30: tag="Release Date"; break;
803 case 35: tag="Release Time"; break;
804 case 40: tag="Special Instructions"; break;
805 case 45: tag="Reference Service"; break;
806 case 47: tag="Reference Date"; break;
807 case 50: tag="Reference Number"; break;
808 case 55: tag="Created Date"; break;
809 case 60: tag="Created Time"; break;
810 case 65: tag="Originating Program"; break;
811 case 70: tag="Program Version"; break;
812 case 75: tag="Object Cycle"; break;
813 case 80: tag="Byline"; break;
814 case 85: tag="Byline Title"; break;
815 case 90: tag="City"; break;
816 case 92: tag="Sub-Location"; break;
817 case 95: tag="Province State"; break;
818 case 100: tag="Country Code"; break;
819 case 101: tag="Country"; break;
820 case 103: tag="Original Transmission Reference"; break;
821 case 105: tag="Headline"; break;
822 case 110: tag="Credit"; break;
823 case 115: tag="Src"; break;
824 case 116: tag="Copyright String"; break;
825 case 120: tag="Caption"; break;
826 case 121: tag="Local Caption"; break;
827 case 122: tag="Caption Writer"; break;
828 case 200: tag="Custom Field 1"; break;
829 case 201: tag="Custom Field 2"; break;
830 case 202: tag="Custom Field 3"; break;
831 case 203: tag="Custom Field 4"; break;
832 case 204: tag="Custom Field 5"; break;
833 case 205: tag="Custom Field 6"; break;
834 case 206: tag="Custom Field 7"; break;
835 case 207: tag="Custom Field 8"; break;
836 case 208: tag="Custom Field 9"; break;
837 case 209: tag="Custom Field 10"; break;
838 case 210: tag="Custom Field 11"; break;
839 case 211: tag="Custom Field 12"; break;
840 case 212: tag="Custom Field 13"; break;
841 case 213: tag="Custom Field 14"; break;
842 case 214: tag="Custom Field 15"; break;
843 case 215: tag="Custom Field 16"; break;
844 case 216: tag="Custom Field 17"; break;
845 case 217: tag="Custom Field 18"; break;
846 case 218: tag="Custom Field 19"; break;
847 case 219: tag="Custom Field 20"; break;
848 default: tag="Unknown"; break;
849 }
850 (void) CopyMagickString(value->tag,tag,strlen(tag)+1);
851 value->record=record;
852 value->dataset=dataset;
853 value->values=(char ***) NULL;
854 value->values_length=0;
855 values[count++]=value;
856 }
857 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
858 length|=GetStringInfoDatum(profile)[i++];
859 attribute=(char *) NULL;
860 if (~length >= (MagickPathExtent-1))
861 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
862 sizeof(*attribute));
863 if (attribute != (char *) NULL)
864 {
865 (void) CopyMagickString(attribute,(char *)
866 GetStringInfoDatum(profile)+i,length+1);
867 attribute_list=StringToList(attribute);
868 if (attribute_list != (char **) NULL)
869 {
870 value->values=(char ***) ResizeQuantumMemory(value->values,
871 value->values_length+1,
872 sizeof(*value->values));
873 if (value->values == (char ***) NULL)
874 break;
875 value->values[value->values_length++]=attribute_list;
876 }
877 attribute=DestroyString(attribute);
878 }
879 }
Cristydb96d692017-10-29 10:37:57 -0400880 if (values != (IPTCInfo **) NULL)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200881 {
Cristy7c7050a2017-09-30 12:12:21 -0400882 for (i=0; i < (ssize_t) count; i++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200883 {
884 value=values[i];
885 (void) FormatLocaleFile(file," \"%s[%.20g,%.20g]\": ",
886 value->tag,(double) value->dataset,(double) value->record);
887 if (value->values_length == 0)
888 (void) FormatLocaleFile(file,"null,");
889 else
890 {
891 (void) FormatLocaleFile(file,"[");
Cristy7c7050a2017-09-30 12:12:21 -0400892 for (j=0; j < (ssize_t) value->values_length; j++)
Dirk Lemstra32b15502017-09-21 17:04:36 +0200893 {
894 for (k=0; value->values[j][k] != (char *) NULL; k++)
895 {
896 if (j > 0 || k > 0)
897 (void) FormatLocaleFile(file,",");
Cristydb96d692017-10-29 10:37:57 -0400898 JSONFormatLocaleFile(file,"%s",value->values[j][k]);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200899 value->values[j][k]=(char *) RelinquishMagickMemory(
900 value->values[j][k]);
901 }
902 value->values[j]=(char **) RelinquishMagickMemory(
903 value->values[j]);
904 }
905 value->values=(char ***) RelinquishMagickMemory(value->values);
906 (void) FormatLocaleFile(file,"],\n");
907 }
Cristydb96d692017-10-29 10:37:57 -0400908 values[i]=(IPTCInfo *) RelinquishMagickMemory(values[i]);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200909 }
Cristydb96d692017-10-29 10:37:57 -0400910 values=(IPTCInfo **) RelinquishMagickMemory(values);
Dirk Lemstra32b15502017-09-21 17:04:36 +0200911 }
912}
913
cristy9e818982014-01-18 14:54:37 +0000914static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
915 ExceptionInfo *exception)
916{
cristy9e818982014-01-18 14:54:37 +0000917 char
cristy151b66d2015-04-15 10:50:31 +0000918 color[MagickPathExtent],
919 format[MagickPathExtent],
920 key[MagickPathExtent];
cristy9e818982014-01-18 14:54:37 +0000921
922 ChannelFeatures
923 *channel_features;
924
925 ChannelMoments
926 *channel_moments;
927
cristydc395172014-02-23 01:33:36 +0000928 ChannelPerceptualHash
929 *channel_phash;
930
cristy9e818982014-01-18 14:54:37 +0000931 ChannelStatistics
932 *channel_statistics;
933
Cristy519e0052016-10-16 15:28:40 -0400934 char
935 *url;
936
cristy9e818982014-01-18 14:54:37 +0000937 const char
938 *artifact,
939 *locate,
940 *name,
941 *property,
942 *registry,
943 *value;
944
945 const MagickInfo
946 *magick_info;
947
948 double
949 elapsed_time,
Cristye7408482020-08-27 20:59:50 -0400950 user_time,
951 version;
cristy9e818982014-01-18 14:54:37 +0000952
953 ImageType
954 type;
955
956 MagickBooleanType
957 ping;
958
959 register const Quantum
960 *p;
961
962 register ssize_t
963 i,
964 x;
965
966 size_t
dirk6c316f22015-06-27 15:44:29 +0000967 depth,
cristy9e818982014-01-18 14:54:37 +0000968 distance,
969 scale;
970
971 ssize_t
972 y;
973
974 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000975 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000976 if (image->debug != MagickFalse)
977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristya10f7442014-01-19 18:32:15 +0000978 *format='\0';
979 elapsed_time=GetElapsedTime(&image->timer);
980 user_time=GetUserTime(&image->timer);
981 GetTimerInfo(&image->timer);
982 p=GetVirtualPixels(image,0,0,1,1,exception);
983 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
cristye1c94d92015-06-28 12:16:33 +0000984 (void) ping;
cristya10f7442014-01-19 18:32:15 +0000985 (void) SignatureImage(image,exception);
Cristye7408482020-08-27 20:59:50 -0400986 (void) FormatLocaleFile(file,"\n{\n");
987 version=1.0;
988 artifact=GetImageArtifact(image,"json:version");
989 if (artifact != (const char *) NULL)
990 version=StringToDouble(artifact,(char **) NULL);
991 if (version >= 1.0)
992 (void) FormatLocaleFile(file," \"version\": \"%.1f\",\n",version);
993 JSONFormatLocaleFile(file," \"image\": {\n \"name\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +0000994 image->filename);
cristya10f7442014-01-19 18:32:15 +0000995 if (*image->magick_filename != '\0')
996 if (LocaleCompare(image->magick_filename,image->filename) != 0)
997 {
998 char
cristy151b66d2015-04-15 10:50:31 +0000999 filename[MagickPathExtent];
cristya10f7442014-01-19 18:32:15 +00001000
1001 GetPathComponent(image->magick_filename,TailPath,filename);
Cristydb96d692017-10-29 10:37:57 -04001002 JSONFormatLocaleFile(file," \"baseName\": %s,\n",filename);
cristya10f7442014-01-19 18:32:15 +00001003 }
Cristydb96d692017-10-29 10:37:57 -04001004 JSONFormatLocaleFile(file," \"format\": %s,\n",image->magick);
cristya10f7442014-01-19 18:32:15 +00001005 magick_info=GetMagickInfo(image->magick,exception);
dirk6c316f22015-06-27 15:44:29 +00001006 if ((magick_info != (const MagickInfo *) NULL) &&
1007 (GetMagickDescription(magick_info) != (const char *) NULL))
Cristydb96d692017-10-29 10:37:57 -04001008 JSONFormatLocaleFile(file," \"formatDescription\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001009 image->magick);
cristy12bcd3d2015-01-28 00:54:23 +00001010 if ((magick_info != (const MagickInfo *) NULL) &&
cristya10f7442014-01-19 18:32:15 +00001011 (GetMagickMimeType(magick_info) != (const char *) NULL))
Cristydb96d692017-10-29 10:37:57 -04001012 JSONFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
cristya10f7442014-01-19 18:32:15 +00001013 magick_info));
Cristydb96d692017-10-29 10:37:57 -04001014 JSONFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001015 MagickClassOptions,(ssize_t) image->storage_class));
dirk6c316f22015-06-27 15:44:29 +00001016 (void) FormatLocaleFile(file," \"geometry\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001017 " \"width\": %g,\n \"height\": %g,\n"
1018 " \"x\": %g,\n \"y\": %g\n },\n",
dirk6c316f22015-06-27 15:44:29 +00001019 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
1020 (double) image->tile_offset.y);
cristya10f7442014-01-19 18:32:15 +00001021 if ((image->magick_columns != 0) || (image->magick_rows != 0))
1022 if ((image->magick_columns != image->columns) ||
1023 (image->magick_rows != image->rows))
dirk6c316f22015-06-27 15:44:29 +00001024 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001025 " \"width\": %g,\n \"height\": %g\n },\n",(double)
1026 image->magick_columns,(double) image->magick_rows);
cristya10f7442014-01-19 18:32:15 +00001027 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
1028 {
dirk6c316f22015-06-27 15:44:29 +00001029 (void) FormatLocaleFile(file," \"resolution\": {\n"
Cristybc978e02017-10-29 13:29:43 -04001030 " \"x\": %g,\n \"y\": %g\n },\n",image->resolution.x,
cristya10f7442014-01-19 18:32:15 +00001031 image->resolution.y);
Cristybc978e02017-10-29 13:29:43 -04001032 (void) FormatLocaleFile(file," \"printSize\": {\n"
1033 " \"x\": %.*g,\n \"y\": %.*g\n },\n",GetMagickPrecision(),
1034 image->columns/image->resolution.x,GetMagickPrecision(),(double)
1035 image->rows/image->resolution.y);
cristya10f7442014-01-19 18:32:15 +00001036 }
Cristydb96d692017-10-29 10:37:57 -04001037 JSONFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001038 MagickResolutionOptions,(ssize_t) image->units));
Cristy95ab3892017-12-24 09:34:52 -05001039 type=IdentifyImageType(image,exception);
Cristydb96d692017-10-29 10:37:57 -04001040 JSONFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +00001041 MagickTypeOptions,(ssize_t) type));
Cristy4826fb42017-12-17 12:05:09 -05001042 if (image->type != type)
Cristydb96d692017-10-29 10:37:57 -04001043 JSONFormatLocaleFile(file," \"baseType\": %s,\n",
Cristy4826fb42017-12-17 12:05:09 -05001044 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) image->type));
Cristye7408482020-08-27 20:59:50 -04001045 if (version < 1.0)
1046 JSONFormatLocaleFile(file," \"endianess\": %s,\n",
1047 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
1048 else
1049 JSONFormatLocaleFile(file," \"endianness\": %s,\n",
1050 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
cristy9e818982014-01-18 14:54:37 +00001051 locate=GetImageArtifact(image,"identify:locate");
cristy3e583dd2014-01-19 14:11:51 +00001052 if (locate == (const char *) NULL)
1053 locate=GetImageArtifact(image,"json:locate");
cristy9e818982014-01-18 14:54:37 +00001054 if (locate != (const char *) NULL)
1055 {
1056 const char
1057 *limit;
1058
1059 size_t
1060 max_locations;
1061
1062 StatisticType
1063 type;
1064
1065 /*
1066 Display minimum, maximum, or mean pixel locations.
1067 */
1068 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
1069 MagickFalse,locate);
1070 limit=GetImageArtifact(image,"identify:limit");
cristy3e583dd2014-01-19 14:11:51 +00001071 if (limit == (const char *) NULL)
1072 limit=GetImageArtifact(image,"json:limit");
cristy9e818982014-01-18 14:54:37 +00001073 max_locations=0;
1074 if (limit != (const char *) NULL)
1075 max_locations=StringToUnsignedLong(limit);
1076 channel_statistics=GetLocationStatistics(image,type,exception);
1077 if (channel_statistics == (ChannelStatistics *) NULL)
1078 return(MagickFalse);
dirk6c316f22015-06-27 15:44:29 +00001079 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
1080 if (image->alpha_trait != UndefinedPixelTrait)
1081 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
1082 type,max_locations,MagickTrue,channel_statistics);
Cristy3889d152017-12-22 19:42:13 -05001083 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001084 {
1085 case RGBColorspace:
1086 default:
1087 {
1088 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
dirk6c316f22015-06-27 15:44:29 +00001089 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001090 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
dirk6c316f22015-06-27 15:44:29 +00001091 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001092 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
dirk6c316f22015-06-27 15:44:29 +00001093 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001094 break;
1095 }
1096 case CMYKColorspace:
1097 {
1098 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
dirk6c316f22015-06-27 15:44:29 +00001099 type,max_locations,MagickTrue,channel_statistics);
Cristy95ab3892017-12-24 09:34:52 -05001100 (void) PrintChannelLocations(file,image,MagentaPixelChannel,
1101 "Magenta",type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001102 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001103 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001104 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001105 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001106 break;
1107 }
Cristybeb4c2b2017-12-26 19:43:17 -05001108 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001109 case GRAYColorspace:
1110 {
1111 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
dirk6c316f22015-06-27 15:44:29 +00001112 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001113 break;
1114 }
1115 }
dirk6c316f22015-06-27 15:44:29 +00001116 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001117 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1118 channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001119 }
cristy9e818982014-01-18 14:54:37 +00001120 /*
1121 Detail channel depth and extrema.
1122 */
Cristydb96d692017-10-29 10:37:57 -04001123 JSONFormatLocaleFile(file," \"colorspace\": %s,\n",
Cristy3889d152017-12-22 19:42:13 -05001124 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
1125 image->colorspace));
cristy9e818982014-01-18 14:54:37 +00001126 channel_statistics=(ChannelStatistics *) NULL;
1127 channel_moments=(ChannelMoments *) NULL;
cristydc395172014-02-23 01:33:36 +00001128 channel_phash=(ChannelPerceptualHash *) NULL;
cristy9e818982014-01-18 14:54:37 +00001129 channel_features=(ChannelFeatures *) NULL;
cristy9e818982014-01-18 14:54:37 +00001130 scale=1;
dirk6c316f22015-06-27 15:44:29 +00001131 channel_statistics=GetImageStatistics(image,exception);
1132 if (channel_statistics == (ChannelStatistics *) NULL)
1133 return(MagickFalse);
1134 artifact=GetImageArtifact(image,"identify:moments");
1135 if (artifact == (const char *) NULL)
1136 artifact=GetImageArtifact(image,"json:moments");
1137 if (artifact != (const char *) NULL)
cristy9e818982014-01-18 14:54:37 +00001138 {
dirk6c316f22015-06-27 15:44:29 +00001139 channel_moments=GetImageMoments(image,exception);
1140 channel_phash=GetImagePerceptualHash(image,exception);
cristy9e818982014-01-18 14:54:37 +00001141 }
dirk6c316f22015-06-27 15:44:29 +00001142 artifact=GetImageArtifact(image,"identify:features");
1143 if (artifact == (const char *) NULL)
1144 artifact=GetImageArtifact(image,"json:features");
1145 if (artifact != (const char *) NULL)
1146 {
1147 distance=StringToUnsignedLong(artifact);
1148 channel_features=GetImageFeatures(image,distance,exception);
1149 }
1150 depth=GetImageDepth(image,exception);
Cristybc978e02017-10-29 13:29:43 -04001151 (void) FormatLocaleFile(file," \"depth\": %g,\n",(double) depth);
1152 (void) FormatLocaleFile(file," \"baseDepth\": %g,\n",(double)
dirk6c316f22015-06-27 15:44:29 +00001153 image->depth);
1154 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
dirk6c316f22015-06-27 15:44:29 +00001155 if (image->alpha_trait != UndefinedPixelTrait)
1156 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
1157 channel_statistics[AlphaPixelChannel].depth);
Cristy3889d152017-12-22 19:42:13 -05001158 switch (image->colorspace)
dirk6c316f22015-06-27 15:44:29 +00001159 {
1160 case RGBColorspace:
1161 default:
1162 {
1163 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
1164 channel_statistics[RedChannel].depth);
1165 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
1166 channel_statistics[GreenChannel].depth);
1167 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
1168 channel_statistics[BlueChannel].depth);
1169 break;
1170 }
1171 case CMYKColorspace:
1172 {
1173 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
1174 channel_statistics[CyanChannel].depth);
1175 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
1176 channel_statistics[MagentaChannel].depth);
1177 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
1178 channel_statistics[YellowChannel].depth);
1179 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
1180 channel_statistics[BlackChannel].depth);
1181 break;
1182 }
Cristybeb4c2b2017-12-26 19:43:17 -05001183 case LinearGRAYColorspace:
dirk6c316f22015-06-27 15:44:29 +00001184 case GRAYColorspace:
1185 {
1186 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
1187 channel_statistics[GrayChannel].depth);
1188 break;
1189 }
1190 }
1191 (void) FormatLocaleFile(file," },\n");
1192 scale=1;
1193 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
1194 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
1195 MAGICKCORE_QUANTUM_DEPTH-image->depth));
cristy9e818982014-01-18 14:54:37 +00001196 if (channel_statistics != (ChannelStatistics *) NULL)
1197 {
dirk6c316f22015-06-27 15:44:29 +00001198 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
cristy9e818982014-01-18 14:54:37 +00001199 channel_statistics[CompositePixelChannel].area);
Cristybeb4c2b2017-12-26 19:43:17 -05001200 if ((image->colorspace != LinearGRAYColorspace) &&
1201 (image->colorspace != GRAYColorspace))
dirk6c316f22015-06-27 15:44:29 +00001202 {
1203 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
1204 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
1205 "Overall",1.0/scale,MagickFalse,channel_statistics);
1206 (void) FormatLocaleFile(file," },\n");
1207 }
1208 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
1209 if (image->alpha_trait != UndefinedPixelTrait)
1210 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
1211 MagickTrue,channel_statistics);
Cristy3889d152017-12-22 19:42:13 -05001212 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001213 {
1214 case RGBColorspace:
1215 default:
1216 {
dirk6c316f22015-06-27 15:44:29 +00001217 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale,
1218 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001219 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
dirk6c316f22015-06-27 15:44:29 +00001220 scale,MagickTrue,channel_statistics);
1221 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale,
1222 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001223 break;
1224 }
1225 case CMYKColorspace:
1226 {
dirk6c316f22015-06-27 15:44:29 +00001227 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale,
1228 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001229 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
dirk6c316f22015-06-27 15:44:29 +00001230 scale,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001231 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
dirk6c316f22015-06-27 15:44:29 +00001232 scale,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001233 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
dirk6c316f22015-06-27 15:44:29 +00001234 scale,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001235 break;
1236 }
Cristybeb4c2b2017-12-26 19:43:17 -05001237 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001238 case GRAYColorspace:
1239 {
dirk6c316f22015-06-27 15:44:29 +00001240 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale,
1241 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001242 break;
1243 }
1244 }
dirk6c316f22015-06-27 15:44:29 +00001245 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001246 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1247 channel_statistics);
1248 }
1249 if (channel_moments != (ChannelMoments *) NULL)
1250 {
dirk6c316f22015-06-27 15:44:29 +00001251 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
1252 if (image->alpha_trait != UndefinedPixelTrait)
1253 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue,
1254 channel_moments);
Cristy3889d152017-12-22 19:42:13 -05001255 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001256 {
1257 case RGBColorspace:
1258 default:
1259 {
dirk6c316f22015-06-27 15:44:29 +00001260 (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001261 channel_moments);
dirk6c316f22015-06-27 15:44:29 +00001262 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001263 channel_moments);
dirk6c316f22015-06-27 15:44:29 +00001264 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001265 channel_moments);
1266 break;
1267 }
1268 case CMYKColorspace:
1269 {
dirk6c316f22015-06-27 15:44:29 +00001270 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001271 channel_moments);
1272 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +00001273 MagickTrue,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001274 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001275 MagickTrue,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001276 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001277 MagickFalse,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001278 break;
1279 }
Cristybeb4c2b2017-12-26 19:43:17 -05001280 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001281 case GRAYColorspace:
1282 {
dirk6c316f22015-06-27 15:44:29 +00001283 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001284 channel_moments);
1285 break;
1286 }
1287 }
dirk6c316f22015-06-27 15:44:29 +00001288 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001289 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1290 channel_moments);
1291 }
cristydc395172014-02-23 01:33:36 +00001292 if (channel_phash != (ChannelPerceptualHash *) NULL)
1293 {
1294 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
Cristye6961802016-09-03 11:31:13 -04001295 (void) PrintChannelPerceptualHash(image,file,channel_phash);
cristydc395172014-02-23 01:33:36 +00001296 (void) FormatLocaleFile(file," },\n");
1297 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1298 channel_phash);
1299 }
cristy9e818982014-01-18 14:54:37 +00001300 if (channel_features != (ChannelFeatures *) NULL)
1301 {
dirk6c316f22015-06-27 15:44:29 +00001302 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1303 if (image->alpha_trait != UndefinedPixelTrait)
1304 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue,
1305 channel_features);
Cristy3889d152017-12-22 19:42:13 -05001306 switch (image->colorspace)
cristy9e818982014-01-18 14:54:37 +00001307 {
1308 case RGBColorspace:
1309 default:
1310 {
dirk6c316f22015-06-27 15:44:29 +00001311 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001312 channel_features);
1313 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
dirk6c316f22015-06-27 15:44:29 +00001314 MagickTrue,channel_features);
1315 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001316 channel_features);
1317 break;
1318 }
1319 case CMYKColorspace:
1320 {
dirk6c316f22015-06-27 15:44:29 +00001321 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001322 channel_features);
1323 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +00001324 MagickTrue,channel_features);
cristy9e818982014-01-18 14:54:37 +00001325 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001326 MagickTrue,channel_features);
cristy9e818982014-01-18 14:54:37 +00001327 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001328 MagickFalse,channel_features);
cristy9e818982014-01-18 14:54:37 +00001329 break;
1330 }
Cristybeb4c2b2017-12-26 19:43:17 -05001331 case LinearGRAYColorspace:
cristy9e818982014-01-18 14:54:37 +00001332 case GRAYColorspace:
1333 {
dirk6c316f22015-06-27 15:44:29 +00001334 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001335 channel_features);
1336 break;
1337 }
1338 }
dirk6c316f22015-06-27 15:44:29 +00001339 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001340 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1341 channel_features);
1342 }
dirk6c316f22015-06-27 15:44:29 +00001343 if (image->colorspace == CMYKColorspace)
1344 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
cristye1c94d92015-06-28 12:16:33 +00001345 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1346 (double) QuantumRange);
dirk6c316f22015-06-27 15:44:29 +00001347 x=0;
1348 if (image->alpha_trait != UndefinedPixelTrait)
1349 {
1350 register const Quantum
1351 *p;
1352
1353 p=(const Quantum *) NULL;
1354 for (y=0; y < (ssize_t) image->rows; y++)
cristy9e818982014-01-18 14:54:37 +00001355 {
dirk6c316f22015-06-27 15:44:29 +00001356 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1357 if (p == (const Quantum *) NULL)
1358 break;
1359 for (x=0; x < (ssize_t) image->columns; x++)
cristy9e818982014-01-18 14:54:37 +00001360 {
dirk6c316f22015-06-27 15:44:29 +00001361 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
cristy9e818982014-01-18 14:54:37 +00001362 break;
dirk6c316f22015-06-27 15:44:29 +00001363 p+=GetPixelChannels(image);
cristy9e818982014-01-18 14:54:37 +00001364 }
dirk6c316f22015-06-27 15:44:29 +00001365 if (x < (ssize_t) image->columns)
1366 break;
cristy9e818982014-01-18 14:54:37 +00001367 }
dirk6c316f22015-06-27 15:44:29 +00001368 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1369 {
1370 PixelInfo
1371 pixel;
1372
1373 GetPixelInfo(image,&pixel);
1374 GetPixelInfoPixel(image,p,&pixel);
1375 GetColorTuple(&pixel,MagickTrue,color);
1376 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1377 }
1378 }
cristy9e818982014-01-18 14:54:37 +00001379 if (image->storage_class == PseudoClass)
1380 {
dirk6c316f22015-06-27 15:44:29 +00001381 register PixelInfo
dirk05d2ff72015-11-18 23:13:43 +01001382 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +00001383
dirk6c316f22015-06-27 15:44:29 +00001384 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1385 (double) image->colors);
1386 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1387 p=image->colormap;
1388 for (i=0; i < (ssize_t) image->colors; i++)
1389 {
1390 GetColorTuple(p,MagickTrue,color);
1391 (void) FormatLocaleFile(file,"\"%s\"",color);
1392 if (i < (ssize_t) (image->colors-1))
1393 (void) FormatLocaleFile(file,",");
1394 if (((i+1) % 5) == 0)
1395 (void) FormatLocaleFile(file,"\n ");
1396 p++;
1397 }
1398 (void) FormatLocaleFile(file,"\n ],\n");
cristy9e818982014-01-18 14:54:37 +00001399 }
1400 if (image->error.mean_error_per_pixel != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001401 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001402 image->error.mean_error_per_pixel);
1403 if (image->error.normalized_mean_error != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001404 (void) FormatLocaleFile(file," \"normalizedMeanError\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001405 image->error.normalized_mean_error);
1406 if (image->error.normalized_maximum_error != 0.0)
Cristybc978e02017-10-29 13:29:43 -04001407 (void) FormatLocaleFile(file," \"normalizedMaximumError\": %g,\n",
cristy9e818982014-01-18 14:54:37 +00001408 image->error.normalized_maximum_error);
Cristydb96d692017-10-29 10:37:57 -04001409 JSONFormatLocaleFile(file," \"renderingIntent\": %s,\n",
cristy9e818982014-01-18 14:54:37 +00001410 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1411 image->rendering_intent));
1412 if (image->gamma != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001413 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
cristy9e818982014-01-18 14:54:37 +00001414 if ((image->chromaticity.red_primary.x != 0.0) ||
1415 (image->chromaticity.green_primary.x != 0.0) ||
1416 (image->chromaticity.blue_primary.x != 0.0) ||
1417 (image->chromaticity.white_point.x != 0.0))
1418 {
1419 /*
1420 Display image chromaticity.
1421 */
dirk6c316f22015-06-27 15:44:29 +00001422 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1423 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1424 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001425 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001426 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1427 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001428 image->chromaticity.green_primary.x,
1429 image->chromaticity.green_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001430 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1431 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001432 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001433 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1434 " \"x\": %g,\n \"y\": %g\n }\n",
cristy9e818982014-01-18 14:54:37 +00001435 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
dirk6c316f22015-06-27 15:44:29 +00001436 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001437 }
1438 if ((image->extract_info.width*image->extract_info.height) != 0)
dirk6c316f22015-06-27 15:44:29 +00001439 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1440 " \"width\": %.20g,\n \"height\": %.20g,\n"
1441 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001442 (double) image->extract_info.width,(double) image->extract_info.height,
1443 (double) image->extract_info.x,(double) image->extract_info.y);
Cristy18b27502017-02-16 07:29:19 -05001444 GetColorTuple(&image->matte_color,MagickTrue,color);
1445 (void) FormatLocaleFile(file," \"matteColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001446 GetColorTuple(&image->background_color,MagickTrue,color);
1447 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1448 GetColorTuple(&image->border_color,MagickTrue,color);
1449 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001450 GetColorTuple(&image->transparent_color,MagickTrue,color);
1451 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
Cristydb96d692017-10-29 10:37:57 -04001452 JSONFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001453 MagickInterlaceOptions,(ssize_t) image->interlace));
Cristydb96d692017-10-29 10:37:57 -04001454 JSONFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001455 MagickPixelIntensityOptions,(ssize_t) image->intensity));
Cristydb96d692017-10-29 10:37:57 -04001456 JSONFormatLocaleFile(file," \"compose\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001457 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
cristy9e818982014-01-18 14:54:37 +00001458 if ((image->page.width != 0) || (image->page.height != 0) ||
1459 (image->page.x != 0) || (image->page.y != 0))
dirk6c316f22015-06-27 15:44:29 +00001460 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1461 " \"width\": %.20g,\n \"height\": %.20g,\n"
1462 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1463 (double) image->page.width,(double) image->page.height,
1464 (double) image->page.x,(double) image->page.y);
cristy9e818982014-01-18 14:54:37 +00001465 if ((image->page.x != 0) || (image->page.y != 0))
Travis Petticrew6e95e022018-02-09 13:33:20 -06001466 (void) FormatLocaleFile(file," \"originGeometry\": \"%+.20g%+.20g\",\n",
dirk6c316f22015-06-27 15:44:29 +00001467 (double) image->page.x,(double) image->page.y);
Cristydb96d692017-10-29 10:37:57 -04001468 JSONFormatLocaleFile(file," \"dispose\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001469 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
cristy9e818982014-01-18 14:54:37 +00001470 if (image->delay != 0)
Darek Finster76c7e832017-10-13 01:57:47 +02001471 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\",\n",
dirk6c316f22015-06-27 15:44:29 +00001472 (double) image->delay,(double) image->ticks_per_second);
cristy9e818982014-01-18 14:54:37 +00001473 if (image->iterations != 1)
dirk6c316f22015-06-27 15:44:29 +00001474 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
cristy9e818982014-01-18 14:54:37 +00001475 image->iterations);
1476 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
Dirk Lemstra3ea0d282017-09-21 13:31:12 +02001477 (void) FormatLocaleFile(file," \"scene\": %.20g,\n \"scenes\": "
1478 "%.20g,\n",(double) image->scene,(double) GetImageListLength(image));
cristy9e818982014-01-18 14:54:37 +00001479 else
1480 if (image->scene != 0)
dirk6c316f22015-06-27 15:44:29 +00001481 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1482 image->scene);
Cristydb96d692017-10-29 10:37:57 -04001483 JSONFormatLocaleFile(file," \"compression\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001484 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1485 image->compression));
cristy9e818982014-01-18 14:54:37 +00001486 if (image->quality != UndefinedCompressionQuality)
dirk6c316f22015-06-27 15:44:29 +00001487 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1488 image->quality);
Cristydb96d692017-10-29 10:37:57 -04001489 JSONFormatLocaleFile(file," \"orientation\": %s,\n",
dirk6c316f22015-06-27 15:44:29 +00001490 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1491 image->orientation));
cristy9e818982014-01-18 14:54:37 +00001492 if (image->montage != (char *) NULL)
Cristydb96d692017-10-29 10:37:57 -04001493 JSONFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
cristy9e818982014-01-18 14:54:37 +00001494 if (image->directory != (char *) NULL)
1495 {
1496 Image
1497 *tile;
1498
1499 ImageInfo
1500 *image_info;
1501
1502 register char
1503 *p,
1504 *q;
1505
1506 WarningHandler
1507 handler;
1508
1509 /*
1510 Display visual image directory.
1511 */
1512 image_info=AcquireImageInfo();
1513 (void) CloneString(&image_info->size,"64x64");
dirk6c316f22015-06-27 15:44:29 +00001514 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1515 p=image->directory;
1516 while (*p != '\0')
cristy9e818982014-01-18 14:54:37 +00001517 {
1518 q=p;
Cristy5d293d22018-02-24 12:45:52 -05001519 while ((*q != '\xff') && (*q != '\0'))
cristy9e818982014-01-18 14:54:37 +00001520 q++;
1521 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
dirk6c316f22015-06-27 15:44:29 +00001522 p=q+1;
Cristydb96d692017-10-29 10:37:57 -04001523 JSONFormatLocaleFile(file,"{\n \"name\": %s",
dirk6c316f22015-06-27 15:44:29 +00001524 image_info->filename);
cristy9e818982014-01-18 14:54:37 +00001525 handler=SetWarningHandler((WarningHandler) NULL);
1526 tile=ReadImage(image_info,exception);
1527 (void) SetWarningHandler(handler);
1528 if (tile == (Image *) NULL)
1529 {
dirk6c316f22015-06-27 15:44:29 +00001530 (void) FormatLocaleFile(file," }");
cristy9e818982014-01-18 14:54:37 +00001531 continue;
1532 }
dirk6c316f22015-06-27 15:44:29 +00001533 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1534 (double) tile->magick_columns,(double) tile->magick_rows,
1535 tile->magick);
cristy9e818982014-01-18 14:54:37 +00001536 (void) SignatureImage(tile,exception);
1537 ResetImagePropertyIterator(tile);
1538 property=GetNextImageProperty(tile);
1539 while (property != (const char *) NULL)
1540 {
Cristydb96d692017-10-29 10:37:57 -04001541 JSONFormatLocaleFile(file,",\n %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001542 value=GetImageProperty(tile,property,exception);
Cristydb96d692017-10-29 10:37:57 -04001543 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001544 property=GetNextImageProperty(tile);
1545 }
Cristy4e72d442018-01-11 06:29:53 -05001546 tile=DestroyImageList(tile);
dirk6c316f22015-06-27 15:44:29 +00001547 if (*p != '\0')
1548 (void) FormatLocaleFile(file,"\n },");
1549 else
1550 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001551 }
dirk6c316f22015-06-27 15:44:29 +00001552 (void) FormatLocaleFile(file,"],\n");
cristy9e818982014-01-18 14:54:37 +00001553 image_info=DestroyImageInfo(image_info);
1554 }
cristy9e818982014-01-18 14:54:37 +00001555 ResetImagePropertyIterator(image);
1556 property=GetNextImageProperty(image);
1557 if (property != (const char *) NULL)
1558 {
dirk6c316f22015-06-27 15:44:29 +00001559 size_t
1560 n;
1561
cristy9e818982014-01-18 14:54:37 +00001562 /*
1563 Display image properties.
1564 */
dirk6c316f22015-06-27 15:44:29 +00001565 n=0;
1566 (void) FormatLocaleFile(file," \"properties\": {\n");
cristy9e818982014-01-18 14:54:37 +00001567 while (property != (const char *) NULL)
1568 {
dirk6c316f22015-06-27 15:44:29 +00001569 if (n++ != 0)
1570 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001571 JSONFormatLocaleFile(file," %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001572 value=GetImageProperty(image,property,exception);
Cristydb96d692017-10-29 10:37:57 -04001573 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001574 property=GetNextImageProperty(image);
1575 }
dirk6c316f22015-06-27 15:44:29 +00001576 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001577 }
cristy151b66d2015-04-15 10:50:31 +00001578 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
cristy9e818982014-01-18 14:54:37 +00001579 value=GetImageProperty(image,key,exception);
1580 if (value != (const char *) NULL)
1581 {
1582 /*
1583 Display clipping path.
1584 */
Cristydb96d692017-10-29 10:37:57 -04001585 JSONFormatLocaleFile(file," \"clipping path\": %s,\n",value);
cristy9e818982014-01-18 14:54:37 +00001586 }
1587 ResetImageProfileIterator(image);
1588 name=GetNextImageProfile(image);
1589 if (name != (char *) NULL)
1590 {
1591 const StringInfo
1592 *profile;
1593
dirk6c316f22015-06-27 15:44:29 +00001594 size_t
1595 n;
1596
cristy9e818982014-01-18 14:54:37 +00001597 /*
1598 Identify image profiles.
1599 */
dirk6c316f22015-06-27 15:44:29 +00001600 n=0;
1601 (void) FormatLocaleFile(file," \"profiles\": {\n");
cristy9e818982014-01-18 14:54:37 +00001602 while (name != (char *) NULL)
1603 {
1604 profile=GetImageProfile(image,name);
1605 if (profile == (StringInfo *) NULL)
1606 continue;
dirk6c316f22015-06-27 15:44:29 +00001607 if (n++ != 0)
1608 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001609 JSONFormatLocaleFile(file," %s: {\n",name);
cristy9e818982014-01-18 14:54:37 +00001610 if (LocaleCompare(name,"iptc") == 0)
Dirk Lemstra32b15502017-09-21 17:04:36 +02001611 EncodeIptcProfile(file,profile);
Cristybc978e02017-10-29 13:29:43 -04001612 (void) FormatLocaleFile(file," \"length\": %.20g",(double)
dirk6c316f22015-06-27 15:44:29 +00001613 GetStringInfoLength(profile));
1614 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001615 name=GetNextImageProfile(image);
1616 }
dirk6c316f22015-06-27 15:44:29 +00001617 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001618 }
1619 ResetImageArtifactIterator(image);
1620 artifact=GetNextImageArtifact(image);
1621 if (artifact != (const char *) NULL)
1622 {
dirk6c316f22015-06-27 15:44:29 +00001623 ssize_t
1624 n;
1625
cristy9e818982014-01-18 14:54:37 +00001626 /*
1627 Display image artifacts.
1628 */
dirk6c316f22015-06-27 15:44:29 +00001629 n=0;
1630 (void) FormatLocaleFile(file," \"artifacts\": {\n");
cristy9e818982014-01-18 14:54:37 +00001631 while (artifact != (const char *) NULL)
1632 {
dirk6c316f22015-06-27 15:44:29 +00001633 if (n++ != 0)
1634 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001635 JSONFormatLocaleFile(file," %s: ",artifact);
cristy9e818982014-01-18 14:54:37 +00001636 value=GetImageArtifact(image,artifact);
Cristydb96d692017-10-29 10:37:57 -04001637 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001638 artifact=GetNextImageArtifact(image);
1639 }
dirk6c316f22015-06-27 15:44:29 +00001640 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001641 }
1642 ResetImageRegistryIterator();
1643 registry=GetNextImageRegistry();
1644 if (registry != (const char *) NULL)
1645 {
dirk6c316f22015-06-27 15:44:29 +00001646 ssize_t
1647 n;
1648
cristy9e818982014-01-18 14:54:37 +00001649 /*
1650 Display image registry.
1651 */
dirk6c316f22015-06-27 15:44:29 +00001652 (void) FormatLocaleFile(file," \"registry\": {\n");
1653 n=0;
cristy9e818982014-01-18 14:54:37 +00001654 while (registry != (const char *) NULL)
1655 {
dirk6c316f22015-06-27 15:44:29 +00001656 if (n++ != 0)
1657 (void) FormatLocaleFile(file,",\n");
Cristydb96d692017-10-29 10:37:57 -04001658 JSONFormatLocaleFile(file," %s: ",registry);
cristy9e818982014-01-18 14:54:37 +00001659 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1660 exception);
Cristydb96d692017-10-29 10:37:57 -04001661 JSONFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001662 registry=GetNextImageRegistry();
1663 }
dirk6c316f22015-06-27 15:44:29 +00001664 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001665 }
dirk6c316f22015-06-27 15:44:29 +00001666 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1667 image->taint != MagickFalse ? "true" : "false");
cristy151b66d2015-04-15 10:50:31 +00001668 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
cristyd4618c02015-04-14 23:54:43 +00001669 format);
Cristydb96d692017-10-29 10:37:57 -04001670 JSONFormatLocaleFile(file," \"filesize\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001671 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
cristy151b66d2015-04-15 10:50:31 +00001672 MagickFalse,"B",MagickPathExtent,format);
cristy9e818982014-01-18 14:54:37 +00001673 if (strlen(format) > 1)
1674 format[strlen(format)-1]='\0';
Cristydb96d692017-10-29 10:37:57 -04001675 JSONFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001676 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristy151b66d2015-04-15 10:50:31 +00001677 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
Cristydb96d692017-10-29 10:37:57 -04001678 JSONFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
dirk6c316f22015-06-27 15:44:29 +00001679 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1680 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1681 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1682 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1683 elapsed_time))));
Cristy519e0052016-10-16 15:28:40 -04001684 url=GetMagickHomeURL();
Cristydb96d692017-10-29 10:37:57 -04001685 JSONFormatLocaleFile(file," \"version\": %s\n",url);
Cristy519e0052016-10-16 15:28:40 -04001686 url=DestroyString(url);
dirk6c316f22015-06-27 15:44:29 +00001687 (void) FormatLocaleFile(file," }\n}\n");
cristy9e818982014-01-18 14:54:37 +00001688 (void) fflush(file);
1689 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1690}
1691
cristy3f07aa32014-01-18 01:16:33 +00001692static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1693 Image *image,ExceptionInfo *exception)
1694{
dirk6c316f22015-06-27 15:44:29 +00001695 FILE
1696 *file;
1697
cristy3f07aa32014-01-18 01:16:33 +00001698 MagickBooleanType
1699 status;
1700
1701 MagickOffsetType
1702 scene;
1703
Cristyc45b2bb2018-04-07 12:32:12 -04001704 size_t
1705 imageListLength;
1706
cristy3f07aa32014-01-18 01:16:33 +00001707 /*
1708 Open output image file.
1709 */
1710 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001711 assert(image_info->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001712 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001713 assert(image->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001714 if (image->debug != MagickFalse)
1715 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1716 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1717 if (status == MagickFalse)
1718 return(status);
dirk6c316f22015-06-27 15:44:29 +00001719 file=GetBlobFileHandle(image);
1720 if (file == (FILE *) NULL)
1721 file=stdout;
cristy3f07aa32014-01-18 01:16:33 +00001722 scene=0;
Cristyc45b2bb2018-04-07 12:32:12 -04001723 imageListLength=GetImageListLength(image);
cristy3f07aa32014-01-18 01:16:33 +00001724 do
1725 {
Dirk Lemstrac9105bd2017-09-21 13:39:00 +02001726 if (scene == 0)
Cristy457c4d62017-12-16 07:45:18 -05001727 (void) WriteBlobString(image,"[");
cristy9e818982014-01-18 14:54:37 +00001728 image->magick_columns=image->columns;
1729 image->magick_rows=image->rows;
Cristy457c4d62017-12-16 07:45:18 -05001730 (void) EncodeImageAttributes(image,file,exception);
cristy3f07aa32014-01-18 01:16:33 +00001731 if (GetNextImageInList(image) == (Image *) NULL)
dirk6c316f22015-06-27 15:44:29 +00001732 {
Cristy457c4d62017-12-16 07:45:18 -05001733 (void) WriteBlobString(image,"]");
dirk6c316f22015-06-27 15:44:29 +00001734 break;
1735 }
Cristy457c4d62017-12-16 07:45:18 -05001736 (void) WriteBlobString(image,",\n");
cristy3f07aa32014-01-18 01:16:33 +00001737 image=SyncNextImageInList(image);
Cristyc45b2bb2018-04-07 12:32:12 -04001738 status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength);
cristy3f07aa32014-01-18 01:16:33 +00001739 if (status == MagickFalse)
1740 break;
1741 } while (image_info->adjoin != MagickFalse);
1742 (void) CloseBlob(image);
1743 return(MagickTrue);
1744}