cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1 | /* |
| 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 | % % |
Cristy | 93b707b | 2017-12-06 07:05:51 -0500 | [diff] [blame] | 20 | % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 21 | % 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 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame] | 26 | % https://www.imagemagick.org/script/license.php % |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 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" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 44 | #include "MagickCore/attribute.h" |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 45 | #include "MagickCore/blob.h" |
| 46 | #include "MagickCore/blob-private.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 47 | #include "MagickCore/cache.h" |
cristy | 4360277 | 2014-01-29 14:07:29 +0000 | [diff] [blame] | 48 | #include "MagickCore/colorspace.h" |
| 49 | #include "MagickCore/colorspace-private.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 50 | #include "MagickCore/constitute.h" |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 51 | #include "MagickCore/exception.h" |
| 52 | #include "MagickCore/exception-private.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 53 | #include "MagickCore/feature.h" |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 54 | #include "MagickCore/image.h" |
| 55 | #include "MagickCore/image-private.h" |
| 56 | #include "MagickCore/list.h" |
| 57 | #include "MagickCore/magick.h" |
| 58 | #include "MagickCore/memory_.h" |
| 59 | #include "MagickCore/monitor.h" |
| 60 | #include "MagickCore/monitor-private.h" |
| 61 | #include "MagickCore/option.h" |
cristy | 4360277 | 2014-01-29 14:07:29 +0000 | [diff] [blame] | 62 | #include "MagickCore/pixel.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 63 | #include "MagickCore/pixel-accessor.h" |
cristy | 4360277 | 2014-01-29 14:07:29 +0000 | [diff] [blame] | 64 | #include "MagickCore/pixel-private.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 65 | #include "MagickCore/prepress.h" |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 66 | #include "MagickCore/property.h" |
cristy | 4360277 | 2014-01-29 14:07:29 +0000 | [diff] [blame] | 67 | #include "MagickCore/quantum-private.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 68 | #include "MagickCore/registry.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 69 | #include "MagickCore/signature.h" |
cristy | 4360277 | 2014-01-29 14:07:29 +0000 | [diff] [blame] | 70 | #include "MagickCore/static.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 71 | #include "MagickCore/statistic.h" |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 72 | #include "MagickCore/string_.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 73 | #include "MagickCore/string-private.h" |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 74 | #include "MagickCore/utility.h" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 75 | #include "MagickCore/version.h" |
cristy | 4360277 | 2014-01-29 14:07:29 +0000 | [diff] [blame] | 76 | #include "MagickCore/module.h" |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | Typedef declarations. |
| 80 | */ |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 81 | typedef struct _IPTCInfo |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 82 | { |
| 83 | long |
| 84 | dataset, |
| 85 | record; |
| 86 | |
| 87 | size_t |
| 88 | values_length; |
| 89 | |
| 90 | char |
| 91 | tag[32], |
| 92 | ***values; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 93 | } IPTCInfo; |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | Forward declarations. |
| 97 | */ |
| 98 | static 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 | */ |
| 124 | ModuleExport size_t RegisterJSONImage(void) |
| 125 | { |
| 126 | MagickInfo |
| 127 | *entry; |
| 128 | |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 129 | entry=AcquireMagickInfo("JSON","JSON","The image format and characteristics"); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 130 | entry->encoder=(EncodeImageHandler *) WriteJSONImage; |
dirk | 2aa15e6 | 2015-09-14 21:33:54 +0200 | [diff] [blame] | 131 | entry->mime_type=ConstantString("application/json"); |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 132 | entry->flags^=CoderBlobSupportFlag; |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 133 | (void) RegisterMagickInfo(entry); |
| 134 | return(MagickImageCoderSignature); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 139 | % % |
| 140 | % % |
| 141 | % % |
| 142 | % U n r e g i s t e r J S O N I m a g e % |
| 143 | % % |
| 144 | % % |
| 145 | % % |
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 147 | % |
| 148 | % UnregisterJSONImage() removes format registrations made by the |
| 149 | % JSON module from the list of supported formats. |
| 150 | % |
| 151 | % The format of the UnregisterJSONImage method is: |
| 152 | % |
| 153 | % UnregisterJSONImage(void) |
| 154 | % |
| 155 | */ |
| 156 | ModuleExport void UnregisterJSONImage(void) |
| 157 | { |
| 158 | (void) UnregisterMagickInfo("JSON"); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 163 | % % |
| 164 | % % |
| 165 | % % |
| 166 | % W r i t e J S O N I m a g e % |
| 167 | % % |
| 168 | % % |
| 169 | % % |
| 170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 171 | % |
| 172 | % WriteJSONImage writes the image attributes in the JSON format. |
| 173 | % |
| 174 | % The format of the WriteJSONImage method is: |
| 175 | % |
| 176 | % MagickBooleanType WriteJSONImage(const ImageInfo *image_info, |
| 177 | % Image *image,ExceptionInfo *exception) |
| 178 | % |
| 179 | % A description of each parameter follows. |
| 180 | % |
| 181 | % o image_info: the image info. |
| 182 | % |
| 183 | % o image: The image. |
| 184 | % |
| 185 | % o exception: return any errors or warnings in this structure. |
| 186 | % |
| 187 | */ |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 188 | |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 189 | static void JSONFormatLocaleFile(FILE *file,const char *format, |
| 190 | const char *value) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 191 | { |
| 192 | char |
| 193 | *escaped_json; |
| 194 | |
| 195 | register char |
| 196 | *q; |
| 197 | |
| 198 | register const char |
| 199 | *p; |
| 200 | |
| 201 | size_t |
| 202 | length; |
| 203 | |
| 204 | assert(format != (const char *) NULL); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 205 | if ((value == (char *) NULL) || (*value == '\0')) |
| 206 | { |
| 207 | (void) FormatLocaleFile(file,format,"null"); |
| 208 | return; |
| 209 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 210 | length=strlen(value)+2; |
| 211 | /* |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 212 | Find all the chars that need escaping and increase the dest length counter. |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 213 | */ |
| 214 | for (p=value; *p != '\0'; p++) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 215 | { |
| 216 | switch (*p) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 217 | { |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 218 | case '"': |
| 219 | case '\b': |
| 220 | case '\f': |
| 221 | case '\n': |
| 222 | case '\r': |
| 223 | case '\t': |
| 224 | case '\\': |
| 225 | { |
| 226 | if (~length < 1) |
| 227 | return; |
| 228 | length++; |
| 229 | break; |
| 230 | } |
| 231 | default: |
| 232 | { |
| 233 | if (((int) *p >= 0x00) && ((int) *p <= 0x1f)) |
| 234 | length+=6; |
| 235 | break; |
| 236 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 237 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 238 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 239 | escaped_json=(char *) NULL; |
| 240 | if (~length >= (MagickPathExtent-1)) |
| 241 | escaped_json=(char *) AcquireQuantumMemory(length+MagickPathExtent, |
| 242 | sizeof(*escaped_json)); |
| 243 | if (escaped_json == (char *) NULL) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 244 | { |
| 245 | (void) FormatLocaleFile(file,format,"null"); |
| 246 | return; |
| 247 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 248 | q=escaped_json; |
| 249 | *q++='"'; |
| 250 | for (p=value; *p != '\0'; p++) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 251 | { |
| 252 | switch (*p) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 253 | { |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 254 | case '"': |
| 255 | { |
| 256 | *q++='\\'; |
| 257 | *q++=(*p); |
| 258 | break; |
| 259 | } |
| 260 | case '\b': |
| 261 | { |
| 262 | *q++='\\'; |
| 263 | *q++='b'; |
| 264 | break; |
| 265 | } |
| 266 | case '\f': |
| 267 | { |
| 268 | *q++='\\'; |
| 269 | *q++='f'; |
| 270 | break; |
| 271 | } |
| 272 | case '\n': |
| 273 | { |
| 274 | *q++='\\'; |
| 275 | *q++='n'; |
| 276 | break; |
| 277 | } |
| 278 | case '\r': |
| 279 | { |
| 280 | *q++='\\'; |
| 281 | *q++='r'; |
| 282 | break; |
| 283 | } |
| 284 | case '\t': |
| 285 | { |
| 286 | *q++='\\'; |
| 287 | *q++='t'; |
| 288 | break; |
| 289 | } |
| 290 | case '\\': |
| 291 | { |
| 292 | *q++='\\'; |
| 293 | *q++='\\'; |
| 294 | break; |
| 295 | } |
| 296 | default: |
| 297 | { |
| 298 | if (((int) *p >= 0x00) && ((int) *p <= 0x1f)) |
| 299 | { |
| 300 | (void) FormatLocaleString(q,7,"\\u%04X",(int) *p); |
| 301 | q+=6; |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 302 | break; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 303 | } |
| 304 | *q++=(*p); |
| 305 | break; |
| 306 | } |
| 307 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 308 | } |
| 309 | *q++='"'; |
| 310 | *q='\0'; |
| 311 | (void) FormatLocaleFile(file,format,escaped_json); |
| 312 | (void) DestroyString(escaped_json); |
| 313 | } |
| 314 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 315 | static ChannelStatistics *GetLocationStatistics(const Image *image, |
| 316 | const StatisticType type,ExceptionInfo *exception) |
| 317 | { |
| 318 | ChannelStatistics |
| 319 | *channel_statistics; |
| 320 | |
| 321 | register ssize_t |
| 322 | i; |
| 323 | |
| 324 | ssize_t |
| 325 | y; |
| 326 | |
| 327 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 328 | assert(image->signature == MagickCoreSignature); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 329 | if (image->debug != MagickFalse) |
| 330 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 331 | channel_statistics=(ChannelStatistics *) AcquireQuantumMemory( |
| 332 | MaxPixelChannels+1,sizeof(*channel_statistics)); |
| 333 | if (channel_statistics == (ChannelStatistics *) NULL) |
| 334 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 335 | (void) memset(channel_statistics,0,(MaxPixelChannels+1)* |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 336 | sizeof(*channel_statistics)); |
| 337 | for (i=0; i <= (ssize_t) MaxPixelChannels; i++) |
| 338 | { |
| 339 | switch (type) |
| 340 | { |
| 341 | case MaximumStatistic: |
| 342 | default: |
| 343 | { |
cristy | fe181a7 | 2014-02-02 21:17:43 +0000 | [diff] [blame] | 344 | channel_statistics[i].maxima=(-MagickMaximumValue); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 345 | break; |
| 346 | } |
| 347 | case MinimumStatistic: |
| 348 | { |
cristy | fe181a7 | 2014-02-02 21:17:43 +0000 | [diff] [blame] | 349 | channel_statistics[i].minima=MagickMaximumValue; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 350 | break; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | for (y=0; y < (ssize_t) image->rows; y++) |
| 355 | { |
| 356 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 357 | *magick_restrict p; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 358 | |
| 359 | register ssize_t |
| 360 | x; |
| 361 | |
| 362 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 363 | if (p == (const Quantum *) NULL) |
| 364 | break; |
| 365 | for (x=0; x < (ssize_t) image->columns; x++) |
| 366 | { |
| 367 | register ssize_t |
| 368 | i; |
| 369 | |
Cristy | d05ae9a | 2017-08-12 07:55:19 -0400 | [diff] [blame] | 370 | if (GetPixelReadMask(image,p) <= (QuantumRange/2)) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 371 | { |
| 372 | p+=GetPixelChannels(image); |
| 373 | continue; |
| 374 | } |
| 375 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 376 | { |
Cristy | 3c296d6 | 2017-08-19 20:09:26 -0400 | [diff] [blame] | 377 | PixelChannel channel = GetPixelChannelChannel(image,i); |
| 378 | PixelTrait traits = GetPixelChannelTraits(image,channel); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 379 | if (traits == UndefinedPixelTrait) |
| 380 | continue; |
| 381 | switch (type) |
| 382 | { |
| 383 | case MaximumStatistic: |
| 384 | default: |
| 385 | { |
| 386 | if ((double) p[i] > channel_statistics[channel].maxima) |
| 387 | channel_statistics[channel].maxima=(double) p[i]; |
| 388 | break; |
| 389 | } |
| 390 | case MinimumStatistic: |
| 391 | { |
| 392 | if ((double) p[i] < channel_statistics[channel].minima) |
| 393 | channel_statistics[channel].minima=(double) p[i]; |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | p+=GetPixelChannels(image); |
| 399 | } |
| 400 | } |
| 401 | return(channel_statistics); |
| 402 | } |
| 403 | |
| 404 | static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel, |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 405 | const char *name,const MagickBooleanType separator, |
| 406 | const ChannelFeatures *channel_features) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 407 | { |
| 408 | #define PrintFeature(feature) \ |
| 409 | GetMagickPrecision(),(feature)[0], \ |
| 410 | GetMagickPrecision(),(feature)[1], \ |
| 411 | GetMagickPrecision(),(feature)[2], \ |
| 412 | GetMagickPrecision(),(feature)[3], \ |
| 413 | GetMagickPrecision(),((feature)[0]+(feature)[1]+(feature)[2]+(feature)[3])/4.0 \ |
| 414 | |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 415 | #define FeaturesFormat " \"%s\": {\n" \ |
| 416 | " \"angularSecondMoment\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 417 | " \"horizontal\": %.*g,\n" \ |
| 418 | " \"vertical\": %.*g,\n" \ |
| 419 | " \"leftDiagonal\": %.*g,\n" \ |
| 420 | " \"rightDiagonal\": %.*g,\n" \ |
| 421 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 422 | " },\n" \ |
| 423 | " \"contrast\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 424 | " \"horizontal\": %.*g,\n" \ |
| 425 | " \"vertical\": %.*g,\n" \ |
| 426 | " \"leftDiagonal\": %.*g,\n" \ |
| 427 | " \"rightDiagonal\": %.*g,\n" \ |
| 428 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 429 | " },\n" \ |
| 430 | " \"correlation\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 431 | " \"horizontal\": %.*g,\n" \ |
| 432 | " \"vertical\": %.*g,\n" \ |
| 433 | " \"leftDiagonal\": %.*g,\n" \ |
| 434 | " \"rightDiagonal\": %.*g,\n" \ |
| 435 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 436 | " },\n" \ |
| 437 | " \"sumOfSquaresVariance\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 438 | " \"horizontal\": %.*g,\n" \ |
| 439 | " \"vertical\": %.*g,\n" \ |
| 440 | " \"leftDiagonal\": %.*g,\n" \ |
| 441 | " \"rightDiagonal\": %.*g,\n" \ |
| 442 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 443 | " },\n" \ |
| 444 | " \"inverseDifferenceMoment\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 445 | " \"horizontal\": %.*g,\n" \ |
| 446 | " \"vertical\": %.*g,\n" \ |
| 447 | " \"leftDiagonal\": %.*g,\n" \ |
| 448 | " \"rightDiagonal\": %.*g,\n" \ |
| 449 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 450 | " },\n" \ |
| 451 | " \"sumAverage\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 452 | " \"horizontal\": %.*g,\n" \ |
| 453 | " \"vertical\": %.*g,\n" \ |
| 454 | " \"leftDiagonal\": %.*g,\n" \ |
| 455 | " \"rightDiagonal\": %.*g,\n" \ |
| 456 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 457 | " },\n" \ |
| 458 | " \"sumVariance\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 459 | " \"horizontal\": %.*g,\n" \ |
| 460 | " \"vertical\": %.*g,\n" \ |
| 461 | " \"leftDiagonal\": %.*g,\n" \ |
| 462 | " \"rightDiagonal\": %.*g,\n" \ |
| 463 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 464 | " },\n" \ |
| 465 | " \"sumEntropy\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 466 | " \"horizontal\": %.*g,\n" \ |
| 467 | " \"vertical\": %.*g,\n" \ |
| 468 | " \"leftDiagonal\": %.*g,\n" \ |
| 469 | " \"rightDiagonal\": %.*g,\n" \ |
| 470 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 471 | " },\n" \ |
| 472 | " \"entropy\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 473 | " \"horizontal\": %.*g,\n" \ |
| 474 | " \"vertical\": %.*g,\n" \ |
| 475 | " \"leftDiagonal\": %.*g,\n" \ |
| 476 | " \"rightDiagonal\": %.*g,\n" \ |
| 477 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 478 | " },\n" \ |
| 479 | " \"differenceVariance\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 480 | " \"horizontal\": %.*g,\n" \ |
| 481 | " \"vertical\": %.*g,\n" \ |
| 482 | " \"leftDiagonal\": %.*g,\n" \ |
| 483 | " \"rightDiagonal\": %.*g,\n" \ |
| 484 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 485 | " },\n" \ |
| 486 | " \"differenceEntropy\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 487 | " \"horizontal\": %.*g,\n" \ |
| 488 | " \"vertical\": %.*g,\n" \ |
| 489 | " \"leftDiagonal\": %.*g,\n" \ |
| 490 | " \"rightDiagonal\": %.*g,\n" \ |
| 491 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 492 | " },\n" \ |
| 493 | " \"informationMeasureOfCorrelation1\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 494 | " \"horizontal\": %.*g,\n" \ |
| 495 | " \"vertical\": %.*g,\n" \ |
| 496 | " \"leftDiagonal\": %.*g,\n" \ |
| 497 | " \"rightDiagonal\": %.*g,\n" \ |
| 498 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 499 | " },\n" \ |
| 500 | " \"informationMeasureOfCorrelation2\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 501 | " \"horizontal\": %.*g,\n" \ |
| 502 | " \"vertical\": %.*g,\n" \ |
| 503 | " \"leftDiagonal\": %.*g,\n" \ |
| 504 | " \"rightDiagonal\": %.*g,\n" \ |
| 505 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 506 | " },\n" \ |
| 507 | " \"maximumCorrelationCoefficient\": {\n" \ |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 508 | " \"horizontal\": %.*g,\n" \ |
| 509 | " \"vertical\": %.*g,\n" \ |
| 510 | " \"leftDiagonal\": %.*g,\n" \ |
| 511 | " \"rightDiagonal\": %.*g,\n" \ |
| 512 | " \"average\": %.*g\n" \ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 513 | " }\n" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 514 | |
| 515 | ssize_t |
| 516 | n; |
| 517 | |
| 518 | n=FormatLocaleFile(file,FeaturesFormat,name, |
| 519 | PrintFeature(channel_features[channel].angular_second_moment), |
| 520 | PrintFeature(channel_features[channel].contrast), |
| 521 | PrintFeature(channel_features[channel].correlation), |
| 522 | PrintFeature(channel_features[channel].variance_sum_of_squares), |
| 523 | PrintFeature(channel_features[channel].inverse_difference_moment), |
| 524 | PrintFeature(channel_features[channel].sum_average), |
| 525 | PrintFeature(channel_features[channel].sum_variance), |
| 526 | PrintFeature(channel_features[channel].sum_entropy), |
| 527 | PrintFeature(channel_features[channel].entropy), |
| 528 | PrintFeature(channel_features[channel].difference_variance), |
| 529 | PrintFeature(channel_features[channel].difference_entropy), |
| 530 | PrintFeature(channel_features[channel].measure_of_correlation_1), |
| 531 | PrintFeature(channel_features[channel].measure_of_correlation_2), |
| 532 | PrintFeature(channel_features[channel].maximum_correlation_coefficient)); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 533 | (void) FormatLocaleFile(file," }"); |
| 534 | if (separator != MagickFalse) |
| 535 | (void) FormatLocaleFile(file,","); |
| 536 | (void) FormatLocaleFile(file,"\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 537 | return(n); |
| 538 | } |
| 539 | |
| 540 | static ssize_t PrintChannelLocations(FILE *file,const Image *image, |
| 541 | const PixelChannel channel,const char *name,const StatisticType type, |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 542 | const size_t max_locations,const MagickBooleanType separator, |
| 543 | const ChannelStatistics *channel_statistics) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 544 | { |
| 545 | double |
| 546 | target; |
| 547 | |
| 548 | ExceptionInfo |
| 549 | *exception; |
| 550 | |
| 551 | ssize_t |
| 552 | n, |
| 553 | y; |
| 554 | |
| 555 | switch (type) |
| 556 | { |
| 557 | case MaximumStatistic: |
| 558 | default: |
| 559 | { |
| 560 | target=channel_statistics[channel].maxima; |
| 561 | break; |
| 562 | } |
| 563 | case MinimumStatistic: |
| 564 | { |
| 565 | target=channel_statistics[channel].minima; |
| 566 | break; |
| 567 | } |
| 568 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 569 | (void) FormatLocaleFile(file," \"%s\": {\n \"intensity\": " |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 570 | "%.*g,\n",name,GetMagickPrecision(),QuantumScale*target); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 571 | exception=AcquireExceptionInfo(); |
| 572 | n=0; |
| 573 | for (y=0; y < (ssize_t) image->rows; y++) |
| 574 | { |
| 575 | register const Quantum |
| 576 | *p; |
| 577 | |
| 578 | ssize_t |
| 579 | offset, |
| 580 | x; |
| 581 | |
| 582 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 583 | if (p == (const Quantum *) NULL) |
| 584 | break; |
| 585 | for (x=0; x < (ssize_t) image->columns; x++) |
| 586 | { |
| 587 | MagickBooleanType |
| 588 | match; |
| 589 | |
Cristy | 3c296d6 | 2017-08-19 20:09:26 -0400 | [diff] [blame] | 590 | PixelTrait traits = GetPixelChannelTraits(image,channel); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 591 | if (traits == UndefinedPixelTrait) |
| 592 | continue; |
| 593 | offset=GetPixelChannelOffset(image,channel); |
cristy | 3bdd925 | 2014-12-21 20:01:43 +0000 | [diff] [blame] | 594 | match=fabs((double) (p[offset]-target)) < 0.5 ? MagickTrue : MagickFalse; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 595 | if (match != MagickFalse) |
| 596 | { |
| 597 | if ((max_locations != 0) && (n >= (ssize_t) max_locations)) |
| 598 | break; |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 599 | if (n != 0) |
| 600 | (void) FormatLocaleFile(file,",\n"); |
| 601 | (void) FormatLocaleFile(file," \"location%.20g\": {\n" |
| 602 | " \"x\": %.20g,\n \"y\": %.20g\n" |
| 603 | " }",(double) n,(double) x,(double) y); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 604 | n++; |
| 605 | } |
| 606 | p+=GetPixelChannels(image); |
| 607 | } |
| 608 | if (x < (ssize_t) image->columns) |
| 609 | break; |
| 610 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 611 | (void) FormatLocaleFile(file,"\n }"); |
| 612 | if (separator != MagickFalse) |
| 613 | (void) FormatLocaleFile(file,","); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 614 | (void) FormatLocaleFile(file,"\n"); |
| 615 | return(n); |
| 616 | } |
| 617 | |
| 618 | static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel, |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 619 | const char *name,const MagickBooleanType separator, |
| 620 | const ChannelMoments *channel_moments) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 621 | { |
| 622 | register ssize_t |
| 623 | i; |
| 624 | |
| 625 | ssize_t |
| 626 | n; |
| 627 | |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 628 | n=FormatLocaleFile(file," \"%s\": {\n",name); |
| 629 | n+=FormatLocaleFile(file," \"centroid\": {\n " |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 630 | " \"x\": %.*g,\n" |
| 631 | " \"y\": %.*g\n },\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 632 | GetMagickPrecision(),channel_moments[channel].centroid.x, |
| 633 | GetMagickPrecision(),channel_moments[channel].centroid.y); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 634 | n+=FormatLocaleFile(file," \"ellipseSemiMajorMinorAxis\": {\n" |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 635 | " \"x\": %.*g,\n" |
| 636 | " \"y\": %.*g\n },\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 637 | GetMagickPrecision(),channel_moments[channel].ellipse_axis.x, |
| 638 | GetMagickPrecision(),channel_moments[channel].ellipse_axis.y); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 639 | n+=FormatLocaleFile(file," \"ellipseAngle\": %.*g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 640 | GetMagickPrecision(),channel_moments[channel].ellipse_angle); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 641 | n+=FormatLocaleFile(file," \"ellipseEccentricity\": %.*g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 642 | GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 643 | n+=FormatLocaleFile(file," \"ellipseIntensity\": %.*g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 644 | GetMagickPrecision(),channel_moments[channel].ellipse_intensity); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 645 | for (i=0; i < 7; i++) |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 646 | n+=FormatLocaleFile(file," \"I%.20g\": %.*g,\n",i+1.0, |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 647 | GetMagickPrecision(),channel_moments[channel].invariant[i]); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 648 | n+=FormatLocaleFile(file," \"I%.20g\": %.*g\n",i+1.0, |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 649 | GetMagickPrecision(),channel_moments[channel].invariant[i]); |
| 650 | (void) FormatLocaleFile(file," }"); |
| 651 | if (separator != MagickFalse) |
| 652 | (void) FormatLocaleFile(file,","); |
| 653 | (void) FormatLocaleFile(file,"\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 654 | return(n); |
| 655 | } |
| 656 | |
Cristy | e696180 | 2016-09-03 11:31:13 -0400 | [diff] [blame] | 657 | static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file, |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 658 | const ChannelPerceptualHash *channel_phash) |
| 659 | { |
| 660 | register ssize_t |
| 661 | i; |
| 662 | |
| 663 | ssize_t |
Cristy | 69a7c2b | 2016-12-24 11:22:36 -0500 | [diff] [blame] | 664 | n = 0; |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 665 | |
Cristy | e696180 | 2016-09-03 11:31:13 -0400 | [diff] [blame] | 666 | (void) FormatLocaleFile(file," \"colorspaces\": [ "); |
| 667 | for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++) |
| 668 | { |
| 669 | (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic( |
| 670 | MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i])); |
| 671 | if (i < (ssize_t) (channel_phash[0].number_colorspaces-1)) |
| 672 | (void) FormatLocaleFile(file,", "); |
| 673 | } |
| 674 | (void) FormatLocaleFile(file,"],\n"); |
| 675 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 676 | { |
| 677 | register ssize_t |
| 678 | j; |
| 679 | |
Cristy | 3c296d6 | 2017-08-19 20:09:26 -0400 | [diff] [blame] | 680 | PixelChannel channel = GetPixelChannelChannel(image,i); |
| 681 | PixelTrait traits = GetPixelChannelTraits(image,channel); |
Cristy | e696180 | 2016-09-03 11:31:13 -0400 | [diff] [blame] | 682 | if (traits == UndefinedPixelTrait) |
| 683 | continue; |
| 684 | n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel); |
| 685 | for (j=0; j < MaximumNumberOfPerceptualHashes; j++) |
| 686 | { |
| 687 | register ssize_t |
| 688 | k; |
| 689 | |
| 690 | n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1); |
| 691 | for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++) |
| 692 | { |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 693 | n+=FormatLocaleFile(file,"%.*g",GetMagickPrecision(), |
Cristy | e696180 | 2016-09-03 11:31:13 -0400 | [diff] [blame] | 694 | channel_phash[channel].phash[k][j]); |
| 695 | if (k < (ssize_t) (channel_phash[0].number_colorspaces-1)) |
| 696 | n+=FormatLocaleFile(file,", "); |
| 697 | } |
| 698 | n+=FormatLocaleFile(file,"]"); |
| 699 | if (j < (MaximumNumberOfPerceptualHashes-1)) |
| 700 | n+=FormatLocaleFile(file,",\n"); |
| 701 | } |
Cristy | 338f088 | 2016-12-10 12:12:35 -0500 | [diff] [blame] | 702 | if (i < (ssize_t) (GetPixelChannels(image)-1)) |
Cristy | e696180 | 2016-09-03 11:31:13 -0400 | [diff] [blame] | 703 | n+=FormatLocaleFile(file,"\n },\n"); |
| 704 | } |
| 705 | n+=FormatLocaleFile(file,"\n }\n"); |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 706 | return(n); |
| 707 | } |
| 708 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 709 | static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel, |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 710 | const char *name,const double scale,const MagickBooleanType separator, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 711 | const ChannelStatistics *channel_statistics) |
| 712 | { |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 713 | #define StatisticsFormat " \"%s\": {\n \"min\": %.*g,\n" \ |
| 714 | " \"max\": %.*g,\n \"mean\": %.*g,\n " \ |
| 715 | "\"standardDeviation\": %.*g,\n \"kurtosis\": %.*g,\n "\ |
| 716 | "\"skewness\": %.*g,\n \"entropy\": %.*g\n }" |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 717 | |
| 718 | ssize_t |
| 719 | n; |
| 720 | |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 721 | n=FormatLocaleFile(file,StatisticsFormat,name,GetMagickPrecision(), |
| 722 | (double) ClampToQuantum(scale*channel_statistics[channel].minima), |
| 723 | GetMagickPrecision(),(double) ClampToQuantum(scale* |
| 724 | channel_statistics[channel].maxima),GetMagickPrecision(),scale* |
| 725 | channel_statistics[channel].mean,GetMagickPrecision(),scale* |
| 726 | channel_statistics[channel].standard_deviation,GetMagickPrecision(), |
| 727 | channel_statistics[channel].kurtosis,GetMagickPrecision(), |
| 728 | channel_statistics[channel].skewness,GetMagickPrecision(), |
| 729 | channel_statistics[channel].entropy); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 730 | if (separator != MagickFalse) |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 731 | (void) FormatLocaleFile(file,","); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 732 | (void) FormatLocaleFile(file,"\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 733 | return(n); |
| 734 | } |
| 735 | |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 736 | static void EncodeIptcProfile(FILE *file,const StringInfo *profile) |
| 737 | { |
| 738 | char |
| 739 | *attribute, |
| 740 | **attribute_list; |
| 741 | |
| 742 | const char |
| 743 | *tag; |
| 744 | |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 745 | IPTCInfo |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 746 | *value, |
| 747 | **values; |
| 748 | |
| 749 | long |
| 750 | dataset, |
| 751 | record, |
| 752 | sentinel; |
| 753 | |
| 754 | register ssize_t |
| 755 | i, |
| 756 | j, |
| 757 | k; |
| 758 | |
| 759 | size_t |
| 760 | count, |
| 761 | length, |
| 762 | profile_length; |
| 763 | |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 764 | values=(IPTCInfo **) NULL; |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 765 | count=0; |
| 766 | profile_length=GetStringInfoLength(profile); |
| 767 | for (i=0; i < (ssize_t) profile_length; i+=(ssize_t) length) |
| 768 | { |
| 769 | length=1; |
| 770 | sentinel=GetStringInfoDatum(profile)[i++]; |
| 771 | if (sentinel != 0x1c) |
| 772 | continue; |
| 773 | dataset=GetStringInfoDatum(profile)[i++]; |
| 774 | record=GetStringInfoDatum(profile)[i++]; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 775 | value=(IPTCInfo *) NULL; |
Cristy | 7c7050a | 2017-09-30 12:12:21 -0400 | [diff] [blame] | 776 | for (j=0; j < (ssize_t) count; j++) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 777 | { |
| 778 | if ((values[j]->record == record) && (values[j]->dataset == dataset)) |
| 779 | value=values[j]; |
| 780 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 781 | if (value == (IPTCInfo *) NULL) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 782 | { |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 783 | values=(IPTCInfo **) ResizeQuantumMemory(values,count+1, |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 784 | sizeof(*values)); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 785 | if (values == (IPTCInfo **) NULL) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 786 | break; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 787 | value=(IPTCInfo *) AcquireMagickMemory(sizeof(*value)); |
| 788 | if (value == (IPTCInfo *) NULL) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 789 | break; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 790 | /* Check the tag length in IPTCInfo when a new tag is added */ |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 791 | switch (record) |
| 792 | { |
| 793 | case 5: tag="Image Name"; break; |
| 794 | case 7: tag="Edit Status"; break; |
| 795 | case 10: tag="Priority"; break; |
| 796 | case 15: tag="Category"; break; |
| 797 | case 20: tag="Supplemental Category"; break; |
| 798 | case 22: tag="Fixture Identifier"; break; |
| 799 | case 25: tag="Keyword"; break; |
| 800 | case 30: tag="Release Date"; break; |
| 801 | case 35: tag="Release Time"; break; |
| 802 | case 40: tag="Special Instructions"; break; |
| 803 | case 45: tag="Reference Service"; break; |
| 804 | case 47: tag="Reference Date"; break; |
| 805 | case 50: tag="Reference Number"; break; |
| 806 | case 55: tag="Created Date"; break; |
| 807 | case 60: tag="Created Time"; break; |
| 808 | case 65: tag="Originating Program"; break; |
| 809 | case 70: tag="Program Version"; break; |
| 810 | case 75: tag="Object Cycle"; break; |
| 811 | case 80: tag="Byline"; break; |
| 812 | case 85: tag="Byline Title"; break; |
| 813 | case 90: tag="City"; break; |
| 814 | case 92: tag="Sub-Location"; break; |
| 815 | case 95: tag="Province State"; break; |
| 816 | case 100: tag="Country Code"; break; |
| 817 | case 101: tag="Country"; break; |
| 818 | case 103: tag="Original Transmission Reference"; break; |
| 819 | case 105: tag="Headline"; break; |
| 820 | case 110: tag="Credit"; break; |
| 821 | case 115: tag="Src"; break; |
| 822 | case 116: tag="Copyright String"; break; |
| 823 | case 120: tag="Caption"; break; |
| 824 | case 121: tag="Local Caption"; break; |
| 825 | case 122: tag="Caption Writer"; break; |
| 826 | case 200: tag="Custom Field 1"; break; |
| 827 | case 201: tag="Custom Field 2"; break; |
| 828 | case 202: tag="Custom Field 3"; break; |
| 829 | case 203: tag="Custom Field 4"; break; |
| 830 | case 204: tag="Custom Field 5"; break; |
| 831 | case 205: tag="Custom Field 6"; break; |
| 832 | case 206: tag="Custom Field 7"; break; |
| 833 | case 207: tag="Custom Field 8"; break; |
| 834 | case 208: tag="Custom Field 9"; break; |
| 835 | case 209: tag="Custom Field 10"; break; |
| 836 | case 210: tag="Custom Field 11"; break; |
| 837 | case 211: tag="Custom Field 12"; break; |
| 838 | case 212: tag="Custom Field 13"; break; |
| 839 | case 213: tag="Custom Field 14"; break; |
| 840 | case 214: tag="Custom Field 15"; break; |
| 841 | case 215: tag="Custom Field 16"; break; |
| 842 | case 216: tag="Custom Field 17"; break; |
| 843 | case 217: tag="Custom Field 18"; break; |
| 844 | case 218: tag="Custom Field 19"; break; |
| 845 | case 219: tag="Custom Field 20"; break; |
| 846 | default: tag="Unknown"; break; |
| 847 | } |
| 848 | (void) CopyMagickString(value->tag,tag,strlen(tag)+1); |
| 849 | value->record=record; |
| 850 | value->dataset=dataset; |
| 851 | value->values=(char ***) NULL; |
| 852 | value->values_length=0; |
| 853 | values[count++]=value; |
| 854 | } |
| 855 | length=(size_t) (GetStringInfoDatum(profile)[i++] << 8); |
| 856 | length|=GetStringInfoDatum(profile)[i++]; |
| 857 | attribute=(char *) NULL; |
| 858 | if (~length >= (MagickPathExtent-1)) |
| 859 | attribute=(char *) AcquireQuantumMemory(length+MagickPathExtent, |
| 860 | sizeof(*attribute)); |
| 861 | if (attribute != (char *) NULL) |
| 862 | { |
| 863 | (void) CopyMagickString(attribute,(char *) |
| 864 | GetStringInfoDatum(profile)+i,length+1); |
| 865 | attribute_list=StringToList(attribute); |
| 866 | if (attribute_list != (char **) NULL) |
| 867 | { |
| 868 | value->values=(char ***) ResizeQuantumMemory(value->values, |
| 869 | value->values_length+1, |
| 870 | sizeof(*value->values)); |
| 871 | if (value->values == (char ***) NULL) |
| 872 | break; |
| 873 | value->values[value->values_length++]=attribute_list; |
| 874 | } |
| 875 | attribute=DestroyString(attribute); |
| 876 | } |
| 877 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 878 | if (values != (IPTCInfo **) NULL) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 879 | { |
Cristy | 7c7050a | 2017-09-30 12:12:21 -0400 | [diff] [blame] | 880 | for (i=0; i < (ssize_t) count; i++) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 881 | { |
| 882 | value=values[i]; |
| 883 | (void) FormatLocaleFile(file," \"%s[%.20g,%.20g]\": ", |
| 884 | value->tag,(double) value->dataset,(double) value->record); |
| 885 | if (value->values_length == 0) |
| 886 | (void) FormatLocaleFile(file,"null,"); |
| 887 | else |
| 888 | { |
| 889 | (void) FormatLocaleFile(file,"["); |
Cristy | 7c7050a | 2017-09-30 12:12:21 -0400 | [diff] [blame] | 890 | for (j=0; j < (ssize_t) value->values_length; j++) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 891 | { |
| 892 | for (k=0; value->values[j][k] != (char *) NULL; k++) |
| 893 | { |
| 894 | if (j > 0 || k > 0) |
| 895 | (void) FormatLocaleFile(file,","); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 896 | JSONFormatLocaleFile(file,"%s",value->values[j][k]); |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 897 | value->values[j][k]=(char *) RelinquishMagickMemory( |
| 898 | value->values[j][k]); |
| 899 | } |
| 900 | value->values[j]=(char **) RelinquishMagickMemory( |
| 901 | value->values[j]); |
| 902 | } |
| 903 | value->values=(char ***) RelinquishMagickMemory(value->values); |
| 904 | (void) FormatLocaleFile(file,"],\n"); |
| 905 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 906 | values[i]=(IPTCInfo *) RelinquishMagickMemory(values[i]); |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 907 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 908 | values=(IPTCInfo **) RelinquishMagickMemory(values); |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 912 | static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file, |
| 913 | ExceptionInfo *exception) |
| 914 | { |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 915 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 916 | color[MagickPathExtent], |
| 917 | format[MagickPathExtent], |
| 918 | key[MagickPathExtent]; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 919 | |
| 920 | ChannelFeatures |
| 921 | *channel_features; |
| 922 | |
| 923 | ChannelMoments |
| 924 | *channel_moments; |
| 925 | |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 926 | ChannelPerceptualHash |
| 927 | *channel_phash; |
| 928 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 929 | ChannelStatistics |
| 930 | *channel_statistics; |
| 931 | |
Cristy | 519e005 | 2016-10-16 15:28:40 -0400 | [diff] [blame] | 932 | char |
| 933 | *url; |
| 934 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 935 | const char |
| 936 | *artifact, |
| 937 | *locate, |
| 938 | *name, |
| 939 | *property, |
| 940 | *registry, |
| 941 | *value; |
| 942 | |
| 943 | const MagickInfo |
| 944 | *magick_info; |
| 945 | |
| 946 | double |
| 947 | elapsed_time, |
| 948 | user_time; |
| 949 | |
| 950 | ImageType |
| 951 | type; |
| 952 | |
| 953 | MagickBooleanType |
| 954 | ping; |
| 955 | |
| 956 | register const Quantum |
| 957 | *p; |
| 958 | |
| 959 | register ssize_t |
| 960 | i, |
| 961 | x; |
| 962 | |
| 963 | size_t |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 964 | depth, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 965 | distance, |
| 966 | scale; |
| 967 | |
| 968 | ssize_t |
| 969 | y; |
| 970 | |
| 971 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 972 | assert(image->signature == MagickCoreSignature); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 973 | if (image->debug != MagickFalse) |
| 974 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 975 | *format='\0'; |
| 976 | elapsed_time=GetElapsedTime(&image->timer); |
| 977 | user_time=GetUserTime(&image->timer); |
| 978 | GetTimerInfo(&image->timer); |
| 979 | p=GetVirtualPixels(image,0,0,1,1,exception); |
| 980 | ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse; |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 981 | (void) ping; |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 982 | (void) SignatureImage(image,exception); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 983 | JSONFormatLocaleFile(file,"{\n \"image\": {\n \"name\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 984 | image->filename); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 985 | if (*image->magick_filename != '\0') |
| 986 | if (LocaleCompare(image->magick_filename,image->filename) != 0) |
| 987 | { |
| 988 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 989 | filename[MagickPathExtent]; |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 990 | |
| 991 | GetPathComponent(image->magick_filename,TailPath,filename); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 992 | JSONFormatLocaleFile(file," \"baseName\": %s,\n",filename); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 993 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 994 | JSONFormatLocaleFile(file," \"format\": %s,\n",image->magick); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 995 | magick_info=GetMagickInfo(image->magick,exception); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 996 | if ((magick_info != (const MagickInfo *) NULL) && |
| 997 | (GetMagickDescription(magick_info) != (const char *) NULL)) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 998 | JSONFormatLocaleFile(file," \"formatDescription\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 999 | image->magick); |
cristy | 12bcd3d | 2015-01-28 00:54:23 +0000 | [diff] [blame] | 1000 | if ((magick_info != (const MagickInfo *) NULL) && |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1001 | (GetMagickMimeType(magick_info) != (const char *) NULL)) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1002 | JSONFormatLocaleFile(file," \"mimeType\": %s,\n",GetMagickMimeType( |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1003 | magick_info)); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1004 | JSONFormatLocaleFile(file," \"class\": %s,\n",CommandOptionToMnemonic( |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1005 | MagickClassOptions,(ssize_t) image->storage_class)); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1006 | (void) FormatLocaleFile(file," \"geometry\": {\n" |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1007 | " \"width\": %g,\n \"height\": %g,\n" |
| 1008 | " \"x\": %g,\n \"y\": %g\n },\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1009 | (double) image->columns,(double) image->rows,(double) image->tile_offset.x, |
| 1010 | (double) image->tile_offset.y); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1011 | if ((image->magick_columns != 0) || (image->magick_rows != 0)) |
| 1012 | if ((image->magick_columns != image->columns) || |
| 1013 | (image->magick_rows != image->rows)) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1014 | (void) FormatLocaleFile(file," \"baseGeometry\": {\n" |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1015 | " \"width\": %g,\n \"height\": %g\n },\n",(double) |
| 1016 | image->magick_columns,(double) image->magick_rows); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1017 | if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0)) |
| 1018 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1019 | (void) FormatLocaleFile(file," \"resolution\": {\n" |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1020 | " \"x\": %g,\n \"y\": %g\n },\n",image->resolution.x, |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1021 | image->resolution.y); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1022 | (void) FormatLocaleFile(file," \"printSize\": {\n" |
| 1023 | " \"x\": %.*g,\n \"y\": %.*g\n },\n",GetMagickPrecision(), |
| 1024 | image->columns/image->resolution.x,GetMagickPrecision(),(double) |
| 1025 | image->rows/image->resolution.y); |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1026 | } |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1027 | JSONFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic( |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1028 | MagickResolutionOptions,(ssize_t) image->units)); |
Cristy | 95ab389 | 2017-12-24 09:34:52 -0500 | [diff] [blame] | 1029 | type=IdentifyImageType(image,exception); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1030 | JSONFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic( |
cristy | a10f744 | 2014-01-19 18:32:15 +0000 | [diff] [blame] | 1031 | MagickTypeOptions,(ssize_t) type)); |
Cristy | 4826fb4 | 2017-12-17 12:05:09 -0500 | [diff] [blame] | 1032 | if (image->type != type) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1033 | JSONFormatLocaleFile(file," \"baseType\": %s,\n", |
Cristy | 4826fb4 | 2017-12-17 12:05:09 -0500 | [diff] [blame] | 1034 | CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) image->type)); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1035 | JSONFormatLocaleFile(file," \"endianess\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1036 | CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1037 | locate=GetImageArtifact(image,"identify:locate"); |
cristy | 3e583dd | 2014-01-19 14:11:51 +0000 | [diff] [blame] | 1038 | if (locate == (const char *) NULL) |
| 1039 | locate=GetImageArtifact(image,"json:locate"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1040 | if (locate != (const char *) NULL) |
| 1041 | { |
| 1042 | const char |
| 1043 | *limit; |
| 1044 | |
| 1045 | size_t |
| 1046 | max_locations; |
| 1047 | |
| 1048 | StatisticType |
| 1049 | type; |
| 1050 | |
| 1051 | /* |
| 1052 | Display minimum, maximum, or mean pixel locations. |
| 1053 | */ |
| 1054 | type=(StatisticType) ParseCommandOption(MagickStatisticOptions, |
| 1055 | MagickFalse,locate); |
| 1056 | limit=GetImageArtifact(image,"identify:limit"); |
cristy | 3e583dd | 2014-01-19 14:11:51 +0000 | [diff] [blame] | 1057 | if (limit == (const char *) NULL) |
| 1058 | limit=GetImageArtifact(image,"json:limit"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1059 | max_locations=0; |
| 1060 | if (limit != (const char *) NULL) |
| 1061 | max_locations=StringToUnsignedLong(limit); |
| 1062 | channel_statistics=GetLocationStatistics(image,type,exception); |
| 1063 | if (channel_statistics == (ChannelStatistics *) NULL) |
| 1064 | return(MagickFalse); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1065 | (void) FormatLocaleFile(file," \"channel%s\": {\n",locate); |
| 1066 | if (image->alpha_trait != UndefinedPixelTrait) |
| 1067 | (void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha", |
| 1068 | type,max_locations,MagickTrue,channel_statistics); |
Cristy | 3889d15 | 2017-12-22 19:42:13 -0500 | [diff] [blame] | 1069 | switch (image->colorspace) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1070 | { |
| 1071 | case RGBColorspace: |
| 1072 | default: |
| 1073 | { |
| 1074 | (void) PrintChannelLocations(file,image,RedPixelChannel,"Red", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1075 | type,max_locations,MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1076 | (void) PrintChannelLocations(file,image,GreenPixelChannel,"Green", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1077 | type,max_locations,MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1078 | (void) PrintChannelLocations(file,image,BluePixelChannel,"Blue", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1079 | type,max_locations,MagickFalse,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1080 | break; |
| 1081 | } |
| 1082 | case CMYKColorspace: |
| 1083 | { |
| 1084 | (void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1085 | type,max_locations,MagickTrue,channel_statistics); |
Cristy | 95ab389 | 2017-12-24 09:34:52 -0500 | [diff] [blame] | 1086 | (void) PrintChannelLocations(file,image,MagentaPixelChannel, |
| 1087 | "Magenta",type,max_locations,MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1088 | (void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1089 | type,max_locations,MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1090 | (void) PrintChannelLocations(file,image,BlackPixelChannel,"Black", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1091 | type,max_locations,MagickFalse,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1092 | break; |
| 1093 | } |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 1094 | case LinearGRAYColorspace: |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1095 | case GRAYColorspace: |
| 1096 | { |
| 1097 | (void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1098 | type,max_locations,MagickFalse,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | } |
| 1101 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1102 | (void) FormatLocaleFile(file," },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1103 | channel_statistics=(ChannelStatistics *) RelinquishMagickMemory( |
| 1104 | channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1105 | } |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1106 | /* |
| 1107 | Detail channel depth and extrema. |
| 1108 | */ |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1109 | JSONFormatLocaleFile(file," \"colorspace\": %s,\n", |
Cristy | 3889d15 | 2017-12-22 19:42:13 -0500 | [diff] [blame] | 1110 | CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) |
| 1111 | image->colorspace)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1112 | channel_statistics=(ChannelStatistics *) NULL; |
| 1113 | channel_moments=(ChannelMoments *) NULL; |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 1114 | channel_phash=(ChannelPerceptualHash *) NULL; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1115 | channel_features=(ChannelFeatures *) NULL; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1116 | scale=1; |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1117 | channel_statistics=GetImageStatistics(image,exception); |
| 1118 | if (channel_statistics == (ChannelStatistics *) NULL) |
| 1119 | return(MagickFalse); |
| 1120 | artifact=GetImageArtifact(image,"identify:moments"); |
| 1121 | if (artifact == (const char *) NULL) |
| 1122 | artifact=GetImageArtifact(image,"json:moments"); |
| 1123 | if (artifact != (const char *) NULL) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1124 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1125 | channel_moments=GetImageMoments(image,exception); |
| 1126 | channel_phash=GetImagePerceptualHash(image,exception); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1127 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1128 | artifact=GetImageArtifact(image,"identify:features"); |
| 1129 | if (artifact == (const char *) NULL) |
| 1130 | artifact=GetImageArtifact(image,"json:features"); |
| 1131 | if (artifact != (const char *) NULL) |
| 1132 | { |
| 1133 | distance=StringToUnsignedLong(artifact); |
| 1134 | channel_features=GetImageFeatures(image,distance,exception); |
| 1135 | } |
| 1136 | depth=GetImageDepth(image,exception); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1137 | (void) FormatLocaleFile(file," \"depth\": %g,\n",(double) depth); |
| 1138 | (void) FormatLocaleFile(file," \"baseDepth\": %g,\n",(double) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1139 | image->depth); |
| 1140 | (void) FormatLocaleFile(file," \"channelDepth\": {\n"); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1141 | if (image->alpha_trait != UndefinedPixelTrait) |
| 1142 | (void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double) |
| 1143 | channel_statistics[AlphaPixelChannel].depth); |
Cristy | 3889d15 | 2017-12-22 19:42:13 -0500 | [diff] [blame] | 1144 | switch (image->colorspace) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1145 | { |
| 1146 | case RGBColorspace: |
| 1147 | default: |
| 1148 | { |
| 1149 | (void) FormatLocaleFile(file," \"red\": %.20g,\n",(double) |
| 1150 | channel_statistics[RedChannel].depth); |
| 1151 | (void) FormatLocaleFile(file," \"green\": %.20g,\n",(double) |
| 1152 | channel_statistics[GreenChannel].depth); |
| 1153 | (void) FormatLocaleFile(file," \"blue\": %.20g\n",(double) |
| 1154 | channel_statistics[BlueChannel].depth); |
| 1155 | break; |
| 1156 | } |
| 1157 | case CMYKColorspace: |
| 1158 | { |
| 1159 | (void) FormatLocaleFile(file," \"cyan\": %.20g,\n",(double) |
| 1160 | channel_statistics[CyanChannel].depth); |
| 1161 | (void) FormatLocaleFile(file," \"magenta\": %.20g,\n",(double) |
| 1162 | channel_statistics[MagentaChannel].depth); |
| 1163 | (void) FormatLocaleFile(file," \"yellow\": %.20g,\n",(double) |
| 1164 | channel_statistics[YellowChannel].depth); |
| 1165 | (void) FormatLocaleFile(file," \"black\": %.20g\n",(double) |
| 1166 | channel_statistics[BlackChannel].depth); |
| 1167 | break; |
| 1168 | } |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 1169 | case LinearGRAYColorspace: |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1170 | case GRAYColorspace: |
| 1171 | { |
| 1172 | (void) FormatLocaleFile(file," \"gray\": %.20g\n",(double) |
| 1173 | channel_statistics[GrayChannel].depth); |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | (void) FormatLocaleFile(file," },\n"); |
| 1178 | scale=1; |
| 1179 | if (image->depth <= MAGICKCORE_QUANTUM_DEPTH) |
| 1180 | scale=QuantumRange/((size_t) QuantumRange >> ((size_t) |
| 1181 | MAGICKCORE_QUANTUM_DEPTH-image->depth)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1182 | if (channel_statistics != (ChannelStatistics *) NULL) |
| 1183 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1184 | (void) FormatLocaleFile(file," \"pixels\": %.20g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1185 | channel_statistics[CompositePixelChannel].area); |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 1186 | if ((image->colorspace != LinearGRAYColorspace) && |
| 1187 | (image->colorspace != GRAYColorspace)) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1188 | { |
| 1189 | (void) FormatLocaleFile(file," \"imageStatistics\": {\n"); |
| 1190 | (void) PrintChannelStatistics(file,(PixelChannel) MaxPixelChannels, |
| 1191 | "Overall",1.0/scale,MagickFalse,channel_statistics); |
| 1192 | (void) FormatLocaleFile(file," },\n"); |
| 1193 | } |
| 1194 | (void) FormatLocaleFile(file," \"channelStatistics\": {\n"); |
| 1195 | if (image->alpha_trait != UndefinedPixelTrait) |
| 1196 | (void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale, |
| 1197 | MagickTrue,channel_statistics); |
Cristy | 3889d15 | 2017-12-22 19:42:13 -0500 | [diff] [blame] | 1198 | switch (image->colorspace) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1199 | { |
| 1200 | case RGBColorspace: |
| 1201 | default: |
| 1202 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1203 | (void) PrintChannelStatistics(file,RedPixelChannel,"Red",1.0/scale, |
| 1204 | MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1205 | (void) PrintChannelStatistics(file,GreenPixelChannel,"Green",1.0/ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1206 | scale,MagickTrue,channel_statistics); |
| 1207 | (void) PrintChannelStatistics(file,BluePixelChannel,"Blue",1.0/scale, |
| 1208 | MagickFalse,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | } |
| 1211 | case CMYKColorspace: |
| 1212 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1213 | (void) PrintChannelStatistics(file,CyanPixelChannel,"Cyan",1.0/scale, |
| 1214 | MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1215 | (void) PrintChannelStatistics(file,MagentaPixelChannel,"Magenta",1.0/ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1216 | scale,MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1217 | (void) PrintChannelStatistics(file,YellowPixelChannel,"Yellow",1.0/ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1218 | scale,MagickTrue,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1219 | (void) PrintChannelStatistics(file,BlackPixelChannel,"Black",1.0/ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1220 | scale,MagickFalse,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1221 | break; |
| 1222 | } |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 1223 | case LinearGRAYColorspace: |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1224 | case GRAYColorspace: |
| 1225 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1226 | (void) PrintChannelStatistics(file,GrayPixelChannel,"Gray",1.0/scale, |
| 1227 | MagickFalse,channel_statistics); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1228 | break; |
| 1229 | } |
| 1230 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1231 | (void) FormatLocaleFile(file," },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1232 | channel_statistics=(ChannelStatistics *) RelinquishMagickMemory( |
| 1233 | channel_statistics); |
| 1234 | } |
| 1235 | if (channel_moments != (ChannelMoments *) NULL) |
| 1236 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1237 | (void) FormatLocaleFile(file," \"channelMoments\": {\n"); |
| 1238 | if (image->alpha_trait != UndefinedPixelTrait) |
| 1239 | (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",MagickTrue, |
| 1240 | channel_moments); |
Cristy | 3889d15 | 2017-12-22 19:42:13 -0500 | [diff] [blame] | 1241 | switch (image->colorspace) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1242 | { |
| 1243 | case RGBColorspace: |
| 1244 | default: |
| 1245 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1246 | (void) PrintChannelMoments(file,RedPixelChannel,"Red",MagickTrue, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1247 | channel_moments); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1248 | (void) PrintChannelMoments(file,GreenPixelChannel,"Green",MagickTrue, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1249 | channel_moments); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1250 | (void) PrintChannelMoments(file,BluePixelChannel,"Blue",MagickFalse, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1251 | channel_moments); |
| 1252 | break; |
| 1253 | } |
| 1254 | case CMYKColorspace: |
| 1255 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1256 | (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",MagickTrue, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1257 | channel_moments); |
| 1258 | (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1259 | MagickTrue,channel_moments); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1260 | (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1261 | MagickTrue,channel_moments); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1262 | (void) PrintChannelMoments(file,BlackPixelChannel,"Black", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1263 | MagickFalse,channel_moments); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1264 | break; |
| 1265 | } |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 1266 | case LinearGRAYColorspace: |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1267 | case GRAYColorspace: |
| 1268 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1269 | (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",MagickFalse, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1270 | channel_moments); |
| 1271 | break; |
| 1272 | } |
| 1273 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1274 | (void) FormatLocaleFile(file," },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1275 | channel_moments=(ChannelMoments *) RelinquishMagickMemory( |
| 1276 | channel_moments); |
| 1277 | } |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 1278 | if (channel_phash != (ChannelPerceptualHash *) NULL) |
| 1279 | { |
| 1280 | (void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n"); |
Cristy | e696180 | 2016-09-03 11:31:13 -0400 | [diff] [blame] | 1281 | (void) PrintChannelPerceptualHash(image,file,channel_phash); |
cristy | dc39517 | 2014-02-23 01:33:36 +0000 | [diff] [blame] | 1282 | (void) FormatLocaleFile(file," },\n"); |
| 1283 | channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory( |
| 1284 | channel_phash); |
| 1285 | } |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1286 | if (channel_features != (ChannelFeatures *) NULL) |
| 1287 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1288 | (void) FormatLocaleFile(file," \"channelFeatures\": {\n"); |
| 1289 | if (image->alpha_trait != UndefinedPixelTrait) |
| 1290 | (void) PrintChannelFeatures(file,AlphaPixelChannel,"Alpha",MagickTrue, |
| 1291 | channel_features); |
Cristy | 3889d15 | 2017-12-22 19:42:13 -0500 | [diff] [blame] | 1292 | switch (image->colorspace) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1293 | { |
| 1294 | case RGBColorspace: |
| 1295 | default: |
| 1296 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1297 | (void) PrintChannelFeatures(file,RedPixelChannel,"Red",MagickTrue, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1298 | channel_features); |
| 1299 | (void) PrintChannelFeatures(file,GreenPixelChannel,"Green", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1300 | MagickTrue,channel_features); |
| 1301 | (void) PrintChannelFeatures(file,BluePixelChannel,"Blue",MagickFalse, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1302 | channel_features); |
| 1303 | break; |
| 1304 | } |
| 1305 | case CMYKColorspace: |
| 1306 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1307 | (void) PrintChannelFeatures(file,CyanPixelChannel,"Cyan",MagickTrue, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1308 | channel_features); |
| 1309 | (void) PrintChannelFeatures(file,MagentaPixelChannel,"Magenta", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1310 | MagickTrue,channel_features); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1311 | (void) PrintChannelFeatures(file,YellowPixelChannel,"Yellow", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1312 | MagickTrue,channel_features); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1313 | (void) PrintChannelFeatures(file,BlackPixelChannel,"Black", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1314 | MagickFalse,channel_features); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1315 | break; |
| 1316 | } |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 1317 | case LinearGRAYColorspace: |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1318 | case GRAYColorspace: |
| 1319 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1320 | (void) PrintChannelFeatures(file,GrayPixelChannel,"Gray",MagickFalse, |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1321 | channel_features); |
| 1322 | break; |
| 1323 | } |
| 1324 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1325 | (void) FormatLocaleFile(file," },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1326 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 1327 | channel_features); |
| 1328 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1329 | if (image->colorspace == CMYKColorspace) |
| 1330 | (void) FormatLocaleFile(file," \"totalInkDensity\": \"%.*g%%\",\n", |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1331 | GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/ |
| 1332 | (double) QuantumRange); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1333 | x=0; |
| 1334 | if (image->alpha_trait != UndefinedPixelTrait) |
| 1335 | { |
| 1336 | register const Quantum |
| 1337 | *p; |
| 1338 | |
| 1339 | p=(const Quantum *) NULL; |
| 1340 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1341 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1342 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 1343 | if (p == (const Quantum *) NULL) |
| 1344 | break; |
| 1345 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1346 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1347 | if (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1348 | break; |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1349 | p+=GetPixelChannels(image); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1350 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1351 | if (x < (ssize_t) image->columns) |
| 1352 | break; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1353 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1354 | if ((x < (ssize_t) image->columns) || (y < (ssize_t) image->rows)) |
| 1355 | { |
| 1356 | PixelInfo |
| 1357 | pixel; |
| 1358 | |
| 1359 | GetPixelInfo(image,&pixel); |
| 1360 | GetPixelInfoPixel(image,p,&pixel); |
| 1361 | GetColorTuple(&pixel,MagickTrue,color); |
| 1362 | (void) FormatLocaleFile(file," \"alpha\": \"%s\",\n",color); |
| 1363 | } |
| 1364 | } |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1365 | if (image->storage_class == PseudoClass) |
| 1366 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1367 | register PixelInfo |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1368 | *magick_restrict p; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1369 | |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1370 | (void) FormatLocaleFile(file," \"colormapEntries\": %.20g,\n", |
| 1371 | (double) image->colors); |
| 1372 | (void) FormatLocaleFile(file," \"colormap\": [\n "); |
| 1373 | p=image->colormap; |
| 1374 | for (i=0; i < (ssize_t) image->colors; i++) |
| 1375 | { |
| 1376 | GetColorTuple(p,MagickTrue,color); |
| 1377 | (void) FormatLocaleFile(file,"\"%s\"",color); |
| 1378 | if (i < (ssize_t) (image->colors-1)) |
| 1379 | (void) FormatLocaleFile(file,","); |
| 1380 | if (((i+1) % 5) == 0) |
| 1381 | (void) FormatLocaleFile(file,"\n "); |
| 1382 | p++; |
| 1383 | } |
| 1384 | (void) FormatLocaleFile(file,"\n ],\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1385 | } |
| 1386 | if (image->error.mean_error_per_pixel != 0.0) |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1387 | (void) FormatLocaleFile(file," \"meanErrorPerPixel\": %g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1388 | image->error.mean_error_per_pixel); |
| 1389 | if (image->error.normalized_mean_error != 0.0) |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1390 | (void) FormatLocaleFile(file," \"normalizedMeanError\": %g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1391 | image->error.normalized_mean_error); |
| 1392 | if (image->error.normalized_maximum_error != 0.0) |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1393 | (void) FormatLocaleFile(file," \"normalizedMaximumError\": %g,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1394 | image->error.normalized_maximum_error); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1395 | JSONFormatLocaleFile(file," \"renderingIntent\": %s,\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1396 | CommandOptionToMnemonic(MagickIntentOptions,(ssize_t) |
| 1397 | image->rendering_intent)); |
| 1398 | if (image->gamma != 0.0) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1399 | (void) FormatLocaleFile(file," \"gamma\": %g,\n",image->gamma); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1400 | if ((image->chromaticity.red_primary.x != 0.0) || |
| 1401 | (image->chromaticity.green_primary.x != 0.0) || |
| 1402 | (image->chromaticity.blue_primary.x != 0.0) || |
| 1403 | (image->chromaticity.white_point.x != 0.0)) |
| 1404 | { |
| 1405 | /* |
| 1406 | Display image chromaticity. |
| 1407 | */ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1408 | (void) FormatLocaleFile(file," \"chromaticity\": {\n"); |
| 1409 | (void) FormatLocaleFile(file," \"redPrimary\": {\n" |
| 1410 | " \"x\": %g,\n \"y\": %g\n },\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1411 | image->chromaticity.red_primary.x,image->chromaticity.red_primary.y); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1412 | (void) FormatLocaleFile(file," \"greenPrimary\": {\n" |
| 1413 | " \"x\": %g,\n \"y\": %g\n },\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1414 | image->chromaticity.green_primary.x, |
| 1415 | image->chromaticity.green_primary.y); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1416 | (void) FormatLocaleFile(file," \"bluePrimary\": {\n" |
| 1417 | " \"x\": %g,\n \"y\": %g\n },\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1418 | image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1419 | (void) FormatLocaleFile(file," \"whitePrimary\": {\n" |
| 1420 | " \"x\": %g,\n \"y\": %g\n }\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1421 | image->chromaticity.white_point.x,image->chromaticity.white_point.y); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1422 | (void) FormatLocaleFile(file," },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1423 | } |
| 1424 | if ((image->extract_info.width*image->extract_info.height) != 0) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1425 | (void) FormatLocaleFile(file," \"tileGeometry\": {\n" |
| 1426 | " \"width\": %.20g,\n \"height\": %.20g,\n" |
| 1427 | " \"x\": %.20g,\n \"y\": %.20g\n },\n", |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1428 | (double) image->extract_info.width,(double) image->extract_info.height, |
| 1429 | (double) image->extract_info.x,(double) image->extract_info.y); |
Cristy | 18b2750 | 2017-02-16 07:29:19 -0500 | [diff] [blame] | 1430 | GetColorTuple(&image->matte_color,MagickTrue,color); |
| 1431 | (void) FormatLocaleFile(file," \"matteColor\": \"%s\",\n",color); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1432 | GetColorTuple(&image->background_color,MagickTrue,color); |
| 1433 | (void) FormatLocaleFile(file," \"backgroundColor\": \"%s\",\n",color); |
| 1434 | GetColorTuple(&image->border_color,MagickTrue,color); |
| 1435 | (void) FormatLocaleFile(file," \"borderColor\": \"%s\",\n",color); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1436 | GetColorTuple(&image->transparent_color,MagickTrue,color); |
| 1437 | (void) FormatLocaleFile(file," \"transparentColor\": \"%s\",\n",color); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1438 | JSONFormatLocaleFile(file," \"interlace\": %s,\n",CommandOptionToMnemonic( |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1439 | MagickInterlaceOptions,(ssize_t) image->interlace)); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1440 | JSONFormatLocaleFile(file," \"intensity\": %s,\n",CommandOptionToMnemonic( |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1441 | MagickPixelIntensityOptions,(ssize_t) image->intensity)); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1442 | JSONFormatLocaleFile(file," \"compose\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1443 | CommandOptionToMnemonic(MagickComposeOptions,(ssize_t) image->compose)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1444 | if ((image->page.width != 0) || (image->page.height != 0) || |
| 1445 | (image->page.x != 0) || (image->page.y != 0)) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1446 | (void) FormatLocaleFile(file," \"pageGeometry\": {\n" |
| 1447 | " \"width\": %.20g,\n \"height\": %.20g,\n" |
| 1448 | " \"x\": %.20g,\n \"y\": %.20g\n },\n", |
| 1449 | (double) image->page.width,(double) image->page.height, |
| 1450 | (double) image->page.x,(double) image->page.y); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1451 | if ((image->page.x != 0) || (image->page.y != 0)) |
Travis Petticrew | 6e95e02 | 2018-02-09 13:33:20 -0600 | [diff] [blame] | 1452 | (void) FormatLocaleFile(file," \"originGeometry\": \"%+.20g%+.20g\",\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1453 | (double) image->page.x,(double) image->page.y); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1454 | JSONFormatLocaleFile(file," \"dispose\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1455 | CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1456 | if (image->delay != 0) |
Darek Finster | 76c7e83 | 2017-10-13 01:57:47 +0200 | [diff] [blame] | 1457 | (void) FormatLocaleFile(file," \"delay\": \"%.20gx%.20g\",\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1458 | (double) image->delay,(double) image->ticks_per_second); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1459 | if (image->iterations != 1) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1460 | (void) FormatLocaleFile(file," \"iterations\": %.20g,\n",(double) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1461 | image->iterations); |
| 1462 | if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL)) |
Dirk Lemstra | 3ea0d28 | 2017-09-21 13:31:12 +0200 | [diff] [blame] | 1463 | (void) FormatLocaleFile(file," \"scene\": %.20g,\n \"scenes\": " |
| 1464 | "%.20g,\n",(double) image->scene,(double) GetImageListLength(image)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1465 | else |
| 1466 | if (image->scene != 0) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1467 | (void) FormatLocaleFile(file," \"scene\": %.20g,\n",(double) |
| 1468 | image->scene); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1469 | JSONFormatLocaleFile(file," \"compression\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1470 | CommandOptionToMnemonic(MagickCompressOptions,(ssize_t) |
| 1471 | image->compression)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1472 | if (image->quality != UndefinedCompressionQuality) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1473 | (void) FormatLocaleFile(file," \"quality\": %.20g,\n",(double) |
| 1474 | image->quality); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1475 | JSONFormatLocaleFile(file," \"orientation\": %s,\n", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1476 | CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t) |
| 1477 | image->orientation)); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1478 | if (image->montage != (char *) NULL) |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1479 | JSONFormatLocaleFile(file," \"montage\": \"%s\",\n",image->montage); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1480 | if (image->directory != (char *) NULL) |
| 1481 | { |
| 1482 | Image |
| 1483 | *tile; |
| 1484 | |
| 1485 | ImageInfo |
| 1486 | *image_info; |
| 1487 | |
| 1488 | register char |
| 1489 | *p, |
| 1490 | *q; |
| 1491 | |
| 1492 | WarningHandler |
| 1493 | handler; |
| 1494 | |
| 1495 | /* |
| 1496 | Display visual image directory. |
| 1497 | */ |
| 1498 | image_info=AcquireImageInfo(); |
| 1499 | (void) CloneString(&image_info->size,"64x64"); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1500 | (void) FormatLocaleFile(file," \"montageDirectory\": ["); |
| 1501 | p=image->directory; |
| 1502 | while (*p != '\0') |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1503 | { |
| 1504 | q=p; |
Cristy | 5d293d2 | 2018-02-24 12:45:52 -0500 | [diff] [blame] | 1505 | while ((*q != '\xff') && (*q != '\0')) |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1506 | q++; |
| 1507 | (void) CopyMagickString(image_info->filename,p,(size_t) (q-p+1)); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1508 | p=q+1; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1509 | JSONFormatLocaleFile(file,"{\n \"name\": %s", |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1510 | image_info->filename); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1511 | handler=SetWarningHandler((WarningHandler) NULL); |
| 1512 | tile=ReadImage(image_info,exception); |
| 1513 | (void) SetWarningHandler(handler); |
| 1514 | if (tile == (Image *) NULL) |
| 1515 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1516 | (void) FormatLocaleFile(file," }"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1517 | continue; |
| 1518 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1519 | (void) FormatLocaleFile(file,",\n \"info\": \"%.20gx%.20g %s\"", |
| 1520 | (double) tile->magick_columns,(double) tile->magick_rows, |
| 1521 | tile->magick); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1522 | (void) SignatureImage(tile,exception); |
| 1523 | ResetImagePropertyIterator(tile); |
| 1524 | property=GetNextImageProperty(tile); |
| 1525 | while (property != (const char *) NULL) |
| 1526 | { |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1527 | JSONFormatLocaleFile(file,",\n %s: ",property); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1528 | value=GetImageProperty(tile,property,exception); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1529 | JSONFormatLocaleFile(file,"%s",value); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1530 | property=GetNextImageProperty(tile); |
| 1531 | } |
Cristy | 4e72d44 | 2018-01-11 06:29:53 -0500 | [diff] [blame] | 1532 | tile=DestroyImageList(tile); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1533 | if (*p != '\0') |
| 1534 | (void) FormatLocaleFile(file,"\n },"); |
| 1535 | else |
| 1536 | (void) FormatLocaleFile(file,"\n }"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1537 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1538 | (void) FormatLocaleFile(file,"],\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1539 | image_info=DestroyImageInfo(image_info); |
| 1540 | } |
| 1541 | (void) GetImageProperty(image,"exif:*",exception); |
cristy | 5516632 | 2014-01-23 01:53:24 +0000 | [diff] [blame] | 1542 | (void) GetImageProperty(image,"icc:*",exception); |
| 1543 | (void) GetImageProperty(image,"iptc:*",exception); |
| 1544 | (void) GetImageProperty(image,"xmp:*",exception); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1545 | ResetImagePropertyIterator(image); |
| 1546 | property=GetNextImageProperty(image); |
| 1547 | if (property != (const char *) NULL) |
| 1548 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1549 | size_t |
| 1550 | n; |
| 1551 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1552 | /* |
| 1553 | Display image properties. |
| 1554 | */ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1555 | n=0; |
| 1556 | (void) FormatLocaleFile(file," \"properties\": {\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1557 | while (property != (const char *) NULL) |
| 1558 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1559 | if (n++ != 0) |
| 1560 | (void) FormatLocaleFile(file,",\n"); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1561 | JSONFormatLocaleFile(file," %s: ",property); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1562 | value=GetImageProperty(image,property,exception); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1563 | JSONFormatLocaleFile(file,"%s",value); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1564 | property=GetNextImageProperty(image); |
| 1565 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1566 | (void) FormatLocaleFile(file,"\n },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1567 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1568 | (void) FormatLocaleString(key,MagickPathExtent,"8BIM:1999,2998:#1"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1569 | value=GetImageProperty(image,key,exception); |
| 1570 | if (value != (const char *) NULL) |
| 1571 | { |
| 1572 | /* |
| 1573 | Display clipping path. |
| 1574 | */ |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1575 | JSONFormatLocaleFile(file," \"clipping path\": %s,\n",value); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1576 | } |
| 1577 | ResetImageProfileIterator(image); |
| 1578 | name=GetNextImageProfile(image); |
| 1579 | if (name != (char *) NULL) |
| 1580 | { |
| 1581 | const StringInfo |
| 1582 | *profile; |
| 1583 | |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1584 | size_t |
| 1585 | n; |
| 1586 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1587 | /* |
| 1588 | Identify image profiles. |
| 1589 | */ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1590 | n=0; |
| 1591 | (void) FormatLocaleFile(file," \"profiles\": {\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1592 | while (name != (char *) NULL) |
| 1593 | { |
| 1594 | profile=GetImageProfile(image,name); |
| 1595 | if (profile == (StringInfo *) NULL) |
| 1596 | continue; |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1597 | if (n++ != 0) |
| 1598 | (void) FormatLocaleFile(file,",\n"); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1599 | JSONFormatLocaleFile(file," %s: {\n",name); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1600 | if (LocaleCompare(name,"iptc") == 0) |
Dirk Lemstra | 32b1550 | 2017-09-21 17:04:36 +0200 | [diff] [blame] | 1601 | EncodeIptcProfile(file,profile); |
Cristy | bc978e0 | 2017-10-29 13:29:43 -0400 | [diff] [blame] | 1602 | (void) FormatLocaleFile(file," \"length\": %.20g",(double) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1603 | GetStringInfoLength(profile)); |
| 1604 | (void) FormatLocaleFile(file,"\n }"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1605 | name=GetNextImageProfile(image); |
| 1606 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1607 | (void) FormatLocaleFile(file,"\n },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1608 | } |
| 1609 | ResetImageArtifactIterator(image); |
| 1610 | artifact=GetNextImageArtifact(image); |
| 1611 | if (artifact != (const char *) NULL) |
| 1612 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1613 | ssize_t |
| 1614 | n; |
| 1615 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1616 | /* |
| 1617 | Display image artifacts. |
| 1618 | */ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1619 | n=0; |
| 1620 | (void) FormatLocaleFile(file," \"artifacts\": {\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1621 | while (artifact != (const char *) NULL) |
| 1622 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1623 | if (n++ != 0) |
| 1624 | (void) FormatLocaleFile(file,",\n"); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1625 | JSONFormatLocaleFile(file," %s: ",artifact); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1626 | value=GetImageArtifact(image,artifact); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1627 | JSONFormatLocaleFile(file,"%s",value); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1628 | artifact=GetNextImageArtifact(image); |
| 1629 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1630 | (void) FormatLocaleFile(file,"\n },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1631 | } |
| 1632 | ResetImageRegistryIterator(); |
| 1633 | registry=GetNextImageRegistry(); |
| 1634 | if (registry != (const char *) NULL) |
| 1635 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1636 | ssize_t |
| 1637 | n; |
| 1638 | |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1639 | /* |
| 1640 | Display image registry. |
| 1641 | */ |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1642 | (void) FormatLocaleFile(file," \"registry\": {\n"); |
| 1643 | n=0; |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1644 | while (registry != (const char *) NULL) |
| 1645 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1646 | if (n++ != 0) |
| 1647 | (void) FormatLocaleFile(file,",\n"); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1648 | JSONFormatLocaleFile(file," %s: ",registry); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1649 | value=(const char *) GetImageRegistry(StringRegistryType,registry, |
| 1650 | exception); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1651 | JSONFormatLocaleFile(file,"%s",value); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1652 | registry=GetNextImageRegistry(); |
| 1653 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1654 | (void) FormatLocaleFile(file," },\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1655 | } |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1656 | (void) FormatLocaleFile(file," \"tainted\": %s,\n", |
| 1657 | image->taint != MagickFalse ? "true" : "false"); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1658 | (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent, |
cristy | d4618c0 | 2015-04-14 23:54:43 +0000 | [diff] [blame] | 1659 | format); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1660 | JSONFormatLocaleFile(file," \"filesize\": %s,\n",format); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1661 | (void) FormatMagickSize((MagickSizeType) image->columns*image->rows, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1662 | MagickFalse,"B",MagickPathExtent,format); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1663 | if (strlen(format) > 1) |
| 1664 | format[strlen(format)-1]='\0'; |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1665 | JSONFormatLocaleFile(file," \"numberPixels\": %s,\n",format); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1666 | (void) FormatMagickSize((MagickSizeType) ((double) image->columns*image->rows/ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1667 | elapsed_time+0.5),MagickFalse,"B",MagickPathExtent,format); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1668 | JSONFormatLocaleFile(file," \"pixelsPerSecond\": %s,\n",format); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1669 | (void) FormatLocaleFile(file," \"userTime\": \"%0.3fu\",\n",user_time); |
| 1670 | (void) FormatLocaleFile(file," \"elapsedTime\": \"%lu:%02lu.%03lu\",\n", |
| 1671 | (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod( |
| 1672 | elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor( |
| 1673 | elapsed_time)))); |
Cristy | 519e005 | 2016-10-16 15:28:40 -0400 | [diff] [blame] | 1674 | url=GetMagickHomeURL(); |
Cristy | db96d69 | 2017-10-29 10:37:57 -0400 | [diff] [blame] | 1675 | JSONFormatLocaleFile(file," \"version\": %s\n",url); |
Cristy | 519e005 | 2016-10-16 15:28:40 -0400 | [diff] [blame] | 1676 | url=DestroyString(url); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1677 | (void) FormatLocaleFile(file," }\n}\n"); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1678 | (void) fflush(file); |
| 1679 | return(ferror(file) != 0 ? MagickFalse : MagickTrue); |
| 1680 | } |
| 1681 | |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1682 | static MagickBooleanType WriteJSONImage(const ImageInfo *image_info, |
| 1683 | Image *image,ExceptionInfo *exception) |
| 1684 | { |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1685 | FILE |
| 1686 | *file; |
| 1687 | |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1688 | MagickBooleanType |
| 1689 | status; |
| 1690 | |
| 1691 | MagickOffsetType |
| 1692 | scene; |
| 1693 | |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame^] | 1694 | size_t |
| 1695 | imageListLength; |
| 1696 | |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1697 | /* |
| 1698 | Open output image file. |
| 1699 | */ |
| 1700 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1701 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1702 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1703 | assert(image->signature == MagickCoreSignature); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1704 | if (image->debug != MagickFalse) |
| 1705 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1706 | status=OpenBlob(image_info,image,WriteBlobMode,exception); |
| 1707 | if (status == MagickFalse) |
| 1708 | return(status); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1709 | file=GetBlobFileHandle(image); |
| 1710 | if (file == (FILE *) NULL) |
| 1711 | file=stdout; |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1712 | scene=0; |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame^] | 1713 | imageListLength=GetImageListLength(image); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1714 | do |
| 1715 | { |
Dirk Lemstra | c9105bd | 2017-09-21 13:39:00 +0200 | [diff] [blame] | 1716 | if (scene == 0) |
Cristy | 457c4d6 | 2017-12-16 07:45:18 -0500 | [diff] [blame] | 1717 | (void) WriteBlobString(image,"["); |
cristy | 9e81898 | 2014-01-18 14:54:37 +0000 | [diff] [blame] | 1718 | image->magick_columns=image->columns; |
| 1719 | image->magick_rows=image->rows; |
Cristy | 457c4d6 | 2017-12-16 07:45:18 -0500 | [diff] [blame] | 1720 | (void) EncodeImageAttributes(image,file,exception); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1721 | if (GetNextImageInList(image) == (Image *) NULL) |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1722 | { |
Cristy | 457c4d6 | 2017-12-16 07:45:18 -0500 | [diff] [blame] | 1723 | (void) WriteBlobString(image,"]"); |
dirk | 6c316f2 | 2015-06-27 15:44:29 +0000 | [diff] [blame] | 1724 | break; |
| 1725 | } |
Cristy | 457c4d6 | 2017-12-16 07:45:18 -0500 | [diff] [blame] | 1726 | (void) WriteBlobString(image,",\n"); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1727 | image=SyncNextImageInList(image); |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame^] | 1728 | status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength); |
cristy | 3f07aa3 | 2014-01-18 01:16:33 +0000 | [diff] [blame] | 1729 | if (status == MagickFalse) |
| 1730 | break; |
| 1731 | } while (image_info->adjoin != MagickFalse); |
| 1732 | (void) CloseBlob(image); |
| 1733 | return(MagickTrue); |
| 1734 | } |