blob: ee43d7d722bf71a906b77d9ea285d08512e30a4c [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% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 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% %
26% http://www.imagemagick.org/script/license.php %
27% %
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"
cristy3f07aa32014-01-18 01:16:33 +000077
78/*
79 Forward declarations.
80*/
81static MagickBooleanType
82 WriteJSONImage(const ImageInfo *,Image *,ExceptionInfo *);
83
84/*
85%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86% %
87% %
88% %
89% R e g i s t e r J S O N I m a g e %
90% %
91% %
92% %
93%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94%
95% RegisterJSONImage() adds attributes for the JSON image format to
96% the list of supported formats. The attributes include the image format
97% tag, a method to read and/or write the format, whether the format
98% supports the saving of more than one frame to the same file or blob,
99% whether the format supports native in-memory I/O, and a brief
100% description of the format.
101%
102% The format of the RegisterJSONImage method is:
103%
104% size_t RegisterJSONImage(void)
105%
106*/
107ModuleExport size_t RegisterJSONImage(void)
108{
109 MagickInfo
110 *entry;
111
cristye1c94d92015-06-28 12:16:33 +0000112 entry=AcquireMagickInfo("JSON","JSON","The image format and characteristics");
cristy3f07aa32014-01-18 01:16:33 +0000113 entry->encoder=(EncodeImageHandler *) WriteJSONImage;
dirk2aa15e62015-09-14 21:33:54 +0200114 entry->mime_type=ConstantString("application/json");
dirk08e9a112015-02-22 01:51:41 +0000115 entry->flags^=CoderBlobSupportFlag;
cristy3f07aa32014-01-18 01:16:33 +0000116 (void) RegisterMagickInfo(entry);
117 return(MagickImageCoderSignature);
118}
119
120/*
121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122% %
123% %
124% %
125% U n r e g i s t e r J S O N I m a g e %
126% %
127% %
128% %
129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130%
131% UnregisterJSONImage() removes format registrations made by the
132% JSON module from the list of supported formats.
133%
134% The format of the UnregisterJSONImage method is:
135%
136% UnregisterJSONImage(void)
137%
138*/
139ModuleExport void UnregisterJSONImage(void)
140{
141 (void) UnregisterMagickInfo("JSON");
142}
143
144/*
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146% %
147% %
148% %
149% W r i t e J S O N I m a g e %
150% %
151% %
152% %
153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154%
155% WriteJSONImage writes the image attributes in the JSON format.
156%
157% The format of the WriteJSONImage method is:
158%
159% MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
160% Image *image,ExceptionInfo *exception)
161%
162% A description of each parameter follows.
163%
164% o image_info: the image info.
165%
166% o image: The image.
167%
168% o exception: return any errors or warnings in this structure.
169%
170*/
cristy9e818982014-01-18 14:54:37 +0000171
dirk6c316f22015-06-27 15:44:29 +0000172static void JsonFormatLocaleFile(FILE *file,const char *format,const char *value)
173{
174 char
175 *escaped_json;
176
177 register char
178 *q;
179
180 register const char
181 *p;
182
183 size_t
184 length;
185
186 assert(format != (const char *) NULL);
187 if (value == (char *) NULL || *value == '\0')
188 {
189 (void) FormatLocaleFile(file,format,"null");
190 return;
191 }
192 length=strlen(value)+2;
193 /*
194 Find all the chars that need escaping and increase the dest length counter
195 */
196 for (p=value; *p != '\0'; p++)
197 {
198 switch (*p)
199 {
200 case '"':
201 case '\b':
202 case '\f':
203 case '\n':
204 case '\r':
205 case '\t':
206 case '\\':
207 if (~length < 1)
208 return;
209 length++;
210 break;
211 default:
212 break;
213 }
214 }
215 escaped_json=(char *) NULL;
216 if (~length >= (MagickPathExtent-1))
217 escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent,
218 sizeof(*escaped_json));
219 if (escaped_json == (char *) NULL)
220 {
221 (void) FormatLocaleFile(file,format,"null");
222 return;
223 }
224 q=escaped_json;
225 *q++='"';
226 for (p=value; *p != '\0'; p++)
227 {
228 switch (*p)
229 {
230 case '"':
231 *q++='\\';
232 *q++=(*p);
233 break;
234 case '\b':
235 *q++='\\';
236 *q++='b';
237 break;
238 case '\f':
239 *q++='\\';
240 *q++='f';
241 break;
242 case '\n':
243 *q++='\\';
244 *q++='n';
245 break;
246 case '\r':
247 *q++='\\';
248 *q++='r';
249 break;
250 case '\t':
251 *q++='\\';
252 *q++='t';
253 break;
254 case '\\':
255 *q++='\\';
256 *q++='\\';
257 break;
258 default:
259 *q++=(*p);
260 break;
261 }
262 }
263 *q++='"';
264 *q='\0';
265 (void) FormatLocaleFile(file,format,escaped_json);
266 (void) DestroyString(escaped_json);
267}
268
cristy9e818982014-01-18 14:54:37 +0000269static ChannelStatistics *GetLocationStatistics(const Image *image,
270 const StatisticType type,ExceptionInfo *exception)
271{
272 ChannelStatistics
273 *channel_statistics;
274
275 register ssize_t
276 i;
277
278 ssize_t
279 y;
280
281 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000282 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000283 if (image->debug != MagickFalse)
284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
285 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
286 MaxPixelChannels+1,sizeof(*channel_statistics));
287 if (channel_statistics == (ChannelStatistics *) NULL)
288 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
289 (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
290 sizeof(*channel_statistics));
291 for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
292 {
293 switch (type)
294 {
295 case MaximumStatistic:
296 default:
297 {
cristyfe181a72014-02-02 21:17:43 +0000298 channel_statistics[i].maxima=(-MagickMaximumValue);
cristy9e818982014-01-18 14:54:37 +0000299 break;
300 }
301 case MinimumStatistic:
302 {
cristyfe181a72014-02-02 21:17:43 +0000303 channel_statistics[i].minima=MagickMaximumValue;
cristy9e818982014-01-18 14:54:37 +0000304 break;
305 }
306 }
307 }
308 for (y=0; y < (ssize_t) image->rows; y++)
309 {
310 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100311 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +0000312
313 register ssize_t
314 x;
315
316 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
317 if (p == (const Quantum *) NULL)
318 break;
319 for (x=0; x < (ssize_t) image->columns; x++)
320 {
321 register ssize_t
322 i;
323
324 if (GetPixelReadMask(image,p) == 0)
325 {
326 p+=GetPixelChannels(image);
327 continue;
328 }
329 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
330 {
331 PixelChannel channel=GetPixelChannelChannel(image,i);
332 PixelTrait traits=GetPixelChannelTraits(image,channel);
333 if (traits == UndefinedPixelTrait)
334 continue;
335 switch (type)
336 {
337 case MaximumStatistic:
338 default:
339 {
340 if ((double) p[i] > channel_statistics[channel].maxima)
341 channel_statistics[channel].maxima=(double) p[i];
342 break;
343 }
344 case MinimumStatistic:
345 {
346 if ((double) p[i] < channel_statistics[channel].minima)
347 channel_statistics[channel].minima=(double) p[i];
348 break;
349 }
350 }
351 }
352 p+=GetPixelChannels(image);
353 }
354 }
355 return(channel_statistics);
356}
357
358static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000359 const char *name,const MagickBooleanType separator,
360 const ChannelFeatures *channel_features)
cristy9e818982014-01-18 14:54:37 +0000361{
362#define PrintFeature(feature) \
363 GetMagickPrecision(),(feature)[0], \
364 GetMagickPrecision(),(feature)[1], \
365 GetMagickPrecision(),(feature)[2], \
366 GetMagickPrecision(),(feature)[3], \
367 GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \
368
dirk6c316f22015-06-27 15:44:29 +0000369#define FeaturesFormat " \"%s\": {\n" \
370 " \"angularSecondMoment\": {\n" \
371 " \"horizontal\": \"%.*g\",\n" \
372 " \"vertical\": \"%.*g\",\n" \
373 " \"leftDiagonal\": \"%.*g\",\n" \
374 " \"rightDiagonal\": \"%.*g\",\n" \
375 " \"average\": \"%.*g\"\n" \
376 " },\n" \
377 " \"contrast\": {\n" \
378 " \"horizontal\": \"%.*g\",\n" \
379 " \"vertical\": \"%.*g\",\n" \
380 " \"leftDiagonal\": \"%.*g\",\n" \
381 " \"rightDiagonal\": \"%.*g\",\n" \
382 " \"average\": \"%.*g\"\n" \
383 " },\n" \
384 " \"correlation\": {\n" \
385 " \"horizontal\": \"%.*g\",\n" \
386 " \"vertical\": \"%.*g\",\n" \
387 " \"leftDiagonal\": \"%.*g\",\n" \
388 " \"rightDiagonal\": \"%.*g\",\n" \
389 " \"average\": \"%.*g\"\n" \
390 " },\n" \
391 " \"sumOfSquaresVariance\": {\n" \
392 " \"horizontal\": \"%.*g\",\n" \
393 " \"vertical\": \"%.*g\",\n" \
394 " \"leftDiagonal\": \"%.*g\",\n" \
395 " \"rightDiagonal\": \"%.*g\",\n" \
396 " \"average\": \"%.*g\"\n" \
397 " },\n" \
398 " \"inverseDifferenceMoment\": {\n" \
399 " \"horizontal\": \"%.*g\",\n" \
400 " \"vertical\": \"%.*g\",\n" \
401 " \"leftDiagonal\": \"%.*g\",\n" \
402 " \"rightDiagonal\": \"%.*g\",\n" \
403 " \"average\": \"%.*g\"\n" \
404 " },\n" \
405 " \"sumAverage\": {\n" \
406 " \"horizontal\": \"%.*g\",\n" \
407 " \"vertical\": \"%.*g\",\n" \
408 " \"leftDiagonal\": \"%.*g\",\n" \
409 " \"rightDiagonal\": \"%.*g\",\n" \
410 " \"average\": \"%.*g\"\n" \
411 " },\n" \
412 " \"sumVariance\": {\n" \
413 " \"horizontal\": \"%.*g\",\n" \
414 " \"vertical\": \"%.*g\",\n" \
415 " \"leftDiagonal\": \"%.*g\",\n" \
416 " \"rightDiagonal\": \"%.*g\",\n" \
417 " \"average\": \"%.*g\"\n" \
418 " },\n" \
419 " \"sumEntropy\": {\n" \
420 " \"horizontal\": \"%.*g\",\n" \
421 " \"vertical\": \"%.*g\",\n" \
422 " \"leftDiagonal\": \"%.*g\",\n" \
423 " \"rightDiagonal\": \"%.*g\",\n" \
424 " \"average\": \"%.*g\"\n" \
425 " },\n" \
426 " \"entropy\": {\n" \
427 " \"horizontal\": \"%.*g\",\n" \
428 " \"vertical\": \"%.*g\",\n" \
429 " \"leftDiagonal\": \"%.*g\",\n" \
430 " \"rightDiagonal\": \"%.*g\",\n" \
431 " \"average\": \"%.*g\"\n" \
432 " },\n" \
433 " \"differenceVariance\": {\n" \
434 " \"horizontal\": \"%.*g\",\n" \
435 " \"vertical\": \"%.*g\",\n" \
436 " \"leftDiagonal\": \"%.*g\",\n" \
437 " \"rightDiagonal\": \"%.*g\",\n" \
438 " \"average\": \"%.*g\"\n" \
439 " },\n" \
440 " \"differenceEntropy\": {\n" \
441 " \"horizontal\": \"%.*g\",\n" \
442 " \"vertical\": \"%.*g\",\n" \
443 " \"leftDiagonal\": \"%.*g\",\n" \
444 " \"rightDiagonal\": \"%.*g\",\n" \
445 " \"average\": \"%.*g\"\n" \
446 " },\n" \
447 " \"informationMeasureOfCorrelation1\": {\n" \
448 " \"horizontal\": \"%.*g\",\n" \
449 " \"vertical\": \"%.*g\",\n" \
450 " \"leftDiagonal\": \"%.*g\",\n" \
451 " \"rightDiagonal\": \"%.*g\",\n" \
452 " \"average\": \"%.*g\"\n" \
453 " },\n" \
454 " \"informationMeasureOfCorrelation2\": {\n" \
455 " \"horizontal\": \"%.*g\",\n" \
456 " \"vertical\": \"%.*g\",\n" \
457 " \"leftDiagonal\": \"%.*g\",\n" \
458 " \"rightDiagonal\": \"%.*g\",\n" \
459 " \"average\": \"%.*g\"\n" \
460 " },\n" \
461 " \"maximumCorrelationCoefficient\": {\n" \
462 " \"horizontal\": \"%.*g\",\n" \
463 " \"vertical\": \"%.*g\",\n" \
464 " \"leftDiagonal\": \"%.*g\",\n" \
465 " \"rightDiagonal\": \"%.*g\",\n" \
466 " \"average\": \"%.*g\"\n" \
467 " }\n"
cristy9e818982014-01-18 14:54:37 +0000468
469 ssize_t
470 n;
471
472 n=FormatLocaleFile(file,FeaturesFormat,name,
473 PrintFeature(channel_features[channel].angular_second_moment),
474 PrintFeature(channel_features[channel].contrast),
475 PrintFeature(channel_features[channel].correlation),
476 PrintFeature(channel_features[channel].variance_sum_of_squares),
477 PrintFeature(channel_features[channel].inverse_difference_moment),
478 PrintFeature(channel_features[channel].sum_average),
479 PrintFeature(channel_features[channel].sum_variance),
480 PrintFeature(channel_features[channel].sum_entropy),
481 PrintFeature(channel_features[channel].entropy),
482 PrintFeature(channel_features[channel].difference_variance),
483 PrintFeature(channel_features[channel].difference_entropy),
484 PrintFeature(channel_features[channel].measure_of_correlation_1),
485 PrintFeature(channel_features[channel].measure_of_correlation_2),
486 PrintFeature(channel_features[channel].maximum_correlation_coefficient));
dirk6c316f22015-06-27 15:44:29 +0000487 (void) FormatLocaleFile(file," }");
488 if (separator != MagickFalse)
489 (void) FormatLocaleFile(file,",");
490 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000491 return(n);
492}
493
494static ssize_t PrintChannelLocations(FILE *file,const Image *image,
495 const PixelChannel channel,const char *name,const StatisticType type,
dirk6c316f22015-06-27 15:44:29 +0000496 const size_t max_locations,const MagickBooleanType separator,
497 const ChannelStatistics *channel_statistics)
cristy9e818982014-01-18 14:54:37 +0000498{
499 double
500 target;
501
502 ExceptionInfo
503 *exception;
504
505 ssize_t
506 n,
507 y;
508
509 switch (type)
510 {
511 case MaximumStatistic:
512 default:
513 {
514 target=channel_statistics[channel].maxima;
515 break;
516 }
517 case MinimumStatistic:
518 {
519 target=channel_statistics[channel].minima;
520 break;
521 }
522 }
dirk6c316f22015-06-27 15:44:29 +0000523 (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": "
524 "\"%.*g\",\n",name,GetMagickPrecision(),QuantumScale*target);
cristy9e818982014-01-18 14:54:37 +0000525 exception=AcquireExceptionInfo();
526 n=0;
527 for (y=0; y < (ssize_t) image->rows; y++)
528 {
529 register const Quantum
530 *p;
531
532 ssize_t
533 offset,
534 x;
535
536 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
537 if (p == (const Quantum *) NULL)
538 break;
539 for (x=0; x < (ssize_t) image->columns; x++)
540 {
541 MagickBooleanType
542 match;
543
544 PixelTrait traits=GetPixelChannelTraits(image,channel);
545 if (traits == UndefinedPixelTrait)
546 continue;
547 offset=GetPixelChannelOffset(image,channel);
cristy3bdd9252014-12-21 20:01:43 +0000548 match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse;
cristy9e818982014-01-18 14:54:37 +0000549 if (match != MagickFalse)
550 {
551 if ((max_locations != 0) && (n >= (ssize_t) max_locations))
552 break;
dirk6c316f22015-06-27 15:44:29 +0000553 if (n != 0)
554 (void) FormatLocaleFile(file,",\n");
555 (void) FormatLocaleFile(file," \"location%.20g\": {\n"
556 " \"x\": %.20g,\n \"y\": %.20g\n"
557 " }",(double) n,(double) x,(double) y);
cristy9e818982014-01-18 14:54:37 +0000558 n++;
559 }
560 p+=GetPixelChannels(image);
561 }
562 if (x < (ssize_t) image->columns)
563 break;
564 }
dirk6c316f22015-06-27 15:44:29 +0000565 (void) FormatLocaleFile(file,"\n }");
566 if (separator != MagickFalse)
567 (void) FormatLocaleFile(file,",");
cristy9e818982014-01-18 14:54:37 +0000568 (void) FormatLocaleFile(file,"\n");
569 return(n);
570}
571
572static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000573 const char *name,const MagickBooleanType separator,
574 const ChannelMoments *channel_moments)
cristy9e818982014-01-18 14:54:37 +0000575{
576 register ssize_t
577 i;
578
579 ssize_t
580 n;
581
dirk6c316f22015-06-27 15:44:29 +0000582 n=FormatLocaleFile(file," \"%s\": {\n",name);
583 n+=FormatLocaleFile(file," \"centroid\": {\n "
584 " \"x\": \"%.*g\",\n"
585 " \"y\": \"%.*g\"\n },\n",
cristy9e818982014-01-18 14:54:37 +0000586 GetMagickPrecision(),channel_moments[channel].centroid.x,
587 GetMagickPrecision(),channel_moments[channel].centroid.y);
dirk6c316f22015-06-27 15:44:29 +0000588 n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n"
589 " \"x\": \"%.*g\",\n"
590 " \"y\": \"%.*g\"\n },\n",
cristy9e818982014-01-18 14:54:37 +0000591 GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
592 GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
dirk6c316f22015-06-27 15:44:29 +0000593 n+=FormatLocaleFile(file," \"ellipseAngle\": \"%.*g\",\n",
cristy9e818982014-01-18 14:54:37 +0000594 GetMagickPrecision(),channel_moments[channel].ellipse_angle);
dirk6c316f22015-06-27 15:44:29 +0000595 n+=FormatLocaleFile(file," \"ellipseEccentricity\": \"%.*g\",\n",
cristy9e818982014-01-18 14:54:37 +0000596 GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
dirk6c316f22015-06-27 15:44:29 +0000597 n+=FormatLocaleFile(file," \"ellipseIntensity\": \"%.*g\",\n",
cristy9e818982014-01-18 14:54:37 +0000598 GetMagickPrecision(),channel_moments[channel].ellipse_intensity);
dirk6c316f22015-06-27 15:44:29 +0000599 for (i=0; i < 7; i++)
600 n+=FormatLocaleFile(file," \"I%.20g\": \"%.*g\",\n",i+1.0,
601 GetMagickPrecision(),channel_moments[channel].invariant[i]);
602 n+=FormatLocaleFile(file," \"I%.20g\": \"%.*g\"\n",i+1.0,
603 GetMagickPrecision(),channel_moments[channel].invariant[i]);
604 (void) FormatLocaleFile(file," }");
605 if (separator != MagickFalse)
606 (void) FormatLocaleFile(file,",");
607 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000608 return(n);
609}
610
Cristye6961802016-09-03 11:31:13 -0400611static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
cristydc395172014-02-23 01:33:36 +0000612 const ChannelPerceptualHash *channel_phash)
613{
614 register ssize_t
615 i;
616
617 ssize_t
618 n;
619
Cristye6961802016-09-03 11:31:13 -0400620 (void) FormatLocaleFile(file," \"colorspaces\": [ ");
621 for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
622 {
623 (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic(
624 MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
625 if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
626 (void) FormatLocaleFile(file,", ");
627 }
628 (void) FormatLocaleFile(file,"],\n");
629 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
630 {
631 register ssize_t
632 j;
633
634 PixelChannel channel=GetPixelChannelChannel(image,i);
635 PixelTrait traits=GetPixelChannelTraits(image,channel);
636 if (traits == UndefinedPixelTrait)
637 continue;
638 n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel);
639 for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
640 {
641 register ssize_t
642 k;
643
644 n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1);
645 for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
646 {
647 n+=FormatLocaleFile(file,"\"%.*g\"",GetMagickPrecision(),
648 channel_phash[channel].phash[k][j]);
649 if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
650 n+=FormatLocaleFile(file,", ");
651 }
652 n+=FormatLocaleFile(file,"]");
653 if (j < (MaximumNumberOfPerceptualHashes-1))
654 n+=FormatLocaleFile(file,",\n");
655 }
656 if (i < (GetPixelChannels(image)-1))
657 n+=FormatLocaleFile(file,"\n },\n");
658 }
659 n+=FormatLocaleFile(file,"\n }\n");
cristydc395172014-02-23 01:33:36 +0000660 return(n);
661}
662
cristy9e818982014-01-18 14:54:37 +0000663static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
dirk6c316f22015-06-27 15:44:29 +0000664 const char *name,const double scale,const MagickBooleanType separator,
cristy9e818982014-01-18 14:54:37 +0000665 const ChannelStatistics *channel_statistics)
666{
dirk6c316f22015-06-27 15:44:29 +0000667#define StatisticsFormat " \"%s\": {\n \"min\": \"" QuantumFormat \
668 "\",\n \"max\": \"" QuantumFormat "\",\n" \
669 " \"mean\": \"%g\",\n \"standardDeviation\": " \
670 "\"%g\",\n \"kurtosis\": \"%g\",\n \"skewness\": " \
671 "\"%g\"\n }"
cristy9e818982014-01-18 14:54:37 +0000672
673 ssize_t
674 n;
675
676 n=FormatLocaleFile(file,StatisticsFormat,name,ClampToQuantum(scale*
cristye1c94d92015-06-28 12:16:33 +0000677 channel_statistics[channel].minima),ClampToQuantum(scale*
678 channel_statistics[channel].maxima),scale*channel_statistics[channel].mean,
679 scale*channel_statistics[channel].standard_deviation,
cristy9e818982014-01-18 14:54:37 +0000680 channel_statistics[channel].kurtosis,channel_statistics[channel].skewness);
dirk6c316f22015-06-27 15:44:29 +0000681 if (separator != MagickFalse)
cristye1c94d92015-06-28 12:16:33 +0000682 (void) FormatLocaleFile(file,",");
dirk6c316f22015-06-27 15:44:29 +0000683 (void) FormatLocaleFile(file,"\n");
cristy9e818982014-01-18 14:54:37 +0000684 return(n);
685}
686
687static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
688 ExceptionInfo *exception)
689{
cristy9e818982014-01-18 14:54:37 +0000690 char
cristy151b66d2015-04-15 10:50:31 +0000691 color[MagickPathExtent],
692 format[MagickPathExtent],
693 key[MagickPathExtent];
cristy9e818982014-01-18 14:54:37 +0000694
695 ChannelFeatures
696 *channel_features;
697
698 ChannelMoments
699 *channel_moments;
700
cristydc395172014-02-23 01:33:36 +0000701 ChannelPerceptualHash
702 *channel_phash;
703
cristy9e818982014-01-18 14:54:37 +0000704 ChannelStatistics
705 *channel_statistics;
706
707 ColorspaceType
708 colorspace;
709
710 const char
711 *artifact,
712 *locate,
713 *name,
714 *property,
715 *registry,
716 *value;
717
718 const MagickInfo
719 *magick_info;
720
721 double
722 elapsed_time,
723 user_time;
724
725 ImageType
dirkab4f0bb2015-07-25 11:46:32 +0000726 base_type,
cristy9e818982014-01-18 14:54:37 +0000727 type;
728
729 MagickBooleanType
730 ping;
731
732 register const Quantum
733 *p;
734
735 register ssize_t
736 i,
737 x;
738
739 size_t
dirk6c316f22015-06-27 15:44:29 +0000740 depth,
cristy9e818982014-01-18 14:54:37 +0000741 distance,
742 scale;
743
744 ssize_t
745 y;
746
747 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000748 assert(image->signature == MagickCoreSignature);
cristy9e818982014-01-18 14:54:37 +0000749 if (image->debug != MagickFalse)
750 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristya10f7442014-01-19 18:32:15 +0000751 *format='\0';
752 elapsed_time=GetElapsedTime(&image->timer);
753 user_time=GetUserTime(&image->timer);
754 GetTimerInfo(&image->timer);
755 p=GetVirtualPixels(image,0,0,1,1,exception);
756 ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
cristye1c94d92015-06-28 12:16:33 +0000757 (void) ping;
cristya10f7442014-01-19 18:32:15 +0000758 (void) SignatureImage(image,exception);
dirk6c316f22015-06-27 15:44:29 +0000759 JsonFormatLocaleFile(file,"{\n \"image\": {\n \"name\": %s,\n",
760 image->filename);
cristya10f7442014-01-19 18:32:15 +0000761 if (*image->magick_filename != '\0')
762 if (LocaleCompare(image->magick_filename,image->filename) != 0)
763 {
764 char
cristy151b66d2015-04-15 10:50:31 +0000765 filename[MagickPathExtent];
cristya10f7442014-01-19 18:32:15 +0000766
767 GetPathComponent(image->magick_filename,TailPath,filename);
dirk6c316f22015-06-27 15:44:29 +0000768 JsonFormatLocaleFile(file," \"baseName\": %s,\n",filename);
cristya10f7442014-01-19 18:32:15 +0000769 }
dirk6c316f22015-06-27 15:44:29 +0000770 JsonFormatLocaleFile(file," \"format\": %s,\n",image->magick);
cristya10f7442014-01-19 18:32:15 +0000771 magick_info=GetMagickInfo(image->magick,exception);
dirk6c316f22015-06-27 15:44:29 +0000772 if ((magick_info != (const MagickInfo *) NULL) &&
773 (GetMagickDescription(magick_info) != (const char *) NULL))
774 JsonFormatLocaleFile(file," \"formatDescription\": %s,\n",
775 image->magick);
cristy12bcd3d2015-01-28 00:54:23 +0000776 if ((magick_info != (const MagickInfo *) NULL) &&
cristya10f7442014-01-19 18:32:15 +0000777 (GetMagickMimeType(magick_info) != (const char *) NULL))
dirk6c316f22015-06-27 15:44:29 +0000778 JsonFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType(
cristya10f7442014-01-19 18:32:15 +0000779 magick_info));
dirk6c316f22015-06-27 15:44:29 +0000780 JsonFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +0000781 MagickClassOptions,(ssize_t) image->storage_class));
dirk6c316f22015-06-27 15:44:29 +0000782 (void) FormatLocaleFile(file," \"geometry\": {\n"
783 " \"width\": %.20g,\n \"height\": %.20g,\n"
784 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
785 (double) image->columns,(double) image->rows,(double) image->tile_offset.x,
786 (double) image->tile_offset.y);
cristya10f7442014-01-19 18:32:15 +0000787 if ((image->magick_columns != 0) || (image->magick_rows != 0))
788 if ((image->magick_columns != image->columns) ||
789 (image->magick_rows != image->rows))
dirk6c316f22015-06-27 15:44:29 +0000790 (void) FormatLocaleFile(file," \"baseGeometry\": {\n"
791 " \"width\": %.20g,\n \"height\": %.20g\n },\n",
792 (double) image->magick_columns,(double) image->magick_rows);
cristya10f7442014-01-19 18:32:15 +0000793 if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
794 {
dirk6c316f22015-06-27 15:44:29 +0000795 (void) FormatLocaleFile(file," \"resolution\": {\n"
796 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
797 image->resolution.x,image->resolution.y);
798 (void) FormatLocaleFile(file," \"printSize\": {\n"
799 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
cristya10f7442014-01-19 18:32:15 +0000800 image->columns/image->resolution.x,(double) image->rows/
801 image->resolution.y);
802 }
dirk6c316f22015-06-27 15:44:29 +0000803 JsonFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +0000804 MagickResolutionOptions,(ssize_t) image->units));
dirkab4f0bb2015-07-25 11:46:32 +0000805 colorspace=image->colorspace;
806 type=IdentifyImageType(image,exception);
807 if ((type == BilevelType) || (type == GrayscaleType) ||
808 (type == GrayscaleAlphaType))
809 colorspace=GRAYColorspace;
dirk6c316f22015-06-27 15:44:29 +0000810 JsonFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
cristya10f7442014-01-19 18:32:15 +0000811 MagickTypeOptions,(ssize_t) type));
dirkab4f0bb2015-07-25 11:46:32 +0000812 base_type=GetImageType(image);
813 if (type != base_type)
dirk6c316f22015-06-27 15:44:29 +0000814 JsonFormatLocaleFile(file," \"baseType\": %s,\n",
dirkab4f0bb2015-07-25 11:46:32 +0000815 CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) base_type));
dirk6c316f22015-06-27 15:44:29 +0000816 JsonFormatLocaleFile(file," \"endianess\": %s,\n",
817 CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
cristy9e818982014-01-18 14:54:37 +0000818 locate=GetImageArtifact(image,"identify:locate");
cristy3e583dd2014-01-19 14:11:51 +0000819 if (locate == (const char *) NULL)
820 locate=GetImageArtifact(image,"json:locate");
cristy9e818982014-01-18 14:54:37 +0000821 if (locate != (const char *) NULL)
822 {
823 const char
824 *limit;
825
826 size_t
827 max_locations;
828
829 StatisticType
830 type;
831
832 /*
833 Display minimum, maximum, or mean pixel locations.
834 */
835 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
836 MagickFalse,locate);
837 limit=GetImageArtifact(image,"identify:limit");
cristy3e583dd2014-01-19 14:11:51 +0000838 if (limit == (const char *) NULL)
839 limit=GetImageArtifact(image,"json:limit");
cristy9e818982014-01-18 14:54:37 +0000840 max_locations=0;
841 if (limit != (const char *) NULL)
842 max_locations=StringToUnsignedLong(limit);
843 channel_statistics=GetLocationStatistics(image,type,exception);
844 if (channel_statistics == (ChannelStatistics *) NULL)
845 return(MagickFalse);
dirk6c316f22015-06-27 15:44:29 +0000846 (void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
847 if (image->alpha_trait != UndefinedPixelTrait)
848 (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
849 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000850 switch (colorspace)
851 {
852 case RGBColorspace:
853 default:
854 {
855 (void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
dirk6c316f22015-06-27 15:44:29 +0000856 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000857 (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
dirk6c316f22015-06-27 15:44:29 +0000858 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000859 (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
dirk6c316f22015-06-27 15:44:29 +0000860 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000861 break;
862 }
863 case CMYKColorspace:
864 {
865 (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
dirk6c316f22015-06-27 15:44:29 +0000866 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000867 (void) PrintChannelLocations(file,image,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +0000868 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000869 (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +0000870 type,max_locations,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000871 (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +0000872 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000873 break;
874 }
875 case GRAYColorspace:
876 {
877 (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
dirk6c316f22015-06-27 15:44:29 +0000878 type,max_locations,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000879 break;
880 }
881 }
dirk6c316f22015-06-27 15:44:29 +0000882 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +0000883 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
884 channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000885 }
cristy9e818982014-01-18 14:54:37 +0000886 /*
887 Detail channel depth and extrema.
888 */
dirk6c316f22015-06-27 15:44:29 +0000889 JsonFormatLocaleFile(file," \"colorspace\": %s,\n",
890 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
891 image->colorspace));
cristy9e818982014-01-18 14:54:37 +0000892 channel_statistics=(ChannelStatistics *) NULL;
893 channel_moments=(ChannelMoments *) NULL;
cristydc395172014-02-23 01:33:36 +0000894 channel_phash=(ChannelPerceptualHash *) NULL;
cristy9e818982014-01-18 14:54:37 +0000895 channel_features=(ChannelFeatures *) NULL;
cristy9e818982014-01-18 14:54:37 +0000896 scale=1;
dirk6c316f22015-06-27 15:44:29 +0000897 channel_statistics=GetImageStatistics(image,exception);
898 if (channel_statistics == (ChannelStatistics *) NULL)
899 return(MagickFalse);
900 artifact=GetImageArtifact(image,"identify:moments");
901 if (artifact == (const char *) NULL)
902 artifact=GetImageArtifact(image,"json:moments");
903 if (artifact != (const char *) NULL)
cristy9e818982014-01-18 14:54:37 +0000904 {
dirk6c316f22015-06-27 15:44:29 +0000905 channel_moments=GetImageMoments(image,exception);
906 channel_phash=GetImagePerceptualHash(image,exception);
cristy9e818982014-01-18 14:54:37 +0000907 }
dirk6c316f22015-06-27 15:44:29 +0000908 artifact=GetImageArtifact(image,"identify:features");
909 if (artifact == (const char *) NULL)
910 artifact=GetImageArtifact(image,"json:features");
911 if (artifact != (const char *) NULL)
912 {
913 distance=StringToUnsignedLong(artifact);
914 channel_features=GetImageFeatures(image,distance,exception);
915 }
916 depth=GetImageDepth(image,exception);
917 (void) FormatLocaleFile(file," \"depth\": %.20g,\n",(double) depth);
918 (void) FormatLocaleFile(file," \"baseDepth\": %.20g,\n",(double)
919 image->depth);
920 (void) FormatLocaleFile(file," \"channelDepth\": {\n");
dirk6c316f22015-06-27 15:44:29 +0000921 if (image->alpha_trait != UndefinedPixelTrait)
922 (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
923 channel_statistics[AlphaPixelChannel].depth);
924 switch (colorspace)
925 {
926 case RGBColorspace:
927 default:
928 {
929 (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double)
930 channel_statistics[RedChannel].depth);
931 (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double)
932 channel_statistics[GreenChannel].depth);
933 (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double)
934 channel_statistics[BlueChannel].depth);
935 break;
936 }
937 case CMYKColorspace:
938 {
939 (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double)
940 channel_statistics[CyanChannel].depth);
941 (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double)
942 channel_statistics[MagentaChannel].depth);
943 (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double)
944 channel_statistics[YellowChannel].depth);
945 (void) FormatLocaleFile(file," \"black\": %.20g\n",(double)
946 channel_statistics[BlackChannel].depth);
947 break;
948 }
949 case GRAYColorspace:
950 {
951 (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double)
952 channel_statistics[GrayChannel].depth);
953 break;
954 }
955 }
956 (void) FormatLocaleFile(file," },\n");
957 scale=1;
958 if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
959 scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
960 MAGICKCORE_QUANTUM_DEPTH-image->depth));
cristy9e818982014-01-18 14:54:37 +0000961 if (channel_statistics != (ChannelStatistics *) NULL)
962 {
dirk6c316f22015-06-27 15:44:29 +0000963 (void) FormatLocaleFile(file," \"pixels\": %.20g,\n",
cristy9e818982014-01-18 14:54:37 +0000964 channel_statistics[CompositePixelChannel].area);
dirk6c316f22015-06-27 15:44:29 +0000965 if (colorspace != GRAYColorspace)
966 {
967 (void) FormatLocaleFile(file," \"imageStatistics\": {\n");
968 (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels,
969 "Overall",1.0/scale,MagickFalse,channel_statistics);
970 (void) FormatLocaleFile(file," },\n");
971 }
972 (void) FormatLocaleFile(file," \"channelStatistics\": {\n");
973 if (image->alpha_trait != UndefinedPixelTrait)
974 (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
975 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000976 switch (colorspace)
977 {
978 case RGBColorspace:
979 default:
980 {
dirk6c316f22015-06-27 15:44:29 +0000981 (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale,
982 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000983 (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/
dirk6c316f22015-06-27 15:44:29 +0000984 scale,MagickTrue,channel_statistics);
985 (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale,
986 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000987 break;
988 }
989 case CMYKColorspace:
990 {
dirk6c316f22015-06-27 15:44:29 +0000991 (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale,
992 MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000993 (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/
dirk6c316f22015-06-27 15:44:29 +0000994 scale,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000995 (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/
dirk6c316f22015-06-27 15:44:29 +0000996 scale,MagickTrue,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000997 (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/
dirk6c316f22015-06-27 15:44:29 +0000998 scale,MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +0000999 break;
1000 }
1001 case GRAYColorspace:
1002 {
dirk6c316f22015-06-27 15:44:29 +00001003 (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale,
1004 MagickFalse,channel_statistics);
cristy9e818982014-01-18 14:54:37 +00001005 break;
1006 }
1007 }
dirk6c316f22015-06-27 15:44:29 +00001008 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001009 channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
1010 channel_statistics);
1011 }
1012 if (channel_moments != (ChannelMoments *) NULL)
1013 {
dirk6c316f22015-06-27 15:44:29 +00001014 (void) FormatLocaleFile(file," \"channelMoments\": {\n");
1015 if (image->alpha_trait != UndefinedPixelTrait)
1016 (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue,
1017 channel_moments);
cristy9e818982014-01-18 14:54:37 +00001018 switch (colorspace)
1019 {
1020 case RGBColorspace:
1021 default:
1022 {
dirk6c316f22015-06-27 15:44:29 +00001023 (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001024 channel_moments);
dirk6c316f22015-06-27 15:44:29 +00001025 (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001026 channel_moments);
dirk6c316f22015-06-27 15:44:29 +00001027 (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001028 channel_moments);
1029 break;
1030 }
1031 case CMYKColorspace:
1032 {
dirk6c316f22015-06-27 15:44:29 +00001033 (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001034 channel_moments);
1035 (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +00001036 MagickTrue,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001037 (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001038 MagickTrue,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001039 (void) PrintChannelMoments(file,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001040 MagickFalse,channel_moments);
cristy9e818982014-01-18 14:54:37 +00001041 break;
1042 }
1043 case GRAYColorspace:
1044 {
dirk6c316f22015-06-27 15:44:29 +00001045 (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001046 channel_moments);
1047 break;
1048 }
1049 }
dirk6c316f22015-06-27 15:44:29 +00001050 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001051 channel_moments=(ChannelMoments *) RelinquishMagickMemory(
1052 channel_moments);
1053 }
cristydc395172014-02-23 01:33:36 +00001054 if (channel_phash != (ChannelPerceptualHash *) NULL)
1055 {
1056 (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
Cristye6961802016-09-03 11:31:13 -04001057 (void) PrintChannelPerceptualHash(image,file,channel_phash);
cristydc395172014-02-23 01:33:36 +00001058 (void) FormatLocaleFile(file," },\n");
1059 channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
1060 channel_phash);
1061 }
cristy9e818982014-01-18 14:54:37 +00001062 if (channel_features != (ChannelFeatures *) NULL)
1063 {
dirk6c316f22015-06-27 15:44:29 +00001064 (void) FormatLocaleFile(file," \"channelFeatures\": {\n");
1065 if (image->alpha_trait != UndefinedPixelTrait)
1066 (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue,
1067 channel_features);
cristy9e818982014-01-18 14:54:37 +00001068 switch (colorspace)
1069 {
1070 case RGBColorspace:
1071 default:
1072 {
dirk6c316f22015-06-27 15:44:29 +00001073 (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001074 channel_features);
1075 (void) PrintChannelFeatures(file,GreenPixelChannel,"Green",
dirk6c316f22015-06-27 15:44:29 +00001076 MagickTrue,channel_features);
1077 (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001078 channel_features);
1079 break;
1080 }
1081 case CMYKColorspace:
1082 {
dirk6c316f22015-06-27 15:44:29 +00001083 (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue,
cristy9e818982014-01-18 14:54:37 +00001084 channel_features);
1085 (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta",
dirk6c316f22015-06-27 15:44:29 +00001086 MagickTrue,channel_features);
cristy9e818982014-01-18 14:54:37 +00001087 (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow",
dirk6c316f22015-06-27 15:44:29 +00001088 MagickTrue,channel_features);
cristy9e818982014-01-18 14:54:37 +00001089 (void) PrintChannelFeatures(file,BlackPixelChannel,"Black",
dirk6c316f22015-06-27 15:44:29 +00001090 MagickFalse,channel_features);
cristy9e818982014-01-18 14:54:37 +00001091 break;
1092 }
1093 case GRAYColorspace:
1094 {
dirk6c316f22015-06-27 15:44:29 +00001095 (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse,
cristy9e818982014-01-18 14:54:37 +00001096 channel_features);
1097 break;
1098 }
1099 }
dirk6c316f22015-06-27 15:44:29 +00001100 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001101 channel_features=(ChannelFeatures *) RelinquishMagickMemory(
1102 channel_features);
1103 }
dirk6c316f22015-06-27 15:44:29 +00001104 if (image->colorspace == CMYKColorspace)
1105 (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n",
cristye1c94d92015-06-28 12:16:33 +00001106 GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
1107 (double) QuantumRange);
dirk6c316f22015-06-27 15:44:29 +00001108 x=0;
1109 if (image->alpha_trait != UndefinedPixelTrait)
1110 {
1111 register const Quantum
1112 *p;
1113
1114 p=(const Quantum *) NULL;
1115 for (y=0; y < (ssize_t) image->rows; y++)
cristy9e818982014-01-18 14:54:37 +00001116 {
dirk6c316f22015-06-27 15:44:29 +00001117 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1118 if (p == (const Quantum *) NULL)
1119 break;
1120 for (x=0; x < (ssize_t) image->columns; x++)
cristy9e818982014-01-18 14:54:37 +00001121 {
dirk6c316f22015-06-27 15:44:29 +00001122 if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)
cristy9e818982014-01-18 14:54:37 +00001123 break;
dirk6c316f22015-06-27 15:44:29 +00001124 p+=GetPixelChannels(image);
cristy9e818982014-01-18 14:54:37 +00001125 }
dirk6c316f22015-06-27 15:44:29 +00001126 if (x < (ssize_t) image->columns)
1127 break;
cristy9e818982014-01-18 14:54:37 +00001128 }
dirk6c316f22015-06-27 15:44:29 +00001129 if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows))
1130 {
1131 PixelInfo
1132 pixel;
1133
1134 GetPixelInfo(image,&pixel);
1135 GetPixelInfoPixel(image,p,&pixel);
1136 GetColorTuple(&pixel,MagickTrue,color);
1137 (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color);
1138 }
1139 }
cristy9e818982014-01-18 14:54:37 +00001140 if (image->storage_class == PseudoClass)
1141 {
dirk6c316f22015-06-27 15:44:29 +00001142 register PixelInfo
dirk05d2ff72015-11-18 23:13:43 +01001143 *magick_restrict p;
cristy9e818982014-01-18 14:54:37 +00001144
dirk6c316f22015-06-27 15:44:29 +00001145 (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n",
1146 (double) image->colors);
1147 (void) FormatLocaleFile(file," \"colormap\": [\n ");
1148 p=image->colormap;
1149 for (i=0; i < (ssize_t) image->colors; i++)
1150 {
1151 GetColorTuple(p,MagickTrue,color);
1152 (void) FormatLocaleFile(file,"\"%s\"",color);
1153 if (i < (ssize_t) (image->colors-1))
1154 (void) FormatLocaleFile(file,",");
1155 if (((i+1) % 5) == 0)
1156 (void) FormatLocaleFile(file,"\n ");
1157 p++;
1158 }
1159 (void) FormatLocaleFile(file,"\n ],\n");
cristy9e818982014-01-18 14:54:37 +00001160 }
1161 if (image->error.mean_error_per_pixel != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001162 (void) FormatLocaleFile(file," \"meanErrorPerPixel\": \"%g\",\n",
cristy9e818982014-01-18 14:54:37 +00001163 image->error.mean_error_per_pixel);
1164 if (image->error.normalized_mean_error != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001165 (void) FormatLocaleFile(file," \"normalizedMeanError\": \"%g\",\n",
cristy9e818982014-01-18 14:54:37 +00001166 image->error.normalized_mean_error);
1167 if (image->error.normalized_maximum_error != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001168 (void) FormatLocaleFile(file," \"normalizedMaximumError\": \"%g\",\n",
cristy9e818982014-01-18 14:54:37 +00001169 image->error.normalized_maximum_error);
dirk6c316f22015-06-27 15:44:29 +00001170 JsonFormatLocaleFile(file," \"renderingIntent\": %s,\n",
cristy9e818982014-01-18 14:54:37 +00001171 CommandOptionToMnemonic(MagickIntentOptions,(ssize_t)
1172 image->rendering_intent));
1173 if (image->gamma != 0.0)
dirk6c316f22015-06-27 15:44:29 +00001174 (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma);
cristy9e818982014-01-18 14:54:37 +00001175 if ((image->chromaticity.red_primary.x != 0.0) ||
1176 (image->chromaticity.green_primary.x != 0.0) ||
1177 (image->chromaticity.blue_primary.x != 0.0) ||
1178 (image->chromaticity.white_point.x != 0.0))
1179 {
1180 /*
1181 Display image chromaticity.
1182 */
dirk6c316f22015-06-27 15:44:29 +00001183 (void) FormatLocaleFile(file," \"chromaticity\": {\n");
1184 (void) FormatLocaleFile(file," \"redPrimary\": {\n"
1185 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001186 image->chromaticity.red_primary.x,image->chromaticity.red_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001187 (void) FormatLocaleFile(file," \"greenPrimary\": {\n"
1188 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001189 image->chromaticity.green_primary.x,
1190 image->chromaticity.green_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001191 (void) FormatLocaleFile(file," \"bluePrimary\": {\n"
1192 " \"x\": %g,\n \"y\": %g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001193 image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y);
dirk6c316f22015-06-27 15:44:29 +00001194 (void) FormatLocaleFile(file," \"whitePrimary\": {\n"
1195 " \"x\": %g,\n \"y\": %g\n }\n",
cristy9e818982014-01-18 14:54:37 +00001196 image->chromaticity.white_point.x,image->chromaticity.white_point.y);
dirk6c316f22015-06-27 15:44:29 +00001197 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001198 }
1199 if ((image->extract_info.width*image->extract_info.height) != 0)
dirk6c316f22015-06-27 15:44:29 +00001200 (void) FormatLocaleFile(file," \"tileGeometry\": {\n"
1201 " \"width\": %.20g,\n \"height\": %.20g,\n"
1202 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
cristy9e818982014-01-18 14:54:37 +00001203 (double) image->extract_info.width,(double) image->extract_info.height,
1204 (double) image->extract_info.x,(double) image->extract_info.y);
dirkb797b2c2016-02-01 22:20:32 +01001205 GetColorTuple(&image->alpha_color,MagickTrue,color);
1206 (void) FormatLocaleFile(file," \"alphaColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001207 GetColorTuple(&image->background_color,MagickTrue,color);
1208 (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color);
1209 GetColorTuple(&image->border_color,MagickTrue,color);
1210 (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color);
dirk6c316f22015-06-27 15:44:29 +00001211 GetColorTuple(&image->transparent_color,MagickTrue,color);
1212 (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color);
1213 JsonFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001214 MagickInterlaceOptions,(ssize_t) image->interlace));
dirk6c316f22015-06-27 15:44:29 +00001215 JsonFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic(
cristy9e818982014-01-18 14:54:37 +00001216 MagickPixelIntensityOptions,(ssize_t) image->intensity));
dirk6c316f22015-06-27 15:44:29 +00001217 JsonFormatLocaleFile(file," \"compose\": %s,\n",
1218 CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose));
cristy9e818982014-01-18 14:54:37 +00001219 if ((image->page.width != 0) || (image->page.height != 0) ||
1220 (image->page.x != 0) || (image->page.y != 0))
dirk6c316f22015-06-27 15:44:29 +00001221 (void) FormatLocaleFile(file," \"pageGeometry\": {\n"
1222 " \"width\": %.20g,\n \"height\": %.20g,\n"
1223 " \"x\": %.20g,\n \"y\": %.20g\n },\n",
1224 (double) image->page.width,(double) image->page.height,
1225 (double) image->page.x,(double) image->page.y);
cristy9e818982014-01-18 14:54:37 +00001226 if ((image->page.x != 0) || (image->page.y != 0))
dirk6c316f22015-06-27 15:44:29 +00001227 (void) FormatLocaleFile(file," \"originGeometry\": %+.20g%+.20g\n",
1228 (double) image->page.x,(double) image->page.y);
1229 JsonFormatLocaleFile(file," \"dispose\": %s,\n",
1230 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
cristy9e818982014-01-18 14:54:37 +00001231 if (image->delay != 0)
dirk6c316f22015-06-27 15:44:29 +00001232 (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\"\n",
1233 (double) image->delay,(double) image->ticks_per_second);
cristy9e818982014-01-18 14:54:37 +00001234 if (image->iterations != 1)
dirk6c316f22015-06-27 15:44:29 +00001235 (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double)
cristy9e818982014-01-18 14:54:37 +00001236 image->iterations);
1237 if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
dirk6c316f22015-06-27 15:44:29 +00001238 (void) FormatLocaleFile(file," \"scene\": %.20g\n \"scenes\": "
1239 "%.20g\n",(double) image->scene,(double) GetImageListLength(image));
cristy9e818982014-01-18 14:54:37 +00001240 else
1241 if (image->scene != 0)
dirk6c316f22015-06-27 15:44:29 +00001242 (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double)
1243 image->scene);
1244 JsonFormatLocaleFile(file," \"compression\": %s,\n",
1245 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
1246 image->compression));
cristy9e818982014-01-18 14:54:37 +00001247 if (image->quality != UndefinedCompressionQuality)
dirk6c316f22015-06-27 15:44:29 +00001248 (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double)
1249 image->quality);
1250 JsonFormatLocaleFile(file," \"orientation\": %s,\n",
1251 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
1252 image->orientation));
cristy9e818982014-01-18 14:54:37 +00001253 if (image->montage != (char *) NULL)
dirk6c316f22015-06-27 15:44:29 +00001254 JsonFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage);
cristy9e818982014-01-18 14:54:37 +00001255 if (image->directory != (char *) NULL)
1256 {
1257 Image
1258 *tile;
1259
1260 ImageInfo
1261 *image_info;
1262
1263 register char
1264 *p,
1265 *q;
1266
1267 WarningHandler
1268 handler;
1269
1270 /*
1271 Display visual image directory.
1272 */
1273 image_info=AcquireImageInfo();
1274 (void) CloneString(&image_info->size,"64x64");
dirk6c316f22015-06-27 15:44:29 +00001275 (void) FormatLocaleFile(file," \"montageDirectory\": [");
1276 p=image->directory;
1277 while (*p != '\0')
cristy9e818982014-01-18 14:54:37 +00001278 {
1279 q=p;
1280 while ((*q != '\n') && (*q != '\0'))
1281 q++;
1282 (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1));
dirk6c316f22015-06-27 15:44:29 +00001283 p=q+1;
1284 JsonFormatLocaleFile(file,"{\n \"name\": %s",
1285 image_info->filename);
cristy9e818982014-01-18 14:54:37 +00001286 handler=SetWarningHandler((WarningHandler) NULL);
1287 tile=ReadImage(image_info,exception);
1288 (void) SetWarningHandler(handler);
1289 if (tile == (Image *) NULL)
1290 {
dirk6c316f22015-06-27 15:44:29 +00001291 (void) FormatLocaleFile(file," }");
cristy9e818982014-01-18 14:54:37 +00001292 continue;
1293 }
dirk6c316f22015-06-27 15:44:29 +00001294 (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"",
1295 (double) tile->magick_columns,(double) tile->magick_rows,
1296 tile->magick);
cristy9e818982014-01-18 14:54:37 +00001297 (void) SignatureImage(tile,exception);
1298 ResetImagePropertyIterator(tile);
1299 property=GetNextImageProperty(tile);
1300 while (property != (const char *) NULL)
1301 {
dirk6c316f22015-06-27 15:44:29 +00001302 JsonFormatLocaleFile(file,",\n %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001303 value=GetImageProperty(tile,property,exception);
dirk6c316f22015-06-27 15:44:29 +00001304 JsonFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001305 property=GetNextImageProperty(tile);
1306 }
1307 tile=DestroyImage(tile);
dirk6c316f22015-06-27 15:44:29 +00001308 if (*p != '\0')
1309 (void) FormatLocaleFile(file,"\n },");
1310 else
1311 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001312 }
dirk6c316f22015-06-27 15:44:29 +00001313 (void) FormatLocaleFile(file,"],\n");
cristy9e818982014-01-18 14:54:37 +00001314 image_info=DestroyImageInfo(image_info);
1315 }
1316 (void) GetImageProperty(image,"exif:*",exception);
cristy55166322014-01-23 01:53:24 +00001317 (void) GetImageProperty(image,"icc:*",exception);
1318 (void) GetImageProperty(image,"iptc:*",exception);
1319 (void) GetImageProperty(image,"xmp:*",exception);
cristy9e818982014-01-18 14:54:37 +00001320 ResetImagePropertyIterator(image);
1321 property=GetNextImageProperty(image);
1322 if (property != (const char *) NULL)
1323 {
dirk6c316f22015-06-27 15:44:29 +00001324 size_t
1325 n;
1326
cristy9e818982014-01-18 14:54:37 +00001327 /*
1328 Display image properties.
1329 */
dirk6c316f22015-06-27 15:44:29 +00001330 n=0;
1331 (void) FormatLocaleFile(file," \"properties\": {\n");
cristy9e818982014-01-18 14:54:37 +00001332 while (property != (const char *) NULL)
1333 {
dirk6c316f22015-06-27 15:44:29 +00001334 if (n++ != 0)
1335 (void) FormatLocaleFile(file,",\n");
1336 JsonFormatLocaleFile(file," %s: ",property);
cristy9e818982014-01-18 14:54:37 +00001337 value=GetImageProperty(image,property,exception);
dirk6c316f22015-06-27 15:44:29 +00001338 JsonFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001339 property=GetNextImageProperty(image);
1340 }
dirk6c316f22015-06-27 15:44:29 +00001341 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001342 }
cristy151b66d2015-04-15 10:50:31 +00001343 (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1");
cristy9e818982014-01-18 14:54:37 +00001344 value=GetImageProperty(image,key,exception);
1345 if (value != (const char *) NULL)
1346 {
1347 /*
1348 Display clipping path.
1349 */
dirk6c316f22015-06-27 15:44:29 +00001350 (void) FormatLocaleFile(file," \"clipping path\": {\n");
1351 JsonFormatLocaleFile(file,"%s\n",value);
1352 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001353 }
1354 ResetImageProfileIterator(image);
1355 name=GetNextImageProfile(image);
1356 if (name != (char *) NULL)
1357 {
1358 const StringInfo
1359 *profile;
1360
dirk6c316f22015-06-27 15:44:29 +00001361 size_t
1362 n;
1363
cristy9e818982014-01-18 14:54:37 +00001364 /*
1365 Identify image profiles.
1366 */
dirk6c316f22015-06-27 15:44:29 +00001367 n=0;
1368 (void) FormatLocaleFile(file," \"profiles\": {\n");
cristy9e818982014-01-18 14:54:37 +00001369 while (name != (char *) NULL)
1370 {
1371 profile=GetImageProfile(image,name);
1372 if (profile == (StringInfo *) NULL)
1373 continue;
dirk6c316f22015-06-27 15:44:29 +00001374 if (n++ != 0)
1375 (void) FormatLocaleFile(file,",\n");
1376 JsonFormatLocaleFile(file," %s: {\n",name);
cristy9e818982014-01-18 14:54:37 +00001377 if (LocaleCompare(name,"iptc") == 0)
1378 {
1379 char
1380 *attribute,
1381 **attribute_list;
1382
1383 const char
1384 *tag;
1385
1386 long
1387 dataset,
1388 record,
1389 sentinel;
1390
1391 register ssize_t
1392 j;
1393
1394 size_t
1395 length,
1396 profile_length;
1397
1398 profile_length=GetStringInfoLength(profile);
1399 for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length)
1400 {
1401 length=1;
1402 sentinel=GetStringInfoDatum(profile)[i++];
1403 if (sentinel != 0x1c)
1404 continue;
1405 dataset=GetStringInfoDatum(profile)[i++];
1406 record=GetStringInfoDatum(profile)[i++];
1407 switch (record)
1408 {
1409 case 5: tag="Image Name"; break;
1410 case 7: tag="Edit Status"; break;
1411 case 10: tag="Priority"; break;
1412 case 15: tag="Category"; break;
1413 case 20: tag="Supplemental Category"; break;
1414 case 22: tag="Fixture Identifier"; break;
1415 case 25: tag="Keyword"; break;
1416 case 30: tag="Release Date"; break;
1417 case 35: tag="Release Time"; break;
1418 case 40: tag="Special Instructions"; break;
1419 case 45: tag="Reference Service"; break;
1420 case 47: tag="Reference Date"; break;
1421 case 50: tag="Reference Number"; break;
1422 case 55: tag="Created Date"; break;
1423 case 60: tag="Created Time"; break;
1424 case 65: tag="Originating Program"; break;
1425 case 70: tag="Program Version"; break;
1426 case 75: tag="Object Cycle"; break;
1427 case 80: tag="Byline"; break;
1428 case 85: tag="Byline Title"; break;
1429 case 90: tag="City"; break;
cristya0b0ad32015-07-02 12:33:54 +00001430 case 92: tag="Sub-Location"; break;
cristy9e818982014-01-18 14:54:37 +00001431 case 95: tag="Province State"; break;
1432 case 100: tag="Country Code"; break;
1433 case 101: tag="Country"; break;
1434 case 103: tag="Original Transmission Reference"; break;
1435 case 105: tag="Headline"; break;
1436 case 110: tag="Credit"; break;
1437 case 115: tag="Src"; break;
1438 case 116: tag="Copyright String"; break;
1439 case 120: tag="Caption"; break;
1440 case 121: tag="Local Caption"; break;
1441 case 122: tag="Caption Writer"; break;
1442 case 200: tag="Custom Field 1"; break;
1443 case 201: tag="Custom Field 2"; break;
1444 case 202: tag="Custom Field 3"; break;
1445 case 203: tag="Custom Field 4"; break;
1446 case 204: tag="Custom Field 5"; break;
1447 case 205: tag="Custom Field 6"; break;
1448 case 206: tag="Custom Field 7"; break;
1449 case 207: tag="Custom Field 8"; break;
1450 case 208: tag="Custom Field 9"; break;
1451 case 209: tag="Custom Field 10"; break;
1452 case 210: tag="Custom Field 11"; break;
1453 case 211: tag="Custom Field 12"; break;
1454 case 212: tag="Custom Field 13"; break;
1455 case 213: tag="Custom Field 14"; break;
1456 case 214: tag="Custom Field 15"; break;
1457 case 215: tag="Custom Field 16"; break;
1458 case 216: tag="Custom Field 17"; break;
1459 case 217: tag="Custom Field 18"; break;
1460 case 218: tag="Custom Field 19"; break;
1461 case 219: tag="Custom Field 20"; break;
1462 default: tag="unknown"; break;
1463 }
1464 (void) FormatLocaleFile(file," %s[%.20g,%.20g]: ",tag,
1465 (double) dataset,(double) record);
1466 length=(size_t) (GetStringInfoDatum(profile)[i++] << 8);
1467 length|=GetStringInfoDatum(profile)[i++];
1468 attribute=(char *) NULL;
cristy151b66d2015-04-15 10:50:31 +00001469 if (~length >= (MagickPathExtent-1))
1470 attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent,
cristy9e818982014-01-18 14:54:37 +00001471 sizeof(*attribute));
1472 if (attribute != (char *) NULL)
1473 {
1474 (void) CopyMagickString(attribute,(char *)
1475 GetStringInfoDatum(profile)+i,length+1);
1476 attribute_list=StringToList(attribute);
1477 if (attribute_list != (char **) NULL)
1478 {
dirk6c316f22015-06-27 15:44:29 +00001479 (void) FormatLocaleFile(file,"[");
cristy9e818982014-01-18 14:54:37 +00001480 for (j=0; attribute_list[j] != (char *) NULL; j++)
1481 {
dirk6c316f22015-06-27 15:44:29 +00001482 if (j != 0)
1483 (void) FormatLocaleFile(file,",");
1484 JsonFormatLocaleFile(file,"%s",attribute_list[j]);
cristy9e818982014-01-18 14:54:37 +00001485 attribute_list[j]=(char *) RelinquishMagickMemory(
1486 attribute_list[j]);
1487 }
dirk6c316f22015-06-27 15:44:29 +00001488 (void) FormatLocaleFile(file,"],");
cristy9e818982014-01-18 14:54:37 +00001489 attribute_list=(char **) RelinquishMagickMemory(
1490 attribute_list);
1491 }
dirk6c316f22015-06-27 15:44:29 +00001492 else
1493 (void) FormatLocaleFile(file,"null,");
cristy9e818982014-01-18 14:54:37 +00001494 attribute=DestroyString(attribute);
1495 }
dirk6c316f22015-06-27 15:44:29 +00001496 else
1497 (void) FormatLocaleFile(file,"null,");
cristy9e818982014-01-18 14:54:37 +00001498 }
1499 }
dirk6c316f22015-06-27 15:44:29 +00001500 (void) FormatLocaleFile(file," \"length\": \"%.20g\"",(double)
1501 GetStringInfoLength(profile));
1502 (void) FormatLocaleFile(file,"\n }");
cristy9e818982014-01-18 14:54:37 +00001503 name=GetNextImageProfile(image);
1504 }
dirk6c316f22015-06-27 15:44:29 +00001505 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001506 }
1507 ResetImageArtifactIterator(image);
1508 artifact=GetNextImageArtifact(image);
1509 if (artifact != (const char *) NULL)
1510 {
dirk6c316f22015-06-27 15:44:29 +00001511 ssize_t
1512 n;
1513
cristy9e818982014-01-18 14:54:37 +00001514 /*
1515 Display image artifacts.
1516 */
dirk6c316f22015-06-27 15:44:29 +00001517 n=0;
1518 (void) FormatLocaleFile(file," \"artifacts\": {\n");
cristy9e818982014-01-18 14:54:37 +00001519 while (artifact != (const char *) NULL)
1520 {
dirk6c316f22015-06-27 15:44:29 +00001521 if (n++ != 0)
1522 (void) FormatLocaleFile(file,",\n");
1523 JsonFormatLocaleFile(file," %s: ",artifact);
cristy9e818982014-01-18 14:54:37 +00001524 value=GetImageArtifact(image,artifact);
dirk6c316f22015-06-27 15:44:29 +00001525 JsonFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001526 artifact=GetNextImageArtifact(image);
1527 }
dirk6c316f22015-06-27 15:44:29 +00001528 (void) FormatLocaleFile(file,"\n },\n");
cristy9e818982014-01-18 14:54:37 +00001529 }
1530 ResetImageRegistryIterator();
1531 registry=GetNextImageRegistry();
1532 if (registry != (const char *) NULL)
1533 {
dirk6c316f22015-06-27 15:44:29 +00001534 ssize_t
1535 n;
1536
cristy9e818982014-01-18 14:54:37 +00001537 /*
1538 Display image registry.
1539 */
dirk6c316f22015-06-27 15:44:29 +00001540 (void) FormatLocaleFile(file," \"registry\": {\n");
1541 n=0;
cristy9e818982014-01-18 14:54:37 +00001542 while (registry != (const char *) NULL)
1543 {
dirk6c316f22015-06-27 15:44:29 +00001544 if (n++ != 0)
1545 (void) FormatLocaleFile(file,",\n");
1546 JsonFormatLocaleFile(file," %s: ",registry);
cristy9e818982014-01-18 14:54:37 +00001547 value=(const char *) GetImageRegistry(StringRegistryType,registry,
1548 exception);
dirk6c316f22015-06-27 15:44:29 +00001549 JsonFormatLocaleFile(file,"%s",value);
cristy9e818982014-01-18 14:54:37 +00001550 registry=GetNextImageRegistry();
1551 }
dirk6c316f22015-06-27 15:44:29 +00001552 (void) FormatLocaleFile(file," },\n");
cristy9e818982014-01-18 14:54:37 +00001553 }
dirk6c316f22015-06-27 15:44:29 +00001554 (void) FormatLocaleFile(file," \"tainted\": %s,\n",
1555 image->taint != MagickFalse ? "true" : "false");
cristy151b66d2015-04-15 10:50:31 +00001556 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
cristyd4618c02015-04-14 23:54:43 +00001557 format);
dirk6c316f22015-06-27 15:44:29 +00001558 JsonFormatLocaleFile(file," \"filesize\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001559 (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
cristy151b66d2015-04-15 10:50:31 +00001560 MagickFalse,"B",MagickPathExtent,format);
cristy9e818982014-01-18 14:54:37 +00001561 if (strlen(format) > 1)
1562 format[strlen(format)-1]='\0';
dirk6c316f22015-06-27 15:44:29 +00001563 JsonFormatLocaleFile(file," \"numberPixels\": %s,\n",format);
cristy9e818982014-01-18 14:54:37 +00001564 (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/
cristy151b66d2015-04-15 10:50:31 +00001565 elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format);
dirk6c316f22015-06-27 15:44:29 +00001566 JsonFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format);
1567 (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time);
1568 (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n",
1569 (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
1570 elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor(
1571 elapsed_time))));
Cristy1b79dcd2016-08-03 17:46:41 -04001572 JsonFormatLocaleFile(file," \"version\": %s\n",GetMagickHomeURL());
dirk6c316f22015-06-27 15:44:29 +00001573 (void) FormatLocaleFile(file," }\n}\n");
cristy9e818982014-01-18 14:54:37 +00001574 (void) fflush(file);
1575 return(ferror(file) != 0 ? MagickFalse : MagickTrue);
1576}
1577
cristy3f07aa32014-01-18 01:16:33 +00001578static MagickBooleanType WriteJSONImage(const ImageInfo *image_info,
1579 Image *image,ExceptionInfo *exception)
1580{
dirk6c316f22015-06-27 15:44:29 +00001581 FILE
1582 *file;
1583
cristy3f07aa32014-01-18 01:16:33 +00001584 MagickBooleanType
1585 status;
1586
1587 MagickOffsetType
1588 scene;
1589
1590 /*
1591 Open output image file.
1592 */
1593 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001594 assert(image_info->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001595 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001596 assert(image->signature == MagickCoreSignature);
cristy3f07aa32014-01-18 01:16:33 +00001597 if (image->debug != MagickFalse)
1598 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1599 status=OpenBlob(image_info,image,WriteBlobMode,exception);
1600 if (status == MagickFalse)
1601 return(status);
dirk6c316f22015-06-27 15:44:29 +00001602 file=GetBlobFileHandle(image);
1603 if (file == (FILE *) NULL)
1604 file=stdout;
cristy3f07aa32014-01-18 01:16:33 +00001605 scene=0;
1606 do
1607 {
dirk6c316f22015-06-27 15:44:29 +00001608 WriteBlobString(image,"[");
cristy9e818982014-01-18 14:54:37 +00001609 image->magick_columns=image->columns;
1610 image->magick_rows=image->rows;
dirk6c316f22015-06-27 15:44:29 +00001611 EncodeImageAttributes(image,file,exception);
cristy3f07aa32014-01-18 01:16:33 +00001612 if (GetNextImageInList(image) == (Image *) NULL)
dirk6c316f22015-06-27 15:44:29 +00001613 {
1614 WriteBlobString(image,"]");
1615 break;
1616 }
1617 WriteBlobString(image,",\n");
cristy3f07aa32014-01-18 01:16:33 +00001618 image=SyncNextImageInList(image);
1619 status=SetImageProgress(image,SaveImagesTag,scene++,
1620 GetImageListLength(image));
1621 if (status == MagickFalse)
1622 break;
1623 } while (image_info->adjoin != MagickFalse);
1624 (void) CloseBlob(image);
1625 return(MagickTrue);
1626}