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