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