| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % DDDD PPPP X X % |
| 7 | % D D P P X X % |
| 8 | % D D PPPP XXX % |
| 9 | % D D P X X % |
| 10 | % DDDD P X X % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write SMTPE DPX Image Format % |
| 14 | % % |
| 15 | % Software Design % |
| cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % March 2001 % |
| 18 | % % |
| 19 | % % |
| cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +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 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/attribute.h" |
| cristy | 76ce6e1 | 2013-04-05 14:33:38 +0000 | [diff] [blame] | 44 | #include "MagickCore/artifact.h" |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 45 | #include "MagickCore/blob.h" |
| 46 | #include "MagickCore/blob-private.h" |
| 47 | #include "MagickCore/cache.h" |
| 48 | #include "MagickCore/colorspace.h" |
| 49 | #include "MagickCore/exception.h" |
| 50 | #include "MagickCore/exception-private.h" |
| 51 | #include "MagickCore/geometry.h" |
| 52 | #include "MagickCore/image.h" |
| 53 | #include "MagickCore/image-private.h" |
| 54 | #include "MagickCore/list.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
| 57 | #include "MagickCore/module.h" |
| 58 | #include "MagickCore/monitor.h" |
| 59 | #include "MagickCore/monitor-private.h" |
| 60 | #include "MagickCore/option.h" |
| cristy | 73a724e | 2011-11-24 18:47:12 +0000 | [diff] [blame] | 61 | #include "MagickCore/pixel-accessor.h" |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 62 | #include "MagickCore/profile.h" |
| 63 | #include "MagickCore/property.h" |
| 64 | #include "MagickCore/quantum-private.h" |
| 65 | #include "MagickCore/static.h" |
| 66 | #include "MagickCore/string_.h" |
| 67 | #include "MagickCore/string-private.h" |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| cristy | 1f7ae7f | 2014-11-28 14:26:15 +0000 | [diff] [blame] | 70 | Define declaration. |
| 71 | */ |
| 72 | #define MaxNumberImageElements 8 |
| 73 | |
| 74 | /* |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 75 | Typedef declaration. |
| 76 | */ |
| 77 | typedef enum |
| 78 | { |
| 79 | UserDefinedColorimetric = 0, |
| 80 | PrintingDensityColorimetric = 1, |
| 81 | LinearColorimetric = 2, |
| 82 | LogarithmicColorimetric = 3, |
| 83 | UnspecifiedVideoColorimetric = 4, |
| 84 | SMTPE_274MColorimetric = 5, |
| 85 | ITU_R709Colorimetric = 6, |
| 86 | ITU_R601_625LColorimetric = 7, |
| 87 | ITU_R601_525LColorimetric = 8, |
| 88 | NTSCCompositeVideoColorimetric = 9, |
| 89 | PALCompositeVideoColorimetric = 10, |
| 90 | ZDepthLinearColorimetric = 11, |
| 91 | DepthHomogeneousColorimetric = 12 |
| 92 | } DPXColorimetric; |
| 93 | |
| 94 | typedef enum |
| 95 | { |
| 96 | UndefinedComponentType = 0, |
| 97 | RedComponentType = 1, |
| 98 | GreenComponentType = 2, |
| 99 | BlueComponentType = 3, |
| 100 | AlphaComponentType = 4, |
| 101 | LumaComponentType = 6, |
| 102 | ColorDifferenceCbCrComponentType = 7, |
| 103 | DepthComponentType = 8, |
| 104 | CompositeVideoComponentType = 9, |
| 105 | RGBComponentType = 50, |
| 106 | RGBAComponentType = 51, |
| 107 | ABGRComponentType = 52, |
| 108 | CbYCrY422ComponentType = 100, |
| 109 | CbYACrYA4224ComponentType = 101, |
| 110 | CbYCr444ComponentType = 102, |
| 111 | CbYCrA4444ComponentType = 103, |
| 112 | UserDef2ElementComponentType = 150, |
| 113 | UserDef3ElementComponentType = 151, |
| 114 | UserDef4ElementComponentType = 152, |
| 115 | UserDef5ElementComponentType = 153, |
| 116 | UserDef6ElementComponentType = 154, |
| 117 | UserDef7ElementComponentType = 155, |
| 118 | UserDef8ElementComponentType = 156 |
| 119 | } DPXComponentType; |
| 120 | |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 121 | typedef enum |
| 122 | { |
| 123 | TransferCharacteristicUserDefined = 0, |
| 124 | TransferCharacteristicPrintingDensity = 1, |
| 125 | TransferCharacteristicLinear = 2, |
| 126 | TransferCharacteristicLogarithmic = 3, |
| 127 | TransferCharacteristicUnspecifiedVideo = 4, |
| 128 | TransferCharacteristicSMTPE274M = 5, /* 1920x1080 TV */ |
| 129 | TransferCharacteristicITU_R709 = 6, /* ITU R709 */ |
| 130 | TransferCharacteristicITU_R601_625L = 7, /* 625 Line */ |
| 131 | TransferCharacteristicITU_R601_525L = 8, /* 525 Line */ |
| 132 | TransferCharacteristicNTSCCompositeVideo = 9, |
| 133 | TransferCharacteristicPALCompositeVideo = 10, |
| 134 | TransferCharacteristicZDepthLinear = 11, |
| 135 | TransferCharacteristicZDepthHomogeneous = 12 |
| 136 | } DPXTransferCharacteristic; |
| 137 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 138 | typedef struct _DPXFileInfo |
| 139 | { |
| 140 | unsigned int |
| 141 | magic, |
| 142 | image_offset; |
| 143 | |
| 144 | char |
| 145 | version[8]; |
| 146 | |
| 147 | unsigned int |
| 148 | file_size, |
| 149 | ditto_key, |
| 150 | generic_size, |
| 151 | industry_size, |
| 152 | user_size; |
| 153 | |
| 154 | char |
| 155 | filename[100], |
| 156 | timestamp[24], |
| 157 | creator[100], |
| 158 | project[200], |
| 159 | copyright[200]; |
| 160 | |
| 161 | unsigned int |
| 162 | encrypt_key; |
| 163 | |
| 164 | char |
| 165 | reserve[104]; |
| 166 | } DPXFileInfo; |
| 167 | |
| 168 | typedef struct _DPXFilmInfo |
| 169 | { |
| 170 | char |
| 171 | id[2], |
| 172 | type[2], |
| 173 | offset[2], |
| 174 | prefix[6], |
| 175 | count[4], |
| 176 | format[32]; |
| 177 | |
| 178 | unsigned int |
| 179 | frame_position, |
| 180 | sequence_extent, |
| 181 | held_count; |
| 182 | |
| 183 | float |
| 184 | frame_rate, |
| 185 | shutter_angle; |
| 186 | |
| 187 | char |
| 188 | frame_id[32], |
| 189 | slate[100], |
| 190 | reserve[56]; |
| 191 | } DPXFilmInfo; |
| 192 | |
| 193 | typedef struct _DPXImageElement |
| 194 | { |
| 195 | unsigned int |
| 196 | data_sign, |
| 197 | low_data; |
| 198 | |
| 199 | float |
| 200 | low_quantity; |
| 201 | |
| 202 | unsigned int |
| 203 | high_data; |
| 204 | |
| 205 | float |
| 206 | high_quantity; |
| 207 | |
| 208 | unsigned char |
| 209 | descriptor, |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 210 | transfer_characteristic, |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | colorimetric, |
| 212 | bit_size; |
| 213 | |
| 214 | unsigned short |
| 215 | packing, |
| 216 | encoding; |
| 217 | |
| 218 | unsigned int |
| 219 | data_offset, |
| 220 | end_of_line_padding, |
| 221 | end_of_image_padding; |
| 222 | |
| 223 | unsigned char |
| 224 | description[32]; |
| 225 | } DPXImageElement; |
| 226 | |
| 227 | typedef struct _DPXImageInfo |
| 228 | { |
| 229 | unsigned short |
| 230 | orientation, |
| 231 | number_elements; |
| 232 | |
| 233 | unsigned int |
| 234 | pixels_per_line, |
| 235 | lines_per_element; |
| 236 | |
| 237 | DPXImageElement |
| cristy | 1f7ae7f | 2014-11-28 14:26:15 +0000 | [diff] [blame] | 238 | image_element[MaxNumberImageElements]; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | |
| 240 | unsigned char |
| 241 | reserve[52]; |
| 242 | } DPXImageInfo; |
| 243 | |
| 244 | typedef struct _DPXOrientationInfo |
| 245 | { |
| 246 | unsigned int |
| 247 | x_offset, |
| 248 | y_offset; |
| 249 | |
| 250 | float |
| 251 | x_center, |
| 252 | y_center; |
| 253 | |
| 254 | unsigned int |
| 255 | x_size, |
| 256 | y_size; |
| 257 | |
| 258 | char |
| 259 | filename[100], |
| 260 | timestamp[24], |
| 261 | device[32], |
| 262 | serial[32]; |
| 263 | |
| 264 | unsigned short |
| 265 | border[4]; |
| 266 | |
| 267 | unsigned int |
| 268 | aspect_ratio[2]; |
| 269 | |
| 270 | unsigned char |
| 271 | reserve[28]; |
| 272 | } DPXOrientationInfo; |
| 273 | |
| 274 | typedef struct _DPXTelevisionInfo |
| 275 | { |
| 276 | unsigned int |
| 277 | time_code, |
| 278 | user_bits; |
| 279 | |
| 280 | unsigned char |
| 281 | interlace, |
| 282 | field_number, |
| 283 | video_signal, |
| 284 | padding; |
| 285 | |
| 286 | float |
| 287 | horizontal_sample_rate, |
| 288 | vertical_sample_rate, |
| 289 | frame_rate, |
| 290 | time_offset, |
| 291 | gamma, |
| 292 | black_level, |
| 293 | black_gain, |
| 294 | break_point, |
| 295 | white_level, |
| 296 | integration_times; |
| 297 | |
| 298 | char |
| 299 | reserve[76]; |
| 300 | } DPXTelevisionInfo; |
| 301 | |
| 302 | typedef struct _DPXUserInfo |
| 303 | { |
| 304 | char |
| 305 | id[32]; |
| 306 | } DPXUserInfo; |
| 307 | |
| 308 | typedef struct DPXInfo |
| 309 | { |
| 310 | DPXFileInfo |
| 311 | file; |
| 312 | |
| 313 | DPXImageInfo |
| 314 | image; |
| 315 | |
| 316 | DPXOrientationInfo |
| 317 | orientation; |
| 318 | |
| 319 | DPXFilmInfo |
| 320 | film; |
| 321 | |
| 322 | DPXTelevisionInfo |
| 323 | television; |
| 324 | |
| 325 | DPXUserInfo |
| 326 | user; |
| 327 | } DPXInfo; |
| 328 | |
| 329 | /* |
| 330 | Forward declaractions. |
| 331 | */ |
| 332 | static MagickBooleanType |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 333 | WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | |
| 335 | /* |
| 336 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 337 | % % |
| 338 | % % |
| 339 | % % |
| 340 | % I s D P X % |
| 341 | % % |
| 342 | % % |
| 343 | % % |
| 344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 345 | % |
| 346 | % IsDPX() returns MagickTrue if the image format type, identified by the |
| 347 | % magick string, is DPX. |
| 348 | % |
| 349 | % The format of the IsDPX method is: |
| 350 | % |
| 351 | % MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent) |
| 352 | % |
| 353 | % A description of each parameter follows: |
| 354 | % |
| 355 | % o magick: compare image format pattern against these bytes. |
| 356 | % |
| 357 | % o extent: Specifies the extent of the magick string. |
| 358 | % |
| 359 | */ |
| 360 | static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent) |
| 361 | { |
| 362 | if (extent < 4) |
| 363 | return(MagickFalse); |
| 364 | if (memcmp(magick,"SDPX",4) == 0) |
| 365 | return(MagickTrue); |
| 366 | if (memcmp(magick,"XPDS",4) == 0) |
| 367 | return(MagickTrue); |
| 368 | return(MagickFalse); |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 373 | % % |
| 374 | % % |
| 375 | % % |
| 376 | % R e a d D P X I m a g e % |
| 377 | % % |
| 378 | % % |
| 379 | % % |
| 380 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 381 | % |
| 382 | % ReadDPXImage() reads an DPX X image file and returns it. It |
| 383 | % allocates the memory necessary for the new Image structure and returns a |
| 384 | % pointer to the new image. |
| 385 | % |
| 386 | % The format of the ReadDPXImage method is: |
| 387 | % |
| 388 | % Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 389 | % |
| 390 | % A description of each parameter follows: |
| 391 | % |
| 392 | % o image_info: the image info. |
| 393 | % |
| 394 | % o exception: return any errors or warnings in this structure. |
| 395 | % |
| 396 | */ |
| 397 | |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 398 | static size_t GetBytesPerRow(const size_t columns, |
| 399 | const size_t samples_per_pixel,const size_t bits_per_pixel, |
| 400 | const MagickBooleanType pad) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 401 | { |
| 402 | size_t |
| 403 | bytes_per_row; |
| 404 | |
| 405 | switch (bits_per_pixel) |
| 406 | { |
| 407 | case 1: |
| 408 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 409 | bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/ |
| 410 | 32); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 411 | break; |
| 412 | } |
| 413 | case 8: |
| 414 | default: |
| 415 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 416 | bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/ |
| 417 | 32); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | break; |
| 419 | } |
| 420 | case 10: |
| 421 | { |
| 422 | if (pad == MagickFalse) |
| 423 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 424 | bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+ |
| 425 | 31)/32); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 426 | break; |
| 427 | } |
| cristy | ff024b4 | 2010-02-21 22:55:09 +0000 | [diff] [blame] | 428 | bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 429 | break; |
| 430 | } |
| 431 | case 12: |
| 432 | { |
| 433 | if (pad == MagickFalse) |
| 434 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 435 | bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+ |
| 436 | 31)/32); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 437 | break; |
| 438 | } |
| 439 | bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16); |
| 440 | break; |
| 441 | } |
| 442 | case 16: |
| 443 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 444 | bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+8)/ |
| 445 | 16); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 446 | break; |
| 447 | } |
| 448 | case 32: |
| 449 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 450 | bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/ |
| 451 | 32); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | break; |
| 453 | } |
| 454 | case 64: |
| 455 | { |
| cristy | 4ccdaa2 | 2012-11-05 16:58:06 +0000 | [diff] [blame] | 456 | bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/ |
| 457 | 64); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | break; |
| 459 | } |
| 460 | } |
| 461 | return(bytes_per_row); |
| 462 | } |
| 463 | |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 464 | static const char *GetImageTransferCharacteristic( |
| 465 | const DPXTransferCharacteristic characteristic) |
| 466 | { |
| 467 | const char |
| 468 | *transfer; |
| 469 | |
| 470 | /* |
| 471 | Get the element transfer characteristic. |
| 472 | */ |
| 473 | switch(characteristic) |
| 474 | { |
| 475 | case TransferCharacteristicUserDefined: |
| 476 | { |
| 477 | transfer="UserDefined"; |
| 478 | break; |
| 479 | } |
| 480 | case TransferCharacteristicPrintingDensity: |
| 481 | { |
| 482 | transfer="PrintingDensity"; |
| 483 | break; |
| 484 | } |
| 485 | case TransferCharacteristicLinear: |
| 486 | { |
| 487 | transfer="Linear"; |
| 488 | break; |
| 489 | } |
| 490 | case TransferCharacteristicLogarithmic: |
| 491 | { |
| 492 | transfer="Logarithmic"; |
| 493 | break; |
| 494 | } |
| 495 | case TransferCharacteristicUnspecifiedVideo: |
| 496 | { |
| 497 | transfer="UnspecifiedVideo"; |
| 498 | break; |
| 499 | } |
| 500 | case TransferCharacteristicSMTPE274M: |
| 501 | { |
| 502 | transfer="SMTPE274M"; |
| 503 | break; |
| 504 | } |
| 505 | case TransferCharacteristicITU_R709: |
| 506 | { |
| 507 | transfer="ITU-R709"; |
| 508 | break; |
| 509 | } |
| 510 | case TransferCharacteristicITU_R601_625L: |
| 511 | { |
| 512 | transfer="ITU-R601-625L"; |
| 513 | break; |
| 514 | } |
| 515 | case TransferCharacteristicITU_R601_525L: |
| 516 | { |
| 517 | transfer="ITU-R601-525L"; |
| 518 | break; |
| 519 | } |
| 520 | case TransferCharacteristicNTSCCompositeVideo: |
| 521 | { |
| 522 | transfer="NTSCCompositeVideo"; |
| 523 | break; |
| 524 | } |
| 525 | case TransferCharacteristicPALCompositeVideo: |
| 526 | { |
| 527 | transfer="PALCompositeVideo"; |
| 528 | break; |
| 529 | } |
| 530 | case TransferCharacteristicZDepthLinear: |
| 531 | { |
| 532 | transfer="ZDepthLinear"; |
| 533 | break; |
| 534 | } |
| 535 | case TransferCharacteristicZDepthHomogeneous: |
| 536 | { |
| 537 | transfer="ZDepthHomogeneous"; |
| 538 | break; |
| 539 | } |
| 540 | default: |
| 541 | transfer="Reserved"; |
| 542 | } |
| 543 | return(transfer); |
| 544 | } |
| 545 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | static inline MagickBooleanType IsFloatDefined(const float value) |
| 547 | { |
| 548 | union |
| 549 | { |
| 550 | unsigned int |
| 551 | unsigned_value; |
| 552 | |
| cristy | 8a8e468 | 2013-09-26 12:55:39 +0000 | [diff] [blame] | 553 | float |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | float_value; |
| 555 | } quantum; |
| 556 | |
| 557 | quantum.unsigned_value=0U; |
| cristy | 8a8e468 | 2013-09-26 12:55:39 +0000 | [diff] [blame] | 558 | quantum.float_value=(float) value; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | if (quantum.unsigned_value == 0U) |
| 560 | return(MagickFalse); |
| 561 | return(MagickTrue); |
| 562 | } |
| 563 | |
| 564 | static void SetPrimaryChromaticity(const DPXColorimetric colorimetric, |
| 565 | ChromaticityInfo *chromaticity_info) |
| 566 | { |
| 567 | switch(colorimetric) |
| 568 | { |
| 569 | case SMTPE_274MColorimetric: |
| 570 | case ITU_R709Colorimetric: |
| 571 | { |
| 572 | chromaticity_info->red_primary.x=0.640; |
| 573 | chromaticity_info->red_primary.y=0.330; |
| 574 | chromaticity_info->red_primary.z=0.030; |
| 575 | chromaticity_info->green_primary.x=0.300; |
| 576 | chromaticity_info->green_primary.y=0.600; |
| 577 | chromaticity_info->green_primary.z=0.100; |
| 578 | chromaticity_info->blue_primary.x=0.150; |
| 579 | chromaticity_info->blue_primary.y=0.060; |
| 580 | chromaticity_info->blue_primary.z=0.790; |
| 581 | chromaticity_info->white_point.x=0.3127; |
| 582 | chromaticity_info->white_point.y=0.3290; |
| 583 | chromaticity_info->white_point.z=0.3582; |
| 584 | break; |
| 585 | } |
| 586 | case NTSCCompositeVideoColorimetric: |
| 587 | { |
| 588 | chromaticity_info->red_primary.x=0.67; |
| 589 | chromaticity_info->red_primary.y=0.33; |
| 590 | chromaticity_info->red_primary.z=0.00; |
| 591 | chromaticity_info->green_primary.x=0.21; |
| 592 | chromaticity_info->green_primary.y=0.71; |
| 593 | chromaticity_info->green_primary.z=0.08; |
| 594 | chromaticity_info->blue_primary.x=0.14; |
| 595 | chromaticity_info->blue_primary.y=0.08; |
| 596 | chromaticity_info->blue_primary.z=0.78; |
| 597 | chromaticity_info->white_point.x=0.310; |
| 598 | chromaticity_info->white_point.y=0.316; |
| 599 | chromaticity_info->white_point.z=0.374; |
| 600 | break; |
| 601 | } |
| 602 | case PALCompositeVideoColorimetric: |
| 603 | { |
| 604 | chromaticity_info->red_primary.x=0.640; |
| 605 | chromaticity_info->red_primary.y=0.330; |
| 606 | chromaticity_info->red_primary.z=0.030; |
| 607 | chromaticity_info->green_primary.x=0.290; |
| 608 | chromaticity_info->green_primary.y=0.600; |
| 609 | chromaticity_info->green_primary.z=0.110; |
| 610 | chromaticity_info->blue_primary.x=0.150; |
| 611 | chromaticity_info->blue_primary.y=0.060; |
| 612 | chromaticity_info->blue_primary.z=0.790; |
| 613 | chromaticity_info->white_point.x=0.3127; |
| 614 | chromaticity_info->white_point.y=0.3290; |
| 615 | chromaticity_info->white_point.z=0.3582; |
| 616 | break; |
| 617 | } |
| 618 | default: |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 623 | static void TimeCodeToString(const size_t timestamp,char *code) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 624 | { |
| 625 | #define TimeFields 7 |
| 626 | |
| 627 | unsigned int |
| 628 | shift; |
| 629 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 630 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 631 | i; |
| 632 | |
| 633 | *code='\0'; |
| 634 | shift=4*TimeFields; |
| 635 | for (i=0; i <= TimeFields; i++) |
| 636 | { |
| cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 637 | (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x", |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 638 | (unsigned int) ((timestamp >> shift) & 0x0fU)); |
| 639 | code++; |
| 640 | if (((i % 2) != 0) && (i < TimeFields)) |
| 641 | *code++=':'; |
| 642 | shift-=4; |
| 643 | *code='\0'; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 648 | { |
| 649 | char |
| 650 | magick[4], |
| 651 | value[MaxTextExtent]; |
| 652 | |
| 653 | DPXInfo |
| 654 | dpx; |
| 655 | |
| 656 | Image |
| 657 | *image; |
| 658 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | MagickBooleanType |
| 660 | status; |
| 661 | |
| 662 | MagickOffsetType |
| 663 | offset; |
| 664 | |
| cristy | ff024b4 | 2010-02-21 22:55:09 +0000 | [diff] [blame] | 665 | QuantumInfo |
| 666 | *quantum_info; |
| 667 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | QuantumType |
| 669 | quantum_type; |
| 670 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 671 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 672 | i; |
| 673 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | size_t |
| cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 675 | extent, |
| 676 | samples_per_pixel; |
| 677 | |
| 678 | ssize_t |
| 679 | count, |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 680 | n, |
| cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 681 | row, |
| 682 | y; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 683 | |
| 684 | unsigned char |
| 685 | component_type; |
| 686 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 687 | /* |
| 688 | Open image file. |
| 689 | */ |
| 690 | assert(image_info != (const ImageInfo *) NULL); |
| 691 | assert(image_info->signature == MagickSignature); |
| 692 | if (image_info->debug != MagickFalse) |
| 693 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 694 | image_info->filename); |
| 695 | assert(exception != (ExceptionInfo *) NULL); |
| 696 | assert(exception->signature == MagickSignature); |
| cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 697 | image=AcquireImage(image_info,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 698 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 699 | if (status == MagickFalse) |
| 700 | { |
| 701 | image=DestroyImageList(image); |
| 702 | return((Image *) NULL); |
| 703 | } |
| 704 | /* |
| 705 | Read DPX file header. |
| 706 | */ |
| 707 | offset=0; |
| 708 | count=ReadBlob(image,4,(unsigned char *) magick); |
| 709 | offset+=count; |
| 710 | if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) && |
| 711 | (LocaleNCompare((char *) magick,"XPDS",4) != 0))) |
| 712 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 713 | image->endian=LSBEndian; |
| 714 | if (LocaleNCompare(magick,"SDPX",4) == 0) |
| 715 | image->endian=MSBEndian; |
| 716 | (void) ResetMagickMemory(&dpx,0,sizeof(dpx)); |
| 717 | dpx.file.image_offset=ReadBlobLong(image); |
| 718 | offset+=4; |
| 719 | offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *) |
| 720 | dpx.file.version); |
| 721 | (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version); |
| 722 | dpx.file.file_size=ReadBlobLong(image); |
| 723 | offset+=4; |
| 724 | dpx.file.ditto_key=ReadBlobLong(image); |
| 725 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 726 | if (dpx.file.ditto_key != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 727 | (void) FormatImageProperty(image,"dpx:file.ditto.key","%u", |
| 728 | dpx.file.ditto_key); |
| 729 | dpx.file.generic_size=ReadBlobLong(image); |
| 730 | offset+=4; |
| 731 | dpx.file.industry_size=ReadBlobLong(image); |
| 732 | offset+=4; |
| 733 | dpx.file.user_size=ReadBlobLong(image); |
| 734 | offset+=4; |
| 735 | offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *) |
| 736 | dpx.file.filename); |
| 737 | (void) FormatImageProperty(image,"dpx:file.filename","%.100s", |
| 738 | dpx.file.filename); |
| 739 | (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename); |
| 740 | offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *) |
| 741 | dpx.file.timestamp); |
| 742 | if (*dpx.file.timestamp != '\0') |
| 743 | (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s", |
| 744 | dpx.file.timestamp); |
| 745 | offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *) |
| 746 | dpx.file.creator); |
| 747 | if (*dpx.file.creator != '\0') |
| 748 | { |
| 749 | (void) FormatImageProperty(image,"dpx:file.creator","%.100s", |
| 750 | dpx.file.creator); |
| 751 | (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator); |
| 752 | } |
| 753 | offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *) |
| 754 | dpx.file.project); |
| 755 | if (*dpx.file.project != '\0') |
| 756 | { |
| 757 | (void) FormatImageProperty(image,"dpx:file.project","%.200s", |
| 758 | dpx.file.project); |
| 759 | (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project); |
| 760 | } |
| 761 | offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *) |
| 762 | dpx.file.copyright); |
| 763 | if (*dpx.file.copyright != '\0') |
| 764 | { |
| 765 | (void) FormatImageProperty(image,"dpx:file.copyright","%.200s", |
| 766 | dpx.file.copyright); |
| 767 | (void) FormatImageProperty(image,"copyright","%.100s", |
| 768 | dpx.file.copyright); |
| 769 | } |
| 770 | dpx.file.encrypt_key=ReadBlobLong(image); |
| 771 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 772 | if (dpx.file.encrypt_key != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 773 | (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u", |
| 774 | dpx.file.encrypt_key); |
| 775 | offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *) |
| 776 | dpx.file.reserve); |
| 777 | /* |
| 778 | Read DPX image header. |
| 779 | */ |
| 780 | dpx.image.orientation=ReadBlobShort(image); |
| cristy | 1f7ae7f | 2014-11-28 14:26:15 +0000 | [diff] [blame] | 781 | if (dpx.image.orientation > 7) |
| 782 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 783 | offset+=2; |
| cristy | 6310e8d | 2013-11-11 12:52:08 +0000 | [diff] [blame] | 784 | if (dpx.image.orientation != (unsigned short) ~0) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 785 | (void) FormatImageProperty(image,"dpx:image.orientation","%d", |
| 786 | dpx.image.orientation); |
| 787 | switch (dpx.image.orientation) |
| 788 | { |
| 789 | default: |
| cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 790 | case 0: image->orientation=TopLeftOrientation; break; |
| 791 | case 1: image->orientation=TopRightOrientation; break; |
| 792 | case 2: image->orientation=BottomLeftOrientation; break; |
| 793 | case 3: image->orientation=BottomRightOrientation; break; |
| 794 | case 4: image->orientation=LeftTopOrientation; break; |
| 795 | case 5: image->orientation=RightTopOrientation; break; |
| 796 | case 6: image->orientation=LeftBottomOrientation; break; |
| 797 | case 7: image->orientation=RightBottomOrientation; break; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 798 | } |
| 799 | dpx.image.number_elements=ReadBlobShort(image); |
| cristy | 1f7ae7f | 2014-11-28 14:26:15 +0000 | [diff] [blame] | 800 | if (dpx.image.number_elements > MaxNumberImageElements) |
| cristy | 7d3fc13 | 2014-11-23 16:36:24 +0000 | [diff] [blame] | 801 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 802 | offset+=2; |
| 803 | dpx.image.pixels_per_line=ReadBlobLong(image); |
| 804 | offset+=4; |
| 805 | image->columns=dpx.image.pixels_per_line; |
| 806 | dpx.image.lines_per_element=ReadBlobLong(image); |
| 807 | offset+=4; |
| 808 | image->rows=dpx.image.lines_per_element; |
| 809 | for (i=0; i < 8; i++) |
| 810 | { |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 811 | char |
| 812 | property[MaxTextExtent]; |
| 813 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 814 | dpx.image.image_element[i].data_sign=ReadBlobLong(image); |
| 815 | offset+=4; |
| 816 | dpx.image.image_element[i].low_data=ReadBlobLong(image); |
| 817 | offset+=4; |
| 818 | dpx.image.image_element[i].low_quantity=ReadBlobFloat(image); |
| 819 | offset+=4; |
| 820 | dpx.image.image_element[i].high_data=ReadBlobLong(image); |
| 821 | offset+=4; |
| 822 | dpx.image.image_element[i].high_quantity=ReadBlobFloat(image); |
| 823 | offset+=4; |
| 824 | dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image); |
| 825 | offset++; |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 826 | dpx.image.image_element[i].transfer_characteristic=(unsigned char) |
| 827 | ReadBlobByte(image); |
| 828 | (void) FormatLocaleString(property,MaxTextExtent, |
| 829 | "dpx:image.element[%lu].transfer-characteristic",(long) i); |
| 830 | (void) FormatImageProperty(image,property,"%s", |
| 831 | GetImageTransferCharacteristic((DPXTransferCharacteristic) |
| 832 | dpx.image.image_element[i].transfer_characteristic)); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 833 | offset++; |
| 834 | dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image); |
| 835 | offset++; |
| 836 | dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image); |
| 837 | offset++; |
| 838 | dpx.image.image_element[i].packing=ReadBlobShort(image); |
| 839 | offset+=2; |
| 840 | dpx.image.image_element[i].encoding=ReadBlobShort(image); |
| 841 | offset+=2; |
| 842 | dpx.image.image_element[i].data_offset=ReadBlobLong(image); |
| 843 | offset+=4; |
| 844 | dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image); |
| 845 | offset+=4; |
| 846 | dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image); |
| 847 | offset+=4; |
| 848 | offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description), |
| 849 | (unsigned char *) dpx.image.image_element[i].description); |
| 850 | } |
| cristy | b2c3f40 | 2012-05-13 18:05:12 +0000 | [diff] [blame] | 851 | SetImageColorspace(image,RGBColorspace,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 852 | offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *) |
| 853 | dpx.image.reserve); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 854 | if (dpx.file.image_offset >= 1664U) |
| 855 | { |
| 856 | /* |
| 857 | Read DPX orientation header. |
| 858 | */ |
| 859 | dpx.orientation.x_offset=ReadBlobLong(image); |
| 860 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 861 | if (dpx.orientation.x_offset != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 862 | (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u", |
| 863 | dpx.orientation.x_offset); |
| 864 | dpx.orientation.y_offset=ReadBlobLong(image); |
| 865 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 866 | if (dpx.orientation.y_offset != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 867 | (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u", |
| 868 | dpx.orientation.y_offset); |
| 869 | dpx.orientation.x_center=ReadBlobFloat(image); |
| 870 | offset+=4; |
| 871 | if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse) |
| 872 | (void) FormatImageProperty(image,"dpx:orientation.x_center","%g", |
| 873 | dpx.orientation.x_center); |
| 874 | dpx.orientation.y_center=ReadBlobFloat(image); |
| 875 | offset+=4; |
| 876 | if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse) |
| 877 | (void) FormatImageProperty(image,"dpx:orientation.y_center","%g", |
| 878 | dpx.orientation.y_center); |
| 879 | dpx.orientation.x_size=ReadBlobLong(image); |
| 880 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 881 | if (dpx.orientation.x_size != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 882 | (void) FormatImageProperty(image,"dpx:orientation.x_size","%u", |
| 883 | dpx.orientation.x_size); |
| 884 | dpx.orientation.y_size=ReadBlobLong(image); |
| 885 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 886 | if (dpx.orientation.y_size != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 887 | (void) FormatImageProperty(image,"dpx:orientation.y_size","%u", |
| 888 | dpx.orientation.y_size); |
| 889 | offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *) |
| 890 | dpx.orientation.filename); |
| 891 | if (*dpx.orientation.filename != '\0') |
| 892 | (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s", |
| 893 | dpx.orientation.filename); |
| 894 | offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *) |
| 895 | dpx.orientation.timestamp); |
| 896 | if (*dpx.orientation.timestamp != '\0') |
| 897 | (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s", |
| 898 | dpx.orientation.timestamp); |
| 899 | offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *) |
| 900 | dpx.orientation.device); |
| 901 | if (*dpx.orientation.device != '\0') |
| 902 | (void) FormatImageProperty(image,"dpx:orientation.device","%.32s", |
| 903 | dpx.orientation.device); |
| 904 | offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *) |
| 905 | dpx.orientation.serial); |
| 906 | if (*dpx.orientation.serial != '\0') |
| 907 | (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s", |
| 908 | dpx.orientation.serial); |
| 909 | for (i=0; i < 4; i++) |
| 910 | { |
| 911 | dpx.orientation.border[i]=ReadBlobShort(image); |
| 912 | offset+=2; |
| 913 | } |
| dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 914 | if ((dpx.orientation.border[0] != (unsigned short) (~0)) && |
| 915 | (dpx.orientation.border[1] != (unsigned short) (~0))) |
| 916 | (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d", |
| 917 | dpx.orientation.border[0],dpx.orientation.border[1], |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 918 | dpx.orientation.border[2],dpx.orientation.border[3]); |
| 919 | for (i=0; i < 2; i++) |
| 920 | { |
| 921 | dpx.orientation.aspect_ratio[i]=ReadBlobLong(image); |
| 922 | offset+=4; |
| 923 | } |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 924 | if ((dpx.orientation.aspect_ratio[0] != ~0U) && |
| 925 | (dpx.orientation.aspect_ratio[1] != ~0U)) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 926 | (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio", |
| 927 | "%ux%u",dpx.orientation.aspect_ratio[0], |
| 928 | dpx.orientation.aspect_ratio[1]); |
| 929 | offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *) |
| 930 | dpx.orientation.reserve); |
| 931 | } |
| 932 | if (dpx.file.image_offset >= 1920U) |
| 933 | { |
| 934 | /* |
| 935 | Read DPX film header. |
| 936 | */ |
| 937 | offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id); |
| cristy | 4d0ca34 | 2014-05-01 00:42:09 +0000 | [diff] [blame] | 938 | if (*dpx.film.id != '\0') |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 939 | (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id); |
| 940 | offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *) |
| 941 | dpx.film.type); |
| 942 | if (*dpx.film.type != '\0') |
| 943 | (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type); |
| 944 | offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *) |
| 945 | dpx.film.offset); |
| 946 | if (*dpx.film.offset != '\0') |
| 947 | (void) FormatImageProperty(image,"dpx:film.offset","%.2s", |
| 948 | dpx.film.offset); |
| 949 | offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *) |
| 950 | dpx.film.prefix); |
| 951 | if (*dpx.film.prefix != '\0') |
| 952 | (void) FormatImageProperty(image,"dpx:film.prefix","%.6s", |
| 953 | dpx.film.prefix); |
| 954 | offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *) |
| 955 | dpx.film.count); |
| 956 | if (*dpx.film.count != '\0') |
| 957 | (void) FormatImageProperty(image,"dpx:film.count","%.4s", |
| 958 | dpx.film.count); |
| 959 | offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *) |
| 960 | dpx.film.format); |
| 961 | if (*dpx.film.format != '\0') |
| 962 | (void) FormatImageProperty(image,"dpx:film.format","%.4s", |
| 963 | dpx.film.format); |
| 964 | dpx.film.frame_position=ReadBlobLong(image); |
| 965 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 966 | if (dpx.film.frame_position != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 967 | (void) FormatImageProperty(image,"dpx:film.frame_position","%u", |
| 968 | dpx.film.frame_position); |
| 969 | dpx.film.sequence_extent=ReadBlobLong(image); |
| 970 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 971 | if (dpx.film.sequence_extent != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 972 | (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u", |
| 973 | dpx.film.sequence_extent); |
| 974 | dpx.film.held_count=ReadBlobLong(image); |
| 975 | offset+=4; |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 976 | if (dpx.film.held_count != ~0U) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 977 | (void) FormatImageProperty(image,"dpx:film.held_count","%u", |
| 978 | dpx.film.held_count); |
| 979 | dpx.film.frame_rate=ReadBlobFloat(image); |
| 980 | offset+=4; |
| 981 | if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse) |
| 982 | (void) FormatImageProperty(image,"dpx:film.frame_rate","%g", |
| 983 | dpx.film.frame_rate); |
| 984 | dpx.film.shutter_angle=ReadBlobFloat(image); |
| 985 | offset+=4; |
| 986 | if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse) |
| 987 | (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g", |
| 988 | dpx.film.shutter_angle); |
| 989 | offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *) |
| 990 | dpx.film.frame_id); |
| 991 | if (*dpx.film.frame_id != '\0') |
| 992 | (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s", |
| 993 | dpx.film.frame_id); |
| 994 | offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *) |
| 995 | dpx.film.slate); |
| 996 | if (*dpx.film.slate != '\0') |
| 997 | (void) FormatImageProperty(image,"dpx:film.slate","%.100s", |
| 998 | dpx.film.slate); |
| 999 | offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *) |
| 1000 | dpx.film.reserve); |
| 1001 | } |
| 1002 | if (dpx.file.image_offset >= 2048U) |
| 1003 | { |
| 1004 | /* |
| 1005 | Read DPX television header. |
| 1006 | */ |
| 1007 | dpx.television.time_code=(unsigned int) ReadBlobLong(image); |
| 1008 | offset+=4; |
| 1009 | TimeCodeToString(dpx.television.time_code,value); |
| cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1010 | (void) SetImageProperty(image,"dpx:television.time.code",value,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1011 | dpx.television.user_bits=(unsigned int) ReadBlobLong(image); |
| 1012 | offset+=4; |
| 1013 | TimeCodeToString(dpx.television.user_bits,value); |
| cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1014 | (void) SetImageProperty(image,"dpx:television.user.bits",value,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1015 | dpx.television.interlace=(unsigned char) ReadBlobByte(image); |
| 1016 | offset++; |
| 1017 | if (dpx.television.interlace != 0) |
| cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1018 | (void) FormatImageProperty(image,"dpx:television.interlace","%.20g", |
| 1019 | (double) dpx.television.interlace); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1020 | dpx.television.field_number=(unsigned char) ReadBlobByte(image); |
| 1021 | offset++; |
| 1022 | if (dpx.television.field_number != 0) |
| cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1023 | (void) FormatImageProperty(image,"dpx:television.field_number","%.20g", |
| 1024 | (double) dpx.television.field_number); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1025 | dpx.television.video_signal=(unsigned char) ReadBlobByte(image); |
| 1026 | offset++; |
| 1027 | if (dpx.television.video_signal != 0) |
| cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1028 | (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g", |
| 1029 | (double) dpx.television.video_signal); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1030 | dpx.television.padding=(unsigned char) ReadBlobByte(image); |
| 1031 | offset++; |
| 1032 | if (dpx.television.padding != 0) |
| 1033 | (void) FormatImageProperty(image,"dpx:television.padding","%d", |
| 1034 | dpx.television.padding); |
| 1035 | dpx.television.horizontal_sample_rate=ReadBlobFloat(image); |
| 1036 | offset+=4; |
| 1037 | if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse) |
| 1038 | (void) FormatImageProperty(image, |
| 1039 | "dpx:television.horizontal_sample_rate","%g", |
| 1040 | dpx.television.horizontal_sample_rate); |
| 1041 | dpx.television.vertical_sample_rate=ReadBlobFloat(image); |
| 1042 | offset+=4; |
| 1043 | if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse) |
| 1044 | (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate", |
| 1045 | "%g",dpx.television.vertical_sample_rate); |
| 1046 | dpx.television.frame_rate=ReadBlobFloat(image); |
| 1047 | offset+=4; |
| 1048 | if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse) |
| 1049 | (void) FormatImageProperty(image,"dpx:television.frame_rate","%g", |
| 1050 | dpx.television.frame_rate); |
| 1051 | dpx.television.time_offset=ReadBlobFloat(image); |
| 1052 | offset+=4; |
| 1053 | if (IsFloatDefined(dpx.television.time_offset) != MagickFalse) |
| 1054 | (void) FormatImageProperty(image,"dpx:television.time_offset","%g", |
| 1055 | dpx.television.time_offset); |
| 1056 | dpx.television.gamma=ReadBlobFloat(image); |
| 1057 | offset+=4; |
| 1058 | if (IsFloatDefined(dpx.television.gamma) != MagickFalse) |
| 1059 | (void) FormatImageProperty(image,"dpx:television.gamma","%g", |
| 1060 | dpx.television.gamma); |
| 1061 | dpx.television.black_level=ReadBlobFloat(image); |
| 1062 | offset+=4; |
| 1063 | if (IsFloatDefined(dpx.television.black_level) != MagickFalse) |
| 1064 | (void) FormatImageProperty(image,"dpx:television.black_level","%g", |
| 1065 | dpx.television.black_level); |
| 1066 | dpx.television.black_gain=ReadBlobFloat(image); |
| 1067 | offset+=4; |
| 1068 | if (IsFloatDefined(dpx.television.black_gain) != MagickFalse) |
| 1069 | (void) FormatImageProperty(image,"dpx:television.black_gain","%g", |
| 1070 | dpx.television.black_gain); |
| 1071 | dpx.television.break_point=ReadBlobFloat(image); |
| 1072 | offset+=4; |
| 1073 | if (IsFloatDefined(dpx.television.break_point) != MagickFalse) |
| 1074 | (void) FormatImageProperty(image,"dpx:television.break_point","%g", |
| 1075 | dpx.television.break_point); |
| 1076 | dpx.television.white_level=ReadBlobFloat(image); |
| 1077 | offset+=4; |
| 1078 | if (IsFloatDefined(dpx.television.white_level) != MagickFalse) |
| 1079 | (void) FormatImageProperty(image,"dpx:television.white_level","%g", |
| 1080 | dpx.television.white_level); |
| 1081 | dpx.television.integration_times=ReadBlobFloat(image); |
| 1082 | offset+=4; |
| 1083 | if (IsFloatDefined(dpx.television.integration_times) != MagickFalse) |
| 1084 | (void) FormatImageProperty(image,"dpx:television.integration_times", |
| 1085 | "%g",dpx.television.integration_times); |
| 1086 | offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *) |
| 1087 | dpx.television.reserve); |
| 1088 | } |
| 1089 | if (dpx.file.image_offset > 2080U) |
| 1090 | { |
| 1091 | /* |
| 1092 | Read DPX user header. |
| 1093 | */ |
| 1094 | offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id); |
| 1095 | if (*dpx.user.id != '\0') |
| 1096 | (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id); |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 1097 | if ((dpx.file.user_size != ~0U) && |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1098 | ((size_t) dpx.file.user_size > sizeof(dpx.user.id))) |
| 1099 | { |
| 1100 | StringInfo |
| 1101 | *profile; |
| 1102 | |
| cristy | 6039529 | 2011-09-01 13:25:56 +0000 | [diff] [blame] | 1103 | profile=BlobToStringInfo((const void *) NULL, |
| 1104 | dpx.file.user_size-sizeof(dpx.user.id)); |
| 1105 | if (profile == (StringInfo *) NULL) |
| 1106 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1107 | offset+=ReadBlob(image,GetStringInfoLength(profile), |
| 1108 | GetStringInfoDatum(profile)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1109 | (void) SetImageProfile(image,"dpx:user-data",profile,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1110 | profile=DestroyStringInfo(profile); |
| 1111 | } |
| 1112 | } |
| cristy | 811f517 | 2010-12-29 17:38:08 +0000 | [diff] [blame] | 1113 | for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1114 | (void) ReadBlobByte(image); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1115 | if (image_info->ping != MagickFalse) |
| 1116 | { |
| 1117 | (void) CloseBlob(image); |
| 1118 | return(GetFirstImageInList(image)); |
| 1119 | } |
| cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 1120 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 1121 | if (status == MagickFalse) |
| 1122 | return(DestroyImageList(image)); |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1123 | for (n=0; n < (ssize_t) dpx.image.number_elements; n++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1124 | { |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1125 | /* |
| 1126 | Convert DPX raster image to pixel packets. |
| 1127 | */ |
| cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 1128 | if ((dpx.image.image_element[n].data_offset != ~0U) && |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1129 | (dpx.image.image_element[n].data_offset != 0U)) |
| cristy | ff024b4 | 2010-02-21 22:55:09 +0000 | [diff] [blame] | 1130 | { |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1131 | MagickOffsetType |
| 1132 | data_offset; |
| 1133 | |
| 1134 | data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset; |
| 1135 | if (data_offset < offset) |
| 1136 | offset=SeekBlob(image,data_offset,SEEK_SET); |
| 1137 | else |
| 1138 | for ( ; offset < data_offset; offset++) |
| 1139 | (void) ReadBlobByte(image); |
| 1140 | if (offset != data_offset) |
| 1141 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 1142 | } |
| cristy | ea48515 | 2012-10-03 11:48:50 +0000 | [diff] [blame] | 1143 | SetPrimaryChromaticity((DPXColorimetric) |
| 1144 | dpx.image.image_element[n].colorimetric,&image->chromaticity); |
| 1145 | image->depth=dpx.image.image_element[n].bit_size; |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1146 | samples_per_pixel=1; |
| 1147 | quantum_type=GrayQuantum; |
| cristy | ea48515 | 2012-10-03 11:48:50 +0000 | [diff] [blame] | 1148 | component_type=dpx.image.image_element[n].descriptor; |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1149 | switch (component_type) |
| 1150 | { |
| 1151 | case CbYCrY422ComponentType: |
| 1152 | { |
| 1153 | samples_per_pixel=2; |
| 1154 | quantum_type=CbYCrYQuantum; |
| 1155 | break; |
| cristy | ff024b4 | 2010-02-21 22:55:09 +0000 | [diff] [blame] | 1156 | } |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1157 | case CbYACrYA4224ComponentType: |
| 1158 | case CbYCr444ComponentType: |
| 1159 | { |
| 1160 | samples_per_pixel=3; |
| 1161 | quantum_type=CbYCrQuantum; |
| 1162 | break; |
| 1163 | } |
| 1164 | case RGBComponentType: |
| 1165 | { |
| 1166 | samples_per_pixel=3; |
| 1167 | quantum_type=RGBQuantum; |
| 1168 | break; |
| 1169 | } |
| 1170 | case ABGRComponentType: |
| 1171 | case RGBAComponentType: |
| 1172 | { |
| 1173 | image->alpha_trait=BlendPixelTrait; |
| 1174 | samples_per_pixel=4; |
| 1175 | quantum_type=RGBAQuantum; |
| 1176 | break; |
| 1177 | } |
| 1178 | default: |
| 1179 | break; |
| 1180 | } |
| 1181 | switch (component_type) |
| 1182 | { |
| 1183 | case CbYCrY422ComponentType: |
| 1184 | case CbYACrYA4224ComponentType: |
| 1185 | case CbYCr444ComponentType: |
| 1186 | { |
| 1187 | SetImageColorspace(image,Rec709YCbCrColorspace,exception); |
| 1188 | break; |
| 1189 | } |
| 1190 | case LumaComponentType: |
| 1191 | { |
| cristy | ea48515 | 2012-10-03 11:48:50 +0000 | [diff] [blame] | 1192 | SetImageColorspace(image,GRAYColorspace,exception); |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1193 | break; |
| 1194 | } |
| 1195 | default: |
| 1196 | { |
| 1197 | SetImageColorspace(image,sRGBColorspace,exception); |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 1198 | if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric) |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1199 | SetImageColorspace(image,LogColorspace,exception); |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 1200 | if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric) |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1201 | SetImageColorspace(image,LogColorspace,exception); |
| 1202 | break; |
| 1203 | } |
| 1204 | } |
| 1205 | extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth, |
| 1206 | dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue); |
| 1207 | /* |
| 1208 | DPX any-bit pixel format. |
| 1209 | */ |
| 1210 | status=MagickTrue; |
| 1211 | row=0; |
| cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 1212 | quantum_info=AcquireQuantumInfo(image_info,image); |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1213 | if (quantum_info == (QuantumInfo *) NULL) |
| 1214 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1215 | SetQuantumQuantum(quantum_info,32); |
| 1216 | SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ? |
| 1217 | MagickTrue : MagickFalse); |
| 1218 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1219 | { |
| cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 1220 | const void |
| 1221 | *pixels; |
| 1222 | |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1223 | MagickBooleanType |
| 1224 | sync; |
| 1225 | |
| 1226 | register Quantum |
| 1227 | *q; |
| 1228 | |
| 1229 | size_t |
| 1230 | length; |
| 1231 | |
| 1232 | ssize_t |
| 1233 | count, |
| 1234 | offset; |
| 1235 | |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1236 | if (status == MagickFalse) |
| 1237 | continue; |
| cristy | cdce6ac | 2015-01-24 23:06:04 +0000 | [diff] [blame] | 1238 | pixels=ReadBlobStream(image,extent,GetQuantumPixels(quantum_info), |
| cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 1239 | &count); |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1240 | if (count != (ssize_t) extent) |
| 1241 | status=MagickFalse; |
| cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 1242 | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
| 1243 | (image->previous == (Image *) NULL)) |
| 1244 | { |
| 1245 | MagickBooleanType |
| 1246 | proceed; |
| 1247 | |
| 1248 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row, |
| 1249 | image->rows); |
| 1250 | if (proceed == MagickFalse) |
| 1251 | status=MagickFalse; |
| 1252 | } |
| 1253 | offset=row++; |
| cristy | 04ea8a0 | 2012-09-30 15:23:28 +0000 | [diff] [blame] | 1254 | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
| 1255 | if (q == (Quantum *) NULL) |
| 1256 | { |
| 1257 | status=MagickFalse; |
| 1258 | continue; |
| 1259 | } |
| 1260 | length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 1261 | quantum_type,pixels,exception); |
| 1262 | (void) length; |
| 1263 | sync=SyncAuthenticPixels(image,exception); |
| 1264 | if (sync == MagickFalse) |
| 1265 | status=MagickFalse; |
| 1266 | } |
| 1267 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1268 | if (status == MagickFalse) |
| 1269 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 1270 | SetQuantumImageType(image,quantum_type); |
| 1271 | if (EOFBlob(image) != MagickFalse) |
| 1272 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 1273 | image->filename); |
| 1274 | if ((i+1) < (ssize_t) dpx.image.number_elements) |
| 1275 | { |
| 1276 | /* |
| 1277 | Allocate next image structure. |
| 1278 | */ |
| 1279 | AcquireNextImage(image_info,image,exception); |
| 1280 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1281 | { |
| 1282 | image=DestroyImageList(image); |
| 1283 | return((Image *) NULL); |
| 1284 | } |
| 1285 | image=SyncNextImageInList(image); |
| 1286 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 1287 | GetBlobSize(image)); |
| 1288 | if (status == MagickFalse) |
| 1289 | break; |
| 1290 | } |
| cristy | ff024b4 | 2010-02-21 22:55:09 +0000 | [diff] [blame] | 1291 | } |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1292 | (void) CloseBlob(image); |
| 1293 | return(GetFirstImageInList(image)); |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1298 | % % |
| 1299 | % % |
| 1300 | % % |
| 1301 | % R e g i s t e r D P X I m a g e % |
| 1302 | % % |
| 1303 | % % |
| 1304 | % % |
| 1305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1306 | % |
| 1307 | % RegisterDPXImage() adds properties for the DPX image format to |
| 1308 | % the list of supported formats. The properties include the image format |
| 1309 | % tag, a method to read and/or write the format, whether the format |
| 1310 | % supports the saving of more than one frame to the same file or blob, |
| 1311 | % whether the format supports native in-memory I/O, and a brief |
| 1312 | % description of the format. |
| 1313 | % |
| 1314 | % The format of the RegisterDPXImage method is: |
| 1315 | % |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1316 | % size_t RegisterDPXImage(void) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1317 | % |
| 1318 | */ |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1319 | ModuleExport size_t RegisterDPXImage(void) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1320 | { |
| 1321 | MagickInfo |
| 1322 | *entry; |
| 1323 | |
| 1324 | static const char |
| 1325 | *DPXNote = |
| 1326 | { |
| 1327 | "Digital Moving Picture Exchange Bitmap, Version 2.0.\n" |
| 1328 | "See SMPTE 268M-2003 specification at http://www.smtpe.org\n" |
| 1329 | }; |
| 1330 | |
| 1331 | entry=SetMagickInfo("DPX"); |
| 1332 | entry->decoder=(DecodeImageHandler *) ReadDPXImage; |
| 1333 | entry->encoder=(EncodeImageHandler *) WriteDPXImage; |
| 1334 | entry->magick=(IsImageFormatHandler *) IsDPX; |
| dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame^] | 1335 | entry->flags^=CoderAdjoinFlag; |
| 1336 | entry->flags|=CoderSeekableStreamFlag; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1337 | entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)"); |
| 1338 | entry->note=ConstantString(DPXNote); |
| 1339 | entry->module=ConstantString("DPX"); |
| 1340 | (void) RegisterMagickInfo(entry); |
| 1341 | return(MagickImageCoderSignature); |
| 1342 | } |
| 1343 | |
| 1344 | /* |
| 1345 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1346 | % % |
| 1347 | % % |
| 1348 | % % |
| 1349 | % U n r e g i s t e r D P X I m a g e % |
| 1350 | % % |
| 1351 | % % |
| 1352 | % % |
| 1353 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1354 | % |
| 1355 | % UnregisterDPXImage() removes format registrations made by the |
| 1356 | % DPX module from the list of supported formats. |
| 1357 | % |
| 1358 | % The format of the UnregisterDPXImage method is: |
| 1359 | % |
| 1360 | % UnregisterDPXImage(void) |
| 1361 | % |
| 1362 | */ |
| 1363 | ModuleExport void UnregisterDPXImage(void) |
| 1364 | { |
| 1365 | (void) UnregisterMagickInfo("DPX"); |
| 1366 | } |
| 1367 | |
| 1368 | /* |
| 1369 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1370 | % % |
| 1371 | % % |
| 1372 | % % |
| 1373 | % W r i t e D P X I m a g e % |
| 1374 | % % |
| 1375 | % % |
| 1376 | % % |
| 1377 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1378 | % |
| 1379 | % WriteDPXImage() writes an image in DPX encoded image format. |
| 1380 | % |
| 1381 | % The format of the WriteDPXImage method is: |
| 1382 | % |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1383 | % MagickBooleanType WriteDPXImage(const ImageInfo *image_info, |
| 1384 | % Image *image,ExceptionInfo *exception) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1385 | % |
| 1386 | % A description of each parameter follows. |
| 1387 | % |
| 1388 | % o image_info: the image info. |
| 1389 | % |
| 1390 | % o image: The image. |
| 1391 | % |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1392 | % o exception: return any errors or warnings in this structure. |
| 1393 | % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1394 | */ |
| 1395 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1396 | static unsigned int StringToTimeCode(const char *key) |
| 1397 | { |
| 1398 | char |
| 1399 | buffer[2]; |
| 1400 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1401 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1402 | i; |
| 1403 | |
| 1404 | unsigned int |
| 1405 | shift, |
| 1406 | value; |
| 1407 | |
| 1408 | value=0; |
| 1409 | shift=28; |
| 1410 | buffer[1]='\0'; |
| 1411 | for (i=0; (*key != 0) && (i < 11); i++) |
| 1412 | { |
| 1413 | if (isxdigit((int) ((unsigned char) *key)) == 0) |
| 1414 | { |
| 1415 | key++; |
| 1416 | continue; |
| 1417 | } |
| 1418 | buffer[0]=(*key++); |
| 1419 | value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift); |
| 1420 | shift-=4; |
| 1421 | } |
| 1422 | return(value); |
| 1423 | } |
| 1424 | |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1425 | static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image, |
| 1426 | ExceptionInfo *exception) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1427 | { |
| 1428 | const char |
| 1429 | *value; |
| 1430 | |
| 1431 | const StringInfo |
| 1432 | *profile; |
| 1433 | |
| 1434 | DPXInfo |
| 1435 | dpx; |
| 1436 | |
| cristy | bccc4f4 | 2011-11-24 17:57:52 +0000 | [diff] [blame] | 1437 | GeometryInfo |
| 1438 | geometry_info; |
| 1439 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1440 | MagickBooleanType |
| 1441 | status; |
| 1442 | |
| 1443 | MagickOffsetType |
| 1444 | offset; |
| 1445 | |
| 1446 | MagickStatusType |
| 1447 | flags; |
| 1448 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1449 | QuantumInfo |
| 1450 | *quantum_info; |
| 1451 | |
| 1452 | QuantumType |
| 1453 | quantum_type; |
| 1454 | |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1455 | register const Quantum |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1456 | *p; |
| 1457 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1458 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1459 | i; |
| 1460 | |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1461 | size_t |
| 1462 | extent; |
| 1463 | |
| cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 1464 | ssize_t |
| 1465 | count, |
| 1466 | horizontal_factor, |
| 1467 | vertical_factor, |
| 1468 | y; |
| 1469 | |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1470 | time_t |
| 1471 | seconds; |
| 1472 | |
| 1473 | unsigned char |
| 1474 | *pixels; |
| 1475 | |
| 1476 | /* |
| 1477 | Open output image file. |
| 1478 | */ |
| 1479 | assert(image_info != (const ImageInfo *) NULL); |
| 1480 | assert(image_info->signature == MagickSignature); |
| 1481 | assert(image != (Image *) NULL); |
| 1482 | assert(image->signature == MagickSignature); |
| 1483 | if (image->debug != MagickFalse) |
| 1484 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1485 | horizontal_factor=4; |
| 1486 | vertical_factor=4; |
| 1487 | if (image_info->sampling_factor != (char *) NULL) |
| 1488 | { |
| 1489 | GeometryInfo |
| 1490 | geometry_info; |
| 1491 | |
| 1492 | MagickStatusType |
| 1493 | flags; |
| 1494 | |
| 1495 | flags=ParseGeometry(image_info->sampling_factor,&geometry_info); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1496 | horizontal_factor=(ssize_t) geometry_info.rho; |
| 1497 | vertical_factor=(ssize_t) geometry_info.sigma; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1498 | if ((flags & SigmaValue) == 0) |
| 1499 | vertical_factor=horizontal_factor; |
| 1500 | if ((horizontal_factor != 1) && (horizontal_factor != 2) && |
| 1501 | (horizontal_factor != 4) && (vertical_factor != 1) && |
| 1502 | (vertical_factor != 2) && (vertical_factor != 4)) |
| 1503 | ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor"); |
| 1504 | } |
| 1505 | if ((image->colorspace == YCbCrColorspace) && |
| 1506 | ((horizontal_factor == 2) || (vertical_factor == 2))) |
| 1507 | if ((image->columns % 2) != 0) |
| 1508 | image->columns++; |
| cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1509 | assert(exception != (ExceptionInfo *) NULL); |
| 1510 | assert(exception->signature == MagickSignature); |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1511 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 | if (status == MagickFalse) |
| 1513 | return(status); |
| 1514 | /* |
| 1515 | Write file header. |
| 1516 | */ |
| 1517 | (void) ResetMagickMemory(&dpx,0,sizeof(dpx)); |
| 1518 | offset=0; |
| 1519 | dpx.file.magic=0x53445058U; |
| 1520 | offset+=WriteBlobLong(image,dpx.file.magic); |
| 1521 | dpx.file.image_offset=0x2000U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1522 | profile=GetImageProfile(image,"dpx:user-data"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1523 | if (profile != (StringInfo *) NULL) |
| 1524 | { |
| cristy | 61047b6 | 2010-05-22 02:15:20 +0000 | [diff] [blame] | 1525 | if (GetStringInfoLength(profile) > 1048576) |
| 1526 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1527 | dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile); |
| 1528 | dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000); |
| 1529 | } |
| 1530 | offset+=WriteBlobLong(image,dpx.file.image_offset); |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1531 | (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1532 | offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version); |
| 1533 | dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+ |
| 1534 | dpx.file.image_offset); |
| 1535 | offset+=WriteBlobLong(image,dpx.file.file_size); |
| 1536 | dpx.file.ditto_key=1U; /* new frame */ |
| 1537 | offset+=WriteBlobLong(image,dpx.file.ditto_key); |
| 1538 | dpx.file.generic_size=0x00000680U; |
| 1539 | offset+=WriteBlobLong(image,dpx.file.generic_size); |
| 1540 | dpx.file.industry_size=0x00000180U; |
| 1541 | offset+=WriteBlobLong(image,dpx.file.industry_size); |
| 1542 | dpx.file.user_size=0; |
| 1543 | if (profile != (StringInfo *) NULL) |
| 1544 | { |
| 1545 | dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile); |
| 1546 | dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000); |
| 1547 | } |
| 1548 | offset+=WriteBlobLong(image,dpx.file.user_size); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1549 | value=GetImageArtifact(image,"dpx:file.filename"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1550 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1551 | (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *) |
| 1553 | dpx.file.filename); |
| 1554 | seconds=time((time_t *) NULL); |
| 1555 | (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp), |
| 1556 | dpx.file.timestamp); |
| 1557 | offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *) |
| 1558 | dpx.file.timestamp); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1559 | (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL), |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1560 | sizeof(dpx.file.creator)-1); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1561 | value=GetImageArtifact(image,"dpx:file.creator"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1562 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1563 | (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1564 | offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *) |
| 1565 | dpx.file.creator); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1566 | value=GetImageArtifact(image,"dpx:file.project"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1567 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1568 | (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1569 | offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *) |
| 1570 | dpx.file.project); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1571 | value=GetImageArtifact(image,"dpx:file.copyright"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1572 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1573 | (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1574 | offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *) |
| 1575 | dpx.file.copyright); |
| cristy | 466a68c | 2013-11-08 15:13:21 +0000 | [diff] [blame] | 1576 | dpx.file.encrypt_key=(~0U); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1577 | offset+=WriteBlobLong(image,dpx.file.encrypt_key); |
| 1578 | offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *) |
| 1579 | dpx.file.reserve); |
| 1580 | /* |
| 1581 | Write image header. |
| 1582 | */ |
| cristy | e782058 | 2013-01-01 23:42:55 +0000 | [diff] [blame] | 1583 | switch (image->orientation) |
| 1584 | { |
| 1585 | default: |
| 1586 | case TopLeftOrientation: dpx.image.orientation=0; break; |
| 1587 | case TopRightOrientation: dpx.image.orientation=1; break; |
| 1588 | case BottomLeftOrientation: dpx.image.orientation=2; break; |
| 1589 | case BottomRightOrientation: dpx.image.orientation=3; break; |
| 1590 | case LeftTopOrientation: dpx.image.orientation=4; break; |
| 1591 | case RightTopOrientation: dpx.image.orientation=5; break; |
| 1592 | case LeftBottomOrientation: dpx.image.orientation=6; break; |
| 1593 | case RightBottomOrientation: dpx.image.orientation=7; break; |
| 1594 | } |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1595 | offset+=WriteBlobShort(image,dpx.image.orientation); |
| 1596 | dpx.image.number_elements=1; |
| 1597 | offset+=WriteBlobShort(image,dpx.image.number_elements); |
| 1598 | if ((image->columns != (unsigned int) image->columns) || |
| 1599 | (image->rows != (unsigned int) image->rows)) |
| 1600 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
| 1601 | offset+=WriteBlobLong(image,(unsigned int) image->columns); |
| 1602 | offset+=WriteBlobLong(image,(unsigned int) image->rows); |
| 1603 | for (i=0; i < 8; i++) |
| 1604 | { |
| 1605 | dpx.image.image_element[i].data_sign=0U; |
| 1606 | offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign); |
| 1607 | dpx.image.image_element[i].low_data=0U; |
| 1608 | offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data); |
| 1609 | dpx.image.image_element[i].low_quantity=0.0f; |
| 1610 | offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity); |
| 1611 | dpx.image.image_element[i].high_data=0U; |
| 1612 | offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data); |
| 1613 | dpx.image.image_element[i].high_quantity=0.0f; |
| 1614 | offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity); |
| 1615 | dpx.image.image_element[i].descriptor=0; |
| 1616 | if (i == 0) |
| 1617 | switch (image->colorspace) |
| 1618 | { |
| 1619 | case Rec601YCbCrColorspace: |
| 1620 | case Rec709YCbCrColorspace: |
| 1621 | case YCbCrColorspace: |
| 1622 | { |
| 1623 | dpx.image.image_element[i].descriptor=CbYCr444ComponentType; |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1624 | if (image->alpha_trait != UndefinedPixelTrait) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1625 | dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType; |
| 1626 | break; |
| 1627 | } |
| 1628 | default: |
| 1629 | { |
| 1630 | dpx.image.image_element[i].descriptor=RGBComponentType; |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1631 | if (image->alpha_trait != UndefinedPixelTrait) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1632 | dpx.image.image_element[i].descriptor=RGBAComponentType; |
| cristy | f59a892 | 2010-02-28 19:51:23 +0000 | [diff] [blame] | 1633 | if ((image_info->type != TrueColorType) && |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1634 | (image->alpha_trait == UndefinedPixelTrait) && |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1635 | (IsImageGray(image,exception) != MagickFalse)) |
| cristy | caac294 | 2009-10-01 13:36:18 +0000 | [diff] [blame] | 1636 | dpx.image.image_element[i].descriptor=LumaComponentType; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | } |
| 1639 | } |
| 1640 | offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor); |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 1641 | dpx.image.image_element[i].transfer_characteristic=0; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1642 | if (image->colorspace == LogColorspace) |
| cristy | c7f92ea | 2013-01-10 19:59:00 +0000 | [diff] [blame] | 1643 | dpx.image.image_element[0].transfer_characteristic= |
| 1644 | PrintingDensityColorimetric; |
| 1645 | offset+=WriteBlobByte(image, |
| 1646 | dpx.image.image_element[i].transfer_characteristic); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1647 | dpx.image.image_element[i].colorimetric=0; |
| 1648 | offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric); |
| 1649 | dpx.image.image_element[i].bit_size=0; |
| 1650 | if (i == 0) |
| 1651 | dpx.image.image_element[i].bit_size=(unsigned char) image->depth; |
| 1652 | offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size); |
| 1653 | dpx.image.image_element[i].packing=0; |
| 1654 | if ((image->depth == 10) || (image->depth == 12)) |
| 1655 | dpx.image.image_element[i].packing=1; |
| 1656 | offset+=WriteBlobShort(image,dpx.image.image_element[i].packing); |
| 1657 | dpx.image.image_element[i].encoding=0; |
| 1658 | offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding); |
| 1659 | dpx.image.image_element[i].data_offset=0U; |
| 1660 | if (i == 0) |
| 1661 | dpx.image.image_element[i].data_offset=dpx.file.image_offset; |
| 1662 | offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset); |
| 1663 | dpx.image.image_element[i].end_of_line_padding=0U; |
| 1664 | offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding); |
| 1665 | offset+=WriteBlobLong(image, |
| 1666 | dpx.image.image_element[i].end_of_image_padding); |
| 1667 | offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description), |
| 1668 | (unsigned char *) dpx.image.image_element[i].description); |
| 1669 | } |
| 1670 | offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *) |
| 1671 | dpx.image.reserve); |
| 1672 | /* |
| 1673 | Write orientation header. |
| 1674 | */ |
| 1675 | if ((image->rows != image->magick_rows) || |
| 1676 | (image->columns != image->magick_columns)) |
| 1677 | { |
| 1678 | /* |
| 1679 | These properties are not valid if image size changed. |
| 1680 | */ |
| 1681 | (void) DeleteImageProperty(image,"dpx:orientation.x_offset"); |
| 1682 | (void) DeleteImageProperty(image,"dpx:orientation.y_offset"); |
| 1683 | (void) DeleteImageProperty(image,"dpx:orientation.x_center"); |
| 1684 | (void) DeleteImageProperty(image,"dpx:orientation.y_center"); |
| 1685 | (void) DeleteImageProperty(image,"dpx:orientation.x_size"); |
| 1686 | (void) DeleteImageProperty(image,"dpx:orientation.y_size"); |
| 1687 | } |
| 1688 | dpx.orientation.x_offset=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1689 | value=GetImageArtifact(image,"dpx:orientation.x_offset"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1690 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1691 | dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1692 | offset+=WriteBlobLong(image,dpx.orientation.x_offset); |
| 1693 | dpx.orientation.y_offset=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1694 | value=GetImageArtifact(image,"dpx:orientation.y_offset"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1695 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1696 | dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1697 | offset+=WriteBlobLong(image,dpx.orientation.y_offset); |
| 1698 | dpx.orientation.x_center=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1699 | value=GetImageArtifact(image,"dpx:orientation.x_center"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1700 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1701 | dpx.orientation.x_center=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1702 | offset+=WriteBlobFloat(image,dpx.orientation.x_center); |
| 1703 | dpx.orientation.y_center=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1704 | value=GetImageArtifact(image,"dpx:orientation.y_center"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1705 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1706 | dpx.orientation.y_center=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1707 | offset+=WriteBlobFloat(image,dpx.orientation.y_center); |
| 1708 | dpx.orientation.x_size=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1709 | value=GetImageArtifact(image,"dpx:orientation.x_size"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1710 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1711 | dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | offset+=WriteBlobLong(image,dpx.orientation.x_size); |
| 1713 | dpx.orientation.y_size=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1714 | value=GetImageArtifact(image,"dpx:orientation.y_size"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1715 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1716 | dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1717 | offset+=WriteBlobLong(image,dpx.orientation.y_size); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1718 | value=GetImageArtifact(image,"dpx:orientation.filename"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1719 | if (value != (const char *) NULL) |
| 1720 | (void) strncpy(dpx.orientation.filename,value, |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1721 | sizeof(dpx.orientation.filename)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1722 | offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *) |
| 1723 | dpx.orientation.filename); |
| 1724 | offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *) |
| 1725 | dpx.orientation.timestamp); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1726 | value=GetImageArtifact(image,"dpx:orientation.device"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1727 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1728 | (void) strncpy(dpx.orientation.device,value, |
| 1729 | sizeof(dpx.orientation.device)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1730 | offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *) |
| 1731 | dpx.orientation.device); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1732 | value=GetImageArtifact(image,"dpx:orientation.serial"); |
| cristy | 7959f82 | 2010-03-07 21:47:41 +0000 | [diff] [blame] | 1733 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1734 | (void) strncpy(dpx.orientation.serial,value, |
| 1735 | sizeof(dpx.orientation.serial)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1736 | offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *) |
| 1737 | dpx.orientation.serial); |
| 1738 | for (i=0; i < 4; i++) |
| 1739 | dpx.orientation.border[i]=0; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1740 | value=GetImageArtifact(image,"dpx:orientation.border"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1741 | if (value != (const char *) NULL) |
| 1742 | { |
| 1743 | flags=ParseGeometry(value,&geometry_info); |
| 1744 | if ((flags & SigmaValue) == 0) |
| 1745 | geometry_info.sigma=geometry_info.rho; |
| 1746 | dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5); |
| 1747 | dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5); |
| 1748 | dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5); |
| 1749 | dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5); |
| 1750 | } |
| 1751 | for (i=0; i < 4; i++) |
| 1752 | offset+=WriteBlobShort(image,dpx.orientation.border[i]); |
| 1753 | for (i=0; i < 2; i++) |
| 1754 | dpx.orientation.aspect_ratio[i]=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1755 | value=GetImageArtifact(image,"dpx:orientation.aspect_ratio"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1756 | if (value != (const char *) NULL) |
| 1757 | { |
| 1758 | flags=ParseGeometry(value,&geometry_info); |
| 1759 | if ((flags & SigmaValue) == 0) |
| 1760 | geometry_info.sigma=geometry_info.rho; |
| 1761 | dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5); |
| 1762 | dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5); |
| 1763 | } |
| 1764 | for (i=0; i < 2; i++) |
| 1765 | offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]); |
| 1766 | offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *) |
| 1767 | dpx.orientation.reserve); |
| 1768 | /* |
| 1769 | Write film header. |
| 1770 | */ |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1771 | (void) ResetMagickMemory(dpx.film.id,0,sizeof(dpx.film.id)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1772 | value=GetImageArtifact(image,"dpx:film.id"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1773 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1774 | (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1775 | offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id); |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1776 | (void) ResetMagickMemory(dpx.film.type,0,sizeof(dpx.film.type)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1777 | value=GetImageArtifact(image,"dpx:film.type"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1778 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1779 | (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1780 | offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *) |
| 1781 | dpx.film.type); |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1782 | (void) ResetMagickMemory(dpx.film.offset,0,sizeof(dpx.film.offset)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1783 | value=GetImageArtifact(image,"dpx:film.offset"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1784 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1785 | (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1786 | offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *) |
| 1787 | dpx.film.offset); |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1788 | (void) ResetMagickMemory(dpx.film.prefix,0,sizeof(dpx.film.prefix)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1789 | value=GetImageArtifact(image,"dpx:film.prefix"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1790 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1791 | (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1792 | offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *) |
| 1793 | dpx.film.prefix); |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1794 | (void) ResetMagickMemory(dpx.film.count,0,sizeof(dpx.film.count)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1795 | value=GetImageArtifact(image,"dpx:film.count"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1796 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1797 | (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1798 | offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *) |
| 1799 | dpx.film.count); |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1800 | (void) ResetMagickMemory(dpx.film.format,0,sizeof(dpx.film.format)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1801 | value=GetImageArtifact(image,"dpx:film.format"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1802 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1803 | (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1804 | offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *) |
| 1805 | dpx.film.format); |
| 1806 | dpx.film.frame_position=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1807 | value=GetImageArtifact(image,"dpx:film.frame_position"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1808 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1809 | dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1810 | offset+=WriteBlobLong(image,dpx.film.frame_position); |
| 1811 | dpx.film.sequence_extent=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1812 | value=GetImageArtifact(image,"dpx:film.sequence_extent"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1813 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1814 | dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1815 | offset+=WriteBlobLong(image,dpx.film.sequence_extent); |
| 1816 | dpx.film.held_count=0U; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1817 | value=GetImageArtifact(image,"dpx:film.held_count"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1818 | if (value != (const char *) NULL) |
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1819 | dpx.film.held_count=(unsigned int) StringToUnsignedLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1820 | offset+=WriteBlobLong(image,dpx.film.held_count); |
| 1821 | dpx.film.frame_rate=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1822 | value=GetImageArtifact(image,"dpx:film.frame_rate"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1823 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1824 | dpx.film.frame_rate=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1825 | offset+=WriteBlobFloat(image,dpx.film.frame_rate); |
| 1826 | dpx.film.shutter_angle=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1827 | value=GetImageArtifact(image,"dpx:film.shutter_angle"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1828 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1829 | dpx.film.shutter_angle=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1830 | offset+=WriteBlobFloat(image,dpx.film.shutter_angle); |
| cristy | c69f5e4 | 2014-04-18 11:05:25 +0000 | [diff] [blame] | 1831 | (void) ResetMagickMemory(dpx.film.frame_id,0,sizeof(dpx.film.frame_id)); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1832 | value=GetImageArtifact(image,"dpx:film.frame_id"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1833 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1834 | (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1835 | offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *) |
| 1836 | dpx.film.frame_id); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1837 | value=GetImageArtifact(image,"dpx:film.slate"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1838 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1839 | (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1840 | offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *) |
| 1841 | dpx.film.slate); |
| 1842 | offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *) |
| 1843 | dpx.film.reserve); |
| 1844 | /* |
| 1845 | Write television header. |
| 1846 | */ |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1847 | value=GetImageArtifact(image,"dpx:television.time.code"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1848 | if (value != (const char *) NULL) |
| 1849 | dpx.television.time_code=StringToTimeCode(value); |
| 1850 | offset+=WriteBlobLong(image,dpx.television.time_code); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1851 | value=GetImageArtifact(image,"dpx:television.user.bits"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1852 | if (value != (const char *) NULL) |
| 1853 | dpx.television.user_bits=StringToTimeCode(value); |
| 1854 | offset+=WriteBlobLong(image,dpx.television.user_bits); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1855 | value=GetImageArtifact(image,"dpx:television.interlace"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1856 | if (value != (const char *) NULL) |
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1857 | dpx.television.interlace=(unsigned char) StringToLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1858 | offset+=WriteBlobByte(image,dpx.television.interlace); |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1859 | value=GetImageArtifact(image,"dpx:television.field_number"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1860 | if (value != (const char *) NULL) |
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1861 | dpx.television.field_number=(unsigned char) StringToLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1862 | offset+=WriteBlobByte(image,dpx.television.field_number); |
| 1863 | dpx.television.video_signal=0; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1864 | value=GetImageArtifact(image,"dpx:television.video_signal"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1865 | if (value != (const char *) NULL) |
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1866 | dpx.television.video_signal=(unsigned char) StringToLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1867 | offset+=WriteBlobByte(image,dpx.television.video_signal); |
| 1868 | dpx.television.padding=0; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1869 | value=GetImageArtifact(image,"dpx:television.padding"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1870 | if (value != (const char *) NULL) |
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1871 | dpx.television.padding=(unsigned char) StringToLong(value); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1872 | offset+=WriteBlobByte(image,dpx.television.padding); |
| 1873 | dpx.television.horizontal_sample_rate=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1874 | value=GetImageArtifact(image,"dpx:television.horizontal_sample_rate"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1875 | if (value != (const char *) NULL) |
| cristy | bccc4f4 | 2011-11-24 17:57:52 +0000 | [diff] [blame] | 1876 | dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1877 | offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate); |
| 1878 | dpx.television.vertical_sample_rate=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1879 | value=GetImageArtifact(image,"dpx:television.vertical_sample_rate"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1880 | if (value != (const char *) NULL) |
| cristy | bccc4f4 | 2011-11-24 17:57:52 +0000 | [diff] [blame] | 1881 | dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1882 | offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate); |
| 1883 | dpx.television.frame_rate=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1884 | value=GetImageArtifact(image,"dpx:television.frame_rate"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1885 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1886 | dpx.television.frame_rate=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1887 | offset+=WriteBlobFloat(image,dpx.television.frame_rate); |
| 1888 | dpx.television.time_offset=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1889 | value=GetImageArtifact(image,"dpx:television.time_offset"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1890 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1891 | dpx.television.time_offset=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1892 | offset+=WriteBlobFloat(image,dpx.television.time_offset); |
| 1893 | dpx.television.gamma=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1894 | value=GetImageArtifact(image,"dpx:television.gamma"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1895 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1896 | dpx.television.gamma=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1897 | offset+=WriteBlobFloat(image,dpx.television.gamma); |
| 1898 | dpx.television.black_level=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1899 | value=GetImageArtifact(image,"dpx:television.black_level"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1900 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1901 | dpx.television.black_level=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1902 | offset+=WriteBlobFloat(image,dpx.television.black_level); |
| 1903 | dpx.television.black_gain=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1904 | value=GetImageArtifact(image,"dpx:television.black_gain"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1905 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1906 | dpx.television.black_gain=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1907 | offset+=WriteBlobFloat(image,dpx.television.black_gain); |
| 1908 | dpx.television.break_point=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1909 | value=GetImageArtifact(image,"dpx:television.break_point"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1910 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1911 | dpx.television.break_point=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1912 | offset+=WriteBlobFloat(image,dpx.television.break_point); |
| 1913 | dpx.television.white_level=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1914 | value=GetImageArtifact(image,"dpx:television.white_level"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1915 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1916 | dpx.television.white_level=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1917 | offset+=WriteBlobFloat(image,dpx.television.white_level); |
| 1918 | dpx.television.integration_times=0.0f; |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1919 | value=GetImageArtifact(image,"dpx:television.integration_times"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1920 | if (value != (const char *) NULL) |
| cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1921 | dpx.television.integration_times=StringToDouble(value,(char **) NULL); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1922 | offset+=WriteBlobFloat(image,dpx.television.integration_times); |
| 1923 | offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *) |
| 1924 | dpx.television.reserve); |
| 1925 | /* |
| 1926 | Write user header. |
| 1927 | */ |
| cristy | 96cf0ac | 2014-02-25 12:28:17 +0000 | [diff] [blame] | 1928 | value=GetImageArtifact(image,"dpx:user.id"); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1929 | if (value != (const char *) NULL) |
| cristy | 4fab663 | 2014-05-12 00:38:45 +0000 | [diff] [blame] | 1930 | (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id)-1); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1931 | offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id); |
| 1932 | if (profile != (StringInfo *) NULL) |
| 1933 | offset+=WriteBlob(image,GetStringInfoLength(profile), |
| 1934 | GetStringInfoDatum(profile)); |
| 1935 | while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset) |
| 1936 | { |
| 1937 | count=WriteBlobByte(image,0x00); |
| 1938 | if (count != 1) |
| 1939 | { |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1940 | ThrowFileException(exception,FileOpenError,"UnableToWriteFile", |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1941 | image->filename); |
| 1942 | break; |
| 1943 | } |
| 1944 | offset+=count; |
| 1945 | } |
| 1946 | /* |
| 1947 | Convert pixel packets to DPX raster image. |
| 1948 | */ |
| cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 1949 | quantum_info=AcquireQuantumInfo(image_info,image); |
| cristy | 891dc79 | 2010-03-04 01:47:16 +0000 | [diff] [blame] | 1950 | SetQuantumQuantum(quantum_info,32); |
| 1951 | SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ? |
| 1952 | MagickTrue : MagickFalse); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1953 | quantum_type=RGBQuantum; |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1954 | if (image->alpha_trait != UndefinedPixelTrait) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1955 | quantum_type=RGBAQuantum; |
| 1956 | if (image->colorspace == YCbCrColorspace) |
| 1957 | { |
| 1958 | quantum_type=CbYCrQuantum; |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1959 | if (image->alpha_trait != UndefinedPixelTrait) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1960 | quantum_type=CbYCrAQuantum; |
| 1961 | if ((horizontal_factor == 2) || (vertical_factor == 2)) |
| 1962 | quantum_type=CbYCrYQuantum; |
| 1963 | } |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1964 | extent=GetBytesPerRow(image->columns,image->alpha_trait != UndefinedPixelTrait ? |
| cristy | 3b23222 | 2012-11-05 16:55:17 +0000 | [diff] [blame] | 1965 | 4UL : 3UL,image->depth,MagickTrue); |
| 1966 | if ((image_info->type != TrueColorType) && |
| cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1967 | (image->alpha_trait == UndefinedPixelTrait) && |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1968 | (IsImageGray(image,exception) != MagickFalse)) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1969 | { |
| 1970 | quantum_type=GrayQuantum; |
| cristy | caac294 | 2009-10-01 13:36:18 +0000 | [diff] [blame] | 1971 | extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1972 | } |
| 1973 | pixels=GetQuantumPixels(quantum_info); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1974 | for (y=0; y < (ssize_t) image->rows; y++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1975 | { |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1976 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1977 | if (p == (const Quantum *) NULL) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1978 | break; |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1979 | (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1980 | quantum_type,pixels,exception); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1981 | count=WriteBlob(image,extent,pixels); |
| 1982 | if (count != (ssize_t) extent) |
| 1983 | break; |
| cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1984 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 1985 | image->rows); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1986 | if (status == MagickFalse) |
| 1987 | break; |
| 1988 | } |
| 1989 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1990 | (void) CloseBlob(image); |
| 1991 | return(status); |
| 1992 | } |