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