]> granicus.if.org Git - imagemagick/blob - coders/dpx.c
b474ee1987db0a7f4b096da646735b192562e8d1
[imagemagick] / coders / dpx.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                            DDDD   PPPP   X   X                              %
7 %                            D   D  P   P   X X                               %
8 %                            D   D  PPPP    XXX                               %
9 %                            D   D  P       X X                               %
10 %                            DDDD   P      X   X                              %
11 %                                                                             %
12 %                                                                             %
13 %                     Read/Write SMTPE DPX Image Format                       %
14 %                                                                             %
15 %                              Software Design                                %
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 \f
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"
55 #include "magick/module.h"
56 #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"
64 #include "magick/string-private.h"
65 \f
66 /*
67   Typedef declaration.
68 */
69 typedef 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
86 typedef 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
113 typedef 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
143 typedef 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
168 typedef 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
202 typedef 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
219 typedef 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
249 typedef 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
277 typedef struct _DPXUserInfo
278 {
279   char
280     id[32];
281 } DPXUserInfo;
282
283 typedef 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 \f
304 /*
305   Forward declaractions.
306 */
307 static MagickBooleanType
308   WriteDPXImage(const ImageInfo *,Image *);
309 \f
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 */
335 static 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 \f
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
373 static 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         }
403       bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
404       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
439 static 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
457 static 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
516 static 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
540 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
541 {
542   CacheView
543     *image_view;
544
545   char
546     magick[4],
547     value[MaxTextExtent];
548
549   DPXInfo
550     dpx;
551
552   Image
553     *image;
554
555   long
556     row,
557     y;
558
559   MagickBooleanType
560     status;
561
562   MagickOffsetType
563     offset;
564
565   QuantumInfo
566     *quantum_info;
567
568   QuantumType
569     quantum_type;
570
571   register long
572     i;
573
574   register PixelPacket
575     *q;
576
577   ssize_t
578     count;
579
580   size_t
581     extent;
582
583   unsigned char
584     component_type;
585
586   unsigned long
587     samples_per_pixel;
588
589   /*
590     Open image file.
591   */
592   assert(image_info != (const ImageInfo *) NULL);
593   assert(image_info->signature == MagickSignature);
594   if (image_info->debug != MagickFalse)
595     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
596       image_info->filename);
597   assert(exception != (ExceptionInfo *) NULL);
598   assert(exception->signature == MagickSignature);
599   image=AcquireImage(image_info);
600   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
601   if (status == MagickFalse)
602     {
603       image=DestroyImageList(image);
604       return((Image *) NULL);
605     }
606   /*
607     Read DPX file header.
608   */
609   offset=0;
610   count=ReadBlob(image,4,(unsigned char *) magick);
611   offset+=count;
612   if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
613       (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
614     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
615   image->endian=LSBEndian;
616   if (LocaleNCompare(magick,"SDPX",4) == 0)
617     image->endian=MSBEndian;
618   (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
619   dpx.file.image_offset=ReadBlobLong(image);
620   offset+=4;
621   offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
622     dpx.file.version);
623   (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
624   dpx.file.file_size=ReadBlobLong(image);
625   offset+=4;
626   dpx.file.ditto_key=ReadBlobLong(image);
627   offset+=4;
628   if (dpx.file.ditto_key != ~0U)
629     (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
630       dpx.file.ditto_key);
631   dpx.file.generic_size=ReadBlobLong(image);
632   offset+=4;
633   dpx.file.industry_size=ReadBlobLong(image);
634   offset+=4;
635   dpx.file.user_size=ReadBlobLong(image);
636   offset+=4;
637   offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
638     dpx.file.filename);
639   (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
640     dpx.file.filename);
641   (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
642   offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
643     dpx.file.timestamp);
644   if (*dpx.file.timestamp != '\0')
645     (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
646       dpx.file.timestamp);
647   offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
648     dpx.file.creator);
649   if (*dpx.file.creator != '\0')
650     {
651       (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
652         dpx.file.creator);
653       (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
654     }
655   offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
656     dpx.file.project);
657   if (*dpx.file.project != '\0')
658     {
659       (void) FormatImageProperty(image,"dpx:file.project","%.200s",
660         dpx.file.project);
661       (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
662     }
663   offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
664     dpx.file.copyright);
665   if (*dpx.file.copyright != '\0')
666     {
667       (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
668         dpx.file.copyright);
669       (void) FormatImageProperty(image,"copyright","%.100s",
670         dpx.file.copyright);
671     }
672   dpx.file.encrypt_key=ReadBlobLong(image);
673   offset+=4;
674   if (dpx.file.encrypt_key != ~0U)
675     (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
676       dpx.file.encrypt_key);
677   offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
678     dpx.file.reserve);
679   /*
680     Read DPX image header.
681   */
682   dpx.image.orientation=ReadBlobShort(image);
683   offset+=2;
684   if (dpx.image.orientation != (unsigned short) (~0U))
685     (void) FormatImageProperty(image,"dpx:image.orientation","%d",
686       dpx.image.orientation);
687   switch (dpx.image.orientation)
688   {
689     default:
690     case 0:  image->orientation=TopLeftOrientation; break;
691     case 1:  image->orientation=TopRightOrientation; break;
692     case 2:  image->orientation=BottomLeftOrientation; break;
693     case 3:  image->orientation=BottomRightOrientation; break;
694     case 4:  image->orientation=LeftTopOrientation; break;
695     case 5:  image->orientation=RightTopOrientation; break;
696     case 6:  image->orientation=LeftBottomOrientation; break;
697     case 7:  image->orientation=RightBottomOrientation; break;
698   }
699   dpx.image.number_elements=ReadBlobShort(image);
700   offset+=2;
701   dpx.image.pixels_per_line=ReadBlobLong(image);
702   offset+=4;
703   image->columns=dpx.image.pixels_per_line;
704   dpx.image.lines_per_element=ReadBlobLong(image);
705   offset+=4;
706   image->rows=dpx.image.lines_per_element;
707   for (i=0; i < 8; i++)
708   {
709     dpx.image.image_element[i].data_sign=ReadBlobLong(image);
710     offset+=4;
711     dpx.image.image_element[i].low_data=ReadBlobLong(image);
712     offset+=4;
713     dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
714     offset+=4;
715     dpx.image.image_element[i].high_data=ReadBlobLong(image);
716     offset+=4;
717     dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
718     offset+=4;
719     dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
720     offset++;
721     dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
722     offset++;
723     dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
724     offset++;
725     dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
726     offset++;
727     dpx.image.image_element[i].packing=ReadBlobShort(image);
728     offset+=2;
729     dpx.image.image_element[i].encoding=ReadBlobShort(image);
730     offset+=2;
731     dpx.image.image_element[i].data_offset=ReadBlobLong(image);
732     offset+=4;
733     dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
734     offset+=4;
735     dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
736     offset+=4;
737     offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
738       (unsigned char *) dpx.image.image_element[i].description);
739   }
740   SetPrimaryChromaticity((DPXColorimetric)
741     dpx.image.image_element[0].colorimetric,&image->chromaticity);
742   offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
743     dpx.image.reserve);
744   component_type=dpx.image.image_element[0].descriptor;
745   image->depth=dpx.image.image_element[0].bit_size;
746   if (dpx.file.image_offset >= 1664U)
747     {
748       /*
749         Read DPX orientation header.
750       */
751       dpx.orientation.x_offset=ReadBlobLong(image);
752       offset+=4;
753       if (dpx.orientation.x_offset != ~0U)
754         (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
755           dpx.orientation.x_offset);
756       dpx.orientation.y_offset=ReadBlobLong(image);
757       offset+=4;
758       if (dpx.orientation.y_offset != ~0U)
759         (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
760           dpx.orientation.y_offset);
761       dpx.orientation.x_center=ReadBlobFloat(image);
762       offset+=4;
763       if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
764         (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
765           dpx.orientation.x_center);
766       dpx.orientation.y_center=ReadBlobFloat(image);
767       offset+=4;
768       if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
769         (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
770           dpx.orientation.y_center);
771       dpx.orientation.x_size=ReadBlobLong(image);
772       offset+=4;
773       if (dpx.orientation.x_size != ~0U)
774         (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
775           dpx.orientation.x_size);
776       dpx.orientation.y_size=ReadBlobLong(image);
777       offset+=4;
778       if (dpx.orientation.y_size != ~0U)
779         (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
780           dpx.orientation.y_size);
781       offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
782         dpx.orientation.filename);
783       if (*dpx.orientation.filename != '\0')
784         (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
785           dpx.orientation.filename);
786       offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
787         dpx.orientation.timestamp);
788       if (*dpx.orientation.timestamp != '\0')
789         (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
790           dpx.orientation.timestamp);
791       offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
792         dpx.orientation.device);
793       if (*dpx.orientation.device != '\0')
794         (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
795           dpx.orientation.device);
796       offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
797         dpx.orientation.serial);
798       if (*dpx.orientation.serial != '\0')
799         (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
800           dpx.orientation.serial);
801       for (i=0; i < 4; i++)
802       {
803         dpx.orientation.border[i]=ReadBlobShort(image);
804         offset+=2;
805       }
806       if ((dpx.orientation.border[0] != (unsigned short) (~0U)) &&
807           (dpx.orientation.border[1] != (unsigned short) (~0U)))
808         (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d",          dpx.orientation.border[0],dpx.orientation.border[1],
809           dpx.orientation.border[2],dpx.orientation.border[3]);
810       for (i=0; i < 2; i++)
811       {
812         dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
813         offset+=4;
814       }
815       if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
816           (dpx.orientation.aspect_ratio[1] != ~0U))
817         (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
818           "%ux%u",dpx.orientation.aspect_ratio[0],
819           dpx.orientation.aspect_ratio[1]);
820       offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
821         dpx.orientation.reserve);
822     }
823   if (dpx.file.image_offset >= 1920U)
824     {
825       /*
826         Read DPX film header.
827       */
828       offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
829       if (*dpx.film.type != '\0')
830         (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
831       offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
832         dpx.film.type);
833       if (*dpx.film.type != '\0')
834         (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
835       offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
836         dpx.film.offset);
837       if (*dpx.film.offset != '\0')
838         (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
839           dpx.film.offset);
840       offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
841         dpx.film.prefix);
842       if (*dpx.film.prefix != '\0')
843         (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
844           dpx.film.prefix);
845       offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
846         dpx.film.count);
847       if (*dpx.film.count != '\0')
848         (void) FormatImageProperty(image,"dpx:film.count","%.4s",
849           dpx.film.count);
850       offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
851         dpx.film.format);
852       if (*dpx.film.format != '\0')
853         (void) FormatImageProperty(image,"dpx:film.format","%.4s",
854           dpx.film.format);
855       dpx.film.frame_position=ReadBlobLong(image);
856       offset+=4;
857       if (dpx.film.frame_position != ~0U)
858         (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
859           dpx.film.frame_position);
860       dpx.film.sequence_extent=ReadBlobLong(image);
861       offset+=4;
862       if (dpx.film.sequence_extent != ~0U)
863         (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
864           dpx.film.sequence_extent);
865       dpx.film.held_count=ReadBlobLong(image);
866       offset+=4;
867       if (dpx.film.held_count != ~0U)
868         (void) FormatImageProperty(image,"dpx:film.held_count","%u",
869           dpx.film.held_count);
870       dpx.film.frame_rate=ReadBlobFloat(image);
871       offset+=4;
872       if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
873         (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
874           dpx.film.frame_rate);
875       dpx.film.shutter_angle=ReadBlobFloat(image);
876       offset+=4;
877       if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
878         (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
879           dpx.film.shutter_angle);
880       offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
881         dpx.film.frame_id);
882       if (*dpx.film.frame_id != '\0')
883         (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
884           dpx.film.frame_id);
885       offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
886         dpx.film.slate);
887       if (*dpx.film.slate != '\0')
888         (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
889           dpx.film.slate);
890       offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
891         dpx.film.reserve);
892     }
893   if (dpx.file.image_offset >= 2048U)
894     {
895       /*
896         Read DPX television header.
897       */
898       dpx.television.time_code=(unsigned int) ReadBlobLong(image);
899       offset+=4;
900       TimeCodeToString(dpx.television.time_code,value);
901       (void) SetImageProperty(image,"dpx:television.time.code",value);
902       dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
903       offset+=4;
904       TimeCodeToString(dpx.television.user_bits,value);
905       (void) SetImageProperty(image,"dpx:television.user.bits",value);
906       dpx.television.interlace=(unsigned char) ReadBlobByte(image);
907       offset++;
908       if (dpx.television.interlace != 0)
909         (void) FormatImageProperty(image,"dpx:television.interlace","%ld",(long)
910           dpx.television.interlace);
911       dpx.television.field_number=(unsigned char) ReadBlobByte(image);
912       offset++;
913       if (dpx.television.field_number != 0)
914         (void) FormatImageProperty(image,"dpx:television.field_number","%ld",
915           (long) dpx.television.field_number);
916       dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
917       offset++;
918       if (dpx.television.video_signal != 0)
919         (void) FormatImageProperty(image,"dpx:television.video_signal","%ld",
920           (long) dpx.television.video_signal);
921       dpx.television.padding=(unsigned char) ReadBlobByte(image);
922       offset++;
923       if (dpx.television.padding != 0)
924         (void) FormatImageProperty(image,"dpx:television.padding","%d",
925           dpx.television.padding);
926       dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
927       offset+=4;
928       if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
929         (void) FormatImageProperty(image,
930           "dpx:television.horizontal_sample_rate","%g",
931           dpx.television.horizontal_sample_rate);
932       dpx.television.vertical_sample_rate=ReadBlobFloat(image);
933       offset+=4;
934       if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
935         (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
936           "%g",dpx.television.vertical_sample_rate);
937       dpx.television.frame_rate=ReadBlobFloat(image);
938       offset+=4;
939       if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
940         (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
941           dpx.television.frame_rate);
942       dpx.television.time_offset=ReadBlobFloat(image);
943       offset+=4;
944       if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
945         (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
946           dpx.television.time_offset);
947       dpx.television.gamma=ReadBlobFloat(image);
948       offset+=4;
949       if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
950         (void) FormatImageProperty(image,"dpx:television.gamma","%g",
951           dpx.television.gamma);
952       dpx.television.black_level=ReadBlobFloat(image);
953       offset+=4;
954       if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
955         (void) FormatImageProperty(image,"dpx:television.black_level","%g",
956           dpx.television.black_level);
957       dpx.television.black_gain=ReadBlobFloat(image);
958       offset+=4;
959       if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
960         (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
961           dpx.television.black_gain);
962       dpx.television.break_point=ReadBlobFloat(image);
963       offset+=4;
964       if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
965         (void) FormatImageProperty(image,"dpx:television.break_point","%g",
966           dpx.television.break_point);
967       dpx.television.white_level=ReadBlobFloat(image);
968       offset+=4;
969       if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
970         (void) FormatImageProperty(image,"dpx:television.white_level","%g",
971           dpx.television.white_level);
972       dpx.television.integration_times=ReadBlobFloat(image);
973       offset+=4;
974       if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
975         (void) FormatImageProperty(image,"dpx:television.integration_times",
976           "%g",dpx.television.integration_times);
977       offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
978         dpx.television.reserve);
979     }
980   if (dpx.file.image_offset > 2080U)
981     {
982       /*
983         Read DPX user header.
984       */
985       offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
986       if (*dpx.user.id != '\0')
987         (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
988       if ((dpx.file.user_size != ~0U) &&
989           ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
990         {
991           StringInfo
992             *profile;
993
994            profile=AcquireStringInfo(dpx.file.user_size-sizeof(dpx.user.id));
995            offset+=ReadBlob(image,GetStringInfoLength(profile),
996              GetStringInfoDatum(profile));
997            (void) SetImageProfile(image,"dpx:user.data",profile);
998            profile=DestroyStringInfo(profile);
999         }
1000     }
1001   for ( ; offset < (long) dpx.file.image_offset; offset++)
1002     (void) ReadBlobByte(image);
1003   /*
1004     Read DPX image header.
1005   */
1006   if (image_info->ping != MagickFalse)
1007     {
1008       (void) CloseBlob(image);
1009       return(GetFirstImageInList(image));
1010     }
1011   /*
1012     Convert DPX raster image to pixel packets.
1013   */
1014   samples_per_pixel=1;
1015   quantum_type=GrayQuantum;
1016   switch (component_type)
1017   {
1018     case CbYCrY422ComponentType:
1019     {
1020       samples_per_pixel=2;
1021       quantum_type=CbYCrYQuantum;
1022       break;
1023     }
1024     case CbYACrYA4224ComponentType:
1025     case CbYCr444ComponentType:
1026     {
1027       samples_per_pixel=3;
1028       quantum_type=CbYCrQuantum;
1029       break;
1030     }
1031     case RGBComponentType:
1032     {
1033       samples_per_pixel=3;
1034       quantum_type=RGBQuantum;
1035       break;
1036     }
1037     case ABGRComponentType:
1038     case RGBAComponentType:
1039     {
1040       image->matte=MagickTrue;
1041       samples_per_pixel=4;
1042       quantum_type=RGBAQuantum;
1043       break;
1044     }
1045     default:
1046       break;
1047   }
1048   switch (component_type)
1049   {
1050     case CbYCrY422ComponentType:
1051     case CbYACrYA4224ComponentType:
1052     case CbYCr444ComponentType:
1053     {
1054       image->colorspace=Rec709YCbCrColorspace;
1055       break;
1056     }
1057     case LumaComponentType:
1058     {
1059       image->colorspace=RGBColorspace;
1060       break;
1061     }
1062     default:
1063     {
1064       image->colorspace=RGBColorspace;
1065       if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
1066         image->colorspace=LogColorspace;
1067       if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
1068         image->colorspace=LogColorspace;
1069       break;
1070     }
1071   }
1072   extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1073     dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1074   /*
1075     DPX any-bit pixel format.
1076   */
1077   status=MagickTrue;
1078   row=0;
1079   quantum_info=AcquireQuantumInfo(image_info,image);
1080   if (quantum_info == (QuantumInfo *) NULL)
1081     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1082   SetQuantumQuantum(quantum_info,32);
1083   SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1084     MagickTrue : MagickFalse);
1085   image_view=AcquireCacheView(image);
1086 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505)
1087   #pragma omp parallel for schedule(static) shared(row,status,quantum_type)
1088 #endif
1089   for (y=0; y < (long) image->rows; y++)
1090   {
1091     long
1092       offset;
1093
1094     MagickBooleanType
1095       sync;
1096
1097     register PixelPacket
1098       *q;
1099
1100     ssize_t
1101       count;
1102
1103     size_t
1104       length;
1105
1106     unsigned char
1107       *pixels;
1108
1109     if (status == MagickFalse)
1110       continue;
1111     pixels=GetQuantumPixels(quantum_info);
1112 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505)
1113   #pragma omp critical (MagickCore_ReadDPXImage)
1114 #endif
1115     {
1116       count=ReadBlob(image,extent,pixels);
1117       if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1118           (image->previous == (Image *) NULL))
1119         {
1120           MagickBooleanType
1121             proceed;
1122
1123           proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
1124           if (proceed == MagickFalse)
1125             status=MagickFalse;
1126         }
1127       offset=row++;
1128     }
1129     if (count != (ssize_t) extent)
1130       status=MagickFalse;
1131     q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1,
1132       exception);
1133     if (q == (PixelPacket *) NULL)
1134       {
1135         status=MagickFalse;
1136         continue;
1137       }
1138     length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
1139       pixels,exception);
1140     sync=SyncCacheViewAuthenticPixels(image_view,exception);
1141     if (sync == MagickFalse)
1142       status=MagickFalse;
1143   }
1144   image_view=DestroyCacheView(image_view);
1145   quantum_info=DestroyQuantumInfo(quantum_info);
1146   if (status == MagickFalse)
1147     ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1148   SetQuantumImageType(image,quantum_type);
1149   if (EOFBlob(image) != MagickFalse)
1150     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1151       image->filename);
1152   (void) CloseBlob(image);
1153   return(GetFirstImageInList(image));
1154 }
1155 \f
1156 /*
1157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1158 %                                                                             %
1159 %                                                                             %
1160 %                                                                             %
1161 %   R e g i s t e r D P X I m a g e                                           %
1162 %                                                                             %
1163 %                                                                             %
1164 %                                                                             %
1165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1166 %
1167 %  RegisterDPXImage() adds properties for the DPX image format to
1168 %  the list of supported formats.  The properties include the image format
1169 %  tag, a method to read and/or write the format, whether the format
1170 %  supports the saving of more than one frame to the same file or blob,
1171 %  whether the format supports native in-memory I/O, and a brief
1172 %  description of the format.
1173 %
1174 %  The format of the RegisterDPXImage method is:
1175 %
1176 %      unsigned long RegisterDPXImage(void)
1177 %
1178 */
1179 ModuleExport unsigned long RegisterDPXImage(void)
1180 {
1181   MagickInfo
1182     *entry;
1183
1184   static const char
1185     *DPXNote =
1186     {
1187       "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1188       "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1189     };
1190
1191   entry=SetMagickInfo("DPX");
1192   entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1193   entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1194   entry->magick=(IsImageFormatHandler *) IsDPX;
1195   entry->adjoin=MagickFalse;
1196   entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1197   entry->note=ConstantString(DPXNote);
1198   entry->module=ConstantString("DPX");
1199   (void) RegisterMagickInfo(entry);
1200   return(MagickImageCoderSignature);
1201 }
1202 \f
1203 /*
1204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1205 %                                                                             %
1206 %                                                                             %
1207 %                                                                             %
1208 %   U n r e g i s t e r D P X I m a g e                                       %
1209 %                                                                             %
1210 %                                                                             %
1211 %                                                                             %
1212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1213 %
1214 %  UnregisterDPXImage() removes format registrations made by the
1215 %  DPX module from the list of supported formats.
1216 %
1217 %  The format of the UnregisterDPXImage method is:
1218 %
1219 %      UnregisterDPXImage(void)
1220 %
1221 */
1222 ModuleExport void UnregisterDPXImage(void)
1223 {
1224   (void) UnregisterMagickInfo("DPX");
1225 }
1226 \f
1227 /*
1228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1229 %                                                                             %
1230 %                                                                             %
1231 %                                                                             %
1232 %   W r i t e D P X I m a g e                                                 %
1233 %                                                                             %
1234 %                                                                             %
1235 %                                                                             %
1236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1237 %
1238 %  WriteDPXImage() writes an image in DPX encoded image format.
1239 %
1240 %  The format of the WriteDPXImage method is:
1241 %
1242 %      MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image)
1243 %
1244 %  A description of each parameter follows.
1245 %
1246 %    o image_info: the image info.
1247 %
1248 %    o image:  The image.
1249 %
1250 */
1251
1252 static inline const char *GetDPXProperty(const ImageInfo *image_info,
1253   const Image *image,const char *property)
1254 {
1255   const char
1256     *value;
1257
1258   value=GetImageOption(image_info,property);
1259   if (value != (const char *) NULL)
1260     return(value);
1261   return(GetImageProperty(image,property));
1262 }
1263
1264 static unsigned int StringToTimeCode(const char *key)
1265 {
1266   char
1267     buffer[2];
1268
1269   register long
1270     i;
1271
1272   unsigned int
1273     shift,
1274     value;
1275
1276   value=0;
1277   shift=28;
1278   buffer[1]='\0';
1279   for (i=0; (*key != 0) && (i < 11); i++)
1280   {
1281     if (isxdigit((int) ((unsigned char) *key)) == 0)
1282       {
1283         key++;
1284         continue;
1285       }
1286     buffer[0]=(*key++);
1287     value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1288     shift-=4;
1289   }
1290   return(value);
1291 }
1292
1293 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image)
1294 {
1295   const char
1296     *value;
1297
1298   const StringInfo
1299     *profile;
1300
1301   DPXInfo
1302     dpx;
1303
1304   long
1305     horizontal_factor,
1306     vertical_factor,
1307     y;
1308
1309   MagickBooleanType
1310     status;
1311
1312   MagickOffsetType
1313     offset;
1314
1315   MagickStatusType
1316     flags;
1317
1318   GeometryInfo
1319     geometry_info;
1320
1321   QuantumInfo
1322     *quantum_info;
1323
1324   QuantumType
1325     quantum_type;
1326
1327   register const PixelPacket
1328     *p;
1329
1330   register long
1331     i;
1332
1333   size_t
1334     extent;
1335
1336   ssize_t
1337     count;
1338
1339   time_t
1340     seconds;
1341
1342   unsigned char
1343     *pixels;
1344
1345   /*
1346     Open output image file.
1347   */
1348   assert(image_info != (const ImageInfo *) NULL);
1349   assert(image_info->signature == MagickSignature);
1350   assert(image != (Image *) NULL);
1351   assert(image->signature == MagickSignature);
1352   if (image->debug != MagickFalse)
1353     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1354   horizontal_factor=4;
1355   vertical_factor=4;
1356   if (image_info->sampling_factor != (char *) NULL)
1357     {
1358       GeometryInfo
1359         geometry_info;
1360
1361       MagickStatusType
1362         flags;
1363
1364       flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1365       horizontal_factor=(long) geometry_info.rho;
1366       vertical_factor=(long) geometry_info.sigma;
1367       if ((flags & SigmaValue) == 0)
1368         vertical_factor=horizontal_factor;
1369       if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1370           (horizontal_factor != 4) && (vertical_factor != 1) &&
1371           (vertical_factor != 2) && (vertical_factor != 4))
1372         ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1373     }
1374   if ((image->colorspace == YCbCrColorspace) &&
1375       ((horizontal_factor == 2) || (vertical_factor == 2)))
1376     if ((image->columns % 2) != 0)
1377       image->columns++;
1378   status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1379   if (status == MagickFalse)
1380     return(status);
1381   /*
1382     Write file header.
1383   */
1384   (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1385   offset=0;
1386   dpx.file.magic=0x53445058U;
1387   offset+=WriteBlobLong(image,dpx.file.magic);
1388   dpx.file.image_offset=0x2000U;
1389   profile=GetImageProfile(image,"dpx:user.data");
1390   if (profile != (StringInfo *) NULL)
1391     {
1392       dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1393       dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1394     }
1395   offset+=WriteBlobLong(image,dpx.file.image_offset);
1396   (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1397   offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1398   dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1399     dpx.file.image_offset);
1400   offset+=WriteBlobLong(image,dpx.file.file_size);
1401   dpx.file.ditto_key=1U;  /* new frame */
1402   offset+=WriteBlobLong(image,dpx.file.ditto_key);
1403   dpx.file.generic_size=0x00000680U;
1404   offset+=WriteBlobLong(image,dpx.file.generic_size);
1405   dpx.file.industry_size=0x00000180U;
1406   offset+=WriteBlobLong(image,dpx.file.industry_size);
1407   dpx.file.user_size=0;
1408   if (profile != (StringInfo *) NULL)
1409     {
1410       dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1411       dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1412     }
1413   offset+=WriteBlobLong(image,dpx.file.user_size);
1414   value=GetDPXProperty(image_info,image,"dpx:file.filename");
1415   if (value != (const char *) NULL)
1416     (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1417   offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1418     dpx.file.filename);
1419   seconds=time((time_t *) NULL);
1420   (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1421     dpx.file.timestamp);
1422   offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1423     dpx.file.timestamp);
1424   (void) strncpy(dpx.file.creator,GetMagickVersion((unsigned long *) NULL),
1425     sizeof(dpx.file.creator));
1426   value=GetDPXProperty(image_info,image,"dpx:file.creator");
1427   if (value != (const char *) NULL)
1428     (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1429   offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1430     dpx.file.creator);
1431   value=GetDPXProperty(image_info,image,"dpx:file.project");
1432   if (value != (const char *) NULL)
1433     (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1434   offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1435     dpx.file.project);
1436   value=GetDPXProperty(image_info,image,"dpx:file.copyright");
1437   if (value != (const char *) NULL)
1438     (void) strncpy(dpx.file.copyright,value,
1439       sizeof(dpx.file.copyright));
1440   offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1441     dpx.file.copyright);
1442   dpx.file.encrypt_key=(~0U);
1443   offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1444   offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1445     dpx.file.reserve);
1446   /*
1447     Write image header.
1448   */
1449   dpx.image.orientation=0x00;  /* left-to-right; top-to-bottom */
1450   offset+=WriteBlobShort(image,dpx.image.orientation);
1451   dpx.image.number_elements=1;
1452   offset+=WriteBlobShort(image,dpx.image.number_elements);
1453   if ((image->columns != (unsigned int) image->columns) ||
1454       (image->rows != (unsigned int) image->rows))
1455     ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1456   offset+=WriteBlobLong(image,(unsigned int) image->columns);
1457   offset+=WriteBlobLong(image,(unsigned int) image->rows);
1458   for (i=0; i < 8; i++)
1459   {
1460     dpx.image.image_element[i].data_sign=0U;
1461     offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1462     dpx.image.image_element[i].low_data=0U;
1463     offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1464     dpx.image.image_element[i].low_quantity=0.0f;
1465     offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1466     dpx.image.image_element[i].high_data=0U;
1467     offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1468     dpx.image.image_element[i].high_quantity=0.0f;
1469     offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1470     dpx.image.image_element[i].descriptor=0;
1471     if (i == 0)
1472       switch (image->colorspace)
1473       {
1474         case Rec601YCbCrColorspace:
1475         case Rec709YCbCrColorspace:
1476         case YCbCrColorspace:
1477         {
1478           dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1479           if (image->matte != MagickFalse)
1480             dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1481           break;
1482         }
1483         default:
1484         {
1485           dpx.image.image_element[i].descriptor=RGBComponentType;
1486           if (image->matte != MagickFalse)
1487             dpx.image.image_element[i].descriptor=RGBAComponentType;
1488           if ((IsGrayImage(image,&image->exception) != MagickFalse) &&
1489               (image->matte == MagickFalse))
1490             dpx.image.image_element[i].descriptor=LumaComponentType;
1491           break;
1492         }
1493       }
1494     offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1495     dpx.image.image_element[i].transfer=0;
1496     if (image->colorspace == LogColorspace)
1497       dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
1498     offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
1499     dpx.image.image_element[i].colorimetric=0;
1500     offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1501     dpx.image.image_element[i].bit_size=0;
1502     if (i == 0)
1503       dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1504     offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1505     dpx.image.image_element[i].packing=0;
1506     if ((image->depth == 10) || (image->depth == 12))
1507       dpx.image.image_element[i].packing=1;
1508     offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1509     dpx.image.image_element[i].encoding=0;
1510     offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1511     dpx.image.image_element[i].data_offset=0U;
1512     if (i == 0)
1513       dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1514     offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1515     dpx.image.image_element[i].end_of_line_padding=0U;
1516     offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1517     offset+=WriteBlobLong(image,
1518       dpx.image.image_element[i].end_of_image_padding);
1519     offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1520       (unsigned char *) dpx.image.image_element[i].description);
1521   }
1522   offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1523     dpx.image.reserve);
1524   /*
1525     Write orientation header.
1526   */
1527   if ((image->rows != image->magick_rows) ||
1528       (image->columns != image->magick_columns))
1529     {
1530       /*
1531         These properties are not valid if image size changed.
1532       */
1533       (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1534       (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1535       (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1536       (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1537       (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1538       (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1539     }
1540   dpx.orientation.x_offset=0U;
1541   value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset");
1542   if (value != (const char *) NULL)
1543     dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1544   offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1545   dpx.orientation.y_offset=0U;
1546   value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset");
1547   if (value != (const char *) NULL)
1548     dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1549   offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1550   dpx.orientation.x_center=0.0f;
1551   value=GetDPXProperty(image_info,image,"dpx:orientation.x_center");
1552   if (value != (const char *) NULL)
1553     dpx.orientation.x_center=StringToDouble(value);
1554   offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1555   dpx.orientation.y_center=0.0f;
1556   value=GetDPXProperty(image_info,image,"dpx:orientation.y_center");
1557   if (value != (const char *) NULL)
1558     dpx.orientation.y_center=StringToDouble(value);
1559   offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1560   dpx.orientation.x_size=0U;
1561   value=GetDPXProperty(image_info,image,"dpx:orientation.x_size");
1562   if (value != (const char *) NULL)
1563     dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1564   offset+=WriteBlobLong(image,dpx.orientation.x_size);
1565   dpx.orientation.y_size=0U;
1566   value=GetDPXProperty(image_info,image,"dpx:orientation.y_size");
1567   if (value != (const char *) NULL)
1568     dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1569   offset+=WriteBlobLong(image,dpx.orientation.y_size);
1570   value=GetDPXProperty(image_info,image,"dpx:orientation.filename");
1571   if (value != (const char *) NULL)
1572     (void) strncpy(dpx.orientation.filename,value,
1573       sizeof(dpx.orientation.filename));
1574   offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1575     dpx.orientation.filename);
1576   offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1577     dpx.orientation.timestamp);
1578   value=GetDPXProperty(image_info,image,"dpx:orientation.device");
1579   if (value != (const char *) NULL)
1580     (void) strncpy(dpx.orientation.device,value,
1581       sizeof(dpx.orientation.device));
1582   offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1583     dpx.orientation.device);
1584   offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1585     dpx.orientation.serial);
1586   for (i=0; i < 4; i++)
1587     dpx.orientation.border[i]=0;
1588   value=GetDPXProperty(image_info,image,"dpx:orientation.border");
1589   if (value != (const char *) NULL)
1590     {
1591       flags=ParseGeometry(value,&geometry_info);
1592       if ((flags & SigmaValue) == 0)
1593         geometry_info.sigma=geometry_info.rho;
1594       dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1595       dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1596       dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1597       dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1598     }
1599   for (i=0; i < 4; i++)
1600     offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1601   for (i=0; i < 2; i++)
1602     dpx.orientation.aspect_ratio[i]=0U;
1603   value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio");
1604   if (value != (const char *) NULL)
1605     {
1606       flags=ParseGeometry(value,&geometry_info);
1607       if ((flags & SigmaValue) == 0)
1608         geometry_info.sigma=geometry_info.rho;
1609       dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1610       dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1611     }
1612   for (i=0; i < 2; i++)
1613     offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1614   offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1615     dpx.orientation.reserve);
1616   /*
1617     Write film header.
1618   */
1619   *dpx.film.id='\0';
1620   value=GetDPXProperty(image_info,image,"dpx:film.id");
1621   if (value != (const char *) NULL)
1622     (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1623   offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1624   *dpx.film.type='\0';
1625   value=GetDPXProperty(image_info,image,"dpx:film.type");
1626   if (value != (const char *) NULL)
1627     (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1628   offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1629     dpx.film.type);
1630   *dpx.film.offset='\0';
1631   value=GetDPXProperty(image_info,image,"dpx:film.offset");
1632   if (value != (const char *) NULL)
1633     (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1634   offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1635     dpx.film.offset);
1636   *dpx.film.prefix='\0';
1637   value=GetDPXProperty(image_info,image,"dpx:film.prefix");
1638   if (value != (const char *) NULL)
1639     (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1640   offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1641     dpx.film.prefix);
1642   *dpx.film.count='\0';
1643   value=GetDPXProperty(image_info,image,"dpx:film.count");
1644   if (value != (const char *) NULL)
1645     (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1646   offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1647     dpx.film.count);
1648   *dpx.film.format='\0';
1649   value=GetDPXProperty(image_info,image,"dpx:film.format");
1650   if (value != (const char *) NULL)
1651     (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1652   offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1653     dpx.film.format);
1654   dpx.film.frame_position=0U;
1655   value=GetDPXProperty(image_info,image,"dpx:film.frame_position");
1656   if (value != (const char *) NULL)
1657     dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1658   offset+=WriteBlobLong(image,dpx.film.frame_position);
1659   dpx.film.sequence_extent=0U;
1660   value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent");
1661   if (value != (const char *) NULL)
1662     dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1663   offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1664   dpx.film.held_count=0U;
1665   value=GetDPXProperty(image_info,image,"dpx:film.held_count");
1666   if (value != (const char *) NULL)
1667     dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1668   offset+=WriteBlobLong(image,dpx.film.held_count);
1669   dpx.film.frame_rate=0.0f;
1670   value=GetDPXProperty(image_info,image,"dpx:film.frame_rate");
1671   if (value != (const char *) NULL)
1672     dpx.film.frame_rate=StringToDouble(value);
1673   offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1674   dpx.film.shutter_angle=0.0f;
1675   value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle");
1676   if (value != (const char *) NULL)
1677     dpx.film.shutter_angle=StringToDouble(value);
1678   offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1679   *dpx.film.frame_id='\0';
1680   value=GetDPXProperty(image_info,image,"dpx:film.frame_id");
1681   if (value != (const char *) NULL)
1682     (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1683   offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1684     dpx.film.frame_id);
1685   value=GetDPXProperty(image_info,image,"dpx:film.slate");
1686   if (value != (const char *) NULL)
1687     (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1688   offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1689     dpx.film.slate);
1690   offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1691     dpx.film.reserve);
1692   /*
1693     Write television header.
1694   */
1695   value=GetDPXProperty(image_info,image,"dpx:television.time.code");
1696   if (value != (const char *) NULL)
1697     dpx.television.time_code=StringToTimeCode(value);
1698   offset+=WriteBlobLong(image,dpx.television.time_code);
1699   value=GetDPXProperty(image_info,image,"dpx:television.user.bits");
1700   if (value != (const char *) NULL)
1701     dpx.television.user_bits=StringToTimeCode(value);
1702   offset+=WriteBlobLong(image,dpx.television.user_bits);
1703   value=GetDPXProperty(image_info,image,"dpx:television.interlace");
1704   if (value != (const char *) NULL)
1705     dpx.television.interlace=(unsigned char) StringToLong(value);
1706   offset+=WriteBlobByte(image,dpx.television.interlace);
1707   value=GetDPXProperty(image_info,image,"dpx:television.field_number");
1708   if (value != (const char *) NULL)
1709     dpx.television.field_number=(unsigned char) StringToLong(value);
1710   offset+=WriteBlobByte(image,dpx.television.field_number);
1711   dpx.television.video_signal=0;
1712   value=GetDPXProperty(image_info,image,"dpx:television.video_signal");
1713   if (value != (const char *) NULL)
1714     dpx.television.video_signal=(unsigned char) StringToLong(value);
1715   offset+=WriteBlobByte(image,dpx.television.video_signal);
1716   dpx.television.padding=0;
1717   value=GetDPXProperty(image_info,image,"dpx:television.padding");
1718   if (value != (const char *) NULL)
1719     dpx.television.padding=(unsigned char) StringToLong(value);
1720   offset+=WriteBlobByte(image,dpx.television.padding);
1721   dpx.television.horizontal_sample_rate=0.0f;
1722   value=GetDPXProperty(image_info,image,
1723     "dpx:television.horizontal_sample_rate");
1724   if (value != (const char *) NULL)
1725     dpx.television.horizontal_sample_rate=StringToDouble(value);
1726   offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1727   dpx.television.vertical_sample_rate=0.0f;
1728   value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate");
1729   if (value != (const char *) NULL)
1730     dpx.television.vertical_sample_rate=StringToDouble(value);
1731   offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1732   dpx.television.frame_rate=0.0f;
1733   value=GetDPXProperty(image_info,image,"dpx:television.frame_rate");
1734   if (value != (const char *) NULL)
1735     dpx.television.frame_rate=StringToDouble(value);
1736   offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1737   dpx.television.time_offset=0.0f;
1738   value=GetDPXProperty(image_info,image,"dpx:television.time_offset");
1739   if (value != (const char *) NULL)
1740     dpx.television.time_offset=StringToDouble(value);
1741   offset+=WriteBlobFloat(image,dpx.television.time_offset);
1742   dpx.television.gamma=0.0f;
1743   value=GetDPXProperty(image_info,image,"dpx:television.gamma");
1744   if (value != (const char *) NULL)
1745     dpx.television.gamma=StringToDouble(value);
1746   offset+=WriteBlobFloat(image,dpx.television.gamma);
1747   dpx.television.black_level=0.0f;
1748   value=GetDPXProperty(image_info,image,"dpx:television.black_level");
1749   if (value != (const char *) NULL)
1750     dpx.television.black_level=StringToDouble(value);
1751   offset+=WriteBlobFloat(image,dpx.television.black_level);
1752   dpx.television.black_gain=0.0f;
1753   value=GetDPXProperty(image_info,image,"dpx:television.black_gain");
1754   if (value != (const char *) NULL)
1755     dpx.television.black_gain=StringToDouble(value);
1756   offset+=WriteBlobFloat(image,dpx.television.black_gain);
1757   dpx.television.break_point=0.0f;
1758   value=GetDPXProperty(image_info,image,"dpx:television.break_point");
1759   if (value != (const char *) NULL)
1760     dpx.television.break_point=StringToDouble(value);
1761   offset+=WriteBlobFloat(image,dpx.television.break_point);
1762   dpx.television.white_level=0.0f;
1763   value=GetDPXProperty(image_info,image,"dpx:television.white_level");
1764   if (value != (const char *) NULL)
1765     dpx.television.white_level=StringToDouble(value);
1766   offset+=WriteBlobFloat(image,dpx.television.white_level);
1767   dpx.television.integration_times=0.0f;
1768   value=GetDPXProperty(image_info,image,"dpx:television.integration_times");
1769   if (value != (const char *) NULL)
1770     dpx.television.integration_times=StringToDouble(value);
1771   offset+=WriteBlobFloat(image,dpx.television.integration_times);
1772   offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1773     dpx.television.reserve);
1774   /*
1775     Write user header.
1776   */
1777   value=GetDPXProperty(image_info,image,"dpx:user.id");
1778   if (value != (const char *) NULL)
1779     (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1780   offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1781   if (profile != (StringInfo *) NULL)
1782     offset+=WriteBlob(image,GetStringInfoLength(profile),
1783       GetStringInfoDatum(profile));
1784   while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1785   {
1786     count=WriteBlobByte(image,0x00);
1787     if (count != 1)
1788       {
1789         ThrowFileException(&image->exception,FileOpenError,"UnableToWriteFile",
1790           image->filename);
1791         break;
1792       }
1793     offset+=count;
1794   }
1795   /*
1796     Convert pixel packets to DPX raster image.
1797   */
1798   quantum_info=AcquireQuantumInfo(image_info,image);
1799   quantum_info->quantum=32;
1800   quantum_info->pack=dpx.image.image_element[0].packing == 0 ? MagickTrue :
1801     MagickFalse;
1802   quantum_type=RGBQuantum;
1803   if (image->matte != MagickFalse)
1804     quantum_type=RGBAQuantum;
1805   if (image->colorspace == YCbCrColorspace)
1806     {
1807       quantum_type=CbYCrQuantum;
1808       if (image->matte != MagickFalse)
1809         quantum_type=CbYCrAQuantum;
1810       if ((horizontal_factor == 2) || (vertical_factor == 2))
1811         quantum_type=CbYCrYQuantum;
1812     }
1813   extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
1814     image->depth,MagickTrue);
1815   if ((IsGrayImage(image,&image->exception) != MagickFalse) &&
1816       (image->matte == MagickFalse))
1817     {
1818       quantum_type=GrayQuantum;
1819       extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
1820     }
1821   pixels=GetQuantumPixels(quantum_info);
1822   for (y=0; y < (long) image->rows; y++)
1823   {
1824     p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1825     if (p == (const PixelPacket *) NULL)
1826       break;
1827     (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
1828       quantum_type,pixels,&image->exception);
1829     count=WriteBlob(image,extent,pixels);
1830     if (count != (ssize_t) extent)
1831       break;
1832     status=SetImageProgress(image,SaveImageTag,y,image->rows);
1833     if (status == MagickFalse)
1834       break;
1835   }
1836   quantum_info=DestroyQuantumInfo(quantum_info);
1837   (void) CloseBlob(image);
1838   return(status);
1839 }