blob: 0dd07c914a10da3346bab8671cdfaee671ede3d1 [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"
60#include "MagickCore/profile.h"
61#include "MagickCore/property.h"
62#include "MagickCore/quantum-private.h"
63#include "MagickCore/static.h"
64#include "MagickCore/string_.h"
65#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68 Typedef declaration.
69*/
70typedef enum
71{
72 UserDefinedColorimetric = 0,
73 PrintingDensityColorimetric = 1,
74 LinearColorimetric = 2,
75 LogarithmicColorimetric = 3,
76 UnspecifiedVideoColorimetric = 4,
77 SMTPE_274MColorimetric = 5,
78 ITU_R709Colorimetric = 6,
79 ITU_R601_625LColorimetric = 7,
80 ITU_R601_525LColorimetric = 8,
81 NTSCCompositeVideoColorimetric = 9,
82 PALCompositeVideoColorimetric = 10,
83 ZDepthLinearColorimetric = 11,
84 DepthHomogeneousColorimetric = 12
85} DPXColorimetric;
86
87typedef enum
88{
89 UndefinedComponentType = 0,
90 RedComponentType = 1,
91 GreenComponentType = 2,
92 BlueComponentType = 3,
93 AlphaComponentType = 4,
94 LumaComponentType = 6,
95 ColorDifferenceCbCrComponentType = 7,
96 DepthComponentType = 8,
97 CompositeVideoComponentType = 9,
98 RGBComponentType = 50,
99 RGBAComponentType = 51,
100 ABGRComponentType = 52,
101 CbYCrY422ComponentType = 100,
102 CbYACrYA4224ComponentType = 101,
103 CbYCr444ComponentType = 102,
104 CbYCrA4444ComponentType = 103,
105 UserDef2ElementComponentType = 150,
106 UserDef3ElementComponentType = 151,
107 UserDef4ElementComponentType = 152,
108 UserDef5ElementComponentType = 153,
109 UserDef6ElementComponentType = 154,
110 UserDef7ElementComponentType = 155,
111 UserDef8ElementComponentType = 156
112} DPXComponentType;
113
114typedef struct _DPXFileInfo
115{
116 unsigned int
117 magic,
118 image_offset;
119
120 char
121 version[8];
122
123 unsigned int
124 file_size,
125 ditto_key,
126 generic_size,
127 industry_size,
128 user_size;
129
130 char
131 filename[100],
132 timestamp[24],
133 creator[100],
134 project[200],
135 copyright[200];
136
137 unsigned int
138 encrypt_key;
139
140 char
141 reserve[104];
142} DPXFileInfo;
143
144typedef struct _DPXFilmInfo
145{
146 char
147 id[2],
148 type[2],
149 offset[2],
150 prefix[6],
151 count[4],
152 format[32];
153
154 unsigned int
155 frame_position,
156 sequence_extent,
157 held_count;
158
159 float
160 frame_rate,
161 shutter_angle;
162
163 char
164 frame_id[32],
165 slate[100],
166 reserve[56];
167} DPXFilmInfo;
168
169typedef struct _DPXImageElement
170{
171 unsigned int
172 data_sign,
173 low_data;
174
175 float
176 low_quantity;
177
178 unsigned int
179 high_data;
180
181 float
182 high_quantity;
183
184 unsigned char
185 descriptor,
186 transfer,
187 colorimetric,
188 bit_size;
189
190 unsigned short
191 packing,
192 encoding;
193
194 unsigned int
195 data_offset,
196 end_of_line_padding,
197 end_of_image_padding;
198
199 unsigned char
200 description[32];
201} DPXImageElement;
202
203typedef struct _DPXImageInfo
204{
205 unsigned short
206 orientation,
207 number_elements;
208
209 unsigned int
210 pixels_per_line,
211 lines_per_element;
212
213 DPXImageElement
214 image_element[8];
215
216 unsigned char
217 reserve[52];
218} DPXImageInfo;
219
220typedef struct _DPXOrientationInfo
221{
222 unsigned int
223 x_offset,
224 y_offset;
225
226 float
227 x_center,
228 y_center;
229
230 unsigned int
231 x_size,
232 y_size;
233
234 char
235 filename[100],
236 timestamp[24],
237 device[32],
238 serial[32];
239
240 unsigned short
241 border[4];
242
243 unsigned int
244 aspect_ratio[2];
245
246 unsigned char
247 reserve[28];
248} DPXOrientationInfo;
249
250typedef struct _DPXTelevisionInfo
251{
252 unsigned int
253 time_code,
254 user_bits;
255
256 unsigned char
257 interlace,
258 field_number,
259 video_signal,
260 padding;
261
262 float
263 horizontal_sample_rate,
264 vertical_sample_rate,
265 frame_rate,
266 time_offset,
267 gamma,
268 black_level,
269 black_gain,
270 break_point,
271 white_level,
272 integration_times;
273
274 char
275 reserve[76];
276} DPXTelevisionInfo;
277
278typedef struct _DPXUserInfo
279{
280 char
281 id[32];
282} DPXUserInfo;
283
284typedef struct DPXInfo
285{
286 DPXFileInfo
287 file;
288
289 DPXImageInfo
290 image;
291
292 DPXOrientationInfo
293 orientation;
294
295 DPXFilmInfo
296 film;
297
298 DPXTelevisionInfo
299 television;
300
301 DPXUserInfo
302 user;
303} DPXInfo;
304
305/*
306 Forward declaractions.
307*/
308static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +0000309 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000310
311/*
312%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313% %
314% %
315% %
316% I s D P X %
317% %
318% %
319% %
320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321%
322% IsDPX() returns MagickTrue if the image format type, identified by the
323% magick string, is DPX.
324%
325% The format of the IsDPX method is:
326%
327% MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
328%
329% A description of each parameter follows:
330%
331% o magick: compare image format pattern against these bytes.
332%
333% o extent: Specifies the extent of the magick string.
334%
335*/
336static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
337{
338 if (extent < 4)
339 return(MagickFalse);
340 if (memcmp(magick,"SDPX",4) == 0)
341 return(MagickTrue);
342 if (memcmp(magick,"XPDS",4) == 0)
343 return(MagickTrue);
344 return(MagickFalse);
345}
346
347/*
348%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349% %
350% %
351% %
352% R e a d D P X I m a g e %
353% %
354% %
355% %
356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357%
358% ReadDPXImage() reads an DPX X image file and returns it. It
359% allocates the memory necessary for the new Image structure and returns a
360% pointer to the new image.
361%
362% The format of the ReadDPXImage method is:
363%
364% Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
365%
366% A description of each parameter follows:
367%
368% o image_info: the image info.
369%
370% o exception: return any errors or warnings in this structure.
371%
372*/
373
cristybb503372010-05-27 20:51:26 +0000374static size_t GetBytesPerRow(size_t columns,
375 size_t samples_per_pixel,size_t bits_per_pixel,
cristy3ed852e2009-09-05 21:47:34 +0000376 MagickBooleanType pad)
377{
378 size_t
379 bytes_per_row;
380
381 switch (bits_per_pixel)
382 {
383 case 1:
384 {
385 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
386 bits_per_pixel+31)/32);
387 break;
388 }
389 case 8:
390 default:
391 {
392 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
393 bits_per_pixel+31)/32);
394 break;
395 }
396 case 10:
397 {
398 if (pad == MagickFalse)
399 {
400 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
401 bits_per_pixel+31)/32);
402 break;
403 }
cristyff024b42010-02-21 22:55:09 +0000404 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
cristy3ed852e2009-09-05 21:47:34 +0000405 break;
406 }
407 case 12:
408 {
409 if (pad == MagickFalse)
410 {
411 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
412 bits_per_pixel+31)/32);
413 break;
414 }
415 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
416 break;
417 }
418 case 16:
419 {
420 bytes_per_row=2*(((size_t) samples_per_pixel*columns*
421 bits_per_pixel+8)/16);
422 break;
423 }
424 case 32:
425 {
426 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
427 bits_per_pixel+31)/32);
428 break;
429 }
430 case 64:
431 {
432 bytes_per_row=8*(((size_t) samples_per_pixel*columns*
433 bits_per_pixel+63)/64);
434 break;
435 }
436 }
437 return(bytes_per_row);
438}
439
440static inline MagickBooleanType IsFloatDefined(const float value)
441{
442 union
443 {
444 unsigned int
445 unsigned_value;
446
cristy97450ff2010-12-29 17:29:17 +0000447 double
cristy3ed852e2009-09-05 21:47:34 +0000448 float_value;
449 } quantum;
450
451 quantum.unsigned_value=0U;
452 quantum.float_value=(double) value;
453 if (quantum.unsigned_value == 0U)
454 return(MagickFalse);
455 return(MagickTrue);
456}
457
458static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
459 ChromaticityInfo *chromaticity_info)
460{
461 switch(colorimetric)
462 {
463 case SMTPE_274MColorimetric:
464 case ITU_R709Colorimetric:
465 {
466 chromaticity_info->red_primary.x=0.640;
467 chromaticity_info->red_primary.y=0.330;
468 chromaticity_info->red_primary.z=0.030;
469 chromaticity_info->green_primary.x=0.300;
470 chromaticity_info->green_primary.y=0.600;
471 chromaticity_info->green_primary.z=0.100;
472 chromaticity_info->blue_primary.x=0.150;
473 chromaticity_info->blue_primary.y=0.060;
474 chromaticity_info->blue_primary.z=0.790;
475 chromaticity_info->white_point.x=0.3127;
476 chromaticity_info->white_point.y=0.3290;
477 chromaticity_info->white_point.z=0.3582;
478 break;
479 }
480 case NTSCCompositeVideoColorimetric:
481 {
482 chromaticity_info->red_primary.x=0.67;
483 chromaticity_info->red_primary.y=0.33;
484 chromaticity_info->red_primary.z=0.00;
485 chromaticity_info->green_primary.x=0.21;
486 chromaticity_info->green_primary.y=0.71;
487 chromaticity_info->green_primary.z=0.08;
488 chromaticity_info->blue_primary.x=0.14;
489 chromaticity_info->blue_primary.y=0.08;
490 chromaticity_info->blue_primary.z=0.78;
491 chromaticity_info->white_point.x=0.310;
492 chromaticity_info->white_point.y=0.316;
493 chromaticity_info->white_point.z=0.374;
494 break;
495 }
496 case PALCompositeVideoColorimetric:
497 {
498 chromaticity_info->red_primary.x=0.640;
499 chromaticity_info->red_primary.y=0.330;
500 chromaticity_info->red_primary.z=0.030;
501 chromaticity_info->green_primary.x=0.290;
502 chromaticity_info->green_primary.y=0.600;
503 chromaticity_info->green_primary.z=0.110;
504 chromaticity_info->blue_primary.x=0.150;
505 chromaticity_info->blue_primary.y=0.060;
506 chromaticity_info->blue_primary.z=0.790;
507 chromaticity_info->white_point.x=0.3127;
508 chromaticity_info->white_point.y=0.3290;
509 chromaticity_info->white_point.z=0.3582;
510 break;
511 }
512 default:
513 break;
514 }
515}
516
cristybb503372010-05-27 20:51:26 +0000517static void TimeCodeToString(const size_t timestamp,char *code)
cristy3ed852e2009-09-05 21:47:34 +0000518{
519#define TimeFields 7
520
521 unsigned int
522 shift;
523
cristybb503372010-05-27 20:51:26 +0000524 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000525 i;
526
527 *code='\0';
528 shift=4*TimeFields;
529 for (i=0; i <= TimeFields; i++)
530 {
cristyb51dff52011-05-19 16:55:47 +0000531 (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x",
cristy3ed852e2009-09-05 21:47:34 +0000532 (unsigned int) ((timestamp >> shift) & 0x0fU));
533 code++;
534 if (((i % 2) != 0) && (i < TimeFields))
535 *code++=':';
536 shift-=4;
537 *code='\0';
538 }
539}
540
541static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
542{
543 char
544 magick[4],
545 value[MaxTextExtent];
546
547 DPXInfo
548 dpx;
549
550 Image
551 *image;
552
cristy3ed852e2009-09-05 21:47:34 +0000553 MagickBooleanType
554 status;
555
556 MagickOffsetType
557 offset;
558
cristyff024b42010-02-21 22:55:09 +0000559 QuantumInfo
560 *quantum_info;
561
cristy3ed852e2009-09-05 21:47:34 +0000562 QuantumType
563 quantum_type;
564
cristybb503372010-05-27 20:51:26 +0000565 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000566 i;
567
cristy3ed852e2009-09-05 21:47:34 +0000568 size_t
cristy202de442011-04-24 18:19:07 +0000569 extent,
570 samples_per_pixel;
571
572 ssize_t
573 count,
574 row,
575 y;
cristy3ed852e2009-09-05 21:47:34 +0000576
577 unsigned char
578 component_type;
579
cristy3ed852e2009-09-05 21:47:34 +0000580 /*
581 Open image file.
582 */
583 assert(image_info != (const ImageInfo *) NULL);
584 assert(image_info->signature == MagickSignature);
585 if (image_info->debug != MagickFalse)
586 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
587 image_info->filename);
588 assert(exception != (ExceptionInfo *) NULL);
589 assert(exception->signature == MagickSignature);
590 image=AcquireImage(image_info);
591 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
592 if (status == MagickFalse)
593 {
594 image=DestroyImageList(image);
595 return((Image *) NULL);
596 }
597 /*
598 Read DPX file header.
599 */
600 offset=0;
601 count=ReadBlob(image,4,(unsigned char *) magick);
602 offset+=count;
603 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
604 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
605 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
606 image->endian=LSBEndian;
607 if (LocaleNCompare(magick,"SDPX",4) == 0)
608 image->endian=MSBEndian;
609 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
610 dpx.file.image_offset=ReadBlobLong(image);
611 offset+=4;
612 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
613 dpx.file.version);
614 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
615 dpx.file.file_size=ReadBlobLong(image);
616 offset+=4;
617 dpx.file.ditto_key=ReadBlobLong(image);
618 offset+=4;
619 if (dpx.file.ditto_key != ~0U)
620 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
621 dpx.file.ditto_key);
622 dpx.file.generic_size=ReadBlobLong(image);
623 offset+=4;
624 dpx.file.industry_size=ReadBlobLong(image);
625 offset+=4;
626 dpx.file.user_size=ReadBlobLong(image);
627 offset+=4;
628 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
629 dpx.file.filename);
630 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
631 dpx.file.filename);
632 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
633 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
634 dpx.file.timestamp);
635 if (*dpx.file.timestamp != '\0')
636 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
637 dpx.file.timestamp);
638 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
639 dpx.file.creator);
640 if (*dpx.file.creator != '\0')
641 {
642 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
643 dpx.file.creator);
644 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
645 }
646 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
647 dpx.file.project);
648 if (*dpx.file.project != '\0')
649 {
650 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
651 dpx.file.project);
652 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
653 }
654 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
655 dpx.file.copyright);
656 if (*dpx.file.copyright != '\0')
657 {
658 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
659 dpx.file.copyright);
660 (void) FormatImageProperty(image,"copyright","%.100s",
661 dpx.file.copyright);
662 }
663 dpx.file.encrypt_key=ReadBlobLong(image);
664 offset+=4;
665 if (dpx.file.encrypt_key != ~0U)
666 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
667 dpx.file.encrypt_key);
668 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
669 dpx.file.reserve);
670 /*
671 Read DPX image header.
672 */
673 dpx.image.orientation=ReadBlobShort(image);
674 offset+=2;
675 if (dpx.image.orientation != (unsigned short) (~0U))
676 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
677 dpx.image.orientation);
678 switch (dpx.image.orientation)
679 {
680 default:
cristy202de442011-04-24 18:19:07 +0000681 case 0: image->orientation=TopLeftOrientation; break;
682 case 1: image->orientation=TopRightOrientation; break;
683 case 2: image->orientation=BottomLeftOrientation; break;
684 case 3: image->orientation=BottomRightOrientation; break;
685 case 4: image->orientation=LeftTopOrientation; break;
686 case 5: image->orientation=RightTopOrientation; break;
687 case 6: image->orientation=LeftBottomOrientation; break;
688 case 7: image->orientation=RightBottomOrientation; break;
cristy3ed852e2009-09-05 21:47:34 +0000689 }
690 dpx.image.number_elements=ReadBlobShort(image);
691 offset+=2;
692 dpx.image.pixels_per_line=ReadBlobLong(image);
693 offset+=4;
694 image->columns=dpx.image.pixels_per_line;
695 dpx.image.lines_per_element=ReadBlobLong(image);
696 offset+=4;
697 image->rows=dpx.image.lines_per_element;
698 for (i=0; i < 8; i++)
699 {
700 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
701 offset+=4;
702 dpx.image.image_element[i].low_data=ReadBlobLong(image);
703 offset+=4;
704 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
705 offset+=4;
706 dpx.image.image_element[i].high_data=ReadBlobLong(image);
707 offset+=4;
708 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
709 offset+=4;
710 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
711 offset++;
712 dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
713 offset++;
714 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
715 offset++;
716 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
717 offset++;
718 dpx.image.image_element[i].packing=ReadBlobShort(image);
719 offset+=2;
720 dpx.image.image_element[i].encoding=ReadBlobShort(image);
721 offset+=2;
722 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
723 offset+=4;
724 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
725 offset+=4;
726 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
727 offset+=4;
728 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
729 (unsigned char *) dpx.image.image_element[i].description);
730 }
731 SetPrimaryChromaticity((DPXColorimetric)
732 dpx.image.image_element[0].colorimetric,&image->chromaticity);
733 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
734 dpx.image.reserve);
735 component_type=dpx.image.image_element[0].descriptor;
736 image->depth=dpx.image.image_element[0].bit_size;
737 if (dpx.file.image_offset >= 1664U)
738 {
739 /*
740 Read DPX orientation header.
741 */
742 dpx.orientation.x_offset=ReadBlobLong(image);
743 offset+=4;
744 if (dpx.orientation.x_offset != ~0U)
745 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
746 dpx.orientation.x_offset);
747 dpx.orientation.y_offset=ReadBlobLong(image);
748 offset+=4;
749 if (dpx.orientation.y_offset != ~0U)
750 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
751 dpx.orientation.y_offset);
752 dpx.orientation.x_center=ReadBlobFloat(image);
753 offset+=4;
754 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
755 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
756 dpx.orientation.x_center);
757 dpx.orientation.y_center=ReadBlobFloat(image);
758 offset+=4;
759 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
760 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
761 dpx.orientation.y_center);
762 dpx.orientation.x_size=ReadBlobLong(image);
763 offset+=4;
764 if (dpx.orientation.x_size != ~0U)
765 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
766 dpx.orientation.x_size);
767 dpx.orientation.y_size=ReadBlobLong(image);
768 offset+=4;
769 if (dpx.orientation.y_size != ~0U)
770 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
771 dpx.orientation.y_size);
772 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
773 dpx.orientation.filename);
774 if (*dpx.orientation.filename != '\0')
775 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
776 dpx.orientation.filename);
777 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
778 dpx.orientation.timestamp);
779 if (*dpx.orientation.timestamp != '\0')
780 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
781 dpx.orientation.timestamp);
782 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
783 dpx.orientation.device);
784 if (*dpx.orientation.device != '\0')
785 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
786 dpx.orientation.device);
787 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
788 dpx.orientation.serial);
789 if (*dpx.orientation.serial != '\0')
790 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
791 dpx.orientation.serial);
792 for (i=0; i < 4; i++)
793 {
794 dpx.orientation.border[i]=ReadBlobShort(image);
795 offset+=2;
796 }
797 if ((dpx.orientation.border[0] != (unsigned short) (~0U)) &&
798 (dpx.orientation.border[1] != (unsigned short) (~0U)))
799 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d", dpx.orientation.border[0],dpx.orientation.border[1],
800 dpx.orientation.border[2],dpx.orientation.border[3]);
801 for (i=0; i < 2; i++)
802 {
803 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
804 offset+=4;
805 }
806 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
807 (dpx.orientation.aspect_ratio[1] != ~0U))
808 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
809 "%ux%u",dpx.orientation.aspect_ratio[0],
810 dpx.orientation.aspect_ratio[1]);
811 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
812 dpx.orientation.reserve);
813 }
814 if (dpx.file.image_offset >= 1920U)
815 {
816 /*
817 Read DPX film header.
818 */
819 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
820 if (*dpx.film.type != '\0')
821 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
822 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
823 dpx.film.type);
824 if (*dpx.film.type != '\0')
825 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
826 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
827 dpx.film.offset);
828 if (*dpx.film.offset != '\0')
829 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
830 dpx.film.offset);
831 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
832 dpx.film.prefix);
833 if (*dpx.film.prefix != '\0')
834 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
835 dpx.film.prefix);
836 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
837 dpx.film.count);
838 if (*dpx.film.count != '\0')
839 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
840 dpx.film.count);
841 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
842 dpx.film.format);
843 if (*dpx.film.format != '\0')
844 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
845 dpx.film.format);
846 dpx.film.frame_position=ReadBlobLong(image);
847 offset+=4;
848 if (dpx.film.frame_position != ~0U)
849 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
850 dpx.film.frame_position);
851 dpx.film.sequence_extent=ReadBlobLong(image);
852 offset+=4;
853 if (dpx.film.sequence_extent != ~0U)
854 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
855 dpx.film.sequence_extent);
856 dpx.film.held_count=ReadBlobLong(image);
857 offset+=4;
858 if (dpx.film.held_count != ~0U)
859 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
860 dpx.film.held_count);
861 dpx.film.frame_rate=ReadBlobFloat(image);
862 offset+=4;
863 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
864 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
865 dpx.film.frame_rate);
866 dpx.film.shutter_angle=ReadBlobFloat(image);
867 offset+=4;
868 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
869 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
870 dpx.film.shutter_angle);
871 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
872 dpx.film.frame_id);
873 if (*dpx.film.frame_id != '\0')
874 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
875 dpx.film.frame_id);
876 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
877 dpx.film.slate);
878 if (*dpx.film.slate != '\0')
879 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
880 dpx.film.slate);
881 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
882 dpx.film.reserve);
883 }
884 if (dpx.file.image_offset >= 2048U)
885 {
886 /*
887 Read DPX television header.
888 */
889 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
890 offset+=4;
891 TimeCodeToString(dpx.television.time_code,value);
892 (void) SetImageProperty(image,"dpx:television.time.code",value);
893 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
894 offset+=4;
895 TimeCodeToString(dpx.television.user_bits,value);
896 (void) SetImageProperty(image,"dpx:television.user.bits",value);
897 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
898 offset++;
899 if (dpx.television.interlace != 0)
cristye8c25f92010-06-03 00:53:06 +0000900 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
901 (double) dpx.television.interlace);
cristy3ed852e2009-09-05 21:47:34 +0000902 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
903 offset++;
904 if (dpx.television.field_number != 0)
cristye8c25f92010-06-03 00:53:06 +0000905 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
906 (double) dpx.television.field_number);
cristy3ed852e2009-09-05 21:47:34 +0000907 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
908 offset++;
909 if (dpx.television.video_signal != 0)
cristye8c25f92010-06-03 00:53:06 +0000910 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
911 (double) dpx.television.video_signal);
cristy3ed852e2009-09-05 21:47:34 +0000912 dpx.television.padding=(unsigned char) ReadBlobByte(image);
913 offset++;
914 if (dpx.television.padding != 0)
915 (void) FormatImageProperty(image,"dpx:television.padding","%d",
916 dpx.television.padding);
917 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
918 offset+=4;
919 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
920 (void) FormatImageProperty(image,
921 "dpx:television.horizontal_sample_rate","%g",
922 dpx.television.horizontal_sample_rate);
923 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
924 offset+=4;
925 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
926 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
927 "%g",dpx.television.vertical_sample_rate);
928 dpx.television.frame_rate=ReadBlobFloat(image);
929 offset+=4;
930 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
931 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
932 dpx.television.frame_rate);
933 dpx.television.time_offset=ReadBlobFloat(image);
934 offset+=4;
935 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
936 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
937 dpx.television.time_offset);
938 dpx.television.gamma=ReadBlobFloat(image);
939 offset+=4;
940 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
941 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
942 dpx.television.gamma);
943 dpx.television.black_level=ReadBlobFloat(image);
944 offset+=4;
945 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
946 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
947 dpx.television.black_level);
948 dpx.television.black_gain=ReadBlobFloat(image);
949 offset+=4;
950 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
951 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
952 dpx.television.black_gain);
953 dpx.television.break_point=ReadBlobFloat(image);
954 offset+=4;
955 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
956 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
957 dpx.television.break_point);
958 dpx.television.white_level=ReadBlobFloat(image);
959 offset+=4;
960 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
961 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
962 dpx.television.white_level);
963 dpx.television.integration_times=ReadBlobFloat(image);
964 offset+=4;
965 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
966 (void) FormatImageProperty(image,"dpx:television.integration_times",
967 "%g",dpx.television.integration_times);
968 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
969 dpx.television.reserve);
970 }
971 if (dpx.file.image_offset > 2080U)
972 {
973 /*
974 Read DPX user header.
975 */
976 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
977 if (*dpx.user.id != '\0')
978 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
979 if ((dpx.file.user_size != ~0U) &&
980 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
981 {
982 StringInfo
983 *profile;
984
cristy1a14f472010-06-20 19:21:48 +0000985 profile=AcquireStringInfo(dpx.file.user_size-sizeof(dpx.user.id));
cristy3ed852e2009-09-05 21:47:34 +0000986 offset+=ReadBlob(image,GetStringInfoLength(profile),
987 GetStringInfoDatum(profile));
cristy61047b62010-05-22 02:15:20 +0000988 (void) SetImageProfile(image,"dpx",profile);
cristy3ed852e2009-09-05 21:47:34 +0000989 profile=DestroyStringInfo(profile);
990 }
991 }
cristy811f5172010-12-29 17:38:08 +0000992 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
cristy3ed852e2009-09-05 21:47:34 +0000993 (void) ReadBlobByte(image);
994 /*
995 Read DPX image header.
996 */
997 if (image_info->ping != MagickFalse)
998 {
999 (void) CloseBlob(image);
1000 return(GetFirstImageInList(image));
1001 }
1002 /*
1003 Convert DPX raster image to pixel packets.
1004 */
1005 samples_per_pixel=1;
1006 quantum_type=GrayQuantum;
1007 switch (component_type)
1008 {
1009 case CbYCrY422ComponentType:
1010 {
1011 samples_per_pixel=2;
1012 quantum_type=CbYCrYQuantum;
1013 break;
1014 }
1015 case CbYACrYA4224ComponentType:
1016 case CbYCr444ComponentType:
1017 {
1018 samples_per_pixel=3;
1019 quantum_type=CbYCrQuantum;
1020 break;
1021 }
1022 case RGBComponentType:
1023 {
1024 samples_per_pixel=3;
1025 quantum_type=RGBQuantum;
1026 break;
1027 }
1028 case ABGRComponentType:
1029 case RGBAComponentType:
1030 {
1031 image->matte=MagickTrue;
1032 samples_per_pixel=4;
1033 quantum_type=RGBAQuantum;
1034 break;
1035 }
1036 default:
1037 break;
1038 }
1039 switch (component_type)
1040 {
1041 case CbYCrY422ComponentType:
1042 case CbYACrYA4224ComponentType:
1043 case CbYCr444ComponentType:
1044 {
1045 image->colorspace=Rec709YCbCrColorspace;
1046 break;
1047 }
1048 case LumaComponentType:
1049 {
1050 image->colorspace=RGBColorspace;
1051 break;
1052 }
1053 default:
1054 {
1055 image->colorspace=RGBColorspace;
1056 if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
1057 image->colorspace=LogColorspace;
1058 if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
1059 image->colorspace=LogColorspace;
1060 break;
1061 }
1062 }
1063 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1064 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
cristyff024b42010-02-21 22:55:09 +00001065 /*
1066 DPX any-bit pixel format.
1067 */
1068 status=MagickTrue;
1069 row=0;
1070 quantum_info=AcquireQuantumInfo(image_info,image);
1071 if (quantum_info == (QuantumInfo *) NULL)
1072 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1073 SetQuantumQuantum(quantum_info,32);
1074 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1075 MagickTrue : MagickFalse);
cristybb503372010-05-27 20:51:26 +00001076 for (y=0; y < (ssize_t) image->rows; y++)
cristyff024b42010-02-21 22:55:09 +00001077 {
cristyff024b42010-02-21 22:55:09 +00001078 MagickBooleanType
1079 sync;
cristy3ed852e2009-09-05 21:47:34 +00001080
cristy4c08aed2011-07-01 19:47:50 +00001081 register Quantum
cristyff024b42010-02-21 22:55:09 +00001082 *q;
cristy3ed852e2009-09-05 21:47:34 +00001083
cristyff024b42010-02-21 22:55:09 +00001084 size_t
1085 length;
cristy3ed852e2009-09-05 21:47:34 +00001086
cristy202de442011-04-24 18:19:07 +00001087 ssize_t
1088 count,
1089 offset;
1090
cristyff024b42010-02-21 22:55:09 +00001091 unsigned char
1092 *pixels;
cristy3ed852e2009-09-05 21:47:34 +00001093
cristyff024b42010-02-21 22:55:09 +00001094 if (status == MagickFalse)
1095 continue;
1096 pixels=GetQuantumPixels(quantum_info);
cristyff024b42010-02-21 22:55:09 +00001097 {
1098 count=ReadBlob(image,extent,pixels);
1099 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1100 (image->previous == (Image *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00001101 {
cristyff024b42010-02-21 22:55:09 +00001102 MagickBooleanType
1103 proceed;
cristy3ed852e2009-09-05 21:47:34 +00001104
cristycee97112010-05-28 00:44:52 +00001105 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
cristy202de442011-04-24 18:19:07 +00001106 image->rows);
cristyff024b42010-02-21 22:55:09 +00001107 if (proceed == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001108 status=MagickFalse;
cristyff024b42010-02-21 22:55:09 +00001109 }
1110 offset=row++;
cristy3ed852e2009-09-05 21:47:34 +00001111 }
cristyff024b42010-02-21 22:55:09 +00001112 if (count != (ssize_t) extent)
1113 status=MagickFalse;
cristyaa740112010-03-30 17:58:44 +00001114 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001115 if (q == (const Quantum *) NULL)
cristyff024b42010-02-21 22:55:09 +00001116 {
1117 status=MagickFalse;
1118 continue;
1119 }
cristyf410d302010-03-30 23:28:56 +00001120 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristyaa740112010-03-30 17:58:44 +00001121 quantum_type,pixels,exception);
cristyda16f162011-02-19 23:52:17 +00001122 (void) length;
cristyaa740112010-03-30 17:58:44 +00001123 sync=SyncAuthenticPixels(image,exception);
cristyff024b42010-02-21 22:55:09 +00001124 if (sync == MagickFalse)
1125 status=MagickFalse;
1126 }
cristyff024b42010-02-21 22:55:09 +00001127 quantum_info=DestroyQuantumInfo(quantum_info);
1128 if (status == MagickFalse)
1129 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
cristy3ed852e2009-09-05 21:47:34 +00001130 SetQuantumImageType(image,quantum_type);
1131 if (EOFBlob(image) != MagickFalse)
1132 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1133 image->filename);
1134 (void) CloseBlob(image);
1135 return(GetFirstImageInList(image));
1136}
1137
1138/*
1139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1140% %
1141% %
1142% %
1143% R e g i s t e r D P X I m a g e %
1144% %
1145% %
1146% %
1147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148%
1149% RegisterDPXImage() adds properties for the DPX image format to
1150% the list of supported formats. The properties include the image format
1151% tag, a method to read and/or write the format, whether the format
1152% supports the saving of more than one frame to the same file or blob,
1153% whether the format supports native in-memory I/O, and a brief
1154% description of the format.
1155%
1156% The format of the RegisterDPXImage method is:
1157%
cristybb503372010-05-27 20:51:26 +00001158% size_t RegisterDPXImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001159%
1160*/
cristybb503372010-05-27 20:51:26 +00001161ModuleExport size_t RegisterDPXImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001162{
1163 MagickInfo
1164 *entry;
1165
1166 static const char
1167 *DPXNote =
1168 {
1169 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1170 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1171 };
1172
1173 entry=SetMagickInfo("DPX");
1174 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1175 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1176 entry->magick=(IsImageFormatHandler *) IsDPX;
1177 entry->adjoin=MagickFalse;
1178 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1179 entry->note=ConstantString(DPXNote);
1180 entry->module=ConstantString("DPX");
1181 (void) RegisterMagickInfo(entry);
1182 return(MagickImageCoderSignature);
1183}
1184
1185/*
1186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1187% %
1188% %
1189% %
1190% U n r e g i s t e r D P X I m a g e %
1191% %
1192% %
1193% %
1194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1195%
1196% UnregisterDPXImage() removes format registrations made by the
1197% DPX module from the list of supported formats.
1198%
1199% The format of the UnregisterDPXImage method is:
1200%
1201% UnregisterDPXImage(void)
1202%
1203*/
1204ModuleExport void UnregisterDPXImage(void)
1205{
1206 (void) UnregisterMagickInfo("DPX");
1207}
1208
1209/*
1210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1211% %
1212% %
1213% %
1214% W r i t e D P X I m a g e %
1215% %
1216% %
1217% %
1218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1219%
1220% WriteDPXImage() writes an image in DPX encoded image format.
1221%
1222% The format of the WriteDPXImage method is:
1223%
cristy1e178e72011-08-28 19:44:34 +00001224% MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1225% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001226%
1227% A description of each parameter follows.
1228%
1229% o image_info: the image info.
1230%
1231% o image: The image.
1232%
cristy1e178e72011-08-28 19:44:34 +00001233% o exception: return any errors or warnings in this structure.
1234%
cristy3ed852e2009-09-05 21:47:34 +00001235*/
1236
1237static inline const char *GetDPXProperty(const ImageInfo *image_info,
1238 const Image *image,const char *property)
1239{
1240 const char
1241 *value;
1242
1243 value=GetImageOption(image_info,property);
1244 if (value != (const char *) NULL)
1245 return(value);
1246 return(GetImageProperty(image,property));
1247}
1248
1249static unsigned int StringToTimeCode(const char *key)
1250{
1251 char
1252 buffer[2];
1253
cristybb503372010-05-27 20:51:26 +00001254 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001255 i;
1256
1257 unsigned int
1258 shift,
1259 value;
1260
1261 value=0;
1262 shift=28;
1263 buffer[1]='\0';
1264 for (i=0; (*key != 0) && (i < 11); i++)
1265 {
1266 if (isxdigit((int) ((unsigned char) *key)) == 0)
1267 {
1268 key++;
1269 continue;
1270 }
1271 buffer[0]=(*key++);
1272 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1273 shift-=4;
1274 }
1275 return(value);
1276}
1277
cristy1e178e72011-08-28 19:44:34 +00001278static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1279 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001280{
1281 const char
1282 *value;
1283
1284 const StringInfo
1285 *profile;
1286
1287 DPXInfo
1288 dpx;
1289
cristy3ed852e2009-09-05 21:47:34 +00001290 MagickBooleanType
1291 status;
1292
1293 MagickOffsetType
1294 offset;
1295
1296 MagickStatusType
1297 flags;
1298
1299 GeometryInfo
1300 geometry_info;
1301
1302 QuantumInfo
1303 *quantum_info;
1304
1305 QuantumType
1306 quantum_type;
1307
cristy4c08aed2011-07-01 19:47:50 +00001308 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001309 *p;
1310
cristybb503372010-05-27 20:51:26 +00001311 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001312 i;
1313
cristy1e178e72011-08-28 19:44:34 +00001314 size_t
1315 extent;
1316
cristy202de442011-04-24 18:19:07 +00001317 ssize_t
1318 count,
1319 horizontal_factor,
1320 vertical_factor,
1321 y;
1322
cristy3ed852e2009-09-05 21:47:34 +00001323 time_t
1324 seconds;
1325
1326 unsigned char
1327 *pixels;
1328
1329 /*
1330 Open output image file.
1331 */
1332 assert(image_info != (const ImageInfo *) NULL);
1333 assert(image_info->signature == MagickSignature);
1334 assert(image != (Image *) NULL);
1335 assert(image->signature == MagickSignature);
1336 if (image->debug != MagickFalse)
1337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1338 horizontal_factor=4;
1339 vertical_factor=4;
1340 if (image_info->sampling_factor != (char *) NULL)
1341 {
1342 GeometryInfo
1343 geometry_info;
1344
1345 MagickStatusType
1346 flags;
1347
1348 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
cristybb503372010-05-27 20:51:26 +00001349 horizontal_factor=(ssize_t) geometry_info.rho;
1350 vertical_factor=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00001351 if ((flags & SigmaValue) == 0)
1352 vertical_factor=horizontal_factor;
1353 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1354 (horizontal_factor != 4) && (vertical_factor != 1) &&
1355 (vertical_factor != 2) && (vertical_factor != 4))
1356 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1357 }
1358 if ((image->colorspace == YCbCrColorspace) &&
1359 ((horizontal_factor == 2) || (vertical_factor == 2)))
1360 if ((image->columns % 2) != 0)
1361 image->columns++;
cristy3a37efd2011-08-28 20:31:03 +00001362 assert(exception != (ExceptionInfo *) NULL);
1363 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +00001364 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001365 if (status == MagickFalse)
1366 return(status);
1367 /*
1368 Write file header.
1369 */
1370 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1371 offset=0;
1372 dpx.file.magic=0x53445058U;
1373 offset+=WriteBlobLong(image,dpx.file.magic);
1374 dpx.file.image_offset=0x2000U;
cristy61047b62010-05-22 02:15:20 +00001375 profile=GetImageProfile(image,"dpx");
cristy3ed852e2009-09-05 21:47:34 +00001376 if (profile != (StringInfo *) NULL)
1377 {
cristy61047b62010-05-22 02:15:20 +00001378 if (GetStringInfoLength(profile) > 1048576)
1379 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
cristy3ed852e2009-09-05 21:47:34 +00001380 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1381 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1382 }
1383 offset+=WriteBlobLong(image,dpx.file.image_offset);
1384 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1385 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1386 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1387 dpx.file.image_offset);
1388 offset+=WriteBlobLong(image,dpx.file.file_size);
1389 dpx.file.ditto_key=1U; /* new frame */
1390 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1391 dpx.file.generic_size=0x00000680U;
1392 offset+=WriteBlobLong(image,dpx.file.generic_size);
1393 dpx.file.industry_size=0x00000180U;
1394 offset+=WriteBlobLong(image,dpx.file.industry_size);
1395 dpx.file.user_size=0;
1396 if (profile != (StringInfo *) NULL)
1397 {
1398 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1399 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1400 }
1401 offset+=WriteBlobLong(image,dpx.file.user_size);
1402 value=GetDPXProperty(image_info,image,"dpx:file.filename");
1403 if (value != (const char *) NULL)
1404 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1405 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1406 dpx.file.filename);
1407 seconds=time((time_t *) NULL);
1408 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1409 dpx.file.timestamp);
1410 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1411 dpx.file.timestamp);
cristybb503372010-05-27 20:51:26 +00001412 (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL),
cristy3ed852e2009-09-05 21:47:34 +00001413 sizeof(dpx.file.creator));
1414 value=GetDPXProperty(image_info,image,"dpx:file.creator");
1415 if (value != (const char *) NULL)
1416 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1417 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1418 dpx.file.creator);
1419 value=GetDPXProperty(image_info,image,"dpx:file.project");
1420 if (value != (const char *) NULL)
1421 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1422 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1423 dpx.file.project);
1424 value=GetDPXProperty(image_info,image,"dpx:file.copyright");
1425 if (value != (const char *) NULL)
1426 (void) strncpy(dpx.file.copyright,value,
1427 sizeof(dpx.file.copyright));
1428 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1429 dpx.file.copyright);
1430 dpx.file.encrypt_key=(~0U);
1431 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1432 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1433 dpx.file.reserve);
1434 /*
1435 Write image header.
1436 */
1437 dpx.image.orientation=0x00; /* left-to-right; top-to-bottom */
1438 offset+=WriteBlobShort(image,dpx.image.orientation);
1439 dpx.image.number_elements=1;
1440 offset+=WriteBlobShort(image,dpx.image.number_elements);
1441 if ((image->columns != (unsigned int) image->columns) ||
1442 (image->rows != (unsigned int) image->rows))
1443 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1444 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1445 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1446 for (i=0; i < 8; i++)
1447 {
1448 dpx.image.image_element[i].data_sign=0U;
1449 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1450 dpx.image.image_element[i].low_data=0U;
1451 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1452 dpx.image.image_element[i].low_quantity=0.0f;
1453 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1454 dpx.image.image_element[i].high_data=0U;
1455 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1456 dpx.image.image_element[i].high_quantity=0.0f;
1457 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1458 dpx.image.image_element[i].descriptor=0;
1459 if (i == 0)
1460 switch (image->colorspace)
1461 {
1462 case Rec601YCbCrColorspace:
1463 case Rec709YCbCrColorspace:
1464 case YCbCrColorspace:
1465 {
1466 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1467 if (image->matte != MagickFalse)
1468 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1469 break;
1470 }
1471 default:
1472 {
1473 dpx.image.image_element[i].descriptor=RGBComponentType;
1474 if (image->matte != MagickFalse)
1475 dpx.image.image_element[i].descriptor=RGBAComponentType;
cristyf59a8922010-02-28 19:51:23 +00001476 if ((image_info->type != TrueColorType) &&
1477 (image->matte == MagickFalse) &&
cristy1e178e72011-08-28 19:44:34 +00001478 (IsImageGray(image,exception) != MagickFalse))
cristycaac2942009-10-01 13:36:18 +00001479 dpx.image.image_element[i].descriptor=LumaComponentType;
cristy3ed852e2009-09-05 21:47:34 +00001480 break;
1481 }
1482 }
1483 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1484 dpx.image.image_element[i].transfer=0;
1485 if (image->colorspace == LogColorspace)
1486 dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
1487 offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
1488 dpx.image.image_element[i].colorimetric=0;
1489 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1490 dpx.image.image_element[i].bit_size=0;
1491 if (i == 0)
1492 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1493 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1494 dpx.image.image_element[i].packing=0;
1495 if ((image->depth == 10) || (image->depth == 12))
1496 dpx.image.image_element[i].packing=1;
1497 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1498 dpx.image.image_element[i].encoding=0;
1499 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1500 dpx.image.image_element[i].data_offset=0U;
1501 if (i == 0)
1502 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1503 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1504 dpx.image.image_element[i].end_of_line_padding=0U;
1505 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1506 offset+=WriteBlobLong(image,
1507 dpx.image.image_element[i].end_of_image_padding);
1508 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1509 (unsigned char *) dpx.image.image_element[i].description);
1510 }
1511 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1512 dpx.image.reserve);
1513 /*
1514 Write orientation header.
1515 */
1516 if ((image->rows != image->magick_rows) ||
1517 (image->columns != image->magick_columns))
1518 {
1519 /*
1520 These properties are not valid if image size changed.
1521 */
1522 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1523 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1524 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1525 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1526 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1527 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1528 }
1529 dpx.orientation.x_offset=0U;
1530 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset");
1531 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001532 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001533 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1534 dpx.orientation.y_offset=0U;
1535 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset");
1536 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001537 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001538 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1539 dpx.orientation.x_center=0.0f;
1540 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center");
1541 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001542 dpx.orientation.x_center=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001543 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1544 dpx.orientation.y_center=0.0f;
1545 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center");
1546 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001547 dpx.orientation.y_center=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001548 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1549 dpx.orientation.x_size=0U;
1550 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size");
1551 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001552 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001553 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1554 dpx.orientation.y_size=0U;
1555 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size");
1556 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001557 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001558 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1559 value=GetDPXProperty(image_info,image,"dpx:orientation.filename");
1560 if (value != (const char *) NULL)
1561 (void) strncpy(dpx.orientation.filename,value,
1562 sizeof(dpx.orientation.filename));
1563 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1564 dpx.orientation.filename);
1565 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1566 dpx.orientation.timestamp);
1567 value=GetDPXProperty(image_info,image,"dpx:orientation.device");
1568 if (value != (const char *) NULL)
cristy7959f822010-03-07 21:47:41 +00001569 (void) strncpy(dpx.orientation.device,value,sizeof(dpx.orientation.device));
cristy3ed852e2009-09-05 21:47:34 +00001570 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1571 dpx.orientation.device);
cristy7959f822010-03-07 21:47:41 +00001572 value=GetDPXProperty(image_info,image,"dpx:orientation.serial");
1573 if (value != (const char *) NULL)
1574 (void) strncpy(dpx.orientation.serial,value,sizeof(dpx.orientation.serial));
cristy3ed852e2009-09-05 21:47:34 +00001575 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1576 dpx.orientation.serial);
1577 for (i=0; i < 4; i++)
1578 dpx.orientation.border[i]=0;
1579 value=GetDPXProperty(image_info,image,"dpx:orientation.border");
1580 if (value != (const char *) NULL)
1581 {
1582 flags=ParseGeometry(value,&geometry_info);
1583 if ((flags & SigmaValue) == 0)
1584 geometry_info.sigma=geometry_info.rho;
1585 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1586 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1587 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1588 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1589 }
1590 for (i=0; i < 4; i++)
1591 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1592 for (i=0; i < 2; i++)
1593 dpx.orientation.aspect_ratio[i]=0U;
1594 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio");
1595 if (value != (const char *) NULL)
1596 {
1597 flags=ParseGeometry(value,&geometry_info);
1598 if ((flags & SigmaValue) == 0)
1599 geometry_info.sigma=geometry_info.rho;
1600 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1601 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1602 }
1603 for (i=0; i < 2; i++)
1604 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1605 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1606 dpx.orientation.reserve);
1607 /*
1608 Write film header.
1609 */
1610 *dpx.film.id='\0';
1611 value=GetDPXProperty(image_info,image,"dpx:film.id");
1612 if (value != (const char *) NULL)
1613 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1614 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1615 *dpx.film.type='\0';
1616 value=GetDPXProperty(image_info,image,"dpx:film.type");
1617 if (value != (const char *) NULL)
1618 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1619 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1620 dpx.film.type);
1621 *dpx.film.offset='\0';
1622 value=GetDPXProperty(image_info,image,"dpx:film.offset");
1623 if (value != (const char *) NULL)
1624 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1625 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1626 dpx.film.offset);
1627 *dpx.film.prefix='\0';
1628 value=GetDPXProperty(image_info,image,"dpx:film.prefix");
1629 if (value != (const char *) NULL)
1630 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1631 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1632 dpx.film.prefix);
1633 *dpx.film.count='\0';
1634 value=GetDPXProperty(image_info,image,"dpx:film.count");
1635 if (value != (const char *) NULL)
1636 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1637 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1638 dpx.film.count);
1639 *dpx.film.format='\0';
1640 value=GetDPXProperty(image_info,image,"dpx:film.format");
1641 if (value != (const char *) NULL)
1642 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1643 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1644 dpx.film.format);
1645 dpx.film.frame_position=0U;
1646 value=GetDPXProperty(image_info,image,"dpx:film.frame_position");
1647 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001648 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001649 offset+=WriteBlobLong(image,dpx.film.frame_position);
1650 dpx.film.sequence_extent=0U;
1651 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent");
1652 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001653 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001654 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1655 dpx.film.held_count=0U;
1656 value=GetDPXProperty(image_info,image,"dpx:film.held_count");
1657 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001658 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001659 offset+=WriteBlobLong(image,dpx.film.held_count);
1660 dpx.film.frame_rate=0.0f;
1661 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate");
1662 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001663 dpx.film.frame_rate=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001664 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1665 dpx.film.shutter_angle=0.0f;
1666 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle");
1667 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001668 dpx.film.shutter_angle=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001669 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1670 *dpx.film.frame_id='\0';
1671 value=GetDPXProperty(image_info,image,"dpx:film.frame_id");
1672 if (value != (const char *) NULL)
1673 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1674 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1675 dpx.film.frame_id);
1676 value=GetDPXProperty(image_info,image,"dpx:film.slate");
1677 if (value != (const char *) NULL)
1678 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1679 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1680 dpx.film.slate);
1681 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1682 dpx.film.reserve);
1683 /*
1684 Write television header.
1685 */
1686 value=GetDPXProperty(image_info,image,"dpx:television.time.code");
1687 if (value != (const char *) NULL)
1688 dpx.television.time_code=StringToTimeCode(value);
1689 offset+=WriteBlobLong(image,dpx.television.time_code);
1690 value=GetDPXProperty(image_info,image,"dpx:television.user.bits");
1691 if (value != (const char *) NULL)
1692 dpx.television.user_bits=StringToTimeCode(value);
1693 offset+=WriteBlobLong(image,dpx.television.user_bits);
1694 value=GetDPXProperty(image_info,image,"dpx:television.interlace");
1695 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001696 dpx.television.interlace=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001697 offset+=WriteBlobByte(image,dpx.television.interlace);
1698 value=GetDPXProperty(image_info,image,"dpx:television.field_number");
1699 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001700 dpx.television.field_number=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001701 offset+=WriteBlobByte(image,dpx.television.field_number);
1702 dpx.television.video_signal=0;
1703 value=GetDPXProperty(image_info,image,"dpx:television.video_signal");
1704 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001705 dpx.television.video_signal=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001706 offset+=WriteBlobByte(image,dpx.television.video_signal);
1707 dpx.television.padding=0;
1708 value=GetDPXProperty(image_info,image,"dpx:television.padding");
1709 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001710 dpx.television.padding=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001711 offset+=WriteBlobByte(image,dpx.television.padding);
1712 dpx.television.horizontal_sample_rate=0.0f;
1713 value=GetDPXProperty(image_info,image,
1714 "dpx:television.horizontal_sample_rate");
1715 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001716 dpx.television.horizontal_sample_rate=InterpretLocaleValue(value,
1717 (char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001718 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1719 dpx.television.vertical_sample_rate=0.0f;
1720 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate");
1721 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001722 dpx.television.vertical_sample_rate=InterpretLocaleValue(value,
1723 (char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001724 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1725 dpx.television.frame_rate=0.0f;
1726 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate");
1727 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001728 dpx.television.frame_rate=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001729 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1730 dpx.television.time_offset=0.0f;
1731 value=GetDPXProperty(image_info,image,"dpx:television.time_offset");
1732 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001733 dpx.television.time_offset=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001734 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1735 dpx.television.gamma=0.0f;
1736 value=GetDPXProperty(image_info,image,"dpx:television.gamma");
1737 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001738 dpx.television.gamma=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001739 offset+=WriteBlobFloat(image,dpx.television.gamma);
1740 dpx.television.black_level=0.0f;
1741 value=GetDPXProperty(image_info,image,"dpx:television.black_level");
1742 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001743 dpx.television.black_level=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001744 offset+=WriteBlobFloat(image,dpx.television.black_level);
1745 dpx.television.black_gain=0.0f;
1746 value=GetDPXProperty(image_info,image,"dpx:television.black_gain");
1747 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001748 dpx.television.black_gain=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001749 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1750 dpx.television.break_point=0.0f;
1751 value=GetDPXProperty(image_info,image,"dpx:television.break_point");
1752 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001753 dpx.television.break_point=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001754 offset+=WriteBlobFloat(image,dpx.television.break_point);
1755 dpx.television.white_level=0.0f;
1756 value=GetDPXProperty(image_info,image,"dpx:television.white_level");
1757 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001758 dpx.television.white_level=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001759 offset+=WriteBlobFloat(image,dpx.television.white_level);
1760 dpx.television.integration_times=0.0f;
1761 value=GetDPXProperty(image_info,image,"dpx:television.integration_times");
1762 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001763 dpx.television.integration_times=InterpretLocaleValue(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001764 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1765 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1766 dpx.television.reserve);
1767 /*
1768 Write user header.
1769 */
1770 value=GetDPXProperty(image_info,image,"dpx:user.id");
1771 if (value != (const char *) NULL)
1772 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1773 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1774 if (profile != (StringInfo *) NULL)
1775 offset+=WriteBlob(image,GetStringInfoLength(profile),
1776 GetStringInfoDatum(profile));
1777 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1778 {
1779 count=WriteBlobByte(image,0x00);
1780 if (count != 1)
1781 {
cristy1e178e72011-08-28 19:44:34 +00001782 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
cristy3ed852e2009-09-05 21:47:34 +00001783 image->filename);
1784 break;
1785 }
1786 offset+=count;
1787 }
1788 /*
1789 Convert pixel packets to DPX raster image.
1790 */
1791 quantum_info=AcquireQuantumInfo(image_info,image);
cristy891dc792010-03-04 01:47:16 +00001792 SetQuantumQuantum(quantum_info,32);
1793 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1794 MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001795 quantum_type=RGBQuantum;
1796 if (image->matte != MagickFalse)
1797 quantum_type=RGBAQuantum;
1798 if (image->colorspace == YCbCrColorspace)
1799 {
1800 quantum_type=CbYCrQuantum;
1801 if (image->matte != MagickFalse)
1802 quantum_type=CbYCrAQuantum;
1803 if ((horizontal_factor == 2) || (vertical_factor == 2))
1804 quantum_type=CbYCrYQuantum;
1805 }
1806 extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
1807 image->depth,MagickTrue);
cristy5f1c1ff2010-12-23 21:38:06 +00001808 if ((image_info->type != UndefinedType) &&
cristyc8e4cd42010-12-23 21:36:08 +00001809 (image_info->type != TrueColorType) && (image->matte == MagickFalse) &&
cristy1e178e72011-08-28 19:44:34 +00001810 (IsImageGray(image,exception) != MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +00001811 {
1812 quantum_type=GrayQuantum;
cristycaac2942009-10-01 13:36:18 +00001813 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00001814 }
1815 pixels=GetQuantumPixels(quantum_info);
cristybb503372010-05-27 20:51:26 +00001816 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001817 {
cristy1e178e72011-08-28 19:44:34 +00001818 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001819 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001820 break;
cristy4c08aed2011-07-01 19:47:50 +00001821 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001822 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001823 count=WriteBlob(image,extent,pixels);
1824 if (count != (ssize_t) extent)
1825 break;
cristycee97112010-05-28 00:44:52 +00001826 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy202de442011-04-24 18:19:07 +00001827 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001828 if (status == MagickFalse)
1829 break;
1830 }
1831 quantum_info=DestroyQuantumInfo(quantum_info);
1832 (void) CloseBlob(image);
1833 return(status);
1834}