blob: 8190e048a4aafeff0748d7c175d46deeb7a6f790 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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 %
16% John Cristy %
17% March 2001 %
18% %
19% %
20% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
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*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/attribute.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/colorspace.h"
48#include "MagickCore/exception.h"
49#include "MagickCore/exception-private.h"
50#include "MagickCore/geometry.h"
51#include "MagickCore/image.h"
52#include "MagickCore/image-private.h"
53#include "MagickCore/list.h"
54#include "MagickCore/magick.h"
55#include "MagickCore/memory_.h"
56#include "MagickCore/module.h"
57#include "MagickCore/monitor.h"
58#include "MagickCore/monitor-private.h"
59#include "MagickCore/option.h"
cristy73a724e2011-11-24 18:47:12 +000060#include "MagickCore/pixel-accessor.h"
cristy4c08aed2011-07-01 19:47:50 +000061#include "MagickCore/profile.h"
62#include "MagickCore/property.h"
63#include "MagickCore/quantum-private.h"
64#include "MagickCore/static.h"
65#include "MagickCore/string_.h"
66#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000067
68/*
69 Typedef declaration.
70*/
71typedef enum
72{
73 UserDefinedColorimetric = 0,
74 PrintingDensityColorimetric = 1,
75 LinearColorimetric = 2,
76 LogarithmicColorimetric = 3,
77 UnspecifiedVideoColorimetric = 4,
78 SMTPE_274MColorimetric = 5,
79 ITU_R709Colorimetric = 6,
80 ITU_R601_625LColorimetric = 7,
81 ITU_R601_525LColorimetric = 8,
82 NTSCCompositeVideoColorimetric = 9,
83 PALCompositeVideoColorimetric = 10,
84 ZDepthLinearColorimetric = 11,
85 DepthHomogeneousColorimetric = 12
86} DPXColorimetric;
87
88typedef enum
89{
90 UndefinedComponentType = 0,
91 RedComponentType = 1,
92 GreenComponentType = 2,
93 BlueComponentType = 3,
94 AlphaComponentType = 4,
95 LumaComponentType = 6,
96 ColorDifferenceCbCrComponentType = 7,
97 DepthComponentType = 8,
98 CompositeVideoComponentType = 9,
99 RGBComponentType = 50,
100 RGBAComponentType = 51,
101 ABGRComponentType = 52,
102 CbYCrY422ComponentType = 100,
103 CbYACrYA4224ComponentType = 101,
104 CbYCr444ComponentType = 102,
105 CbYCrA4444ComponentType = 103,
106 UserDef2ElementComponentType = 150,
107 UserDef3ElementComponentType = 151,
108 UserDef4ElementComponentType = 152,
109 UserDef5ElementComponentType = 153,
110 UserDef6ElementComponentType = 154,
111 UserDef7ElementComponentType = 155,
112 UserDef8ElementComponentType = 156
113} DPXComponentType;
114
115typedef struct _DPXFileInfo
116{
117 unsigned int
118 magic,
119 image_offset;
120
121 char
122 version[8];
123
124 unsigned int
125 file_size,
126 ditto_key,
127 generic_size,
128 industry_size,
129 user_size;
130
131 char
132 filename[100],
133 timestamp[24],
134 creator[100],
135 project[200],
136 copyright[200];
137
138 unsigned int
139 encrypt_key;
140
141 char
142 reserve[104];
143} DPXFileInfo;
144
145typedef struct _DPXFilmInfo
146{
147 char
148 id[2],
149 type[2],
150 offset[2],
151 prefix[6],
152 count[4],
153 format[32];
154
155 unsigned int
156 frame_position,
157 sequence_extent,
158 held_count;
159
160 float
161 frame_rate,
162 shutter_angle;
163
164 char
165 frame_id[32],
166 slate[100],
167 reserve[56];
168} DPXFilmInfo;
169
170typedef struct _DPXImageElement
171{
172 unsigned int
173 data_sign,
174 low_data;
175
176 float
177 low_quantity;
178
179 unsigned int
180 high_data;
181
182 float
183 high_quantity;
184
185 unsigned char
186 descriptor,
187 transfer,
188 colorimetric,
189 bit_size;
190
191 unsigned short
192 packing,
193 encoding;
194
195 unsigned int
196 data_offset,
197 end_of_line_padding,
198 end_of_image_padding;
199
200 unsigned char
201 description[32];
202} DPXImageElement;
203
204typedef struct _DPXImageInfo
205{
206 unsigned short
207 orientation,
208 number_elements;
209
210 unsigned int
211 pixels_per_line,
212 lines_per_element;
213
214 DPXImageElement
215 image_element[8];
216
217 unsigned char
218 reserve[52];
219} DPXImageInfo;
220
221typedef struct _DPXOrientationInfo
222{
223 unsigned int
224 x_offset,
225 y_offset;
226
227 float
228 x_center,
229 y_center;
230
231 unsigned int
232 x_size,
233 y_size;
234
235 char
236 filename[100],
237 timestamp[24],
238 device[32],
239 serial[32];
240
241 unsigned short
242 border[4];
243
244 unsigned int
245 aspect_ratio[2];
246
247 unsigned char
248 reserve[28];
249} DPXOrientationInfo;
250
251typedef struct _DPXTelevisionInfo
252{
253 unsigned int
254 time_code,
255 user_bits;
256
257 unsigned char
258 interlace,
259 field_number,
260 video_signal,
261 padding;
262
263 float
264 horizontal_sample_rate,
265 vertical_sample_rate,
266 frame_rate,
267 time_offset,
268 gamma,
269 black_level,
270 black_gain,
271 break_point,
272 white_level,
273 integration_times;
274
275 char
276 reserve[76];
277} DPXTelevisionInfo;
278
279typedef struct _DPXUserInfo
280{
281 char
282 id[32];
283} DPXUserInfo;
284
285typedef struct DPXInfo
286{
287 DPXFileInfo
288 file;
289
290 DPXImageInfo
291 image;
292
293 DPXOrientationInfo
294 orientation;
295
296 DPXFilmInfo
297 film;
298
299 DPXTelevisionInfo
300 television;
301
302 DPXUserInfo
303 user;
304} DPXInfo;
305
306/*
307 Forward declaractions.
308*/
309static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +0000310 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000311
312/*
313%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314% %
315% %
316% %
317% I s D P X %
318% %
319% %
320% %
321%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322%
323% IsDPX() returns MagickTrue if the image format type, identified by the
324% magick string, is DPX.
325%
326% The format of the IsDPX method is:
327%
328% MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
329%
330% A description of each parameter follows:
331%
332% o magick: compare image format pattern against these bytes.
333%
334% o extent: Specifies the extent of the magick string.
335%
336*/
337static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
338{
339 if (extent < 4)
340 return(MagickFalse);
341 if (memcmp(magick,"SDPX",4) == 0)
342 return(MagickTrue);
343 if (memcmp(magick,"XPDS",4) == 0)
344 return(MagickTrue);
345 return(MagickFalse);
346}
347
348/*
349%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350% %
351% %
352% %
353% R e a d D P X I m a g e %
354% %
355% %
356% %
357%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358%
359% ReadDPXImage() reads an DPX X image file and returns it. It
360% allocates the memory necessary for the new Image structure and returns a
361% pointer to the new image.
362%
363% The format of the ReadDPXImage method is:
364%
365% Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
366%
367% A description of each parameter follows:
368%
369% o image_info: the image info.
370%
371% o exception: return any errors or warnings in this structure.
372%
373*/
374
cristybb503372010-05-27 20:51:26 +0000375static size_t GetBytesPerRow(size_t columns,
376 size_t samples_per_pixel,size_t bits_per_pixel,
cristy3ed852e2009-09-05 21:47:34 +0000377 MagickBooleanType pad)
378{
379 size_t
380 bytes_per_row;
381
382 switch (bits_per_pixel)
383 {
384 case 1:
385 {
386 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
387 bits_per_pixel+31)/32);
388 break;
389 }
390 case 8:
391 default:
392 {
393 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
394 bits_per_pixel+31)/32);
395 break;
396 }
397 case 10:
398 {
399 if (pad == MagickFalse)
400 {
401 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
402 bits_per_pixel+31)/32);
403 break;
404 }
cristyff024b42010-02-21 22:55:09 +0000405 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
cristy3ed852e2009-09-05 21:47:34 +0000406 break;
407 }
408 case 12:
409 {
410 if (pad == MagickFalse)
411 {
412 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
413 bits_per_pixel+31)/32);
414 break;
415 }
416 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
417 break;
418 }
419 case 16:
420 {
421 bytes_per_row=2*(((size_t) samples_per_pixel*columns*
422 bits_per_pixel+8)/16);
423 break;
424 }
425 case 32:
426 {
427 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
428 bits_per_pixel+31)/32);
429 break;
430 }
431 case 64:
432 {
433 bytes_per_row=8*(((size_t) samples_per_pixel*columns*
434 bits_per_pixel+63)/64);
435 break;
436 }
437 }
438 return(bytes_per_row);
439}
440
441static inline MagickBooleanType IsFloatDefined(const float value)
442{
443 union
444 {
445 unsigned int
446 unsigned_value;
447
cristy97450ff2010-12-29 17:29:17 +0000448 double
cristy3ed852e2009-09-05 21:47:34 +0000449 float_value;
450 } quantum;
451
452 quantum.unsigned_value=0U;
453 quantum.float_value=(double) value;
454 if (quantum.unsigned_value == 0U)
455 return(MagickFalse);
456 return(MagickTrue);
457}
458
459static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
460 ChromaticityInfo *chromaticity_info)
461{
462 switch(colorimetric)
463 {
464 case SMTPE_274MColorimetric:
465 case ITU_R709Colorimetric:
466 {
467 chromaticity_info->red_primary.x=0.640;
468 chromaticity_info->red_primary.y=0.330;
469 chromaticity_info->red_primary.z=0.030;
470 chromaticity_info->green_primary.x=0.300;
471 chromaticity_info->green_primary.y=0.600;
472 chromaticity_info->green_primary.z=0.100;
473 chromaticity_info->blue_primary.x=0.150;
474 chromaticity_info->blue_primary.y=0.060;
475 chromaticity_info->blue_primary.z=0.790;
476 chromaticity_info->white_point.x=0.3127;
477 chromaticity_info->white_point.y=0.3290;
478 chromaticity_info->white_point.z=0.3582;
479 break;
480 }
481 case NTSCCompositeVideoColorimetric:
482 {
483 chromaticity_info->red_primary.x=0.67;
484 chromaticity_info->red_primary.y=0.33;
485 chromaticity_info->red_primary.z=0.00;
486 chromaticity_info->green_primary.x=0.21;
487 chromaticity_info->green_primary.y=0.71;
488 chromaticity_info->green_primary.z=0.08;
489 chromaticity_info->blue_primary.x=0.14;
490 chromaticity_info->blue_primary.y=0.08;
491 chromaticity_info->blue_primary.z=0.78;
492 chromaticity_info->white_point.x=0.310;
493 chromaticity_info->white_point.y=0.316;
494 chromaticity_info->white_point.z=0.374;
495 break;
496 }
497 case PALCompositeVideoColorimetric:
498 {
499 chromaticity_info->red_primary.x=0.640;
500 chromaticity_info->red_primary.y=0.330;
501 chromaticity_info->red_primary.z=0.030;
502 chromaticity_info->green_primary.x=0.290;
503 chromaticity_info->green_primary.y=0.600;
504 chromaticity_info->green_primary.z=0.110;
505 chromaticity_info->blue_primary.x=0.150;
506 chromaticity_info->blue_primary.y=0.060;
507 chromaticity_info->blue_primary.z=0.790;
508 chromaticity_info->white_point.x=0.3127;
509 chromaticity_info->white_point.y=0.3290;
510 chromaticity_info->white_point.z=0.3582;
511 break;
512 }
513 default:
514 break;
515 }
516}
517
cristybb503372010-05-27 20:51:26 +0000518static void TimeCodeToString(const size_t timestamp,char *code)
cristy3ed852e2009-09-05 21:47:34 +0000519{
520#define TimeFields 7
521
522 unsigned int
523 shift;
524
cristybb503372010-05-27 20:51:26 +0000525 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000526 i;
527
528 *code='\0';
529 shift=4*TimeFields;
530 for (i=0; i <= TimeFields; i++)
531 {
cristyb51dff52011-05-19 16:55:47 +0000532 (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x",
cristy3ed852e2009-09-05 21:47:34 +0000533 (unsigned int) ((timestamp >> shift) & 0x0fU));
534 code++;
535 if (((i % 2) != 0) && (i < TimeFields))
536 *code++=':';
537 shift-=4;
538 *code='\0';
539 }
540}
541
542static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
543{
544 char
545 magick[4],
546 value[MaxTextExtent];
547
548 DPXInfo
549 dpx;
550
551 Image
552 *image;
553
cristy3ed852e2009-09-05 21:47:34 +0000554 MagickBooleanType
555 status;
556
557 MagickOffsetType
558 offset;
559
cristyff024b42010-02-21 22:55:09 +0000560 QuantumInfo
561 *quantum_info;
562
cristy3ed852e2009-09-05 21:47:34 +0000563 QuantumType
564 quantum_type;
565
cristybb503372010-05-27 20:51:26 +0000566 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000567 i;
568
cristy3ed852e2009-09-05 21:47:34 +0000569 size_t
cristy202de442011-04-24 18:19:07 +0000570 extent,
571 samples_per_pixel;
572
573 ssize_t
574 count,
575 row,
576 y;
cristy3ed852e2009-09-05 21:47:34 +0000577
578 unsigned char
579 component_type;
580
cristy3ed852e2009-09-05 21:47:34 +0000581 /*
582 Open image file.
583 */
584 assert(image_info != (const ImageInfo *) NULL);
585 assert(image_info->signature == MagickSignature);
586 if (image_info->debug != MagickFalse)
587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
588 image_info->filename);
589 assert(exception != (ExceptionInfo *) NULL);
590 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000591 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000592 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
593 if (status == MagickFalse)
594 {
595 image=DestroyImageList(image);
596 return((Image *) NULL);
597 }
598 /*
599 Read DPX file header.
600 */
cristye2c4f182012-05-12 14:11:53 +0000601 SetImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000602 offset=0;
603 count=ReadBlob(image,4,(unsigned char *) magick);
604 offset+=count;
605 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
606 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
607 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
608 image->endian=LSBEndian;
609 if (LocaleNCompare(magick,"SDPX",4) == 0)
610 image->endian=MSBEndian;
611 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
612 dpx.file.image_offset=ReadBlobLong(image);
613 offset+=4;
614 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
615 dpx.file.version);
616 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
617 dpx.file.file_size=ReadBlobLong(image);
618 offset+=4;
619 dpx.file.ditto_key=ReadBlobLong(image);
620 offset+=4;
621 if (dpx.file.ditto_key != ~0U)
622 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
623 dpx.file.ditto_key);
624 dpx.file.generic_size=ReadBlobLong(image);
625 offset+=4;
626 dpx.file.industry_size=ReadBlobLong(image);
627 offset+=4;
628 dpx.file.user_size=ReadBlobLong(image);
629 offset+=4;
630 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
631 dpx.file.filename);
632 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
633 dpx.file.filename);
634 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
635 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
636 dpx.file.timestamp);
637 if (*dpx.file.timestamp != '\0')
638 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
639 dpx.file.timestamp);
640 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
641 dpx.file.creator);
642 if (*dpx.file.creator != '\0')
643 {
644 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
645 dpx.file.creator);
646 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
647 }
648 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
649 dpx.file.project);
650 if (*dpx.file.project != '\0')
651 {
652 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
653 dpx.file.project);
654 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
655 }
656 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
657 dpx.file.copyright);
658 if (*dpx.file.copyright != '\0')
659 {
660 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
661 dpx.file.copyright);
662 (void) FormatImageProperty(image,"copyright","%.100s",
663 dpx.file.copyright);
664 }
665 dpx.file.encrypt_key=ReadBlobLong(image);
666 offset+=4;
667 if (dpx.file.encrypt_key != ~0U)
668 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
669 dpx.file.encrypt_key);
670 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
671 dpx.file.reserve);
672 /*
673 Read DPX image header.
674 */
675 dpx.image.orientation=ReadBlobShort(image);
676 offset+=2;
677 if (dpx.image.orientation != (unsigned short) (~0U))
678 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
679 dpx.image.orientation);
680 switch (dpx.image.orientation)
681 {
682 default:
cristy202de442011-04-24 18:19:07 +0000683 case 0: image->orientation=TopLeftOrientation; break;
684 case 1: image->orientation=TopRightOrientation; break;
685 case 2: image->orientation=BottomLeftOrientation; break;
686 case 3: image->orientation=BottomRightOrientation; break;
687 case 4: image->orientation=LeftTopOrientation; break;
688 case 5: image->orientation=RightTopOrientation; break;
689 case 6: image->orientation=LeftBottomOrientation; break;
690 case 7: image->orientation=RightBottomOrientation; break;
cristy3ed852e2009-09-05 21:47:34 +0000691 }
692 dpx.image.number_elements=ReadBlobShort(image);
693 offset+=2;
694 dpx.image.pixels_per_line=ReadBlobLong(image);
695 offset+=4;
696 image->columns=dpx.image.pixels_per_line;
697 dpx.image.lines_per_element=ReadBlobLong(image);
698 offset+=4;
699 image->rows=dpx.image.lines_per_element;
700 for (i=0; i < 8; i++)
701 {
702 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
703 offset+=4;
704 dpx.image.image_element[i].low_data=ReadBlobLong(image);
705 offset+=4;
706 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
707 offset+=4;
708 dpx.image.image_element[i].high_data=ReadBlobLong(image);
709 offset+=4;
710 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
711 offset+=4;
712 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
713 offset++;
714 dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
715 offset++;
716 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
717 offset++;
718 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
719 offset++;
720 dpx.image.image_element[i].packing=ReadBlobShort(image);
721 offset+=2;
722 dpx.image.image_element[i].encoding=ReadBlobShort(image);
723 offset+=2;
724 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
725 offset+=4;
726 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
727 offset+=4;
728 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
729 offset+=4;
730 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
731 (unsigned char *) dpx.image.image_element[i].description);
732 }
733 SetPrimaryChromaticity((DPXColorimetric)
734 dpx.image.image_element[0].colorimetric,&image->chromaticity);
735 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
736 dpx.image.reserve);
737 component_type=dpx.image.image_element[0].descriptor;
738 image->depth=dpx.image.image_element[0].bit_size;
739 if (dpx.file.image_offset >= 1664U)
740 {
741 /*
742 Read DPX orientation header.
743 */
744 dpx.orientation.x_offset=ReadBlobLong(image);
745 offset+=4;
746 if (dpx.orientation.x_offset != ~0U)
747 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
748 dpx.orientation.x_offset);
749 dpx.orientation.y_offset=ReadBlobLong(image);
750 offset+=4;
751 if (dpx.orientation.y_offset != ~0U)
752 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
753 dpx.orientation.y_offset);
754 dpx.orientation.x_center=ReadBlobFloat(image);
755 offset+=4;
756 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
757 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
758 dpx.orientation.x_center);
759 dpx.orientation.y_center=ReadBlobFloat(image);
760 offset+=4;
761 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
762 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
763 dpx.orientation.y_center);
764 dpx.orientation.x_size=ReadBlobLong(image);
765 offset+=4;
766 if (dpx.orientation.x_size != ~0U)
767 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
768 dpx.orientation.x_size);
769 dpx.orientation.y_size=ReadBlobLong(image);
770 offset+=4;
771 if (dpx.orientation.y_size != ~0U)
772 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
773 dpx.orientation.y_size);
774 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
775 dpx.orientation.filename);
776 if (*dpx.orientation.filename != '\0')
777 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
778 dpx.orientation.filename);
779 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
780 dpx.orientation.timestamp);
781 if (*dpx.orientation.timestamp != '\0')
782 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
783 dpx.orientation.timestamp);
784 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
785 dpx.orientation.device);
786 if (*dpx.orientation.device != '\0')
787 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
788 dpx.orientation.device);
789 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
790 dpx.orientation.serial);
791 if (*dpx.orientation.serial != '\0')
792 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
793 dpx.orientation.serial);
794 for (i=0; i < 4; i++)
795 {
796 dpx.orientation.border[i]=ReadBlobShort(image);
797 offset+=2;
798 }
799 if ((dpx.orientation.border[0] != (unsigned short) (~0U)) &&
800 (dpx.orientation.border[1] != (unsigned short) (~0U)))
801 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d", dpx.orientation.border[0],dpx.orientation.border[1],
802 dpx.orientation.border[2],dpx.orientation.border[3]);
803 for (i=0; i < 2; i++)
804 {
805 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
806 offset+=4;
807 }
808 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
809 (dpx.orientation.aspect_ratio[1] != ~0U))
810 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
811 "%ux%u",dpx.orientation.aspect_ratio[0],
812 dpx.orientation.aspect_ratio[1]);
813 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
814 dpx.orientation.reserve);
815 }
816 if (dpx.file.image_offset >= 1920U)
817 {
818 /*
819 Read DPX film header.
820 */
821 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
822 if (*dpx.film.type != '\0')
823 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
824 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
825 dpx.film.type);
826 if (*dpx.film.type != '\0')
827 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
828 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
829 dpx.film.offset);
830 if (*dpx.film.offset != '\0')
831 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
832 dpx.film.offset);
833 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
834 dpx.film.prefix);
835 if (*dpx.film.prefix != '\0')
836 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
837 dpx.film.prefix);
838 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
839 dpx.film.count);
840 if (*dpx.film.count != '\0')
841 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
842 dpx.film.count);
843 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
844 dpx.film.format);
845 if (*dpx.film.format != '\0')
846 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
847 dpx.film.format);
848 dpx.film.frame_position=ReadBlobLong(image);
849 offset+=4;
850 if (dpx.film.frame_position != ~0U)
851 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
852 dpx.film.frame_position);
853 dpx.film.sequence_extent=ReadBlobLong(image);
854 offset+=4;
855 if (dpx.film.sequence_extent != ~0U)
856 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
857 dpx.film.sequence_extent);
858 dpx.film.held_count=ReadBlobLong(image);
859 offset+=4;
860 if (dpx.film.held_count != ~0U)
861 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
862 dpx.film.held_count);
863 dpx.film.frame_rate=ReadBlobFloat(image);
864 offset+=4;
865 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
866 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
867 dpx.film.frame_rate);
868 dpx.film.shutter_angle=ReadBlobFloat(image);
869 offset+=4;
870 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
871 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
872 dpx.film.shutter_angle);
873 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
874 dpx.film.frame_id);
875 if (*dpx.film.frame_id != '\0')
876 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
877 dpx.film.frame_id);
878 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
879 dpx.film.slate);
880 if (*dpx.film.slate != '\0')
881 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
882 dpx.film.slate);
883 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
884 dpx.film.reserve);
885 }
886 if (dpx.file.image_offset >= 2048U)
887 {
888 /*
889 Read DPX television header.
890 */
891 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
892 offset+=4;
893 TimeCodeToString(dpx.television.time_code,value);
cristyd15e6592011-10-15 00:13:06 +0000894 (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
cristy3ed852e2009-09-05 21:47:34 +0000895 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
896 offset+=4;
897 TimeCodeToString(dpx.television.user_bits,value);
cristyd15e6592011-10-15 00:13:06 +0000898 (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
cristy3ed852e2009-09-05 21:47:34 +0000899 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
900 offset++;
901 if (dpx.television.interlace != 0)
cristye8c25f92010-06-03 00:53:06 +0000902 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
903 (double) dpx.television.interlace);
cristy3ed852e2009-09-05 21:47:34 +0000904 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
905 offset++;
906 if (dpx.television.field_number != 0)
cristye8c25f92010-06-03 00:53:06 +0000907 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
908 (double) dpx.television.field_number);
cristy3ed852e2009-09-05 21:47:34 +0000909 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
910 offset++;
911 if (dpx.television.video_signal != 0)
cristye8c25f92010-06-03 00:53:06 +0000912 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
913 (double) dpx.television.video_signal);
cristy3ed852e2009-09-05 21:47:34 +0000914 dpx.television.padding=(unsigned char) ReadBlobByte(image);
915 offset++;
916 if (dpx.television.padding != 0)
917 (void) FormatImageProperty(image,"dpx:television.padding","%d",
918 dpx.television.padding);
919 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
920 offset+=4;
921 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
922 (void) FormatImageProperty(image,
923 "dpx:television.horizontal_sample_rate","%g",
924 dpx.television.horizontal_sample_rate);
925 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
926 offset+=4;
927 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
928 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
929 "%g",dpx.television.vertical_sample_rate);
930 dpx.television.frame_rate=ReadBlobFloat(image);
931 offset+=4;
932 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
933 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
934 dpx.television.frame_rate);
935 dpx.television.time_offset=ReadBlobFloat(image);
936 offset+=4;
937 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
938 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
939 dpx.television.time_offset);
940 dpx.television.gamma=ReadBlobFloat(image);
941 offset+=4;
942 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
943 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
944 dpx.television.gamma);
945 dpx.television.black_level=ReadBlobFloat(image);
946 offset+=4;
947 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
948 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
949 dpx.television.black_level);
950 dpx.television.black_gain=ReadBlobFloat(image);
951 offset+=4;
952 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
953 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
954 dpx.television.black_gain);
955 dpx.television.break_point=ReadBlobFloat(image);
956 offset+=4;
957 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
958 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
959 dpx.television.break_point);
960 dpx.television.white_level=ReadBlobFloat(image);
961 offset+=4;
962 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
963 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
964 dpx.television.white_level);
965 dpx.television.integration_times=ReadBlobFloat(image);
966 offset+=4;
967 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
968 (void) FormatImageProperty(image,"dpx:television.integration_times",
969 "%g",dpx.television.integration_times);
970 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
971 dpx.television.reserve);
972 }
973 if (dpx.file.image_offset > 2080U)
974 {
975 /*
976 Read DPX user header.
977 */
978 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
979 if (*dpx.user.id != '\0')
980 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
981 if ((dpx.file.user_size != ~0U) &&
982 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
983 {
984 StringInfo
985 *profile;
986
cristy60395292011-09-01 13:25:56 +0000987 profile=BlobToStringInfo((const void *) NULL,
988 dpx.file.user_size-sizeof(dpx.user.id));
989 if (profile == (StringInfo *) NULL)
990 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +0000991 offset+=ReadBlob(image,GetStringInfoLength(profile),
992 GetStringInfoDatum(profile));
cristyd15e6592011-10-15 00:13:06 +0000993 (void) SetImageProfile(image,"dpx",profile,exception);
cristy3ed852e2009-09-05 21:47:34 +0000994 profile=DestroyStringInfo(profile);
995 }
996 }
cristy811f5172010-12-29 17:38:08 +0000997 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
cristy3ed852e2009-09-05 21:47:34 +0000998 (void) ReadBlobByte(image);
999 /*
1000 Read DPX image header.
1001 */
1002 if (image_info->ping != MagickFalse)
1003 {
1004 (void) CloseBlob(image);
1005 return(GetFirstImageInList(image));
1006 }
1007 /*
1008 Convert DPX raster image to pixel packets.
1009 */
1010 samples_per_pixel=1;
1011 quantum_type=GrayQuantum;
1012 switch (component_type)
1013 {
1014 case CbYCrY422ComponentType:
1015 {
1016 samples_per_pixel=2;
1017 quantum_type=CbYCrYQuantum;
1018 break;
1019 }
1020 case CbYACrYA4224ComponentType:
1021 case CbYCr444ComponentType:
1022 {
1023 samples_per_pixel=3;
1024 quantum_type=CbYCrQuantum;
1025 break;
1026 }
1027 case RGBComponentType:
1028 {
1029 samples_per_pixel=3;
1030 quantum_type=RGBQuantum;
1031 break;
1032 }
1033 case ABGRComponentType:
1034 case RGBAComponentType:
1035 {
1036 image->matte=MagickTrue;
1037 samples_per_pixel=4;
1038 quantum_type=RGBAQuantum;
1039 break;
1040 }
1041 default:
1042 break;
1043 }
1044 switch (component_type)
1045 {
1046 case CbYCrY422ComponentType:
1047 case CbYACrYA4224ComponentType:
1048 case CbYCr444ComponentType:
1049 {
cristye2c4f182012-05-12 14:11:53 +00001050 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001051 break;
1052 }
1053 case LumaComponentType:
1054 {
cristye2c4f182012-05-12 14:11:53 +00001055 SetImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001056 break;
1057 }
1058 default:
1059 {
cristye2c4f182012-05-12 14:11:53 +00001060 SetImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001061 if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
cristye2c4f182012-05-12 14:11:53 +00001062 SetImageColorspace(image,LogColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001063 if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
cristye2c4f182012-05-12 14:11:53 +00001064 SetImageColorspace(image,LogColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001065 break;
1066 }
1067 }
1068 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1069 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
cristyff024b42010-02-21 22:55:09 +00001070 /*
1071 DPX any-bit pixel format.
1072 */
1073 status=MagickTrue;
1074 row=0;
1075 quantum_info=AcquireQuantumInfo(image_info,image);
1076 if (quantum_info == (QuantumInfo *) NULL)
1077 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1078 SetQuantumQuantum(quantum_info,32);
1079 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1080 MagickTrue : MagickFalse);
cristybb503372010-05-27 20:51:26 +00001081 for (y=0; y < (ssize_t) image->rows; y++)
cristyff024b42010-02-21 22:55:09 +00001082 {
cristyff024b42010-02-21 22:55:09 +00001083 MagickBooleanType
1084 sync;
cristy3ed852e2009-09-05 21:47:34 +00001085
cristy4c08aed2011-07-01 19:47:50 +00001086 register Quantum
cristyff024b42010-02-21 22:55:09 +00001087 *q;
cristy3ed852e2009-09-05 21:47:34 +00001088
cristyff024b42010-02-21 22:55:09 +00001089 size_t
1090 length;
cristy3ed852e2009-09-05 21:47:34 +00001091
cristy202de442011-04-24 18:19:07 +00001092 ssize_t
1093 count,
1094 offset;
1095
cristyff024b42010-02-21 22:55:09 +00001096 unsigned char
1097 *pixels;
cristy3ed852e2009-09-05 21:47:34 +00001098
cristyff024b42010-02-21 22:55:09 +00001099 if (status == MagickFalse)
1100 continue;
1101 pixels=GetQuantumPixels(quantum_info);
cristyff024b42010-02-21 22:55:09 +00001102 {
1103 count=ReadBlob(image,extent,pixels);
1104 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1105 (image->previous == (Image *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00001106 {
cristyff024b42010-02-21 22:55:09 +00001107 MagickBooleanType
1108 proceed;
cristy3ed852e2009-09-05 21:47:34 +00001109
cristycee97112010-05-28 00:44:52 +00001110 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
cristy202de442011-04-24 18:19:07 +00001111 image->rows);
cristyff024b42010-02-21 22:55:09 +00001112 if (proceed == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001113 status=MagickFalse;
cristyff024b42010-02-21 22:55:09 +00001114 }
1115 offset=row++;
cristy3ed852e2009-09-05 21:47:34 +00001116 }
cristyff024b42010-02-21 22:55:09 +00001117 if (count != (ssize_t) extent)
1118 status=MagickFalse;
cristyaa740112010-03-30 17:58:44 +00001119 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00001120 if (q == (Quantum *) NULL)
cristyff024b42010-02-21 22:55:09 +00001121 {
1122 status=MagickFalse;
1123 continue;
1124 }
cristyf410d302010-03-30 23:28:56 +00001125 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristyaa740112010-03-30 17:58:44 +00001126 quantum_type,pixels,exception);
cristyda16f162011-02-19 23:52:17 +00001127 (void) length;
cristyaa740112010-03-30 17:58:44 +00001128 sync=SyncAuthenticPixels(image,exception);
cristyff024b42010-02-21 22:55:09 +00001129 if (sync == MagickFalse)
1130 status=MagickFalse;
1131 }
cristyff024b42010-02-21 22:55:09 +00001132 quantum_info=DestroyQuantumInfo(quantum_info);
1133 if (status == MagickFalse)
1134 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
cristy3ed852e2009-09-05 21:47:34 +00001135 SetQuantumImageType(image,quantum_type);
1136 if (EOFBlob(image) != MagickFalse)
1137 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1138 image->filename);
1139 (void) CloseBlob(image);
1140 return(GetFirstImageInList(image));
1141}
1142
1143/*
1144%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1145% %
1146% %
1147% %
1148% R e g i s t e r D P X I m a g e %
1149% %
1150% %
1151% %
1152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1153%
1154% RegisterDPXImage() adds properties for the DPX image format to
1155% the list of supported formats. The properties include the image format
1156% tag, a method to read and/or write the format, whether the format
1157% supports the saving of more than one frame to the same file or blob,
1158% whether the format supports native in-memory I/O, and a brief
1159% description of the format.
1160%
1161% The format of the RegisterDPXImage method is:
1162%
cristybb503372010-05-27 20:51:26 +00001163% size_t RegisterDPXImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001164%
1165*/
cristybb503372010-05-27 20:51:26 +00001166ModuleExport size_t RegisterDPXImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001167{
1168 MagickInfo
1169 *entry;
1170
1171 static const char
1172 *DPXNote =
1173 {
1174 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1175 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1176 };
1177
1178 entry=SetMagickInfo("DPX");
1179 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1180 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1181 entry->magick=(IsImageFormatHandler *) IsDPX;
1182 entry->adjoin=MagickFalse;
1183 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1184 entry->note=ConstantString(DPXNote);
1185 entry->module=ConstantString("DPX");
1186 (void) RegisterMagickInfo(entry);
1187 return(MagickImageCoderSignature);
1188}
1189
1190/*
1191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1192% %
1193% %
1194% %
1195% U n r e g i s t e r D P X I m a g e %
1196% %
1197% %
1198% %
1199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200%
1201% UnregisterDPXImage() removes format registrations made by the
1202% DPX module from the list of supported formats.
1203%
1204% The format of the UnregisterDPXImage method is:
1205%
1206% UnregisterDPXImage(void)
1207%
1208*/
1209ModuleExport void UnregisterDPXImage(void)
1210{
1211 (void) UnregisterMagickInfo("DPX");
1212}
1213
1214/*
1215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1216% %
1217% %
1218% %
1219% W r i t e D P X I m a g e %
1220% %
1221% %
1222% %
1223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224%
1225% WriteDPXImage() writes an image in DPX encoded image format.
1226%
1227% The format of the WriteDPXImage method is:
1228%
cristy1e178e72011-08-28 19:44:34 +00001229% MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1230% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001231%
1232% A description of each parameter follows.
1233%
1234% o image_info: the image info.
1235%
1236% o image: The image.
1237%
cristy1e178e72011-08-28 19:44:34 +00001238% o exception: return any errors or warnings in this structure.
1239%
cristy3ed852e2009-09-05 21:47:34 +00001240*/
1241
1242static inline const char *GetDPXProperty(const ImageInfo *image_info,
cristyd15e6592011-10-15 00:13:06 +00001243 const Image *image,const char *property,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001244{
1245 const char
1246 *value;
1247
1248 value=GetImageOption(image_info,property);
1249 if (value != (const char *) NULL)
1250 return(value);
cristyd15e6592011-10-15 00:13:06 +00001251 return(GetImageProperty(image,property,exception));
cristy3ed852e2009-09-05 21:47:34 +00001252}
1253
1254static unsigned int StringToTimeCode(const char *key)
1255{
1256 char
1257 buffer[2];
1258
cristybb503372010-05-27 20:51:26 +00001259 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001260 i;
1261
1262 unsigned int
1263 shift,
1264 value;
1265
1266 value=0;
1267 shift=28;
1268 buffer[1]='\0';
1269 for (i=0; (*key != 0) && (i < 11); i++)
1270 {
1271 if (isxdigit((int) ((unsigned char) *key)) == 0)
1272 {
1273 key++;
1274 continue;
1275 }
1276 buffer[0]=(*key++);
1277 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1278 shift-=4;
1279 }
1280 return(value);
1281}
1282
cristy1e178e72011-08-28 19:44:34 +00001283static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1284 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001285{
1286 const char
1287 *value;
1288
1289 const StringInfo
1290 *profile;
1291
1292 DPXInfo
1293 dpx;
1294
cristybccc4f42011-11-24 17:57:52 +00001295 GeometryInfo
1296 geometry_info;
1297
cristy3ed852e2009-09-05 21:47:34 +00001298 MagickBooleanType
1299 status;
1300
1301 MagickOffsetType
1302 offset;
1303
1304 MagickStatusType
1305 flags;
1306
cristy3ed852e2009-09-05 21:47:34 +00001307 QuantumInfo
1308 *quantum_info;
1309
1310 QuantumType
1311 quantum_type;
1312
cristy4c08aed2011-07-01 19:47:50 +00001313 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001314 *p;
1315
cristybb503372010-05-27 20:51:26 +00001316 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001317 i;
1318
cristy1e178e72011-08-28 19:44:34 +00001319 size_t
1320 extent;
1321
cristy202de442011-04-24 18:19:07 +00001322 ssize_t
1323 count,
1324 horizontal_factor,
1325 vertical_factor,
1326 y;
1327
cristy3ed852e2009-09-05 21:47:34 +00001328 time_t
1329 seconds;
1330
1331 unsigned char
1332 *pixels;
1333
1334 /*
1335 Open output image file.
1336 */
1337 assert(image_info != (const ImageInfo *) NULL);
1338 assert(image_info->signature == MagickSignature);
1339 assert(image != (Image *) NULL);
1340 assert(image->signature == MagickSignature);
1341 if (image->debug != MagickFalse)
1342 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1343 horizontal_factor=4;
1344 vertical_factor=4;
1345 if (image_info->sampling_factor != (char *) NULL)
1346 {
1347 GeometryInfo
1348 geometry_info;
1349
1350 MagickStatusType
1351 flags;
1352
1353 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
cristybb503372010-05-27 20:51:26 +00001354 horizontal_factor=(ssize_t) geometry_info.rho;
1355 vertical_factor=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00001356 if ((flags & SigmaValue) == 0)
1357 vertical_factor=horizontal_factor;
1358 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1359 (horizontal_factor != 4) && (vertical_factor != 1) &&
1360 (vertical_factor != 2) && (vertical_factor != 4))
1361 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1362 }
1363 if ((image->colorspace == YCbCrColorspace) &&
1364 ((horizontal_factor == 2) || (vertical_factor == 2)))
1365 if ((image->columns % 2) != 0)
1366 image->columns++;
cristy3a37efd2011-08-28 20:31:03 +00001367 assert(exception != (ExceptionInfo *) NULL);
1368 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +00001369 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001370 if (status == MagickFalse)
1371 return(status);
1372 /*
1373 Write file header.
1374 */
1375 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1376 offset=0;
1377 dpx.file.magic=0x53445058U;
1378 offset+=WriteBlobLong(image,dpx.file.magic);
1379 dpx.file.image_offset=0x2000U;
cristy61047b62010-05-22 02:15:20 +00001380 profile=GetImageProfile(image,"dpx");
cristy3ed852e2009-09-05 21:47:34 +00001381 if (profile != (StringInfo *) NULL)
1382 {
cristy61047b62010-05-22 02:15:20 +00001383 if (GetStringInfoLength(profile) > 1048576)
1384 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
cristy3ed852e2009-09-05 21:47:34 +00001385 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1386 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1387 }
1388 offset+=WriteBlobLong(image,dpx.file.image_offset);
1389 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1390 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1391 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1392 dpx.file.image_offset);
1393 offset+=WriteBlobLong(image,dpx.file.file_size);
1394 dpx.file.ditto_key=1U; /* new frame */
1395 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1396 dpx.file.generic_size=0x00000680U;
1397 offset+=WriteBlobLong(image,dpx.file.generic_size);
1398 dpx.file.industry_size=0x00000180U;
1399 offset+=WriteBlobLong(image,dpx.file.industry_size);
1400 dpx.file.user_size=0;
1401 if (profile != (StringInfo *) NULL)
1402 {
1403 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1404 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1405 }
1406 offset+=WriteBlobLong(image,dpx.file.user_size);
cristyd15e6592011-10-15 00:13:06 +00001407 value=GetDPXProperty(image_info,image,"dpx:file.filename",exception);
cristy3ed852e2009-09-05 21:47:34 +00001408 if (value != (const char *) NULL)
1409 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1410 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1411 dpx.file.filename);
1412 seconds=time((time_t *) NULL);
1413 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1414 dpx.file.timestamp);
1415 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1416 dpx.file.timestamp);
cristybb503372010-05-27 20:51:26 +00001417 (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL),
cristy3ed852e2009-09-05 21:47:34 +00001418 sizeof(dpx.file.creator));
cristyd15e6592011-10-15 00:13:06 +00001419 value=GetDPXProperty(image_info,image,"dpx:file.creator",exception);
cristy3ed852e2009-09-05 21:47:34 +00001420 if (value != (const char *) NULL)
1421 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1422 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1423 dpx.file.creator);
cristyd15e6592011-10-15 00:13:06 +00001424 value=GetDPXProperty(image_info,image,"dpx:file.project",exception);
cristy3ed852e2009-09-05 21:47:34 +00001425 if (value != (const char *) NULL)
1426 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1427 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1428 dpx.file.project);
cristyd15e6592011-10-15 00:13:06 +00001429 value=GetDPXProperty(image_info,image,"dpx:file.copyright",exception);
cristy3ed852e2009-09-05 21:47:34 +00001430 if (value != (const char *) NULL)
cristyd15e6592011-10-15 00:13:06 +00001431 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright));
cristy3ed852e2009-09-05 21:47:34 +00001432 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1433 dpx.file.copyright);
1434 dpx.file.encrypt_key=(~0U);
1435 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1436 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1437 dpx.file.reserve);
1438 /*
1439 Write image header.
1440 */
1441 dpx.image.orientation=0x00; /* left-to-right; top-to-bottom */
1442 offset+=WriteBlobShort(image,dpx.image.orientation);
1443 dpx.image.number_elements=1;
1444 offset+=WriteBlobShort(image,dpx.image.number_elements);
1445 if ((image->columns != (unsigned int) image->columns) ||
1446 (image->rows != (unsigned int) image->rows))
1447 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1448 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1449 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1450 for (i=0; i < 8; i++)
1451 {
1452 dpx.image.image_element[i].data_sign=0U;
1453 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1454 dpx.image.image_element[i].low_data=0U;
1455 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1456 dpx.image.image_element[i].low_quantity=0.0f;
1457 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1458 dpx.image.image_element[i].high_data=0U;
1459 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1460 dpx.image.image_element[i].high_quantity=0.0f;
1461 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1462 dpx.image.image_element[i].descriptor=0;
1463 if (i == 0)
1464 switch (image->colorspace)
1465 {
1466 case Rec601YCbCrColorspace:
1467 case Rec709YCbCrColorspace:
1468 case YCbCrColorspace:
1469 {
1470 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1471 if (image->matte != MagickFalse)
1472 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1473 break;
1474 }
1475 default:
1476 {
1477 dpx.image.image_element[i].descriptor=RGBComponentType;
1478 if (image->matte != MagickFalse)
1479 dpx.image.image_element[i].descriptor=RGBAComponentType;
cristyf59a8922010-02-28 19:51:23 +00001480 if ((image_info->type != TrueColorType) &&
1481 (image->matte == MagickFalse) &&
cristy1e178e72011-08-28 19:44:34 +00001482 (IsImageGray(image,exception) != MagickFalse))
cristycaac2942009-10-01 13:36:18 +00001483 dpx.image.image_element[i].descriptor=LumaComponentType;
cristy3ed852e2009-09-05 21:47:34 +00001484 break;
1485 }
1486 }
1487 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1488 dpx.image.image_element[i].transfer=0;
1489 if (image->colorspace == LogColorspace)
1490 dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
1491 offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
1492 dpx.image.image_element[i].colorimetric=0;
1493 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1494 dpx.image.image_element[i].bit_size=0;
1495 if (i == 0)
1496 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1497 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1498 dpx.image.image_element[i].packing=0;
1499 if ((image->depth == 10) || (image->depth == 12))
1500 dpx.image.image_element[i].packing=1;
1501 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1502 dpx.image.image_element[i].encoding=0;
1503 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1504 dpx.image.image_element[i].data_offset=0U;
1505 if (i == 0)
1506 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1507 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1508 dpx.image.image_element[i].end_of_line_padding=0U;
1509 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1510 offset+=WriteBlobLong(image,
1511 dpx.image.image_element[i].end_of_image_padding);
1512 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1513 (unsigned char *) dpx.image.image_element[i].description);
1514 }
1515 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1516 dpx.image.reserve);
1517 /*
1518 Write orientation header.
1519 */
1520 if ((image->rows != image->magick_rows) ||
1521 (image->columns != image->magick_columns))
1522 {
1523 /*
1524 These properties are not valid if image size changed.
1525 */
1526 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1527 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1528 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1529 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1530 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1531 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1532 }
1533 dpx.orientation.x_offset=0U;
cristyd15e6592011-10-15 00:13:06 +00001534 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001535 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001536 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001537 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1538 dpx.orientation.y_offset=0U;
cristyd15e6592011-10-15 00:13:06 +00001539 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001540 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001541 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001542 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1543 dpx.orientation.x_center=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001544 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center",exception);
cristy3ed852e2009-09-05 21:47:34 +00001545 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001546 dpx.orientation.x_center=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001547 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1548 dpx.orientation.y_center=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001549 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center",exception);
cristy3ed852e2009-09-05 21:47:34 +00001550 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001551 dpx.orientation.y_center=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001552 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1553 dpx.orientation.x_size=0U;
cristyd15e6592011-10-15 00:13:06 +00001554 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size",exception);
cristy3ed852e2009-09-05 21:47:34 +00001555 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001556 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001557 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1558 dpx.orientation.y_size=0U;
cristyd15e6592011-10-15 00:13:06 +00001559 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size",exception);
cristy3ed852e2009-09-05 21:47:34 +00001560 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001561 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001562 offset+=WriteBlobLong(image,dpx.orientation.y_size);
cristyd15e6592011-10-15 00:13:06 +00001563 value=GetDPXProperty(image_info,image,"dpx:orientation.filename",exception);
cristy3ed852e2009-09-05 21:47:34 +00001564 if (value != (const char *) NULL)
1565 (void) strncpy(dpx.orientation.filename,value,
1566 sizeof(dpx.orientation.filename));
1567 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1568 dpx.orientation.filename);
1569 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1570 dpx.orientation.timestamp);
cristyd15e6592011-10-15 00:13:06 +00001571 value=GetDPXProperty(image_info,image,"dpx:orientation.device",exception);
cristy3ed852e2009-09-05 21:47:34 +00001572 if (value != (const char *) NULL)
cristy7959f822010-03-07 21:47:41 +00001573 (void) strncpy(dpx.orientation.device,value,sizeof(dpx.orientation.device));
cristy3ed852e2009-09-05 21:47:34 +00001574 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1575 dpx.orientation.device);
cristyd15e6592011-10-15 00:13:06 +00001576 value=GetDPXProperty(image_info,image,"dpx:orientation.serial",exception);
cristy7959f822010-03-07 21:47:41 +00001577 if (value != (const char *) NULL)
1578 (void) strncpy(dpx.orientation.serial,value,sizeof(dpx.orientation.serial));
cristy3ed852e2009-09-05 21:47:34 +00001579 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1580 dpx.orientation.serial);
1581 for (i=0; i < 4; i++)
1582 dpx.orientation.border[i]=0;
cristyd15e6592011-10-15 00:13:06 +00001583 value=GetDPXProperty(image_info,image,"dpx:orientation.border",exception);
cristy3ed852e2009-09-05 21:47:34 +00001584 if (value != (const char *) NULL)
1585 {
1586 flags=ParseGeometry(value,&geometry_info);
1587 if ((flags & SigmaValue) == 0)
1588 geometry_info.sigma=geometry_info.rho;
1589 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1590 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1591 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1592 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1593 }
1594 for (i=0; i < 4; i++)
1595 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1596 for (i=0; i < 2; i++)
1597 dpx.orientation.aspect_ratio[i]=0U;
cristyd15e6592011-10-15 00:13:06 +00001598 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio",
1599 exception);
cristy3ed852e2009-09-05 21:47:34 +00001600 if (value != (const char *) NULL)
1601 {
1602 flags=ParseGeometry(value,&geometry_info);
1603 if ((flags & SigmaValue) == 0)
1604 geometry_info.sigma=geometry_info.rho;
1605 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1606 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1607 }
1608 for (i=0; i < 2; i++)
1609 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1610 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1611 dpx.orientation.reserve);
1612 /*
1613 Write film header.
1614 */
1615 *dpx.film.id='\0';
cristyd15e6592011-10-15 00:13:06 +00001616 value=GetDPXProperty(image_info,image,"dpx:film.id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001617 if (value != (const char *) NULL)
1618 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1619 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1620 *dpx.film.type='\0';
cristyd15e6592011-10-15 00:13:06 +00001621 value=GetDPXProperty(image_info,image,"dpx:film.type",exception);
cristy3ed852e2009-09-05 21:47:34 +00001622 if (value != (const char *) NULL)
1623 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1624 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1625 dpx.film.type);
1626 *dpx.film.offset='\0';
cristyd15e6592011-10-15 00:13:06 +00001627 value=GetDPXProperty(image_info,image,"dpx:film.offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001628 if (value != (const char *) NULL)
1629 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1630 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1631 dpx.film.offset);
1632 *dpx.film.prefix='\0';
cristyd15e6592011-10-15 00:13:06 +00001633 value=GetDPXProperty(image_info,image,"dpx:film.prefix",exception);
cristy3ed852e2009-09-05 21:47:34 +00001634 if (value != (const char *) NULL)
1635 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1636 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1637 dpx.film.prefix);
1638 *dpx.film.count='\0';
cristyd15e6592011-10-15 00:13:06 +00001639 value=GetDPXProperty(image_info,image,"dpx:film.count",exception);
cristy3ed852e2009-09-05 21:47:34 +00001640 if (value != (const char *) NULL)
1641 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1642 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1643 dpx.film.count);
1644 *dpx.film.format='\0';
cristyd15e6592011-10-15 00:13:06 +00001645 value=GetDPXProperty(image_info,image,"dpx:film.format",exception);
cristy3ed852e2009-09-05 21:47:34 +00001646 if (value != (const char *) NULL)
1647 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1648 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1649 dpx.film.format);
1650 dpx.film.frame_position=0U;
cristyd15e6592011-10-15 00:13:06 +00001651 value=GetDPXProperty(image_info,image,"dpx:film.frame_position",exception);
cristy3ed852e2009-09-05 21:47:34 +00001652 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001653 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001654 offset+=WriteBlobLong(image,dpx.film.frame_position);
1655 dpx.film.sequence_extent=0U;
cristyd15e6592011-10-15 00:13:06 +00001656 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent",exception);
cristy3ed852e2009-09-05 21:47:34 +00001657 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001658 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001659 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1660 dpx.film.held_count=0U;
cristyd15e6592011-10-15 00:13:06 +00001661 value=GetDPXProperty(image_info,image,"dpx:film.held_count",exception);
cristy3ed852e2009-09-05 21:47:34 +00001662 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001663 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001664 offset+=WriteBlobLong(image,dpx.film.held_count);
1665 dpx.film.frame_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001666 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001667 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001668 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001669 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1670 dpx.film.shutter_angle=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001671 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle",exception);
cristy3ed852e2009-09-05 21:47:34 +00001672 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001673 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001674 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1675 *dpx.film.frame_id='\0';
cristyd15e6592011-10-15 00:13:06 +00001676 value=GetDPXProperty(image_info,image,"dpx:film.frame_id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001677 if (value != (const char *) NULL)
1678 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1679 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1680 dpx.film.frame_id);
cristyd15e6592011-10-15 00:13:06 +00001681 value=GetDPXProperty(image_info,image,"dpx:film.slate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001682 if (value != (const char *) NULL)
1683 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1684 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1685 dpx.film.slate);
1686 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1687 dpx.film.reserve);
1688 /*
1689 Write television header.
1690 */
cristyd15e6592011-10-15 00:13:06 +00001691 value=GetDPXProperty(image_info,image,"dpx:television.time.code",exception);
cristy3ed852e2009-09-05 21:47:34 +00001692 if (value != (const char *) NULL)
1693 dpx.television.time_code=StringToTimeCode(value);
1694 offset+=WriteBlobLong(image,dpx.television.time_code);
cristyd15e6592011-10-15 00:13:06 +00001695 value=GetDPXProperty(image_info,image,"dpx:television.user.bits",exception);
cristy3ed852e2009-09-05 21:47:34 +00001696 if (value != (const char *) NULL)
1697 dpx.television.user_bits=StringToTimeCode(value);
1698 offset+=WriteBlobLong(image,dpx.television.user_bits);
cristyd15e6592011-10-15 00:13:06 +00001699 value=GetDPXProperty(image_info,image,"dpx:television.interlace",exception);
cristy3ed852e2009-09-05 21:47:34 +00001700 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001701 dpx.television.interlace=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001702 offset+=WriteBlobByte(image,dpx.television.interlace);
cristyd15e6592011-10-15 00:13:06 +00001703 value=GetDPXProperty(image_info,image,"dpx:television.field_number",
1704 exception);
cristy3ed852e2009-09-05 21:47:34 +00001705 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001706 dpx.television.field_number=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001707 offset+=WriteBlobByte(image,dpx.television.field_number);
1708 dpx.television.video_signal=0;
cristybccc4f42011-11-24 17:57:52 +00001709 value=GetDPXProperty(image_info,image,"dpx:television.video_signal",
1710 exception);
cristy3ed852e2009-09-05 21:47:34 +00001711 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001712 dpx.television.video_signal=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001713 offset+=WriteBlobByte(image,dpx.television.video_signal);
1714 dpx.television.padding=0;
cristyd15e6592011-10-15 00:13:06 +00001715 value=GetDPXProperty(image_info,image,"dpx:television.padding",exception);
cristy3ed852e2009-09-05 21:47:34 +00001716 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001717 dpx.television.padding=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001718 offset+=WriteBlobByte(image,dpx.television.padding);
1719 dpx.television.horizontal_sample_rate=0.0f;
cristybccc4f42011-11-24 17:57:52 +00001720 value=GetDPXProperty(image_info,image,"dpx:television.horizontal_sample_rate", exception);
cristy3ed852e2009-09-05 21:47:34 +00001721 if (value != (const char *) NULL)
cristybccc4f42011-11-24 17:57:52 +00001722 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001723 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1724 dpx.television.vertical_sample_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001725 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate",
1726 exception);
cristy3ed852e2009-09-05 21:47:34 +00001727 if (value != (const char *) NULL)
cristybccc4f42011-11-24 17:57:52 +00001728 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001729 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1730 dpx.television.frame_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001731 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001732 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001733 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001734 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1735 dpx.television.time_offset=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001736 value=GetDPXProperty(image_info,image,"dpx:television.time_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001737 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001738 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001739 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1740 dpx.television.gamma=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001741 value=GetDPXProperty(image_info,image,"dpx:television.gamma",exception);
cristy3ed852e2009-09-05 21:47:34 +00001742 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001743 dpx.television.gamma=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001744 offset+=WriteBlobFloat(image,dpx.television.gamma);
1745 dpx.television.black_level=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001746 value=GetDPXProperty(image_info,image,"dpx:television.black_level",exception);
cristy3ed852e2009-09-05 21:47:34 +00001747 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001748 dpx.television.black_level=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001749 offset+=WriteBlobFloat(image,dpx.television.black_level);
1750 dpx.television.black_gain=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001751 value=GetDPXProperty(image_info,image,"dpx:television.black_gain",exception);
cristy3ed852e2009-09-05 21:47:34 +00001752 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001753 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001754 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1755 dpx.television.break_point=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001756 value=GetDPXProperty(image_info,image,"dpx:television.break_point",exception);
cristy3ed852e2009-09-05 21:47:34 +00001757 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001758 dpx.television.break_point=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001759 offset+=WriteBlobFloat(image,dpx.television.break_point);
1760 dpx.television.white_level=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001761 value=GetDPXProperty(image_info,image,"dpx:television.white_level",exception);
cristy3ed852e2009-09-05 21:47:34 +00001762 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001763 dpx.television.white_level=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001764 offset+=WriteBlobFloat(image,dpx.television.white_level);
1765 dpx.television.integration_times=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001766 value=GetDPXProperty(image_info,image,"dpx:television.integration_times",
1767 exception);
cristy3ed852e2009-09-05 21:47:34 +00001768 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001769 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001770 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1771 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1772 dpx.television.reserve);
1773 /*
1774 Write user header.
1775 */
cristyd15e6592011-10-15 00:13:06 +00001776 value=GetDPXProperty(image_info,image,"dpx:user.id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001777 if (value != (const char *) NULL)
1778 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1779 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1780 if (profile != (StringInfo *) NULL)
1781 offset+=WriteBlob(image,GetStringInfoLength(profile),
1782 GetStringInfoDatum(profile));
1783 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1784 {
1785 count=WriteBlobByte(image,0x00);
1786 if (count != 1)
1787 {
cristy1e178e72011-08-28 19:44:34 +00001788 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
cristy3ed852e2009-09-05 21:47:34 +00001789 image->filename);
1790 break;
1791 }
1792 offset+=count;
1793 }
1794 /*
1795 Convert pixel packets to DPX raster image.
1796 */
1797 quantum_info=AcquireQuantumInfo(image_info,image);
cristy891dc792010-03-04 01:47:16 +00001798 SetQuantumQuantum(quantum_info,32);
1799 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1800 MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001801 quantum_type=RGBQuantum;
1802 if (image->matte != MagickFalse)
1803 quantum_type=RGBAQuantum;
1804 if (image->colorspace == YCbCrColorspace)
1805 {
1806 quantum_type=CbYCrQuantum;
1807 if (image->matte != MagickFalse)
1808 quantum_type=CbYCrAQuantum;
1809 if ((horizontal_factor == 2) || (vertical_factor == 2))
1810 quantum_type=CbYCrYQuantum;
1811 }
1812 extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
1813 image->depth,MagickTrue);
cristy73a724e2011-11-24 18:47:12 +00001814 if ((image_info->type != TrueColorType) && (image->matte == MagickFalse) &&
cristy1e178e72011-08-28 19:44:34 +00001815 (IsImageGray(image,exception) != MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +00001816 {
1817 quantum_type=GrayQuantum;
cristycaac2942009-10-01 13:36:18 +00001818 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00001819 }
1820 pixels=GetQuantumPixels(quantum_info);
cristybb503372010-05-27 20:51:26 +00001821 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001822 {
cristy1e178e72011-08-28 19:44:34 +00001823 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001824 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001825 break;
cristy4c08aed2011-07-01 19:47:50 +00001826 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001827 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001828 count=WriteBlob(image,extent,pixels);
1829 if (count != (ssize_t) extent)
1830 break;
cristycee97112010-05-28 00:44:52 +00001831 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy202de442011-04-24 18:19:07 +00001832 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001833 if (status == MagickFalse)
1834 break;
1835 }
1836 quantum_info=DestroyQuantumInfo(quantum_info);
1837 (void) CloseBlob(image);
1838 return(status);
1839}