2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write SMTPE DPX Image Format %
20 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/blob-private.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/colorspace.h"
49 #include "MagickCore/exception.h"
50 #include "MagickCore/exception-private.h"
51 #include "MagickCore/geometry.h"
52 #include "MagickCore/image.h"
53 #include "MagickCore/image-private.h"
54 #include "MagickCore/list.h"
55 #include "MagickCore/magick.h"
56 #include "MagickCore/memory_.h"
57 #include "MagickCore/module.h"
58 #include "MagickCore/monitor.h"
59 #include "MagickCore/monitor-private.h"
60 #include "MagickCore/option.h"
61 #include "MagickCore/pixel-accessor.h"
62 #include "MagickCore/profile.h"
63 #include "MagickCore/property.h"
64 #include "MagickCore/quantum-private.h"
65 #include "MagickCore/static.h"
66 #include "MagickCore/string_.h"
67 #include "MagickCore/string-private.h"
74 UserDefinedColorimetric = 0,
75 PrintingDensityColorimetric = 1,
76 LinearColorimetric = 2,
77 LogarithmicColorimetric = 3,
78 UnspecifiedVideoColorimetric = 4,
79 SMTPE_274MColorimetric = 5,
80 ITU_R709Colorimetric = 6,
81 ITU_R601_625LColorimetric = 7,
82 ITU_R601_525LColorimetric = 8,
83 NTSCCompositeVideoColorimetric = 9,
84 PALCompositeVideoColorimetric = 10,
85 ZDepthLinearColorimetric = 11,
86 DepthHomogeneousColorimetric = 12
91 UndefinedComponentType = 0,
93 GreenComponentType = 2,
94 BlueComponentType = 3,
95 AlphaComponentType = 4,
96 LumaComponentType = 6,
97 ColorDifferenceCbCrComponentType = 7,
98 DepthComponentType = 8,
99 CompositeVideoComponentType = 9,
100 RGBComponentType = 50,
101 RGBAComponentType = 51,
102 ABGRComponentType = 52,
103 CbYCrY422ComponentType = 100,
104 CbYACrYA4224ComponentType = 101,
105 CbYCr444ComponentType = 102,
106 CbYCrA4444ComponentType = 103,
107 UserDef2ElementComponentType = 150,
108 UserDef3ElementComponentType = 151,
109 UserDef4ElementComponentType = 152,
110 UserDef5ElementComponentType = 153,
111 UserDef6ElementComponentType = 154,
112 UserDef7ElementComponentType = 155,
113 UserDef8ElementComponentType = 156
118 TransferCharacteristicUserDefined = 0,
119 TransferCharacteristicPrintingDensity = 1,
120 TransferCharacteristicLinear = 2,
121 TransferCharacteristicLogarithmic = 3,
122 TransferCharacteristicUnspecifiedVideo = 4,
123 TransferCharacteristicSMTPE274M = 5, /* 1920x1080 TV */
124 TransferCharacteristicITU_R709 = 6, /* ITU R709 */
125 TransferCharacteristicITU_R601_625L = 7, /* 625 Line */
126 TransferCharacteristicITU_R601_525L = 8, /* 525 Line */
127 TransferCharacteristicNTSCCompositeVideo = 9,
128 TransferCharacteristicPALCompositeVideo = 10,
129 TransferCharacteristicZDepthLinear = 11,
130 TransferCharacteristicZDepthHomogeneous = 12
131 } DPXTransferCharacteristic;
133 typedef struct _DPXFileInfo
163 typedef struct _DPXFilmInfo
188 typedef struct _DPXImageElement
205 transfer_characteristic,
216 end_of_image_padding;
222 typedef struct _DPXImageInfo
239 typedef struct _DPXOrientationInfo
267 } DPXOrientationInfo;
269 typedef struct _DPXTelevisionInfo
282 horizontal_sample_rate,
283 vertical_sample_rate,
297 typedef struct _DPXUserInfo
303 typedef struct DPXInfo
325 Forward declaractions.
327 static MagickBooleanType
328 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % IsDPX() returns MagickTrue if the image format type, identified by the
342 % magick string, is DPX.
344 % The format of the IsDPX method is:
346 % MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
348 % A description of each parameter follows:
350 % o magick: compare image format pattern against these bytes.
352 % o extent: Specifies the extent of the magick string.
355 static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
359 if (memcmp(magick,"SDPX",4) == 0)
361 if (memcmp(magick,"XPDS",4) == 0)
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371 % R e a d D P X I m a g e %
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 % ReadDPXImage() reads an DPX X image file and returns it. It
378 % allocates the memory necessary for the new Image structure and returns a
379 % pointer to the new image.
381 % The format of the ReadDPXImage method is:
383 % Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
385 % A description of each parameter follows:
387 % o image_info: the image info.
389 % o exception: return any errors or warnings in this structure.
393 static size_t GetBytesPerRow(const size_t columns,
394 const size_t samples_per_pixel,const size_t bits_per_pixel,
395 const MagickBooleanType pad)
400 switch (bits_per_pixel)
404 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
411 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
417 if (pad == MagickFalse)
419 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
423 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
428 if (pad == MagickFalse)
430 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
434 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
439 bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+8)/
445 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
451 bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
456 return(bytes_per_row);
459 static const char *GetImageTransferCharacteristic(
460 const DPXTransferCharacteristic characteristic)
466 Get the element transfer characteristic.
468 switch(characteristic)
470 case TransferCharacteristicUserDefined:
472 transfer="UserDefined";
475 case TransferCharacteristicPrintingDensity:
477 transfer="PrintingDensity";
480 case TransferCharacteristicLinear:
485 case TransferCharacteristicLogarithmic:
487 transfer="Logarithmic";
490 case TransferCharacteristicUnspecifiedVideo:
492 transfer="UnspecifiedVideo";
495 case TransferCharacteristicSMTPE274M:
497 transfer="SMTPE274M";
500 case TransferCharacteristicITU_R709:
505 case TransferCharacteristicITU_R601_625L:
507 transfer="ITU-R601-625L";
510 case TransferCharacteristicITU_R601_525L:
512 transfer="ITU-R601-525L";
515 case TransferCharacteristicNTSCCompositeVideo:
517 transfer="NTSCCompositeVideo";
520 case TransferCharacteristicPALCompositeVideo:
522 transfer="PALCompositeVideo";
525 case TransferCharacteristicZDepthLinear:
527 transfer="ZDepthLinear";
530 case TransferCharacteristicZDepthHomogeneous:
532 transfer="ZDepthHomogeneous";
541 static inline MagickBooleanType IsFloatDefined(const float value)
552 quantum.unsigned_value=0U;
553 quantum.float_value=(float) value;
554 if (quantum.unsigned_value == 0U)
559 static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
560 ChromaticityInfo *chromaticity_info)
564 case SMTPE_274MColorimetric:
565 case ITU_R709Colorimetric:
567 chromaticity_info->red_primary.x=0.640;
568 chromaticity_info->red_primary.y=0.330;
569 chromaticity_info->red_primary.z=0.030;
570 chromaticity_info->green_primary.x=0.300;
571 chromaticity_info->green_primary.y=0.600;
572 chromaticity_info->green_primary.z=0.100;
573 chromaticity_info->blue_primary.x=0.150;
574 chromaticity_info->blue_primary.y=0.060;
575 chromaticity_info->blue_primary.z=0.790;
576 chromaticity_info->white_point.x=0.3127;
577 chromaticity_info->white_point.y=0.3290;
578 chromaticity_info->white_point.z=0.3582;
581 case NTSCCompositeVideoColorimetric:
583 chromaticity_info->red_primary.x=0.67;
584 chromaticity_info->red_primary.y=0.33;
585 chromaticity_info->red_primary.z=0.00;
586 chromaticity_info->green_primary.x=0.21;
587 chromaticity_info->green_primary.y=0.71;
588 chromaticity_info->green_primary.z=0.08;
589 chromaticity_info->blue_primary.x=0.14;
590 chromaticity_info->blue_primary.y=0.08;
591 chromaticity_info->blue_primary.z=0.78;
592 chromaticity_info->white_point.x=0.310;
593 chromaticity_info->white_point.y=0.316;
594 chromaticity_info->white_point.z=0.374;
597 case PALCompositeVideoColorimetric:
599 chromaticity_info->red_primary.x=0.640;
600 chromaticity_info->red_primary.y=0.330;
601 chromaticity_info->red_primary.z=0.030;
602 chromaticity_info->green_primary.x=0.290;
603 chromaticity_info->green_primary.y=0.600;
604 chromaticity_info->green_primary.z=0.110;
605 chromaticity_info->blue_primary.x=0.150;
606 chromaticity_info->blue_primary.y=0.060;
607 chromaticity_info->blue_primary.z=0.790;
608 chromaticity_info->white_point.x=0.3127;
609 chromaticity_info->white_point.y=0.3290;
610 chromaticity_info->white_point.z=0.3582;
618 static void TimeCodeToString(const size_t timestamp,char *code)
630 for (i=0; i <= TimeFields; i++)
632 (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x",
633 (unsigned int) ((timestamp >> shift) & 0x0fU));
635 if (((i % 2) != 0) && (i < TimeFields))
642 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
646 value[MaxTextExtent];
685 assert(image_info != (const ImageInfo *) NULL);
686 assert(image_info->signature == MagickSignature);
687 if (image_info->debug != MagickFalse)
688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
689 image_info->filename);
690 assert(exception != (ExceptionInfo *) NULL);
691 assert(exception->signature == MagickSignature);
692 image=AcquireImage(image_info,exception);
693 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
694 if (status == MagickFalse)
696 image=DestroyImageList(image);
697 return((Image *) NULL);
700 Read DPX file header.
703 count=ReadBlob(image,4,(unsigned char *) magick);
705 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
706 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
707 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
708 image->endian=LSBEndian;
709 if (LocaleNCompare(magick,"SDPX",4) == 0)
710 image->endian=MSBEndian;
711 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
712 dpx.file.image_offset=ReadBlobLong(image);
714 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
716 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
717 dpx.file.file_size=ReadBlobLong(image);
719 dpx.file.ditto_key=ReadBlobLong(image);
721 if (dpx.file.ditto_key != ~0UL)
722 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
724 dpx.file.generic_size=ReadBlobLong(image);
726 dpx.file.industry_size=ReadBlobLong(image);
728 dpx.file.user_size=ReadBlobLong(image);
730 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
732 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
734 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
735 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
737 if (*dpx.file.timestamp != '\0')
738 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
740 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
742 if (*dpx.file.creator != '\0')
744 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
746 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
748 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
750 if (*dpx.file.project != '\0')
752 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
754 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
756 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
758 if (*dpx.file.copyright != '\0')
760 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
762 (void) FormatImageProperty(image,"copyright","%.100s",
765 dpx.file.encrypt_key=ReadBlobLong(image);
767 if (dpx.file.encrypt_key != ~0UL)
768 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
769 dpx.file.encrypt_key);
770 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
773 Read DPX image header.
775 dpx.image.orientation=ReadBlobShort(image);
777 if (dpx.image.orientation != (unsigned short) ~0)
778 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
779 dpx.image.orientation);
780 switch (dpx.image.orientation)
783 case 0: image->orientation=TopLeftOrientation; break;
784 case 1: image->orientation=TopRightOrientation; break;
785 case 2: image->orientation=BottomLeftOrientation; break;
786 case 3: image->orientation=BottomRightOrientation; break;
787 case 4: image->orientation=LeftTopOrientation; break;
788 case 5: image->orientation=RightTopOrientation; break;
789 case 6: image->orientation=LeftBottomOrientation; break;
790 case 7: image->orientation=RightBottomOrientation; break;
792 dpx.image.number_elements=ReadBlobShort(image);
794 dpx.image.pixels_per_line=ReadBlobLong(image);
796 image->columns=dpx.image.pixels_per_line;
797 dpx.image.lines_per_element=ReadBlobLong(image);
799 image->rows=dpx.image.lines_per_element;
800 for (i=0; i < 8; i++)
803 property[MaxTextExtent];
805 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
807 dpx.image.image_element[i].low_data=ReadBlobLong(image);
809 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
811 dpx.image.image_element[i].high_data=ReadBlobLong(image);
813 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
815 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
817 dpx.image.image_element[i].transfer_characteristic=(unsigned char)
819 (void) FormatLocaleString(property,MaxTextExtent,
820 "dpx:image.element[%lu].transfer-characteristic",(long) i);
821 (void) FormatImageProperty(image,property,"%s",
822 GetImageTransferCharacteristic((DPXTransferCharacteristic)
823 dpx.image.image_element[i].transfer_characteristic));
825 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
827 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
829 dpx.image.image_element[i].packing=ReadBlobShort(image);
831 dpx.image.image_element[i].encoding=ReadBlobShort(image);
833 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
835 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
837 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
839 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
840 (unsigned char *) dpx.image.image_element[i].description);
842 SetImageColorspace(image,RGBColorspace,exception);
843 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
845 if (dpx.file.image_offset >= 1664U)
848 Read DPX orientation header.
850 dpx.orientation.x_offset=ReadBlobLong(image);
852 if (dpx.orientation.x_offset != ~0UL)
853 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
854 dpx.orientation.x_offset);
855 dpx.orientation.y_offset=ReadBlobLong(image);
857 if (dpx.orientation.y_offset != ~0UL)
858 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
859 dpx.orientation.y_offset);
860 dpx.orientation.x_center=ReadBlobFloat(image);
862 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
863 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
864 dpx.orientation.x_center);
865 dpx.orientation.y_center=ReadBlobFloat(image);
867 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
868 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
869 dpx.orientation.y_center);
870 dpx.orientation.x_size=ReadBlobLong(image);
872 if (dpx.orientation.x_size != ~0UL)
873 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
874 dpx.orientation.x_size);
875 dpx.orientation.y_size=ReadBlobLong(image);
877 if (dpx.orientation.y_size != ~0UL)
878 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
879 dpx.orientation.y_size);
880 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
881 dpx.orientation.filename);
882 if (*dpx.orientation.filename != '\0')
883 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
884 dpx.orientation.filename);
885 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
886 dpx.orientation.timestamp);
887 if (*dpx.orientation.timestamp != '\0')
888 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
889 dpx.orientation.timestamp);
890 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
891 dpx.orientation.device);
892 if (*dpx.orientation.device != '\0')
893 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
894 dpx.orientation.device);
895 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
896 dpx.orientation.serial);
897 if (*dpx.orientation.serial != '\0')
898 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
899 dpx.orientation.serial);
900 for (i=0; i < 4; i++)
902 dpx.orientation.border[i]=ReadBlobShort(image);
905 if ((dpx.orientation.border[0] != (unsigned short) (~0)) &&
906 (dpx.orientation.border[1] != (unsigned short) (~0)))
907 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d",
908 dpx.orientation.border[0],dpx.orientation.border[1],
909 dpx.orientation.border[2],dpx.orientation.border[3]);
910 for (i=0; i < 2; i++)
912 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
915 if ((dpx.orientation.aspect_ratio[0] != ~0UL) &&
916 (dpx.orientation.aspect_ratio[1] != ~0UL))
917 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
918 "%ux%u",dpx.orientation.aspect_ratio[0],
919 dpx.orientation.aspect_ratio[1]);
920 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
921 dpx.orientation.reserve);
923 if (dpx.file.image_offset >= 1920U)
926 Read DPX film header.
928 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
929 if (*dpx.film.type != '\0')
930 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
931 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
933 if (*dpx.film.type != '\0')
934 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
935 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
937 if (*dpx.film.offset != '\0')
938 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
940 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
942 if (*dpx.film.prefix != '\0')
943 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
945 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
947 if (*dpx.film.count != '\0')
948 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
950 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
952 if (*dpx.film.format != '\0')
953 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
955 dpx.film.frame_position=ReadBlobLong(image);
957 if (dpx.film.frame_position != ~0UL)
958 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
959 dpx.film.frame_position);
960 dpx.film.sequence_extent=ReadBlobLong(image);
962 if (dpx.film.sequence_extent != ~0UL)
963 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
964 dpx.film.sequence_extent);
965 dpx.film.held_count=ReadBlobLong(image);
967 if (dpx.film.held_count != ~0UL)
968 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
969 dpx.film.held_count);
970 dpx.film.frame_rate=ReadBlobFloat(image);
972 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
973 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
974 dpx.film.frame_rate);
975 dpx.film.shutter_angle=ReadBlobFloat(image);
977 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
978 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
979 dpx.film.shutter_angle);
980 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
982 if (*dpx.film.frame_id != '\0')
983 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
985 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
987 if (*dpx.film.slate != '\0')
988 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
990 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
993 if (dpx.file.image_offset >= 2048U)
996 Read DPX television header.
998 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
1000 TimeCodeToString(dpx.television.time_code,value);
1001 (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
1002 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
1004 TimeCodeToString(dpx.television.user_bits,value);
1005 (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
1006 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
1008 if (dpx.television.interlace != 0)
1009 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
1010 (double) dpx.television.interlace);
1011 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
1013 if (dpx.television.field_number != 0)
1014 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
1015 (double) dpx.television.field_number);
1016 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
1018 if (dpx.television.video_signal != 0)
1019 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
1020 (double) dpx.television.video_signal);
1021 dpx.television.padding=(unsigned char) ReadBlobByte(image);
1023 if (dpx.television.padding != 0)
1024 (void) FormatImageProperty(image,"dpx:television.padding","%d",
1025 dpx.television.padding);
1026 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
1028 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
1029 (void) FormatImageProperty(image,
1030 "dpx:television.horizontal_sample_rate","%g",
1031 dpx.television.horizontal_sample_rate);
1032 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
1034 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
1035 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
1036 "%g",dpx.television.vertical_sample_rate);
1037 dpx.television.frame_rate=ReadBlobFloat(image);
1039 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
1040 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
1041 dpx.television.frame_rate);
1042 dpx.television.time_offset=ReadBlobFloat(image);
1044 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
1045 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
1046 dpx.television.time_offset);
1047 dpx.television.gamma=ReadBlobFloat(image);
1049 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
1050 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
1051 dpx.television.gamma);
1052 dpx.television.black_level=ReadBlobFloat(image);
1054 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
1055 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
1056 dpx.television.black_level);
1057 dpx.television.black_gain=ReadBlobFloat(image);
1059 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
1060 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
1061 dpx.television.black_gain);
1062 dpx.television.break_point=ReadBlobFloat(image);
1064 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
1065 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
1066 dpx.television.break_point);
1067 dpx.television.white_level=ReadBlobFloat(image);
1069 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
1070 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
1071 dpx.television.white_level);
1072 dpx.television.integration_times=ReadBlobFloat(image);
1074 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
1075 (void) FormatImageProperty(image,"dpx:television.integration_times",
1076 "%g",dpx.television.integration_times);
1077 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1078 dpx.television.reserve);
1080 if (dpx.file.image_offset > 2080U)
1083 Read DPX user header.
1085 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1086 if (*dpx.user.id != '\0')
1087 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
1088 if ((dpx.file.user_size != ~0UL) &&
1089 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
1094 profile=BlobToStringInfo((const void *) NULL,
1095 dpx.file.user_size-sizeof(dpx.user.id));
1096 if (profile == (StringInfo *) NULL)
1097 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1098 offset+=ReadBlob(image,GetStringInfoLength(profile),
1099 GetStringInfoDatum(profile));
1100 (void) SetImageProfile(image,"dpx",profile,exception);
1101 profile=DestroyStringInfo(profile);
1104 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
1105 (void) ReadBlobByte(image);
1106 if (image_info->ping != MagickFalse)
1108 (void) CloseBlob(image);
1109 return(GetFirstImageInList(image));
1111 for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
1114 Convert DPX raster image to pixel packets.
1116 if ((dpx.image.image_element[n].data_offset != (unsigned int) (~0UL)) &&
1117 (dpx.image.image_element[n].data_offset != 0U))
1122 data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
1123 if (data_offset < offset)
1124 offset=SeekBlob(image,data_offset,SEEK_SET);
1126 for ( ; offset < data_offset; offset++)
1127 (void) ReadBlobByte(image);
1128 if (offset != data_offset)
1129 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1131 SetPrimaryChromaticity((DPXColorimetric)
1132 dpx.image.image_element[n].colorimetric,&image->chromaticity);
1133 image->depth=dpx.image.image_element[n].bit_size;
1134 samples_per_pixel=1;
1135 quantum_type=GrayQuantum;
1136 component_type=dpx.image.image_element[n].descriptor;
1137 switch (component_type)
1139 case CbYCrY422ComponentType:
1141 samples_per_pixel=2;
1142 quantum_type=CbYCrYQuantum;
1145 case CbYACrYA4224ComponentType:
1146 case CbYCr444ComponentType:
1148 samples_per_pixel=3;
1149 quantum_type=CbYCrQuantum;
1152 case RGBComponentType:
1154 samples_per_pixel=3;
1155 quantum_type=RGBQuantum;
1158 case ABGRComponentType:
1159 case RGBAComponentType:
1161 image->alpha_trait=BlendPixelTrait;
1162 samples_per_pixel=4;
1163 quantum_type=RGBAQuantum;
1169 switch (component_type)
1171 case CbYCrY422ComponentType:
1172 case CbYACrYA4224ComponentType:
1173 case CbYCr444ComponentType:
1175 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1178 case LumaComponentType:
1180 SetImageColorspace(image,GRAYColorspace,exception);
1185 SetImageColorspace(image,sRGBColorspace,exception);
1186 if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
1187 SetImageColorspace(image,LogColorspace,exception);
1188 if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
1189 SetImageColorspace(image,LogColorspace,exception);
1193 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1194 dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
1196 DPX any-bit pixel format.
1200 quantum_info=AcquireQuantumInfo(image_info,image);
1201 if (quantum_info == (QuantumInfo *) NULL)
1202 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1203 SetQuantumQuantum(quantum_info,32);
1204 SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
1205 MagickTrue : MagickFalse);
1206 for (y=0; y < (ssize_t) image->rows; y++)
1224 if (status == MagickFalse)
1226 pixels=GetQuantumPixels(quantum_info);
1228 count=ReadBlob(image,extent,pixels);
1229 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1230 (image->previous == (Image *) NULL))
1235 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1237 if (proceed == MagickFalse)
1242 if (count != (ssize_t) extent)
1244 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
1245 if (q == (Quantum *) NULL)
1250 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1251 quantum_type,pixels,exception);
1253 sync=SyncAuthenticPixels(image,exception);
1254 if (sync == MagickFalse)
1257 quantum_info=DestroyQuantumInfo(quantum_info);
1258 if (status == MagickFalse)
1259 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1260 SetQuantumImageType(image,quantum_type);
1261 if (EOFBlob(image) != MagickFalse)
1262 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1264 if ((i+1) < (ssize_t) dpx.image.number_elements)
1267 Allocate next image structure.
1269 AcquireNextImage(image_info,image,exception);
1270 if (GetNextImageInList(image) == (Image *) NULL)
1272 image=DestroyImageList(image);
1273 return((Image *) NULL);
1275 image=SyncNextImageInList(image);
1276 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1277 GetBlobSize(image));
1278 if (status == MagickFalse)
1282 (void) CloseBlob(image);
1283 return(GetFirstImageInList(image));
1287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 % R e g i s t e r D P X I m a g e %
1295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 % RegisterDPXImage() adds properties for the DPX image format to
1298 % the list of supported formats. The properties include the image format
1299 % tag, a method to read and/or write the format, whether the format
1300 % supports the saving of more than one frame to the same file or blob,
1301 % whether the format supports native in-memory I/O, and a brief
1302 % description of the format.
1304 % The format of the RegisterDPXImage method is:
1306 % size_t RegisterDPXImage(void)
1309 ModuleExport size_t RegisterDPXImage(void)
1317 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1318 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1321 entry=SetMagickInfo("DPX");
1322 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1323 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1324 entry->magick=(IsImageFormatHandler *) IsDPX;
1325 entry->adjoin=MagickFalse;
1326 entry->seekable_stream=MagickTrue;
1327 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1328 entry->note=ConstantString(DPXNote);
1329 entry->module=ConstantString("DPX");
1330 (void) RegisterMagickInfo(entry);
1331 return(MagickImageCoderSignature);
1335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1339 % U n r e g i s t e r D P X I m a g e %
1343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345 % UnregisterDPXImage() removes format registrations made by the
1346 % DPX module from the list of supported formats.
1348 % The format of the UnregisterDPXImage method is:
1350 % UnregisterDPXImage(void)
1353 ModuleExport void UnregisterDPXImage(void)
1355 (void) UnregisterMagickInfo("DPX");
1359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1363 % W r i t e D P X I m a g e %
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1369 % WriteDPXImage() writes an image in DPX encoded image format.
1371 % The format of the WriteDPXImage method is:
1373 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1374 % Image *image,ExceptionInfo *exception)
1376 % A description of each parameter follows.
1378 % o image_info: the image info.
1380 % o image: The image.
1382 % o exception: return any errors or warnings in this structure.
1386 static inline const char *GetDPXProperty(const ImageInfo *image_info,
1387 const Image *image,const char *property,ExceptionInfo *exception)
1392 value=GetImageOption(image_info,property);
1393 if (value != (const char *) NULL)
1395 return(GetImageProperty(image,property,exception));
1398 static unsigned int StringToTimeCode(const char *key)
1413 for (i=0; (*key != 0) && (i < 11); i++)
1415 if (isxdigit((int) ((unsigned char) *key)) == 0)
1421 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1427 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1428 ExceptionInfo *exception)
1457 register const Quantum
1479 Open output image file.
1481 assert(image_info != (const ImageInfo *) NULL);
1482 assert(image_info->signature == MagickSignature);
1483 assert(image != (Image *) NULL);
1484 assert(image->signature == MagickSignature);
1485 if (image->debug != MagickFalse)
1486 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1487 horizontal_factor=4;
1489 if (image_info->sampling_factor != (char *) NULL)
1497 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1498 horizontal_factor=(ssize_t) geometry_info.rho;
1499 vertical_factor=(ssize_t) geometry_info.sigma;
1500 if ((flags & SigmaValue) == 0)
1501 vertical_factor=horizontal_factor;
1502 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1503 (horizontal_factor != 4) && (vertical_factor != 1) &&
1504 (vertical_factor != 2) && (vertical_factor != 4))
1505 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1507 if ((image->colorspace == YCbCrColorspace) &&
1508 ((horizontal_factor == 2) || (vertical_factor == 2)))
1509 if ((image->columns % 2) != 0)
1511 assert(exception != (ExceptionInfo *) NULL);
1512 assert(exception->signature == MagickSignature);
1513 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1514 if (status == MagickFalse)
1519 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1521 dpx.file.magic=0x53445058U;
1522 offset+=WriteBlobLong(image,dpx.file.magic);
1523 dpx.file.image_offset=0x2000U;
1524 profile=GetImageProfile(image,"dpx");
1525 if (profile != (StringInfo *) NULL)
1527 if (GetStringInfoLength(profile) > 1048576)
1528 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1529 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1530 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1532 offset+=WriteBlobLong(image,dpx.file.image_offset);
1533 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1534 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1535 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1536 dpx.file.image_offset);
1537 offset+=WriteBlobLong(image,dpx.file.file_size);
1538 dpx.file.ditto_key=1U; /* new frame */
1539 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1540 dpx.file.generic_size=0x00000680U;
1541 offset+=WriteBlobLong(image,dpx.file.generic_size);
1542 dpx.file.industry_size=0x00000180U;
1543 offset+=WriteBlobLong(image,dpx.file.industry_size);
1544 dpx.file.user_size=0;
1545 if (profile != (StringInfo *) NULL)
1547 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1548 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1550 offset+=WriteBlobLong(image,dpx.file.user_size);
1551 value=GetDPXProperty(image_info,image,"dpx:file.filename",exception);
1552 if (value != (const char *) NULL)
1553 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1554 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1556 seconds=time((time_t *) NULL);
1557 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1558 dpx.file.timestamp);
1559 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1560 dpx.file.timestamp);
1561 (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL),
1562 sizeof(dpx.file.creator));
1563 value=GetDPXProperty(image_info,image,"dpx:file.creator",exception);
1564 if (value != (const char *) NULL)
1565 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1566 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1568 value=GetDPXProperty(image_info,image,"dpx:file.project",exception);
1569 if (value != (const char *) NULL)
1570 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1571 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1573 value=GetDPXProperty(image_info,image,"dpx:file.copyright",exception);
1574 if (value != (const char *) NULL)
1575 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright));
1576 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1577 dpx.file.copyright);
1578 dpx.file.encrypt_key=(~0U);
1579 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1580 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1585 switch (image->orientation)
1588 case TopLeftOrientation: dpx.image.orientation=0; break;
1589 case TopRightOrientation: dpx.image.orientation=1; break;
1590 case BottomLeftOrientation: dpx.image.orientation=2; break;
1591 case BottomRightOrientation: dpx.image.orientation=3; break;
1592 case LeftTopOrientation: dpx.image.orientation=4; break;
1593 case RightTopOrientation: dpx.image.orientation=5; break;
1594 case LeftBottomOrientation: dpx.image.orientation=6; break;
1595 case RightBottomOrientation: dpx.image.orientation=7; break;
1597 offset+=WriteBlobShort(image,dpx.image.orientation);
1598 dpx.image.number_elements=1;
1599 offset+=WriteBlobShort(image,dpx.image.number_elements);
1600 if ((image->columns != (unsigned int) image->columns) ||
1601 (image->rows != (unsigned int) image->rows))
1602 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1603 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1604 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1605 for (i=0; i < 8; i++)
1607 dpx.image.image_element[i].data_sign=0U;
1608 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1609 dpx.image.image_element[i].low_data=0U;
1610 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1611 dpx.image.image_element[i].low_quantity=0.0f;
1612 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1613 dpx.image.image_element[i].high_data=0U;
1614 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1615 dpx.image.image_element[i].high_quantity=0.0f;
1616 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1617 dpx.image.image_element[i].descriptor=0;
1619 switch (image->colorspace)
1621 case Rec601YCbCrColorspace:
1622 case Rec709YCbCrColorspace:
1623 case YCbCrColorspace:
1625 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1626 if (image->alpha_trait == BlendPixelTrait)
1627 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1632 dpx.image.image_element[i].descriptor=RGBComponentType;
1633 if (image->alpha_trait == BlendPixelTrait)
1634 dpx.image.image_element[i].descriptor=RGBAComponentType;
1635 if ((image_info->type != TrueColorType) &&
1636 (image->alpha_trait != BlendPixelTrait) &&
1637 (IsImageGray(image,exception) != MagickFalse))
1638 dpx.image.image_element[i].descriptor=LumaComponentType;
1642 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1643 dpx.image.image_element[i].transfer_characteristic=0;
1644 if (image->colorspace == LogColorspace)
1645 dpx.image.image_element[0].transfer_characteristic=
1646 PrintingDensityColorimetric;
1647 offset+=WriteBlobByte(image,
1648 dpx.image.image_element[i].transfer_characteristic);
1649 dpx.image.image_element[i].colorimetric=0;
1650 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1651 dpx.image.image_element[i].bit_size=0;
1653 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1654 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1655 dpx.image.image_element[i].packing=0;
1656 if ((image->depth == 10) || (image->depth == 12))
1657 dpx.image.image_element[i].packing=1;
1658 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1659 dpx.image.image_element[i].encoding=0;
1660 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1661 dpx.image.image_element[i].data_offset=0U;
1663 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1664 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1665 dpx.image.image_element[i].end_of_line_padding=0U;
1666 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1667 offset+=WriteBlobLong(image,
1668 dpx.image.image_element[i].end_of_image_padding);
1669 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1670 (unsigned char *) dpx.image.image_element[i].description);
1672 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1675 Write orientation header.
1677 if ((image->rows != image->magick_rows) ||
1678 (image->columns != image->magick_columns))
1681 These properties are not valid if image size changed.
1683 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1684 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1685 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1686 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1687 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1688 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1690 dpx.orientation.x_offset=0U;
1691 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset",exception);
1692 if (value != (const char *) NULL)
1693 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1694 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1695 dpx.orientation.y_offset=0U;
1696 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset",exception);
1697 if (value != (const char *) NULL)
1698 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1699 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1700 dpx.orientation.x_center=0.0f;
1701 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center",exception);
1702 if (value != (const char *) NULL)
1703 dpx.orientation.x_center=StringToDouble(value,(char **) NULL);
1704 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1705 dpx.orientation.y_center=0.0f;
1706 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center",exception);
1707 if (value != (const char *) NULL)
1708 dpx.orientation.y_center=StringToDouble(value,(char **) NULL);
1709 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1710 dpx.orientation.x_size=0U;
1711 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size",exception);
1712 if (value != (const char *) NULL)
1713 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1714 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1715 dpx.orientation.y_size=0U;
1716 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size",exception);
1717 if (value != (const char *) NULL)
1718 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1719 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1720 value=GetDPXProperty(image_info,image,"dpx:orientation.filename",exception);
1721 if (value != (const char *) NULL)
1722 (void) strncpy(dpx.orientation.filename,value,
1723 sizeof(dpx.orientation.filename));
1724 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1725 dpx.orientation.filename);
1726 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1727 dpx.orientation.timestamp);
1728 value=GetDPXProperty(image_info,image,"dpx:orientation.device",exception);
1729 if (value != (const char *) NULL)
1730 (void) strncpy(dpx.orientation.device,value,sizeof(dpx.orientation.device));
1731 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1732 dpx.orientation.device);
1733 value=GetDPXProperty(image_info,image,"dpx:orientation.serial",exception);
1734 if (value != (const char *) NULL)
1735 (void) strncpy(dpx.orientation.serial,value,sizeof(dpx.orientation.serial));
1736 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1737 dpx.orientation.serial);
1738 for (i=0; i < 4; i++)
1739 dpx.orientation.border[i]=0;
1740 value=GetDPXProperty(image_info,image,"dpx:orientation.border",exception);
1741 if (value != (const char *) NULL)
1743 flags=ParseGeometry(value,&geometry_info);
1744 if ((flags & SigmaValue) == 0)
1745 geometry_info.sigma=geometry_info.rho;
1746 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1747 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1748 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1749 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1751 for (i=0; i < 4; i++)
1752 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1753 for (i=0; i < 2; i++)
1754 dpx.orientation.aspect_ratio[i]=0U;
1755 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio",
1757 if (value != (const char *) NULL)
1759 flags=ParseGeometry(value,&geometry_info);
1760 if ((flags & SigmaValue) == 0)
1761 geometry_info.sigma=geometry_info.rho;
1762 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1763 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1765 for (i=0; i < 2; i++)
1766 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1767 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1768 dpx.orientation.reserve);
1773 value=GetDPXProperty(image_info,image,"dpx:film.id",exception);
1774 if (value != (const char *) NULL)
1775 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1776 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1777 *dpx.film.type='\0';
1778 value=GetDPXProperty(image_info,image,"dpx:film.type",exception);
1779 if (value != (const char *) NULL)
1780 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1781 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1783 *dpx.film.offset='\0';
1784 value=GetDPXProperty(image_info,image,"dpx:film.offset",exception);
1785 if (value != (const char *) NULL)
1786 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1787 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1789 *dpx.film.prefix='\0';
1790 value=GetDPXProperty(image_info,image,"dpx:film.prefix",exception);
1791 if (value != (const char *) NULL)
1792 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1793 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1795 *dpx.film.count='\0';
1796 value=GetDPXProperty(image_info,image,"dpx:film.count",exception);
1797 if (value != (const char *) NULL)
1798 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1799 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1801 *dpx.film.format='\0';
1802 value=GetDPXProperty(image_info,image,"dpx:film.format",exception);
1803 if (value != (const char *) NULL)
1804 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1805 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1807 dpx.film.frame_position=0U;
1808 value=GetDPXProperty(image_info,image,"dpx:film.frame_position",exception);
1809 if (value != (const char *) NULL)
1810 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1811 offset+=WriteBlobLong(image,dpx.film.frame_position);
1812 dpx.film.sequence_extent=0U;
1813 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent",exception);
1814 if (value != (const char *) NULL)
1815 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1816 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1817 dpx.film.held_count=0U;
1818 value=GetDPXProperty(image_info,image,"dpx:film.held_count",exception);
1819 if (value != (const char *) NULL)
1820 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1821 offset+=WriteBlobLong(image,dpx.film.held_count);
1822 dpx.film.frame_rate=0.0f;
1823 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate",exception);
1824 if (value != (const char *) NULL)
1825 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
1826 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1827 dpx.film.shutter_angle=0.0f;
1828 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle",exception);
1829 if (value != (const char *) NULL)
1830 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
1831 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1832 *dpx.film.frame_id='\0';
1833 value=GetDPXProperty(image_info,image,"dpx:film.frame_id",exception);
1834 if (value != (const char *) NULL)
1835 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1836 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1838 value=GetDPXProperty(image_info,image,"dpx:film.slate",exception);
1839 if (value != (const char *) NULL)
1840 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1841 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1843 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1846 Write television header.
1848 value=GetDPXProperty(image_info,image,"dpx:television.time.code",exception);
1849 if (value != (const char *) NULL)
1850 dpx.television.time_code=StringToTimeCode(value);
1851 offset+=WriteBlobLong(image,dpx.television.time_code);
1852 value=GetDPXProperty(image_info,image,"dpx:television.user.bits",exception);
1853 if (value != (const char *) NULL)
1854 dpx.television.user_bits=StringToTimeCode(value);
1855 offset+=WriteBlobLong(image,dpx.television.user_bits);
1856 value=GetDPXProperty(image_info,image,"dpx:television.interlace",exception);
1857 if (value != (const char *) NULL)
1858 dpx.television.interlace=(unsigned char) StringToLong(value);
1859 offset+=WriteBlobByte(image,dpx.television.interlace);
1860 value=GetDPXProperty(image_info,image,"dpx:television.field_number",
1862 if (value != (const char *) NULL)
1863 dpx.television.field_number=(unsigned char) StringToLong(value);
1864 offset+=WriteBlobByte(image,dpx.television.field_number);
1865 dpx.television.video_signal=0;
1866 value=GetDPXProperty(image_info,image,"dpx:television.video_signal",
1868 if (value != (const char *) NULL)
1869 dpx.television.video_signal=(unsigned char) StringToLong(value);
1870 offset+=WriteBlobByte(image,dpx.television.video_signal);
1871 dpx.television.padding=0;
1872 value=GetDPXProperty(image_info,image,"dpx:television.padding",exception);
1873 if (value != (const char *) NULL)
1874 dpx.television.padding=(unsigned char) StringToLong(value);
1875 offset+=WriteBlobByte(image,dpx.television.padding);
1876 dpx.television.horizontal_sample_rate=0.0f;
1877 value=GetDPXProperty(image_info,image,"dpx:television.horizontal_sample_rate", exception);
1878 if (value != (const char *) NULL)
1879 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
1880 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1881 dpx.television.vertical_sample_rate=0.0f;
1882 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate",
1884 if (value != (const char *) NULL)
1885 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
1886 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1887 dpx.television.frame_rate=0.0f;
1888 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate",exception);
1889 if (value != (const char *) NULL)
1890 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
1891 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1892 dpx.television.time_offset=0.0f;
1893 value=GetDPXProperty(image_info,image,"dpx:television.time_offset",exception);
1894 if (value != (const char *) NULL)
1895 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
1896 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1897 dpx.television.gamma=0.0f;
1898 value=GetDPXProperty(image_info,image,"dpx:television.gamma",exception);
1899 if (value != (const char *) NULL)
1900 dpx.television.gamma=StringToDouble(value,(char **) NULL);
1901 offset+=WriteBlobFloat(image,dpx.television.gamma);
1902 dpx.television.black_level=0.0f;
1903 value=GetDPXProperty(image_info,image,"dpx:television.black_level",exception);
1904 if (value != (const char *) NULL)
1905 dpx.television.black_level=StringToDouble(value,(char **) NULL);
1906 offset+=WriteBlobFloat(image,dpx.television.black_level);
1907 dpx.television.black_gain=0.0f;
1908 value=GetDPXProperty(image_info,image,"dpx:television.black_gain",exception);
1909 if (value != (const char *) NULL)
1910 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
1911 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1912 dpx.television.break_point=0.0f;
1913 value=GetDPXProperty(image_info,image,"dpx:television.break_point",exception);
1914 if (value != (const char *) NULL)
1915 dpx.television.break_point=StringToDouble(value,(char **) NULL);
1916 offset+=WriteBlobFloat(image,dpx.television.break_point);
1917 dpx.television.white_level=0.0f;
1918 value=GetDPXProperty(image_info,image,"dpx:television.white_level",exception);
1919 if (value != (const char *) NULL)
1920 dpx.television.white_level=StringToDouble(value,(char **) NULL);
1921 offset+=WriteBlobFloat(image,dpx.television.white_level);
1922 dpx.television.integration_times=0.0f;
1923 value=GetDPXProperty(image_info,image,"dpx:television.integration_times",
1925 if (value != (const char *) NULL)
1926 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
1927 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1928 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1929 dpx.television.reserve);
1933 value=GetDPXProperty(image_info,image,"dpx:user.id",exception);
1934 if (value != (const char *) NULL)
1935 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1936 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1937 if (profile != (StringInfo *) NULL)
1938 offset+=WriteBlob(image,GetStringInfoLength(profile),
1939 GetStringInfoDatum(profile));
1940 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1942 count=WriteBlobByte(image,0x00);
1945 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
1952 Convert pixel packets to DPX raster image.
1954 quantum_info=AcquireQuantumInfo(image_info,image);
1955 SetQuantumQuantum(quantum_info,32);
1956 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1957 MagickTrue : MagickFalse);
1958 quantum_type=RGBQuantum;
1959 if (image->alpha_trait == BlendPixelTrait)
1960 quantum_type=RGBAQuantum;
1961 if (image->colorspace == YCbCrColorspace)
1963 quantum_type=CbYCrQuantum;
1964 if (image->alpha_trait == BlendPixelTrait)
1965 quantum_type=CbYCrAQuantum;
1966 if ((horizontal_factor == 2) || (vertical_factor == 2))
1967 quantum_type=CbYCrYQuantum;
1969 extent=GetBytesPerRow(image->columns,image->alpha_trait == BlendPixelTrait ?
1970 4UL : 3UL,image->depth,MagickTrue);
1971 if ((image_info->type != TrueColorType) &&
1972 (image->alpha_trait != BlendPixelTrait) &&
1973 (IsImageGray(image,exception) != MagickFalse))
1975 quantum_type=GrayQuantum;
1976 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
1978 pixels=GetQuantumPixels(quantum_info);
1979 for (y=0; y < (ssize_t) image->rows; y++)
1981 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1982 if (p == (const Quantum *) NULL)
1984 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1985 quantum_type,pixels,exception);
1986 count=WriteBlob(image,extent,pixels);
1987 if (count != (ssize_t) extent)
1989 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1991 if (status == MagickFalse)
1994 quantum_info=DestroyQuantumInfo(quantum_info);
1995 (void) CloseBlob(image);