blob: 7c40e63cef4344727e86d2ad4dcaf77eb8a1ed74 [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% %
cristye03a12a2012-12-30 17:33:30 +000020% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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"
cristy76ce6e12013-04-05 14:33:38 +000044#include "MagickCore/artifact.h"
cristy4c08aed2011-07-01 19:47:50 +000045#include "MagickCore/blob.h"
46#include "MagickCore/blob-private.h"
47#include "MagickCore/cache.h"
48#include "MagickCore/colorspace.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/geometry.h"
52#include "MagickCore/image.h"
53#include "MagickCore/image-private.h"
54#include "MagickCore/list.h"
55#include "MagickCore/magick.h"
56#include "MagickCore/memory_.h"
57#include "MagickCore/module.h"
58#include "MagickCore/monitor.h"
59#include "MagickCore/monitor-private.h"
60#include "MagickCore/option.h"
cristy73a724e2011-11-24 18:47:12 +000061#include "MagickCore/pixel-accessor.h"
cristy4c08aed2011-07-01 19:47:50 +000062#include "MagickCore/profile.h"
63#include "MagickCore/property.h"
64#include "MagickCore/quantum-private.h"
65#include "MagickCore/static.h"
66#include "MagickCore/string_.h"
67#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000068
69/*
70 Typedef declaration.
71*/
72typedef enum
73{
74 UserDefinedColorimetric = 0,
75 PrintingDensityColorimetric = 1,
76 LinearColorimetric = 2,
77 LogarithmicColorimetric = 3,
78 UnspecifiedVideoColorimetric = 4,
79 SMTPE_274MColorimetric = 5,
80 ITU_R709Colorimetric = 6,
81 ITU_R601_625LColorimetric = 7,
82 ITU_R601_525LColorimetric = 8,
83 NTSCCompositeVideoColorimetric = 9,
84 PALCompositeVideoColorimetric = 10,
85 ZDepthLinearColorimetric = 11,
86 DepthHomogeneousColorimetric = 12
87} DPXColorimetric;
88
89typedef enum
90{
91 UndefinedComponentType = 0,
92 RedComponentType = 1,
93 GreenComponentType = 2,
94 BlueComponentType = 3,
95 AlphaComponentType = 4,
96 LumaComponentType = 6,
97 ColorDifferenceCbCrComponentType = 7,
98 DepthComponentType = 8,
99 CompositeVideoComponentType = 9,
100 RGBComponentType = 50,
101 RGBAComponentType = 51,
102 ABGRComponentType = 52,
103 CbYCrY422ComponentType = 100,
104 CbYACrYA4224ComponentType = 101,
105 CbYCr444ComponentType = 102,
106 CbYCrA4444ComponentType = 103,
107 UserDef2ElementComponentType = 150,
108 UserDef3ElementComponentType = 151,
109 UserDef4ElementComponentType = 152,
110 UserDef5ElementComponentType = 153,
111 UserDef6ElementComponentType = 154,
112 UserDef7ElementComponentType = 155,
113 UserDef8ElementComponentType = 156
114} DPXComponentType;
115
cristyc7f92ea2013-01-10 19:59:00 +0000116typedef enum
117{
118 TransferCharacteristicUserDefined = 0,
119 TransferCharacteristicPrintingDensity = 1,
120 TransferCharacteristicLinear = 2,
121 TransferCharacteristicLogarithmic = 3,
122 TransferCharacteristicUnspecifiedVideo = 4,
123 TransferCharacteristicSMTPE274M = 5, /* 1920x1080 TV */
124 TransferCharacteristicITU_R709 = 6, /* ITU R709 */
125 TransferCharacteristicITU_R601_625L = 7, /* 625 Line */
126 TransferCharacteristicITU_R601_525L = 8, /* 525 Line */
127 TransferCharacteristicNTSCCompositeVideo = 9,
128 TransferCharacteristicPALCompositeVideo = 10,
129 TransferCharacteristicZDepthLinear = 11,
130 TransferCharacteristicZDepthHomogeneous = 12
131} DPXTransferCharacteristic;
132
cristy3ed852e2009-09-05 21:47:34 +0000133typedef struct _DPXFileInfo
134{
135 unsigned int
136 magic,
137 image_offset;
138
139 char
140 version[8];
141
142 unsigned int
143 file_size,
144 ditto_key,
145 generic_size,
146 industry_size,
147 user_size;
148
149 char
150 filename[100],
151 timestamp[24],
152 creator[100],
153 project[200],
154 copyright[200];
155
156 unsigned int
157 encrypt_key;
158
159 char
160 reserve[104];
161} DPXFileInfo;
162
163typedef struct _DPXFilmInfo
164{
165 char
166 id[2],
167 type[2],
168 offset[2],
169 prefix[6],
170 count[4],
171 format[32];
172
173 unsigned int
174 frame_position,
175 sequence_extent,
176 held_count;
177
178 float
179 frame_rate,
180 shutter_angle;
181
182 char
183 frame_id[32],
184 slate[100],
185 reserve[56];
186} DPXFilmInfo;
187
188typedef struct _DPXImageElement
189{
190 unsigned int
191 data_sign,
192 low_data;
193
194 float
195 low_quantity;
196
197 unsigned int
198 high_data;
199
200 float
201 high_quantity;
202
203 unsigned char
204 descriptor,
cristyc7f92ea2013-01-10 19:59:00 +0000205 transfer_characteristic,
cristy3ed852e2009-09-05 21:47:34 +0000206 colorimetric,
207 bit_size;
208
209 unsigned short
210 packing,
211 encoding;
212
213 unsigned int
214 data_offset,
215 end_of_line_padding,
216 end_of_image_padding;
217
218 unsigned char
219 description[32];
220} DPXImageElement;
221
222typedef struct _DPXImageInfo
223{
224 unsigned short
225 orientation,
226 number_elements;
227
228 unsigned int
229 pixels_per_line,
230 lines_per_element;
231
232 DPXImageElement
233 image_element[8];
234
235 unsigned char
236 reserve[52];
237} DPXImageInfo;
238
239typedef struct _DPXOrientationInfo
240{
241 unsigned int
242 x_offset,
243 y_offset;
244
245 float
246 x_center,
247 y_center;
248
249 unsigned int
250 x_size,
251 y_size;
252
253 char
254 filename[100],
255 timestamp[24],
256 device[32],
257 serial[32];
258
259 unsigned short
260 border[4];
261
262 unsigned int
263 aspect_ratio[2];
264
265 unsigned char
266 reserve[28];
267} DPXOrientationInfo;
268
269typedef struct _DPXTelevisionInfo
270{
271 unsigned int
272 time_code,
273 user_bits;
274
275 unsigned char
276 interlace,
277 field_number,
278 video_signal,
279 padding;
280
281 float
282 horizontal_sample_rate,
283 vertical_sample_rate,
284 frame_rate,
285 time_offset,
286 gamma,
287 black_level,
288 black_gain,
289 break_point,
290 white_level,
291 integration_times;
292
293 char
294 reserve[76];
295} DPXTelevisionInfo;
296
297typedef struct _DPXUserInfo
298{
299 char
300 id[32];
301} DPXUserInfo;
302
303typedef struct DPXInfo
304{
305 DPXFileInfo
306 file;
307
308 DPXImageInfo
309 image;
310
311 DPXOrientationInfo
312 orientation;
313
314 DPXFilmInfo
315 film;
316
317 DPXTelevisionInfo
318 television;
319
320 DPXUserInfo
321 user;
322} DPXInfo;
323
324/*
325 Forward declaractions.
326*/
327static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +0000328 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000329
330/*
331%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332% %
333% %
334% %
335% I s D P X %
336% %
337% %
338% %
339%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340%
341% IsDPX() returns MagickTrue if the image format type, identified by the
342% magick string, is DPX.
343%
344% The format of the IsDPX method is:
345%
346% MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
347%
348% A description of each parameter follows:
349%
350% o magick: compare image format pattern against these bytes.
351%
352% o extent: Specifies the extent of the magick string.
353%
354*/
355static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
356{
357 if (extent < 4)
358 return(MagickFalse);
359 if (memcmp(magick,"SDPX",4) == 0)
360 return(MagickTrue);
361 if (memcmp(magick,"XPDS",4) == 0)
362 return(MagickTrue);
363 return(MagickFalse);
364}
365
366/*
367%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368% %
369% %
370% %
371% R e a d D P X I m a g e %
372% %
373% %
374% %
375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376%
377% ReadDPXImage() reads an DPX X image file and returns it. It
378% allocates the memory necessary for the new Image structure and returns a
379% pointer to the new image.
380%
381% The format of the ReadDPXImage method is:
382%
383% Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
384%
385% A description of each parameter follows:
386%
387% o image_info: the image info.
388%
389% o exception: return any errors or warnings in this structure.
390%
391*/
392
cristy4ccdaa22012-11-05 16:58:06 +0000393static size_t GetBytesPerRow(const size_t columns,
394 const size_t samples_per_pixel,const size_t bits_per_pixel,
395 const MagickBooleanType pad)
cristy3ed852e2009-09-05 21:47:34 +0000396{
397 size_t
398 bytes_per_row;
399
400 switch (bits_per_pixel)
401 {
402 case 1:
403 {
cristy4ccdaa22012-11-05 16:58:06 +0000404 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
405 32);
cristy3ed852e2009-09-05 21:47:34 +0000406 break;
407 }
408 case 8:
409 default:
410 {
cristy4ccdaa22012-11-05 16:58:06 +0000411 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
412 32);
cristy3ed852e2009-09-05 21:47:34 +0000413 break;
414 }
415 case 10:
416 {
417 if (pad == MagickFalse)
418 {
cristy4ccdaa22012-11-05 16:58:06 +0000419 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
420 31)/32);
cristy3ed852e2009-09-05 21:47:34 +0000421 break;
422 }
cristyff024b42010-02-21 22:55:09 +0000423 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
cristy3ed852e2009-09-05 21:47:34 +0000424 break;
425 }
426 case 12:
427 {
428 if (pad == MagickFalse)
429 {
cristy4ccdaa22012-11-05 16:58:06 +0000430 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
431 31)/32);
cristy3ed852e2009-09-05 21:47:34 +0000432 break;
433 }
434 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
435 break;
436 }
437 case 16:
438 {
cristy4ccdaa22012-11-05 16:58:06 +0000439 bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+8)/
440 16);
cristy3ed852e2009-09-05 21:47:34 +0000441 break;
442 }
443 case 32:
444 {
cristy4ccdaa22012-11-05 16:58:06 +0000445 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
446 32);
cristy3ed852e2009-09-05 21:47:34 +0000447 break;
448 }
449 case 64:
450 {
cristy4ccdaa22012-11-05 16:58:06 +0000451 bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
452 64);
cristy3ed852e2009-09-05 21:47:34 +0000453 break;
454 }
455 }
456 return(bytes_per_row);
457}
458
cristyc7f92ea2013-01-10 19:59:00 +0000459static const char *GetImageTransferCharacteristic(
460 const DPXTransferCharacteristic characteristic)
461{
462 const char
463 *transfer;
464
465 /*
466 Get the element transfer characteristic.
467 */
468 switch(characteristic)
469 {
470 case TransferCharacteristicUserDefined:
471 {
472 transfer="UserDefined";
473 break;
474 }
475 case TransferCharacteristicPrintingDensity:
476 {
477 transfer="PrintingDensity";
478 break;
479 }
480 case TransferCharacteristicLinear:
481 {
482 transfer="Linear";
483 break;
484 }
485 case TransferCharacteristicLogarithmic:
486 {
487 transfer="Logarithmic";
488 break;
489 }
490 case TransferCharacteristicUnspecifiedVideo:
491 {
492 transfer="UnspecifiedVideo";
493 break;
494 }
495 case TransferCharacteristicSMTPE274M:
496 {
497 transfer="SMTPE274M";
498 break;
499 }
500 case TransferCharacteristicITU_R709:
501 {
502 transfer="ITU-R709";
503 break;
504 }
505 case TransferCharacteristicITU_R601_625L:
506 {
507 transfer="ITU-R601-625L";
508 break;
509 }
510 case TransferCharacteristicITU_R601_525L:
511 {
512 transfer="ITU-R601-525L";
513 break;
514 }
515 case TransferCharacteristicNTSCCompositeVideo:
516 {
517 transfer="NTSCCompositeVideo";
518 break;
519 }
520 case TransferCharacteristicPALCompositeVideo:
521 {
522 transfer="PALCompositeVideo";
523 break;
524 }
525 case TransferCharacteristicZDepthLinear:
526 {
527 transfer="ZDepthLinear";
528 break;
529 }
530 case TransferCharacteristicZDepthHomogeneous:
531 {
532 transfer="ZDepthHomogeneous";
533 break;
534 }
535 default:
536 transfer="Reserved";
537 }
538 return(transfer);
539}
540
cristy3ed852e2009-09-05 21:47:34 +0000541static inline MagickBooleanType IsFloatDefined(const float value)
542{
543 union
544 {
545 unsigned int
546 unsigned_value;
547
cristy8a8e4682013-09-26 12:55:39 +0000548 float
cristy3ed852e2009-09-05 21:47:34 +0000549 float_value;
550 } quantum;
551
552 quantum.unsigned_value=0U;
cristy8a8e4682013-09-26 12:55:39 +0000553 quantum.float_value=(float) value;
cristy3ed852e2009-09-05 21:47:34 +0000554 if (quantum.unsigned_value == 0U)
555 return(MagickFalse);
556 return(MagickTrue);
557}
558
559static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
560 ChromaticityInfo *chromaticity_info)
561{
562 switch(colorimetric)
563 {
564 case SMTPE_274MColorimetric:
565 case ITU_R709Colorimetric:
566 {
567 chromaticity_info->red_primary.x=0.640;
568 chromaticity_info->red_primary.y=0.330;
569 chromaticity_info->red_primary.z=0.030;
570 chromaticity_info->green_primary.x=0.300;
571 chromaticity_info->green_primary.y=0.600;
572 chromaticity_info->green_primary.z=0.100;
573 chromaticity_info->blue_primary.x=0.150;
574 chromaticity_info->blue_primary.y=0.060;
575 chromaticity_info->blue_primary.z=0.790;
576 chromaticity_info->white_point.x=0.3127;
577 chromaticity_info->white_point.y=0.3290;
578 chromaticity_info->white_point.z=0.3582;
579 break;
580 }
581 case NTSCCompositeVideoColorimetric:
582 {
583 chromaticity_info->red_primary.x=0.67;
584 chromaticity_info->red_primary.y=0.33;
585 chromaticity_info->red_primary.z=0.00;
586 chromaticity_info->green_primary.x=0.21;
587 chromaticity_info->green_primary.y=0.71;
588 chromaticity_info->green_primary.z=0.08;
589 chromaticity_info->blue_primary.x=0.14;
590 chromaticity_info->blue_primary.y=0.08;
591 chromaticity_info->blue_primary.z=0.78;
592 chromaticity_info->white_point.x=0.310;
593 chromaticity_info->white_point.y=0.316;
594 chromaticity_info->white_point.z=0.374;
595 break;
596 }
597 case PALCompositeVideoColorimetric:
598 {
599 chromaticity_info->red_primary.x=0.640;
600 chromaticity_info->red_primary.y=0.330;
601 chromaticity_info->red_primary.z=0.030;
602 chromaticity_info->green_primary.x=0.290;
603 chromaticity_info->green_primary.y=0.600;
604 chromaticity_info->green_primary.z=0.110;
605 chromaticity_info->blue_primary.x=0.150;
606 chromaticity_info->blue_primary.y=0.060;
607 chromaticity_info->blue_primary.z=0.790;
608 chromaticity_info->white_point.x=0.3127;
609 chromaticity_info->white_point.y=0.3290;
610 chromaticity_info->white_point.z=0.3582;
611 break;
612 }
613 default:
614 break;
615 }
616}
617
cristybb503372010-05-27 20:51:26 +0000618static void TimeCodeToString(const size_t timestamp,char *code)
cristy3ed852e2009-09-05 21:47:34 +0000619{
620#define TimeFields 7
621
622 unsigned int
623 shift;
624
cristybb503372010-05-27 20:51:26 +0000625 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000626 i;
627
628 *code='\0';
629 shift=4*TimeFields;
630 for (i=0; i <= TimeFields; i++)
631 {
cristyb51dff52011-05-19 16:55:47 +0000632 (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x",
cristy3ed852e2009-09-05 21:47:34 +0000633 (unsigned int) ((timestamp >> shift) & 0x0fU));
634 code++;
635 if (((i % 2) != 0) && (i < TimeFields))
636 *code++=':';
637 shift-=4;
638 *code='\0';
639 }
640}
641
642static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
643{
644 char
645 magick[4],
646 value[MaxTextExtent];
647
648 DPXInfo
649 dpx;
650
651 Image
652 *image;
653
cristy3ed852e2009-09-05 21:47:34 +0000654 MagickBooleanType
655 status;
656
657 MagickOffsetType
658 offset;
659
cristyff024b42010-02-21 22:55:09 +0000660 QuantumInfo
661 *quantum_info;
662
cristy3ed852e2009-09-05 21:47:34 +0000663 QuantumType
664 quantum_type;
665
cristybb503372010-05-27 20:51:26 +0000666 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000667 i;
668
cristy3ed852e2009-09-05 21:47:34 +0000669 size_t
cristy202de442011-04-24 18:19:07 +0000670 extent,
671 samples_per_pixel;
672
673 ssize_t
674 count,
cristy04ea8a02012-09-30 15:23:28 +0000675 n,
cristy202de442011-04-24 18:19:07 +0000676 row,
677 y;
cristy3ed852e2009-09-05 21:47:34 +0000678
679 unsigned char
680 component_type;
681
cristy3ed852e2009-09-05 21:47:34 +0000682 /*
683 Open image file.
684 */
685 assert(image_info != (const ImageInfo *) NULL);
686 assert(image_info->signature == MagickSignature);
687 if (image_info->debug != MagickFalse)
688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
689 image_info->filename);
690 assert(exception != (ExceptionInfo *) NULL);
691 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000692 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000693 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
694 if (status == MagickFalse)
695 {
696 image=DestroyImageList(image);
697 return((Image *) NULL);
698 }
699 /*
700 Read DPX file header.
701 */
702 offset=0;
703 count=ReadBlob(image,4,(unsigned char *) magick);
704 offset+=count;
705 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
706 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
707 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
708 image->endian=LSBEndian;
709 if (LocaleNCompare(magick,"SDPX",4) == 0)
710 image->endian=MSBEndian;
711 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
712 dpx.file.image_offset=ReadBlobLong(image);
713 offset+=4;
714 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
715 dpx.file.version);
716 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
717 dpx.file.file_size=ReadBlobLong(image);
718 offset+=4;
719 dpx.file.ditto_key=ReadBlobLong(image);
720 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000721 if (dpx.file.ditto_key != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000722 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
723 dpx.file.ditto_key);
724 dpx.file.generic_size=ReadBlobLong(image);
725 offset+=4;
726 dpx.file.industry_size=ReadBlobLong(image);
727 offset+=4;
728 dpx.file.user_size=ReadBlobLong(image);
729 offset+=4;
730 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
731 dpx.file.filename);
732 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
733 dpx.file.filename);
734 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
735 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
736 dpx.file.timestamp);
737 if (*dpx.file.timestamp != '\0')
738 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
739 dpx.file.timestamp);
740 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
741 dpx.file.creator);
742 if (*dpx.file.creator != '\0')
743 {
744 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
745 dpx.file.creator);
746 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
747 }
748 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
749 dpx.file.project);
750 if (*dpx.file.project != '\0')
751 {
752 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
753 dpx.file.project);
754 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
755 }
756 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
757 dpx.file.copyright);
758 if (*dpx.file.copyright != '\0')
759 {
760 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
761 dpx.file.copyright);
762 (void) FormatImageProperty(image,"copyright","%.100s",
763 dpx.file.copyright);
764 }
765 dpx.file.encrypt_key=ReadBlobLong(image);
766 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000767 if (dpx.file.encrypt_key != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000768 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
769 dpx.file.encrypt_key);
770 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
771 dpx.file.reserve);
772 /*
773 Read DPX image header.
774 */
775 dpx.image.orientation=ReadBlobShort(image);
776 offset+=2;
cristy924a1012013-10-30 20:25:56 +0000777 if (dpx.image.orientation != ~0)
cristy3ed852e2009-09-05 21:47:34 +0000778 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
779 dpx.image.orientation);
780 switch (dpx.image.orientation)
781 {
782 default:
cristy202de442011-04-24 18:19:07 +0000783 case 0: image->orientation=TopLeftOrientation; break;
784 case 1: image->orientation=TopRightOrientation; break;
785 case 2: image->orientation=BottomLeftOrientation; break;
786 case 3: image->orientation=BottomRightOrientation; break;
787 case 4: image->orientation=LeftTopOrientation; break;
788 case 5: image->orientation=RightTopOrientation; break;
789 case 6: image->orientation=LeftBottomOrientation; break;
790 case 7: image->orientation=RightBottomOrientation; break;
cristy3ed852e2009-09-05 21:47:34 +0000791 }
792 dpx.image.number_elements=ReadBlobShort(image);
793 offset+=2;
794 dpx.image.pixels_per_line=ReadBlobLong(image);
795 offset+=4;
796 image->columns=dpx.image.pixels_per_line;
797 dpx.image.lines_per_element=ReadBlobLong(image);
798 offset+=4;
799 image->rows=dpx.image.lines_per_element;
800 for (i=0; i < 8; i++)
801 {
cristyc7f92ea2013-01-10 19:59:00 +0000802 char
803 property[MaxTextExtent];
804
cristy3ed852e2009-09-05 21:47:34 +0000805 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
806 offset+=4;
807 dpx.image.image_element[i].low_data=ReadBlobLong(image);
808 offset+=4;
809 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
810 offset+=4;
811 dpx.image.image_element[i].high_data=ReadBlobLong(image);
812 offset+=4;
813 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
814 offset+=4;
815 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
816 offset++;
cristyc7f92ea2013-01-10 19:59:00 +0000817 dpx.image.image_element[i].transfer_characteristic=(unsigned char)
818 ReadBlobByte(image);
819 (void) FormatLocaleString(property,MaxTextExtent,
820 "dpx:image.element[%lu].transfer-characteristic",(long) i);
821 (void) FormatImageProperty(image,property,"%s",
822 GetImageTransferCharacteristic((DPXTransferCharacteristic)
823 dpx.image.image_element[i].transfer_characteristic));
cristy3ed852e2009-09-05 21:47:34 +0000824 offset++;
825 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
826 offset++;
827 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
828 offset++;
829 dpx.image.image_element[i].packing=ReadBlobShort(image);
830 offset+=2;
831 dpx.image.image_element[i].encoding=ReadBlobShort(image);
832 offset+=2;
833 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
834 offset+=4;
835 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
836 offset+=4;
837 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
838 offset+=4;
839 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
840 (unsigned char *) dpx.image.image_element[i].description);
841 }
cristyb2c3f402012-05-13 18:05:12 +0000842 SetImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000843 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
844 dpx.image.reserve);
cristy3ed852e2009-09-05 21:47:34 +0000845 if (dpx.file.image_offset >= 1664U)
846 {
847 /*
848 Read DPX orientation header.
849 */
850 dpx.orientation.x_offset=ReadBlobLong(image);
851 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000852 if (dpx.orientation.x_offset != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000853 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
854 dpx.orientation.x_offset);
855 dpx.orientation.y_offset=ReadBlobLong(image);
856 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000857 if (dpx.orientation.y_offset != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000858 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
859 dpx.orientation.y_offset);
860 dpx.orientation.x_center=ReadBlobFloat(image);
861 offset+=4;
862 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
863 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
864 dpx.orientation.x_center);
865 dpx.orientation.y_center=ReadBlobFloat(image);
866 offset+=4;
867 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
868 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
869 dpx.orientation.y_center);
870 dpx.orientation.x_size=ReadBlobLong(image);
871 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000872 if (dpx.orientation.x_size != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000873 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
874 dpx.orientation.x_size);
875 dpx.orientation.y_size=ReadBlobLong(image);
876 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000877 if (dpx.orientation.y_size != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000878 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
879 dpx.orientation.y_size);
880 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
881 dpx.orientation.filename);
882 if (*dpx.orientation.filename != '\0')
883 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
884 dpx.orientation.filename);
885 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
886 dpx.orientation.timestamp);
887 if (*dpx.orientation.timestamp != '\0')
888 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
889 dpx.orientation.timestamp);
890 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
891 dpx.orientation.device);
892 if (*dpx.orientation.device != '\0')
893 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
894 dpx.orientation.device);
895 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
896 dpx.orientation.serial);
897 if (*dpx.orientation.serial != '\0')
898 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
899 dpx.orientation.serial);
900 for (i=0; i < 4; i++)
901 {
902 dpx.orientation.border[i]=ReadBlobShort(image);
903 offset+=2;
904 }
cristy3a5987c2013-11-07 14:18:46 +0000905 if ((dpx.orientation.border[0] != (unsigned short) (~0UL)) &&
906 (dpx.orientation.border[1] != (unsigned short) (~0UL)))
cristy3ed852e2009-09-05 21:47:34 +0000907 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d", dpx.orientation.border[0],dpx.orientation.border[1],
908 dpx.orientation.border[2],dpx.orientation.border[3]);
909 for (i=0; i < 2; i++)
910 {
911 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
912 offset+=4;
913 }
cristy3a5987c2013-11-07 14:18:46 +0000914 if ((dpx.orientation.aspect_ratio[0] != ~0UL) &&
915 (dpx.orientation.aspect_ratio[1] != ~0UL))
cristy3ed852e2009-09-05 21:47:34 +0000916 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
917 "%ux%u",dpx.orientation.aspect_ratio[0],
918 dpx.orientation.aspect_ratio[1]);
919 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
920 dpx.orientation.reserve);
921 }
922 if (dpx.file.image_offset >= 1920U)
923 {
924 /*
925 Read DPX film header.
926 */
927 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
928 if (*dpx.film.type != '\0')
929 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
930 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
931 dpx.film.type);
932 if (*dpx.film.type != '\0')
933 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
934 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
935 dpx.film.offset);
936 if (*dpx.film.offset != '\0')
937 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
938 dpx.film.offset);
939 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
940 dpx.film.prefix);
941 if (*dpx.film.prefix != '\0')
942 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
943 dpx.film.prefix);
944 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
945 dpx.film.count);
946 if (*dpx.film.count != '\0')
947 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
948 dpx.film.count);
949 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
950 dpx.film.format);
951 if (*dpx.film.format != '\0')
952 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
953 dpx.film.format);
954 dpx.film.frame_position=ReadBlobLong(image);
955 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000956 if (dpx.film.frame_position != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000957 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
958 dpx.film.frame_position);
959 dpx.film.sequence_extent=ReadBlobLong(image);
960 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000961 if (dpx.film.sequence_extent != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000962 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
963 dpx.film.sequence_extent);
964 dpx.film.held_count=ReadBlobLong(image);
965 offset+=4;
cristy3a5987c2013-11-07 14:18:46 +0000966 if (dpx.film.held_count != ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000967 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
968 dpx.film.held_count);
969 dpx.film.frame_rate=ReadBlobFloat(image);
970 offset+=4;
971 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
972 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
973 dpx.film.frame_rate);
974 dpx.film.shutter_angle=ReadBlobFloat(image);
975 offset+=4;
976 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
977 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
978 dpx.film.shutter_angle);
979 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
980 dpx.film.frame_id);
981 if (*dpx.film.frame_id != '\0')
982 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
983 dpx.film.frame_id);
984 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
985 dpx.film.slate);
986 if (*dpx.film.slate != '\0')
987 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
988 dpx.film.slate);
989 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
990 dpx.film.reserve);
991 }
992 if (dpx.file.image_offset >= 2048U)
993 {
994 /*
995 Read DPX television header.
996 */
997 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
998 offset+=4;
999 TimeCodeToString(dpx.television.time_code,value);
cristyd15e6592011-10-15 00:13:06 +00001000 (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
cristy3ed852e2009-09-05 21:47:34 +00001001 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
1002 offset+=4;
1003 TimeCodeToString(dpx.television.user_bits,value);
cristyd15e6592011-10-15 00:13:06 +00001004 (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
cristy3ed852e2009-09-05 21:47:34 +00001005 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
1006 offset++;
1007 if (dpx.television.interlace != 0)
cristye8c25f92010-06-03 00:53:06 +00001008 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
1009 (double) dpx.television.interlace);
cristy3ed852e2009-09-05 21:47:34 +00001010 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
1011 offset++;
1012 if (dpx.television.field_number != 0)
cristye8c25f92010-06-03 00:53:06 +00001013 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
1014 (double) dpx.television.field_number);
cristy3ed852e2009-09-05 21:47:34 +00001015 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
1016 offset++;
1017 if (dpx.television.video_signal != 0)
cristye8c25f92010-06-03 00:53:06 +00001018 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
1019 (double) dpx.television.video_signal);
cristy3ed852e2009-09-05 21:47:34 +00001020 dpx.television.padding=(unsigned char) ReadBlobByte(image);
1021 offset++;
1022 if (dpx.television.padding != 0)
1023 (void) FormatImageProperty(image,"dpx:television.padding","%d",
1024 dpx.television.padding);
1025 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
1026 offset+=4;
1027 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
1028 (void) FormatImageProperty(image,
1029 "dpx:television.horizontal_sample_rate","%g",
1030 dpx.television.horizontal_sample_rate);
1031 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
1032 offset+=4;
1033 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
1034 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
1035 "%g",dpx.television.vertical_sample_rate);
1036 dpx.television.frame_rate=ReadBlobFloat(image);
1037 offset+=4;
1038 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
1039 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
1040 dpx.television.frame_rate);
1041 dpx.television.time_offset=ReadBlobFloat(image);
1042 offset+=4;
1043 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
1044 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
1045 dpx.television.time_offset);
1046 dpx.television.gamma=ReadBlobFloat(image);
1047 offset+=4;
1048 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
1049 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
1050 dpx.television.gamma);
1051 dpx.television.black_level=ReadBlobFloat(image);
1052 offset+=4;
1053 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
1054 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
1055 dpx.television.black_level);
1056 dpx.television.black_gain=ReadBlobFloat(image);
1057 offset+=4;
1058 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
1059 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
1060 dpx.television.black_gain);
1061 dpx.television.break_point=ReadBlobFloat(image);
1062 offset+=4;
1063 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
1064 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
1065 dpx.television.break_point);
1066 dpx.television.white_level=ReadBlobFloat(image);
1067 offset+=4;
1068 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
1069 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
1070 dpx.television.white_level);
1071 dpx.television.integration_times=ReadBlobFloat(image);
1072 offset+=4;
1073 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
1074 (void) FormatImageProperty(image,"dpx:television.integration_times",
1075 "%g",dpx.television.integration_times);
1076 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1077 dpx.television.reserve);
1078 }
1079 if (dpx.file.image_offset > 2080U)
1080 {
1081 /*
1082 Read DPX user header.
1083 */
1084 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1085 if (*dpx.user.id != '\0')
1086 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
cristy3a5987c2013-11-07 14:18:46 +00001087 if ((dpx.file.user_size != ~0UL) &&
cristy3ed852e2009-09-05 21:47:34 +00001088 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
1089 {
1090 StringInfo
1091 *profile;
1092
cristy60395292011-09-01 13:25:56 +00001093 profile=BlobToStringInfo((const void *) NULL,
1094 dpx.file.user_size-sizeof(dpx.user.id));
1095 if (profile == (StringInfo *) NULL)
1096 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +00001097 offset+=ReadBlob(image,GetStringInfoLength(profile),
1098 GetStringInfoDatum(profile));
cristyd15e6592011-10-15 00:13:06 +00001099 (void) SetImageProfile(image,"dpx",profile,exception);
cristy3ed852e2009-09-05 21:47:34 +00001100 profile=DestroyStringInfo(profile);
1101 }
1102 }
cristy811f5172010-12-29 17:38:08 +00001103 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
cristy3ed852e2009-09-05 21:47:34 +00001104 (void) ReadBlobByte(image);
cristy3ed852e2009-09-05 21:47:34 +00001105 if (image_info->ping != MagickFalse)
1106 {
1107 (void) CloseBlob(image);
1108 return(GetFirstImageInList(image));
1109 }
cristy04ea8a02012-09-30 15:23:28 +00001110 for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
cristy3ed852e2009-09-05 21:47:34 +00001111 {
cristy04ea8a02012-09-30 15:23:28 +00001112 /*
1113 Convert DPX raster image to pixel packets.
1114 */
cristy3a5987c2013-11-07 14:18:46 +00001115 if ((dpx.image.image_element[n].data_offset != (unsigned int) (~0UL)) &&
cristy04ea8a02012-09-30 15:23:28 +00001116 (dpx.image.image_element[n].data_offset != 0U))
cristyff024b42010-02-21 22:55:09 +00001117 {
cristy04ea8a02012-09-30 15:23:28 +00001118 MagickOffsetType
1119 data_offset;
1120
1121 data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
1122 if (data_offset < offset)
1123 offset=SeekBlob(image,data_offset,SEEK_SET);
1124 else
1125 for ( ; offset < data_offset; offset++)
1126 (void) ReadBlobByte(image);
1127 if (offset != data_offset)
1128 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1129 }
cristyea485152012-10-03 11:48:50 +00001130 SetPrimaryChromaticity((DPXColorimetric)
1131 dpx.image.image_element[n].colorimetric,&image->chromaticity);
1132 image->depth=dpx.image.image_element[n].bit_size;
cristy04ea8a02012-09-30 15:23:28 +00001133 samples_per_pixel=1;
1134 quantum_type=GrayQuantum;
cristyea485152012-10-03 11:48:50 +00001135 component_type=dpx.image.image_element[n].descriptor;
cristy04ea8a02012-09-30 15:23:28 +00001136 switch (component_type)
1137 {
1138 case CbYCrY422ComponentType:
1139 {
1140 samples_per_pixel=2;
1141 quantum_type=CbYCrYQuantum;
1142 break;
cristyff024b42010-02-21 22:55:09 +00001143 }
cristy04ea8a02012-09-30 15:23:28 +00001144 case CbYACrYA4224ComponentType:
1145 case CbYCr444ComponentType:
1146 {
1147 samples_per_pixel=3;
1148 quantum_type=CbYCrQuantum;
1149 break;
1150 }
1151 case RGBComponentType:
1152 {
1153 samples_per_pixel=3;
1154 quantum_type=RGBQuantum;
1155 break;
1156 }
1157 case ABGRComponentType:
1158 case RGBAComponentType:
1159 {
1160 image->alpha_trait=BlendPixelTrait;
1161 samples_per_pixel=4;
1162 quantum_type=RGBAQuantum;
1163 break;
1164 }
1165 default:
1166 break;
1167 }
1168 switch (component_type)
1169 {
1170 case CbYCrY422ComponentType:
1171 case CbYACrYA4224ComponentType:
1172 case CbYCr444ComponentType:
1173 {
1174 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1175 break;
1176 }
1177 case LumaComponentType:
1178 {
cristyea485152012-10-03 11:48:50 +00001179 SetImageColorspace(image,GRAYColorspace,exception);
cristy04ea8a02012-09-30 15:23:28 +00001180 break;
1181 }
1182 default:
1183 {
1184 SetImageColorspace(image,sRGBColorspace,exception);
cristyc7f92ea2013-01-10 19:59:00 +00001185 if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
cristy04ea8a02012-09-30 15:23:28 +00001186 SetImageColorspace(image,LogColorspace,exception);
cristyc7f92ea2013-01-10 19:59:00 +00001187 if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
cristy04ea8a02012-09-30 15:23:28 +00001188 SetImageColorspace(image,LogColorspace,exception);
1189 break;
1190 }
1191 }
1192 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1193 dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
1194 /*
1195 DPX any-bit pixel format.
1196 */
1197 status=MagickTrue;
1198 row=0;
1199 quantum_info=AcquireQuantumInfo(image_info,image);
1200 if (quantum_info == (QuantumInfo *) NULL)
1201 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1202 SetQuantumQuantum(quantum_info,32);
1203 SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
1204 MagickTrue : MagickFalse);
1205 for (y=0; y < (ssize_t) image->rows; y++)
1206 {
1207 MagickBooleanType
1208 sync;
1209
1210 register Quantum
1211 *q;
1212
1213 size_t
1214 length;
1215
1216 ssize_t
1217 count,
1218 offset;
1219
1220 unsigned char
1221 *pixels;
1222
1223 if (status == MagickFalse)
1224 continue;
1225 pixels=GetQuantumPixels(quantum_info);
1226 {
1227 count=ReadBlob(image,extent,pixels);
1228 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1229 (image->previous == (Image *) NULL))
1230 {
1231 MagickBooleanType
1232 proceed;
1233
1234 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1235 image->rows);
1236 if (proceed == MagickFalse)
1237 status=MagickFalse;
1238 }
1239 offset=row++;
1240 }
1241 if (count != (ssize_t) extent)
1242 status=MagickFalse;
1243 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
1244 if (q == (Quantum *) NULL)
1245 {
1246 status=MagickFalse;
1247 continue;
1248 }
1249 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1250 quantum_type,pixels,exception);
1251 (void) length;
1252 sync=SyncAuthenticPixels(image,exception);
1253 if (sync == MagickFalse)
1254 status=MagickFalse;
1255 }
1256 quantum_info=DestroyQuantumInfo(quantum_info);
1257 if (status == MagickFalse)
1258 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1259 SetQuantumImageType(image,quantum_type);
1260 if (EOFBlob(image) != MagickFalse)
1261 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1262 image->filename);
1263 if ((i+1) < (ssize_t) dpx.image.number_elements)
1264 {
1265 /*
1266 Allocate next image structure.
1267 */
1268 AcquireNextImage(image_info,image,exception);
1269 if (GetNextImageInList(image) == (Image *) NULL)
1270 {
1271 image=DestroyImageList(image);
1272 return((Image *) NULL);
1273 }
1274 image=SyncNextImageInList(image);
1275 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1276 GetBlobSize(image));
1277 if (status == MagickFalse)
1278 break;
1279 }
cristyff024b42010-02-21 22:55:09 +00001280 }
cristy3ed852e2009-09-05 21:47:34 +00001281 (void) CloseBlob(image);
1282 return(GetFirstImageInList(image));
1283}
1284
1285/*
1286%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1287% %
1288% %
1289% %
1290% R e g i s t e r D P X I m a g e %
1291% %
1292% %
1293% %
1294%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1295%
1296% RegisterDPXImage() adds properties for the DPX image format to
1297% the list of supported formats. The properties include the image format
1298% tag, a method to read and/or write the format, whether the format
1299% supports the saving of more than one frame to the same file or blob,
1300% whether the format supports native in-memory I/O, and a brief
1301% description of the format.
1302%
1303% The format of the RegisterDPXImage method is:
1304%
cristybb503372010-05-27 20:51:26 +00001305% size_t RegisterDPXImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001306%
1307*/
cristybb503372010-05-27 20:51:26 +00001308ModuleExport size_t RegisterDPXImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001309{
1310 MagickInfo
1311 *entry;
1312
1313 static const char
1314 *DPXNote =
1315 {
1316 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1317 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1318 };
1319
1320 entry=SetMagickInfo("DPX");
1321 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1322 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1323 entry->magick=(IsImageFormatHandler *) IsDPX;
1324 entry->adjoin=MagickFalse;
cristy04ea8a02012-09-30 15:23:28 +00001325 entry->seekable_stream=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001326 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1327 entry->note=ConstantString(DPXNote);
1328 entry->module=ConstantString("DPX");
1329 (void) RegisterMagickInfo(entry);
1330 return(MagickImageCoderSignature);
1331}
1332
1333/*
1334%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1335% %
1336% %
1337% %
1338% U n r e g i s t e r D P X I m a g e %
1339% %
1340% %
1341% %
1342%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1343%
1344% UnregisterDPXImage() removes format registrations made by the
1345% DPX module from the list of supported formats.
1346%
1347% The format of the UnregisterDPXImage method is:
1348%
1349% UnregisterDPXImage(void)
1350%
1351*/
1352ModuleExport void UnregisterDPXImage(void)
1353{
1354 (void) UnregisterMagickInfo("DPX");
1355}
1356
1357/*
1358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1359% %
1360% %
1361% %
1362% W r i t e D P X I m a g e %
1363% %
1364% %
1365% %
1366%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1367%
1368% WriteDPXImage() writes an image in DPX encoded image format.
1369%
1370% The format of the WriteDPXImage method is:
1371%
cristy1e178e72011-08-28 19:44:34 +00001372% MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1373% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001374%
1375% A description of each parameter follows.
1376%
1377% o image_info: the image info.
1378%
1379% o image: The image.
1380%
cristy1e178e72011-08-28 19:44:34 +00001381% o exception: return any errors or warnings in this structure.
1382%
cristy3ed852e2009-09-05 21:47:34 +00001383*/
1384
1385static inline const char *GetDPXProperty(const ImageInfo *image_info,
cristyd15e6592011-10-15 00:13:06 +00001386 const Image *image,const char *property,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001387{
1388 const char
1389 *value;
1390
cristy092ec8d2013-04-26 13:46:22 +00001391 value=GetImageOption(image_info,property);
cristy3ed852e2009-09-05 21:47:34 +00001392 if (value != (const char *) NULL)
1393 return(value);
cristyd15e6592011-10-15 00:13:06 +00001394 return(GetImageProperty(image,property,exception));
cristy3ed852e2009-09-05 21:47:34 +00001395}
1396
1397static unsigned int StringToTimeCode(const char *key)
1398{
1399 char
1400 buffer[2];
1401
cristybb503372010-05-27 20:51:26 +00001402 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001403 i;
1404
1405 unsigned int
1406 shift,
1407 value;
1408
1409 value=0;
1410 shift=28;
1411 buffer[1]='\0';
1412 for (i=0; (*key != 0) && (i < 11); i++)
1413 {
1414 if (isxdigit((int) ((unsigned char) *key)) == 0)
1415 {
1416 key++;
1417 continue;
1418 }
1419 buffer[0]=(*key++);
1420 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1421 shift-=4;
1422 }
1423 return(value);
1424}
1425
cristy1e178e72011-08-28 19:44:34 +00001426static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1427 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001428{
1429 const char
1430 *value;
1431
1432 const StringInfo
1433 *profile;
1434
1435 DPXInfo
1436 dpx;
1437
cristybccc4f42011-11-24 17:57:52 +00001438 GeometryInfo
1439 geometry_info;
1440
cristy3ed852e2009-09-05 21:47:34 +00001441 MagickBooleanType
1442 status;
1443
1444 MagickOffsetType
1445 offset;
1446
1447 MagickStatusType
1448 flags;
1449
cristy3ed852e2009-09-05 21:47:34 +00001450 QuantumInfo
1451 *quantum_info;
1452
1453 QuantumType
1454 quantum_type;
1455
cristy4c08aed2011-07-01 19:47:50 +00001456 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001457 *p;
1458
cristybb503372010-05-27 20:51:26 +00001459 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001460 i;
1461
cristy1e178e72011-08-28 19:44:34 +00001462 size_t
1463 extent;
1464
cristy202de442011-04-24 18:19:07 +00001465 ssize_t
1466 count,
1467 horizontal_factor,
1468 vertical_factor,
1469 y;
1470
cristy3ed852e2009-09-05 21:47:34 +00001471 time_t
1472 seconds;
1473
1474 unsigned char
1475 *pixels;
1476
1477 /*
1478 Open output image file.
1479 */
1480 assert(image_info != (const ImageInfo *) NULL);
1481 assert(image_info->signature == MagickSignature);
1482 assert(image != (Image *) NULL);
1483 assert(image->signature == MagickSignature);
1484 if (image->debug != MagickFalse)
1485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1486 horizontal_factor=4;
1487 vertical_factor=4;
1488 if (image_info->sampling_factor != (char *) NULL)
1489 {
1490 GeometryInfo
1491 geometry_info;
1492
1493 MagickStatusType
1494 flags;
1495
1496 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
cristybb503372010-05-27 20:51:26 +00001497 horizontal_factor=(ssize_t) geometry_info.rho;
1498 vertical_factor=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00001499 if ((flags & SigmaValue) == 0)
1500 vertical_factor=horizontal_factor;
1501 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1502 (horizontal_factor != 4) && (vertical_factor != 1) &&
1503 (vertical_factor != 2) && (vertical_factor != 4))
1504 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1505 }
1506 if ((image->colorspace == YCbCrColorspace) &&
1507 ((horizontal_factor == 2) || (vertical_factor == 2)))
1508 if ((image->columns % 2) != 0)
1509 image->columns++;
cristy3a37efd2011-08-28 20:31:03 +00001510 assert(exception != (ExceptionInfo *) NULL);
1511 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +00001512 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001513 if (status == MagickFalse)
1514 return(status);
1515 /*
1516 Write file header.
1517 */
1518 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1519 offset=0;
1520 dpx.file.magic=0x53445058U;
1521 offset+=WriteBlobLong(image,dpx.file.magic);
1522 dpx.file.image_offset=0x2000U;
cristy61047b62010-05-22 02:15:20 +00001523 profile=GetImageProfile(image,"dpx");
cristy3ed852e2009-09-05 21:47:34 +00001524 if (profile != (StringInfo *) NULL)
1525 {
cristy61047b62010-05-22 02:15:20 +00001526 if (GetStringInfoLength(profile) > 1048576)
1527 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
cristy3ed852e2009-09-05 21:47:34 +00001528 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1529 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1530 }
1531 offset+=WriteBlobLong(image,dpx.file.image_offset);
1532 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1533 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1534 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1535 dpx.file.image_offset);
1536 offset+=WriteBlobLong(image,dpx.file.file_size);
1537 dpx.file.ditto_key=1U; /* new frame */
1538 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1539 dpx.file.generic_size=0x00000680U;
1540 offset+=WriteBlobLong(image,dpx.file.generic_size);
1541 dpx.file.industry_size=0x00000180U;
1542 offset+=WriteBlobLong(image,dpx.file.industry_size);
1543 dpx.file.user_size=0;
1544 if (profile != (StringInfo *) NULL)
1545 {
1546 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1547 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1548 }
1549 offset+=WriteBlobLong(image,dpx.file.user_size);
cristyd15e6592011-10-15 00:13:06 +00001550 value=GetDPXProperty(image_info,image,"dpx:file.filename",exception);
cristy3ed852e2009-09-05 21:47:34 +00001551 if (value != (const char *) NULL)
1552 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1553 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1554 dpx.file.filename);
1555 seconds=time((time_t *) NULL);
1556 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1557 dpx.file.timestamp);
1558 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1559 dpx.file.timestamp);
cristybb503372010-05-27 20:51:26 +00001560 (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL),
cristy3ed852e2009-09-05 21:47:34 +00001561 sizeof(dpx.file.creator));
cristyd15e6592011-10-15 00:13:06 +00001562 value=GetDPXProperty(image_info,image,"dpx:file.creator",exception);
cristy3ed852e2009-09-05 21:47:34 +00001563 if (value != (const char *) NULL)
1564 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1565 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1566 dpx.file.creator);
cristyd15e6592011-10-15 00:13:06 +00001567 value=GetDPXProperty(image_info,image,"dpx:file.project",exception);
cristy3ed852e2009-09-05 21:47:34 +00001568 if (value != (const char *) NULL)
1569 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1570 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1571 dpx.file.project);
cristyd15e6592011-10-15 00:13:06 +00001572 value=GetDPXProperty(image_info,image,"dpx:file.copyright",exception);
cristy3ed852e2009-09-05 21:47:34 +00001573 if (value != (const char *) NULL)
cristyd15e6592011-10-15 00:13:06 +00001574 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright));
cristy3ed852e2009-09-05 21:47:34 +00001575 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1576 dpx.file.copyright);
cristy3a5987c2013-11-07 14:18:46 +00001577 dpx.file.encrypt_key=(~0UL);
cristy3ed852e2009-09-05 21:47:34 +00001578 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1579 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1580 dpx.file.reserve);
1581 /*
1582 Write image header.
1583 */
cristye7820582013-01-01 23:42:55 +00001584 switch (image->orientation)
1585 {
1586 default:
1587 case TopLeftOrientation: dpx.image.orientation=0; break;
1588 case TopRightOrientation: dpx.image.orientation=1; break;
1589 case BottomLeftOrientation: dpx.image.orientation=2; break;
1590 case BottomRightOrientation: dpx.image.orientation=3; break;
1591 case LeftTopOrientation: dpx.image.orientation=4; break;
1592 case RightTopOrientation: dpx.image.orientation=5; break;
1593 case LeftBottomOrientation: dpx.image.orientation=6; break;
1594 case RightBottomOrientation: dpx.image.orientation=7; break;
1595 }
cristy3ed852e2009-09-05 21:47:34 +00001596 offset+=WriteBlobShort(image,dpx.image.orientation);
1597 dpx.image.number_elements=1;
1598 offset+=WriteBlobShort(image,dpx.image.number_elements);
1599 if ((image->columns != (unsigned int) image->columns) ||
1600 (image->rows != (unsigned int) image->rows))
1601 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1602 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1603 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1604 for (i=0; i < 8; i++)
1605 {
1606 dpx.image.image_element[i].data_sign=0U;
1607 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1608 dpx.image.image_element[i].low_data=0U;
1609 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1610 dpx.image.image_element[i].low_quantity=0.0f;
1611 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1612 dpx.image.image_element[i].high_data=0U;
1613 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1614 dpx.image.image_element[i].high_quantity=0.0f;
1615 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1616 dpx.image.image_element[i].descriptor=0;
1617 if (i == 0)
1618 switch (image->colorspace)
1619 {
1620 case Rec601YCbCrColorspace:
1621 case Rec709YCbCrColorspace:
1622 case YCbCrColorspace:
1623 {
1624 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
cristy8a46d822012-08-28 23:32:39 +00001625 if (image->alpha_trait == BlendPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +00001626 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1627 break;
1628 }
1629 default:
1630 {
1631 dpx.image.image_element[i].descriptor=RGBComponentType;
cristy8a46d822012-08-28 23:32:39 +00001632 if (image->alpha_trait == BlendPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +00001633 dpx.image.image_element[i].descriptor=RGBAComponentType;
cristyf59a8922010-02-28 19:51:23 +00001634 if ((image_info->type != TrueColorType) &&
cristy8a46d822012-08-28 23:32:39 +00001635 (image->alpha_trait != BlendPixelTrait) &&
cristy1e178e72011-08-28 19:44:34 +00001636 (IsImageGray(image,exception) != MagickFalse))
cristycaac2942009-10-01 13:36:18 +00001637 dpx.image.image_element[i].descriptor=LumaComponentType;
cristy3ed852e2009-09-05 21:47:34 +00001638 break;
1639 }
1640 }
1641 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
cristyc7f92ea2013-01-10 19:59:00 +00001642 dpx.image.image_element[i].transfer_characteristic=0;
cristy3ed852e2009-09-05 21:47:34 +00001643 if (image->colorspace == LogColorspace)
cristyc7f92ea2013-01-10 19:59:00 +00001644 dpx.image.image_element[0].transfer_characteristic=
1645 PrintingDensityColorimetric;
1646 offset+=WriteBlobByte(image,
1647 dpx.image.image_element[i].transfer_characteristic);
cristy3ed852e2009-09-05 21:47:34 +00001648 dpx.image.image_element[i].colorimetric=0;
1649 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1650 dpx.image.image_element[i].bit_size=0;
1651 if (i == 0)
1652 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1653 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1654 dpx.image.image_element[i].packing=0;
1655 if ((image->depth == 10) || (image->depth == 12))
1656 dpx.image.image_element[i].packing=1;
1657 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1658 dpx.image.image_element[i].encoding=0;
1659 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1660 dpx.image.image_element[i].data_offset=0U;
1661 if (i == 0)
1662 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1663 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1664 dpx.image.image_element[i].end_of_line_padding=0U;
1665 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1666 offset+=WriteBlobLong(image,
1667 dpx.image.image_element[i].end_of_image_padding);
1668 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1669 (unsigned char *) dpx.image.image_element[i].description);
1670 }
1671 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1672 dpx.image.reserve);
1673 /*
1674 Write orientation header.
1675 */
1676 if ((image->rows != image->magick_rows) ||
1677 (image->columns != image->magick_columns))
1678 {
1679 /*
1680 These properties are not valid if image size changed.
1681 */
1682 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1683 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1684 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1685 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1686 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1687 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1688 }
1689 dpx.orientation.x_offset=0U;
cristyd15e6592011-10-15 00:13:06 +00001690 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001691 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001692 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001693 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1694 dpx.orientation.y_offset=0U;
cristyd15e6592011-10-15 00:13:06 +00001695 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001696 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001697 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001698 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1699 dpx.orientation.x_center=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001700 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center",exception);
cristy3ed852e2009-09-05 21:47:34 +00001701 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001702 dpx.orientation.x_center=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001703 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1704 dpx.orientation.y_center=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001705 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center",exception);
cristy3ed852e2009-09-05 21:47:34 +00001706 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001707 dpx.orientation.y_center=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001708 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1709 dpx.orientation.x_size=0U;
cristyd15e6592011-10-15 00:13:06 +00001710 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size",exception);
cristy3ed852e2009-09-05 21:47:34 +00001711 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001712 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001713 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1714 dpx.orientation.y_size=0U;
cristyd15e6592011-10-15 00:13:06 +00001715 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size",exception);
cristy3ed852e2009-09-05 21:47:34 +00001716 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001717 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001718 offset+=WriteBlobLong(image,dpx.orientation.y_size);
cristyd15e6592011-10-15 00:13:06 +00001719 value=GetDPXProperty(image_info,image,"dpx:orientation.filename",exception);
cristy3ed852e2009-09-05 21:47:34 +00001720 if (value != (const char *) NULL)
1721 (void) strncpy(dpx.orientation.filename,value,
1722 sizeof(dpx.orientation.filename));
1723 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1724 dpx.orientation.filename);
1725 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1726 dpx.orientation.timestamp);
cristyd15e6592011-10-15 00:13:06 +00001727 value=GetDPXProperty(image_info,image,"dpx:orientation.device",exception);
cristy3ed852e2009-09-05 21:47:34 +00001728 if (value != (const char *) NULL)
cristy7959f822010-03-07 21:47:41 +00001729 (void) strncpy(dpx.orientation.device,value,sizeof(dpx.orientation.device));
cristy3ed852e2009-09-05 21:47:34 +00001730 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1731 dpx.orientation.device);
cristyd15e6592011-10-15 00:13:06 +00001732 value=GetDPXProperty(image_info,image,"dpx:orientation.serial",exception);
cristy7959f822010-03-07 21:47:41 +00001733 if (value != (const char *) NULL)
1734 (void) strncpy(dpx.orientation.serial,value,sizeof(dpx.orientation.serial));
cristy3ed852e2009-09-05 21:47:34 +00001735 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1736 dpx.orientation.serial);
1737 for (i=0; i < 4; i++)
1738 dpx.orientation.border[i]=0;
cristyd15e6592011-10-15 00:13:06 +00001739 value=GetDPXProperty(image_info,image,"dpx:orientation.border",exception);
cristy3ed852e2009-09-05 21:47:34 +00001740 if (value != (const char *) NULL)
1741 {
1742 flags=ParseGeometry(value,&geometry_info);
1743 if ((flags & SigmaValue) == 0)
1744 geometry_info.sigma=geometry_info.rho;
1745 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1746 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1747 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1748 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1749 }
1750 for (i=0; i < 4; i++)
1751 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1752 for (i=0; i < 2; i++)
1753 dpx.orientation.aspect_ratio[i]=0U;
cristyd15e6592011-10-15 00:13:06 +00001754 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio",
1755 exception);
cristy3ed852e2009-09-05 21:47:34 +00001756 if (value != (const char *) NULL)
1757 {
1758 flags=ParseGeometry(value,&geometry_info);
1759 if ((flags & SigmaValue) == 0)
1760 geometry_info.sigma=geometry_info.rho;
1761 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1762 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1763 }
1764 for (i=0; i < 2; i++)
1765 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1766 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1767 dpx.orientation.reserve);
1768 /*
1769 Write film header.
1770 */
1771 *dpx.film.id='\0';
cristyd15e6592011-10-15 00:13:06 +00001772 value=GetDPXProperty(image_info,image,"dpx:film.id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001773 if (value != (const char *) NULL)
1774 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1775 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1776 *dpx.film.type='\0';
cristyd15e6592011-10-15 00:13:06 +00001777 value=GetDPXProperty(image_info,image,"dpx:film.type",exception);
cristy3ed852e2009-09-05 21:47:34 +00001778 if (value != (const char *) NULL)
1779 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1780 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1781 dpx.film.type);
1782 *dpx.film.offset='\0';
cristyd15e6592011-10-15 00:13:06 +00001783 value=GetDPXProperty(image_info,image,"dpx:film.offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001784 if (value != (const char *) NULL)
1785 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1786 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1787 dpx.film.offset);
1788 *dpx.film.prefix='\0';
cristyd15e6592011-10-15 00:13:06 +00001789 value=GetDPXProperty(image_info,image,"dpx:film.prefix",exception);
cristy3ed852e2009-09-05 21:47:34 +00001790 if (value != (const char *) NULL)
1791 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1792 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1793 dpx.film.prefix);
1794 *dpx.film.count='\0';
cristyd15e6592011-10-15 00:13:06 +00001795 value=GetDPXProperty(image_info,image,"dpx:film.count",exception);
cristy3ed852e2009-09-05 21:47:34 +00001796 if (value != (const char *) NULL)
1797 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1798 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1799 dpx.film.count);
1800 *dpx.film.format='\0';
cristyd15e6592011-10-15 00:13:06 +00001801 value=GetDPXProperty(image_info,image,"dpx:film.format",exception);
cristy3ed852e2009-09-05 21:47:34 +00001802 if (value != (const char *) NULL)
1803 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1804 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1805 dpx.film.format);
1806 dpx.film.frame_position=0U;
cristyd15e6592011-10-15 00:13:06 +00001807 value=GetDPXProperty(image_info,image,"dpx:film.frame_position",exception);
cristy3ed852e2009-09-05 21:47:34 +00001808 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001809 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001810 offset+=WriteBlobLong(image,dpx.film.frame_position);
1811 dpx.film.sequence_extent=0U;
cristyd15e6592011-10-15 00:13:06 +00001812 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent",exception);
cristy3ed852e2009-09-05 21:47:34 +00001813 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001814 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001815 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1816 dpx.film.held_count=0U;
cristyd15e6592011-10-15 00:13:06 +00001817 value=GetDPXProperty(image_info,image,"dpx:film.held_count",exception);
cristy3ed852e2009-09-05 21:47:34 +00001818 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001819 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001820 offset+=WriteBlobLong(image,dpx.film.held_count);
1821 dpx.film.frame_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001822 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001823 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001824 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001825 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1826 dpx.film.shutter_angle=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001827 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle",exception);
cristy3ed852e2009-09-05 21:47:34 +00001828 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001829 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001830 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1831 *dpx.film.frame_id='\0';
cristyd15e6592011-10-15 00:13:06 +00001832 value=GetDPXProperty(image_info,image,"dpx:film.frame_id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001833 if (value != (const char *) NULL)
1834 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1835 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1836 dpx.film.frame_id);
cristyd15e6592011-10-15 00:13:06 +00001837 value=GetDPXProperty(image_info,image,"dpx:film.slate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001838 if (value != (const char *) NULL)
1839 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1840 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1841 dpx.film.slate);
1842 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1843 dpx.film.reserve);
1844 /*
1845 Write television header.
1846 */
cristyd15e6592011-10-15 00:13:06 +00001847 value=GetDPXProperty(image_info,image,"dpx:television.time.code",exception);
cristy3ed852e2009-09-05 21:47:34 +00001848 if (value != (const char *) NULL)
1849 dpx.television.time_code=StringToTimeCode(value);
1850 offset+=WriteBlobLong(image,dpx.television.time_code);
cristyd15e6592011-10-15 00:13:06 +00001851 value=GetDPXProperty(image_info,image,"dpx:television.user.bits",exception);
cristy3ed852e2009-09-05 21:47:34 +00001852 if (value != (const char *) NULL)
1853 dpx.television.user_bits=StringToTimeCode(value);
1854 offset+=WriteBlobLong(image,dpx.television.user_bits);
cristyd15e6592011-10-15 00:13:06 +00001855 value=GetDPXProperty(image_info,image,"dpx:television.interlace",exception);
cristy3ed852e2009-09-05 21:47:34 +00001856 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001857 dpx.television.interlace=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001858 offset+=WriteBlobByte(image,dpx.television.interlace);
cristyd15e6592011-10-15 00:13:06 +00001859 value=GetDPXProperty(image_info,image,"dpx:television.field_number",
1860 exception);
cristy3ed852e2009-09-05 21:47:34 +00001861 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001862 dpx.television.field_number=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001863 offset+=WriteBlobByte(image,dpx.television.field_number);
1864 dpx.television.video_signal=0;
cristybccc4f42011-11-24 17:57:52 +00001865 value=GetDPXProperty(image_info,image,"dpx:television.video_signal",
1866 exception);
cristy3ed852e2009-09-05 21:47:34 +00001867 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001868 dpx.television.video_signal=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001869 offset+=WriteBlobByte(image,dpx.television.video_signal);
1870 dpx.television.padding=0;
cristyd15e6592011-10-15 00:13:06 +00001871 value=GetDPXProperty(image_info,image,"dpx:television.padding",exception);
cristy3ed852e2009-09-05 21:47:34 +00001872 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001873 dpx.television.padding=(unsigned char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001874 offset+=WriteBlobByte(image,dpx.television.padding);
1875 dpx.television.horizontal_sample_rate=0.0f;
cristybccc4f42011-11-24 17:57:52 +00001876 value=GetDPXProperty(image_info,image,"dpx:television.horizontal_sample_rate", exception);
cristy3ed852e2009-09-05 21:47:34 +00001877 if (value != (const char *) NULL)
cristybccc4f42011-11-24 17:57:52 +00001878 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001879 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1880 dpx.television.vertical_sample_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001881 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate",
1882 exception);
cristy3ed852e2009-09-05 21:47:34 +00001883 if (value != (const char *) NULL)
cristybccc4f42011-11-24 17:57:52 +00001884 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001885 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1886 dpx.television.frame_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001887 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001888 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001889 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001890 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1891 dpx.television.time_offset=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001892 value=GetDPXProperty(image_info,image,"dpx:television.time_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001893 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001894 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001895 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1896 dpx.television.gamma=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001897 value=GetDPXProperty(image_info,image,"dpx:television.gamma",exception);
cristy3ed852e2009-09-05 21:47:34 +00001898 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001899 dpx.television.gamma=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001900 offset+=WriteBlobFloat(image,dpx.television.gamma);
1901 dpx.television.black_level=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001902 value=GetDPXProperty(image_info,image,"dpx:television.black_level",exception);
cristy3ed852e2009-09-05 21:47:34 +00001903 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001904 dpx.television.black_level=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001905 offset+=WriteBlobFloat(image,dpx.television.black_level);
1906 dpx.television.black_gain=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001907 value=GetDPXProperty(image_info,image,"dpx:television.black_gain",exception);
cristy3ed852e2009-09-05 21:47:34 +00001908 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001909 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001910 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1911 dpx.television.break_point=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001912 value=GetDPXProperty(image_info,image,"dpx:television.break_point",exception);
cristy3ed852e2009-09-05 21:47:34 +00001913 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001914 dpx.television.break_point=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001915 offset+=WriteBlobFloat(image,dpx.television.break_point);
1916 dpx.television.white_level=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001917 value=GetDPXProperty(image_info,image,"dpx:television.white_level",exception);
cristy3ed852e2009-09-05 21:47:34 +00001918 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001919 dpx.television.white_level=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001920 offset+=WriteBlobFloat(image,dpx.television.white_level);
1921 dpx.television.integration_times=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001922 value=GetDPXProperty(image_info,image,"dpx:television.integration_times",
1923 exception);
cristy3ed852e2009-09-05 21:47:34 +00001924 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001925 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001926 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1927 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1928 dpx.television.reserve);
1929 /*
1930 Write user header.
1931 */
cristyd15e6592011-10-15 00:13:06 +00001932 value=GetDPXProperty(image_info,image,"dpx:user.id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001933 if (value != (const char *) NULL)
1934 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1935 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1936 if (profile != (StringInfo *) NULL)
1937 offset+=WriteBlob(image,GetStringInfoLength(profile),
1938 GetStringInfoDatum(profile));
1939 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1940 {
1941 count=WriteBlobByte(image,0x00);
1942 if (count != 1)
1943 {
cristy1e178e72011-08-28 19:44:34 +00001944 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
cristy3ed852e2009-09-05 21:47:34 +00001945 image->filename);
1946 break;
1947 }
1948 offset+=count;
1949 }
1950 /*
1951 Convert pixel packets to DPX raster image.
1952 */
1953 quantum_info=AcquireQuantumInfo(image_info,image);
cristy891dc792010-03-04 01:47:16 +00001954 SetQuantumQuantum(quantum_info,32);
1955 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1956 MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001957 quantum_type=RGBQuantum;
cristy8a46d822012-08-28 23:32:39 +00001958 if (image->alpha_trait == BlendPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +00001959 quantum_type=RGBAQuantum;
1960 if (image->colorspace == YCbCrColorspace)
1961 {
1962 quantum_type=CbYCrQuantum;
cristy8a46d822012-08-28 23:32:39 +00001963 if (image->alpha_trait == BlendPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +00001964 quantum_type=CbYCrAQuantum;
1965 if ((horizontal_factor == 2) || (vertical_factor == 2))
1966 quantum_type=CbYCrYQuantum;
1967 }
cristy3b232222012-11-05 16:55:17 +00001968 extent=GetBytesPerRow(image->columns,image->alpha_trait == BlendPixelTrait ?
1969 4UL : 3UL,image->depth,MagickTrue);
1970 if ((image_info->type != TrueColorType) &&
1971 (image->alpha_trait != BlendPixelTrait) &&
cristy1e178e72011-08-28 19:44:34 +00001972 (IsImageGray(image,exception) != MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +00001973 {
1974 quantum_type=GrayQuantum;
cristycaac2942009-10-01 13:36:18 +00001975 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00001976 }
1977 pixels=GetQuantumPixels(quantum_info);
cristybb503372010-05-27 20:51:26 +00001978 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001979 {
cristy1e178e72011-08-28 19:44:34 +00001980 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001981 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001982 break;
cristy4c08aed2011-07-01 19:47:50 +00001983 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001984 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001985 count=WriteBlob(image,extent,pixels);
1986 if (count != (ssize_t) extent)
1987 break;
cristycee97112010-05-28 00:44:52 +00001988 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy202de442011-04-24 18:19:07 +00001989 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001990 if (status == MagickFalse)
1991 break;
1992 }
1993 quantum_info=DestroyQuantumInfo(quantum_info);
1994 (void) CloseBlob(image);
1995 return(status);
1996}