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