2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write SMTPE DPX Image Format %
20 % Copyright 1999-2015 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"
72 #define MaxNumberImageElements 8
79 UserDefinedColorimetric = 0,
80 PrintingDensityColorimetric = 1,
81 LinearColorimetric = 2,
82 LogarithmicColorimetric = 3,
83 UnspecifiedVideoColorimetric = 4,
84 SMTPE_274MColorimetric = 5,
85 ITU_R709Colorimetric = 6,
86 ITU_R601_625LColorimetric = 7,
87 ITU_R601_525LColorimetric = 8,
88 NTSCCompositeVideoColorimetric = 9,
89 PALCompositeVideoColorimetric = 10,
90 ZDepthLinearColorimetric = 11,
91 DepthHomogeneousColorimetric = 12
96 UndefinedComponentType = 0,
98 GreenComponentType = 2,
99 BlueComponentType = 3,
100 AlphaComponentType = 4,
101 LumaComponentType = 6,
102 ColorDifferenceCbCrComponentType = 7,
103 DepthComponentType = 8,
104 CompositeVideoComponentType = 9,
105 RGBComponentType = 50,
106 RGBAComponentType = 51,
107 ABGRComponentType = 52,
108 CbYCrY422ComponentType = 100,
109 CbYACrYA4224ComponentType = 101,
110 CbYCr444ComponentType = 102,
111 CbYCrA4444ComponentType = 103,
112 UserDef2ElementComponentType = 150,
113 UserDef3ElementComponentType = 151,
114 UserDef4ElementComponentType = 152,
115 UserDef5ElementComponentType = 153,
116 UserDef6ElementComponentType = 154,
117 UserDef7ElementComponentType = 155,
118 UserDef8ElementComponentType = 156
123 TransferCharacteristicUserDefined = 0,
124 TransferCharacteristicPrintingDensity = 1,
125 TransferCharacteristicLinear = 2,
126 TransferCharacteristicLogarithmic = 3,
127 TransferCharacteristicUnspecifiedVideo = 4,
128 TransferCharacteristicSMTPE274M = 5, /* 1920x1080 TV */
129 TransferCharacteristicITU_R709 = 6, /* ITU R709 */
130 TransferCharacteristicITU_R601_625L = 7, /* 625 Line */
131 TransferCharacteristicITU_R601_525L = 8, /* 525 Line */
132 TransferCharacteristicNTSCCompositeVideo = 9,
133 TransferCharacteristicPALCompositeVideo = 10,
134 TransferCharacteristicZDepthLinear = 11,
135 TransferCharacteristicZDepthHomogeneous = 12
136 } DPXTransferCharacteristic;
138 typedef struct _DPXFileInfo
168 typedef struct _DPXFilmInfo
193 typedef struct _DPXImageElement
210 transfer_characteristic,
221 end_of_image_padding;
227 typedef struct _DPXImageInfo
238 image_element[MaxNumberImageElements];
244 typedef struct _DPXOrientationInfo
272 } DPXOrientationInfo;
274 typedef struct _DPXTelevisionInfo
287 horizontal_sample_rate,
288 vertical_sample_rate,
302 typedef struct _DPXUserInfo
308 typedef struct DPXInfo
330 Forward declaractions.
332 static MagickBooleanType
333 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 % IsDPX() returns MagickTrue if the image format type, identified by the
347 % magick string, is DPX.
349 % The format of the IsDPX method is:
351 % MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
353 % A description of each parameter follows:
355 % o magick: compare image format pattern against these bytes.
357 % o extent: Specifies the extent of the magick string.
360 static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
364 if (memcmp(magick,"SDPX",4) == 0)
366 if (memcmp(magick,"XPDS",4) == 0)
372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376 % R e a d D P X I m a g e %
380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382 % ReadDPXImage() reads an DPX X image file and returns it. It
383 % allocates the memory necessary for the new Image structure and returns a
384 % pointer to the new image.
386 % The format of the ReadDPXImage method is:
388 % Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
390 % A description of each parameter follows:
392 % o image_info: the image info.
394 % o exception: return any errors or warnings in this structure.
398 static size_t GetBytesPerRow(const size_t columns,
399 const size_t samples_per_pixel,const size_t bits_per_pixel,
400 const MagickBooleanType pad)
405 switch (bits_per_pixel)
409 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
416 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
422 if (pad == MagickFalse)
424 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
428 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
433 if (pad == MagickFalse)
435 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
439 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
444 bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+8)/
450 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
456 bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
461 return(bytes_per_row);
464 static const char *GetImageTransferCharacteristic(
465 const DPXTransferCharacteristic characteristic)
471 Get the element transfer characteristic.
473 switch(characteristic)
475 case TransferCharacteristicUserDefined:
477 transfer="UserDefined";
480 case TransferCharacteristicPrintingDensity:
482 transfer="PrintingDensity";
485 case TransferCharacteristicLinear:
490 case TransferCharacteristicLogarithmic:
492 transfer="Logarithmic";
495 case TransferCharacteristicUnspecifiedVideo:
497 transfer="UnspecifiedVideo";
500 case TransferCharacteristicSMTPE274M:
502 transfer="SMTPE274M";
505 case TransferCharacteristicITU_R709:
510 case TransferCharacteristicITU_R601_625L:
512 transfer="ITU-R601-625L";
515 case TransferCharacteristicITU_R601_525L:
517 transfer="ITU-R601-525L";
520 case TransferCharacteristicNTSCCompositeVideo:
522 transfer="NTSCCompositeVideo";
525 case TransferCharacteristicPALCompositeVideo:
527 transfer="PALCompositeVideo";
530 case TransferCharacteristicZDepthLinear:
532 transfer="ZDepthLinear";
535 case TransferCharacteristicZDepthHomogeneous:
537 transfer="ZDepthHomogeneous";
546 static inline MagickBooleanType IsFloatDefined(const float value)
557 quantum.unsigned_value=0U;
558 quantum.float_value=(float) value;
559 if (quantum.unsigned_value == 0U)
564 static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
565 ChromaticityInfo *chromaticity_info)
569 case SMTPE_274MColorimetric:
570 case ITU_R709Colorimetric:
572 chromaticity_info->red_primary.x=0.640;
573 chromaticity_info->red_primary.y=0.330;
574 chromaticity_info->red_primary.z=0.030;
575 chromaticity_info->green_primary.x=0.300;
576 chromaticity_info->green_primary.y=0.600;
577 chromaticity_info->green_primary.z=0.100;
578 chromaticity_info->blue_primary.x=0.150;
579 chromaticity_info->blue_primary.y=0.060;
580 chromaticity_info->blue_primary.z=0.790;
581 chromaticity_info->white_point.x=0.3127;
582 chromaticity_info->white_point.y=0.3290;
583 chromaticity_info->white_point.z=0.3582;
586 case NTSCCompositeVideoColorimetric:
588 chromaticity_info->red_primary.x=0.67;
589 chromaticity_info->red_primary.y=0.33;
590 chromaticity_info->red_primary.z=0.00;
591 chromaticity_info->green_primary.x=0.21;
592 chromaticity_info->green_primary.y=0.71;
593 chromaticity_info->green_primary.z=0.08;
594 chromaticity_info->blue_primary.x=0.14;
595 chromaticity_info->blue_primary.y=0.08;
596 chromaticity_info->blue_primary.z=0.78;
597 chromaticity_info->white_point.x=0.310;
598 chromaticity_info->white_point.y=0.316;
599 chromaticity_info->white_point.z=0.374;
602 case PALCompositeVideoColorimetric:
604 chromaticity_info->red_primary.x=0.640;
605 chromaticity_info->red_primary.y=0.330;
606 chromaticity_info->red_primary.z=0.030;
607 chromaticity_info->green_primary.x=0.290;
608 chromaticity_info->green_primary.y=0.600;
609 chromaticity_info->green_primary.z=0.110;
610 chromaticity_info->blue_primary.x=0.150;
611 chromaticity_info->blue_primary.y=0.060;
612 chromaticity_info->blue_primary.z=0.790;
613 chromaticity_info->white_point.x=0.3127;
614 chromaticity_info->white_point.y=0.3290;
615 chromaticity_info->white_point.z=0.3582;
623 static void TimeCodeToString(const size_t timestamp,char *code)
635 for (i=0; i <= TimeFields; i++)
637 (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x",
638 (unsigned int) ((timestamp >> shift) & 0x0fU));
640 if (((i % 2) != 0) && (i < TimeFields))
647 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
651 value[MaxTextExtent];
690 assert(image_info != (const ImageInfo *) NULL);
691 assert(image_info->signature == MagickSignature);
692 if (image_info->debug != MagickFalse)
693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
694 image_info->filename);
695 assert(exception != (ExceptionInfo *) NULL);
696 assert(exception->signature == MagickSignature);
697 image=AcquireImage(image_info,exception);
698 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
699 if (status == MagickFalse)
701 image=DestroyImageList(image);
702 return((Image *) NULL);
705 Read DPX file header.
708 count=ReadBlob(image,4,(unsigned char *) magick);
710 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
711 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
712 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
713 image->endian=LSBEndian;
714 if (LocaleNCompare(magick,"SDPX",4) == 0)
715 image->endian=MSBEndian;
716 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
717 dpx.file.image_offset=ReadBlobLong(image);
719 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
721 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
722 dpx.file.file_size=ReadBlobLong(image);
724 dpx.file.ditto_key=ReadBlobLong(image);
726 if (dpx.file.ditto_key != ~0U)
727 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
729 dpx.file.generic_size=ReadBlobLong(image);
731 dpx.file.industry_size=ReadBlobLong(image);
733 dpx.file.user_size=ReadBlobLong(image);
735 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
737 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
739 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
740 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
742 if (*dpx.file.timestamp != '\0')
743 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
745 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
747 if (*dpx.file.creator != '\0')
749 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
751 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
753 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
755 if (*dpx.file.project != '\0')
757 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
759 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
761 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
763 if (*dpx.file.copyright != '\0')
765 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
767 (void) FormatImageProperty(image,"copyright","%.100s",
770 dpx.file.encrypt_key=ReadBlobLong(image);
772 if (dpx.file.encrypt_key != ~0U)
773 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
774 dpx.file.encrypt_key);
775 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
778 Read DPX image header.
780 dpx.image.orientation=ReadBlobShort(image);
781 if (dpx.image.orientation > 7)
782 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
784 if (dpx.image.orientation != (unsigned short) ~0)
785 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
786 dpx.image.orientation);
787 switch (dpx.image.orientation)
790 case 0: image->orientation=TopLeftOrientation; break;
791 case 1: image->orientation=TopRightOrientation; break;
792 case 2: image->orientation=BottomLeftOrientation; break;
793 case 3: image->orientation=BottomRightOrientation; break;
794 case 4: image->orientation=LeftTopOrientation; break;
795 case 5: image->orientation=RightTopOrientation; break;
796 case 6: image->orientation=LeftBottomOrientation; break;
797 case 7: image->orientation=RightBottomOrientation; break;
799 dpx.image.number_elements=ReadBlobShort(image);
800 if (dpx.image.number_elements > MaxNumberImageElements)
801 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
803 dpx.image.pixels_per_line=ReadBlobLong(image);
805 image->columns=dpx.image.pixels_per_line;
806 dpx.image.lines_per_element=ReadBlobLong(image);
808 image->rows=dpx.image.lines_per_element;
809 for (i=0; i < 8; i++)
812 property[MaxTextExtent];
814 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
816 dpx.image.image_element[i].low_data=ReadBlobLong(image);
818 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
820 dpx.image.image_element[i].high_data=ReadBlobLong(image);
822 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
824 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
826 dpx.image.image_element[i].transfer_characteristic=(unsigned char)
828 (void) FormatLocaleString(property,MaxTextExtent,
829 "dpx:image.element[%lu].transfer-characteristic",(long) i);
830 (void) FormatImageProperty(image,property,"%s",
831 GetImageTransferCharacteristic((DPXTransferCharacteristic)
832 dpx.image.image_element[i].transfer_characteristic));
834 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
836 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
838 dpx.image.image_element[i].packing=ReadBlobShort(image);
840 dpx.image.image_element[i].encoding=ReadBlobShort(image);
842 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
844 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
846 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
848 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
849 (unsigned char *) dpx.image.image_element[i].description);
851 SetImageColorspace(image,RGBColorspace,exception);
852 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
854 if (dpx.file.image_offset >= 1664U)
857 Read DPX orientation header.
859 dpx.orientation.x_offset=ReadBlobLong(image);
861 if (dpx.orientation.x_offset != ~0U)
862 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
863 dpx.orientation.x_offset);
864 dpx.orientation.y_offset=ReadBlobLong(image);
866 if (dpx.orientation.y_offset != ~0U)
867 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
868 dpx.orientation.y_offset);
869 dpx.orientation.x_center=ReadBlobFloat(image);
871 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
872 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
873 dpx.orientation.x_center);
874 dpx.orientation.y_center=ReadBlobFloat(image);
876 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
877 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
878 dpx.orientation.y_center);
879 dpx.orientation.x_size=ReadBlobLong(image);
881 if (dpx.orientation.x_size != ~0U)
882 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
883 dpx.orientation.x_size);
884 dpx.orientation.y_size=ReadBlobLong(image);
886 if (dpx.orientation.y_size != ~0U)
887 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
888 dpx.orientation.y_size);
889 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
890 dpx.orientation.filename);
891 if (*dpx.orientation.filename != '\0')
892 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
893 dpx.orientation.filename);
894 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
895 dpx.orientation.timestamp);
896 if (*dpx.orientation.timestamp != '\0')
897 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
898 dpx.orientation.timestamp);
899 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
900 dpx.orientation.device);
901 if (*dpx.orientation.device != '\0')
902 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
903 dpx.orientation.device);
904 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
905 dpx.orientation.serial);
906 if (*dpx.orientation.serial != '\0')
907 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
908 dpx.orientation.serial);
909 for (i=0; i < 4; i++)
911 dpx.orientation.border[i]=ReadBlobShort(image);
914 if ((dpx.orientation.border[0] != (unsigned short) (~0)) &&
915 (dpx.orientation.border[1] != (unsigned short) (~0)))
916 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d",
917 dpx.orientation.border[0],dpx.orientation.border[1],
918 dpx.orientation.border[2],dpx.orientation.border[3]);
919 for (i=0; i < 2; i++)
921 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
924 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
925 (dpx.orientation.aspect_ratio[1] != ~0U))
926 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
927 "%ux%u",dpx.orientation.aspect_ratio[0],
928 dpx.orientation.aspect_ratio[1]);
929 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
930 dpx.orientation.reserve);
932 if (dpx.file.image_offset >= 1920U)
935 Read DPX film header.
937 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
938 if (*dpx.film.id != '\0')
939 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
940 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
942 if (*dpx.film.type != '\0')
943 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
944 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
946 if (*dpx.film.offset != '\0')
947 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
949 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
951 if (*dpx.film.prefix != '\0')
952 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
954 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
956 if (*dpx.film.count != '\0')
957 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
959 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
961 if (*dpx.film.format != '\0')
962 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
964 dpx.film.frame_position=ReadBlobLong(image);
966 if (dpx.film.frame_position != ~0U)
967 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
968 dpx.film.frame_position);
969 dpx.film.sequence_extent=ReadBlobLong(image);
971 if (dpx.film.sequence_extent != ~0U)
972 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
973 dpx.film.sequence_extent);
974 dpx.film.held_count=ReadBlobLong(image);
976 if (dpx.film.held_count != ~0U)
977 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
978 dpx.film.held_count);
979 dpx.film.frame_rate=ReadBlobFloat(image);
981 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
982 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
983 dpx.film.frame_rate);
984 dpx.film.shutter_angle=ReadBlobFloat(image);
986 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
987 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
988 dpx.film.shutter_angle);
989 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
991 if (*dpx.film.frame_id != '\0')
992 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
994 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
996 if (*dpx.film.slate != '\0')
997 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
999 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1002 if (dpx.file.image_offset >= 2048U)
1005 Read DPX television header.
1007 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
1009 TimeCodeToString(dpx.television.time_code,value);
1010 (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
1011 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
1013 TimeCodeToString(dpx.television.user_bits,value);
1014 (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
1015 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
1017 if (dpx.television.interlace != 0)
1018 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
1019 (double) dpx.television.interlace);
1020 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
1022 if (dpx.television.field_number != 0)
1023 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
1024 (double) dpx.television.field_number);
1025 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
1027 if (dpx.television.video_signal != 0)
1028 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
1029 (double) dpx.television.video_signal);
1030 dpx.television.padding=(unsigned char) ReadBlobByte(image);
1032 if (dpx.television.padding != 0)
1033 (void) FormatImageProperty(image,"dpx:television.padding","%d",
1034 dpx.television.padding);
1035 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
1037 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
1038 (void) FormatImageProperty(image,
1039 "dpx:television.horizontal_sample_rate","%g",
1040 dpx.television.horizontal_sample_rate);
1041 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
1043 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
1044 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
1045 "%g",dpx.television.vertical_sample_rate);
1046 dpx.television.frame_rate=ReadBlobFloat(image);
1048 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
1049 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
1050 dpx.television.frame_rate);
1051 dpx.television.time_offset=ReadBlobFloat(image);
1053 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
1054 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
1055 dpx.television.time_offset);
1056 dpx.television.gamma=ReadBlobFloat(image);
1058 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
1059 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
1060 dpx.television.gamma);
1061 dpx.television.black_level=ReadBlobFloat(image);
1063 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
1064 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
1065 dpx.television.black_level);
1066 dpx.television.black_gain=ReadBlobFloat(image);
1068 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
1069 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
1070 dpx.television.black_gain);
1071 dpx.television.break_point=ReadBlobFloat(image);
1073 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
1074 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
1075 dpx.television.break_point);
1076 dpx.television.white_level=ReadBlobFloat(image);
1078 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
1079 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
1080 dpx.television.white_level);
1081 dpx.television.integration_times=ReadBlobFloat(image);
1083 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
1084 (void) FormatImageProperty(image,"dpx:television.integration_times",
1085 "%g",dpx.television.integration_times);
1086 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1087 dpx.television.reserve);
1089 if (dpx.file.image_offset > 2080U)
1092 Read DPX user header.
1094 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1095 if (*dpx.user.id != '\0')
1096 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
1097 if ((dpx.file.user_size != ~0U) &&
1098 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
1103 profile=BlobToStringInfo((const void *) NULL,
1104 dpx.file.user_size-sizeof(dpx.user.id));
1105 if (profile == (StringInfo *) NULL)
1106 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1107 offset+=ReadBlob(image,GetStringInfoLength(profile),
1108 GetStringInfoDatum(profile));
1109 (void) SetImageProfile(image,"dpx:user-data",profile,exception);
1110 profile=DestroyStringInfo(profile);
1113 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
1114 (void) ReadBlobByte(image);
1115 if (image_info->ping != MagickFalse)
1117 (void) CloseBlob(image);
1118 return(GetFirstImageInList(image));
1120 status=SetImageExtent(image,image->columns,image->rows,exception);
1121 if (status == MagickFalse)
1122 return(DestroyImageList(image));
1123 for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
1126 Convert DPX raster image to pixel packets.
1128 if ((dpx.image.image_element[n].data_offset != ~0U) &&
1129 (dpx.image.image_element[n].data_offset != 0U))
1134 data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
1135 if (data_offset < offset)
1136 offset=SeekBlob(image,data_offset,SEEK_SET);
1138 for ( ; offset < data_offset; offset++)
1139 (void) ReadBlobByte(image);
1140 if (offset != data_offset)
1141 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1143 SetPrimaryChromaticity((DPXColorimetric)
1144 dpx.image.image_element[n].colorimetric,&image->chromaticity);
1145 image->depth=dpx.image.image_element[n].bit_size;
1146 samples_per_pixel=1;
1147 quantum_type=GrayQuantum;
1148 component_type=dpx.image.image_element[n].descriptor;
1149 switch (component_type)
1151 case CbYCrY422ComponentType:
1153 samples_per_pixel=2;
1154 quantum_type=CbYCrYQuantum;
1157 case CbYACrYA4224ComponentType:
1158 case CbYCr444ComponentType:
1160 samples_per_pixel=3;
1161 quantum_type=CbYCrQuantum;
1164 case RGBComponentType:
1166 samples_per_pixel=3;
1167 quantum_type=RGBQuantum;
1170 case ABGRComponentType:
1171 case RGBAComponentType:
1173 image->alpha_trait=BlendPixelTrait;
1174 samples_per_pixel=4;
1175 quantum_type=RGBAQuantum;
1181 switch (component_type)
1183 case CbYCrY422ComponentType:
1184 case CbYACrYA4224ComponentType:
1185 case CbYCr444ComponentType:
1187 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1190 case LumaComponentType:
1192 SetImageColorspace(image,GRAYColorspace,exception);
1197 SetImageColorspace(image,sRGBColorspace,exception);
1198 if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
1199 SetImageColorspace(image,LogColorspace,exception);
1200 if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
1201 SetImageColorspace(image,LogColorspace,exception);
1205 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1206 dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
1208 DPX any-bit pixel format.
1212 quantum_info=AcquireQuantumInfo(image_info,image);
1213 if (quantum_info == (QuantumInfo *) NULL)
1214 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1215 SetQuantumQuantum(quantum_info,32);
1216 SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
1217 MagickTrue : MagickFalse);
1218 for (y=0; y < (ssize_t) image->rows; y++)
1236 if (status == MagickFalse)
1238 pixels=GetQuantumPixels(quantum_info);
1240 count=ReadBlob(image,extent,pixels);
1241 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1242 (image->previous == (Image *) NULL))
1247 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1249 if (proceed == MagickFalse)
1254 if (count != (ssize_t) extent)
1256 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
1257 if (q == (Quantum *) NULL)
1262 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1263 quantum_type,pixels,exception);
1265 sync=SyncAuthenticPixels(image,exception);
1266 if (sync == MagickFalse)
1269 quantum_info=DestroyQuantumInfo(quantum_info);
1270 if (status == MagickFalse)
1271 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1272 SetQuantumImageType(image,quantum_type);
1273 if (EOFBlob(image) != MagickFalse)
1274 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1276 if ((i+1) < (ssize_t) dpx.image.number_elements)
1279 Allocate next image structure.
1281 AcquireNextImage(image_info,image,exception);
1282 if (GetNextImageInList(image) == (Image *) NULL)
1284 image=DestroyImageList(image);
1285 return((Image *) NULL);
1287 image=SyncNextImageInList(image);
1288 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1289 GetBlobSize(image));
1290 if (status == MagickFalse)
1294 (void) CloseBlob(image);
1295 return(GetFirstImageInList(image));
1299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1303 % R e g i s t e r D P X I m a g e %
1307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1309 % RegisterDPXImage() adds properties for the DPX image format to
1310 % the list of supported formats. The properties include the image format
1311 % tag, a method to read and/or write the format, whether the format
1312 % supports the saving of more than one frame to the same file or blob,
1313 % whether the format supports native in-memory I/O, and a brief
1314 % description of the format.
1316 % The format of the RegisterDPXImage method is:
1318 % size_t RegisterDPXImage(void)
1321 ModuleExport size_t RegisterDPXImage(void)
1329 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1330 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1333 entry=SetMagickInfo("DPX");
1334 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1335 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1336 entry->magick=(IsImageFormatHandler *) IsDPX;
1337 entry->adjoin=MagickFalse;
1338 entry->seekable_stream=MagickTrue;
1339 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1340 entry->note=ConstantString(DPXNote);
1341 entry->module=ConstantString("DPX");
1342 (void) RegisterMagickInfo(entry);
1343 return(MagickImageCoderSignature);
1347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1351 % U n r e g i s t e r D P X I m a g e %
1355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1357 % UnregisterDPXImage() removes format registrations made by the
1358 % DPX module from the list of supported formats.
1360 % The format of the UnregisterDPXImage method is:
1362 % UnregisterDPXImage(void)
1365 ModuleExport void UnregisterDPXImage(void)
1367 (void) UnregisterMagickInfo("DPX");
1371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1375 % W r i t e D P X I m a g e %
1379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % WriteDPXImage() writes an image in DPX encoded image format.
1383 % The format of the WriteDPXImage method is:
1385 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1386 % Image *image,ExceptionInfo *exception)
1388 % A description of each parameter follows.
1390 % o image_info: the image info.
1392 % o image: The image.
1394 % o exception: return any errors or warnings in this structure.
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:user-data");
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)-1);
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=GetImageArtifact(image,"dpx:file.filename");
1552 if (value != (const char *) NULL)
1553 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename)-1);
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)-1);
1563 value=GetImageArtifact(image,"dpx:file.creator");
1564 if (value != (const char *) NULL)
1565 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator)-1);
1566 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1568 value=GetImageArtifact(image,"dpx:file.project");
1569 if (value != (const char *) NULL)
1570 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project)-1);
1571 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1573 value=GetImageArtifact(image,"dpx:file.copyright");
1574 if (value != (const char *) NULL)
1575 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright)-1);
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 != UndefinedPixelTrait)
1627 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1632 dpx.image.image_element[i].descriptor=RGBComponentType;
1633 if (image->alpha_trait != UndefinedPixelTrait)
1634 dpx.image.image_element[i].descriptor=RGBAComponentType;
1635 if ((image_info->type != TrueColorType) &&
1636 (image->alpha_trait == UndefinedPixelTrait) &&
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=GetImageArtifact(image,"dpx:orientation.x_offset");
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=GetImageArtifact(image,"dpx:orientation.y_offset");
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=GetImageArtifact(image,"dpx:orientation.x_center");
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=GetImageArtifact(image,"dpx:orientation.y_center");
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=GetImageArtifact(image,"dpx:orientation.x_size");
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=GetImageArtifact(image,"dpx:orientation.y_size");
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=GetImageArtifact(image,"dpx:orientation.filename");
1721 if (value != (const char *) NULL)
1722 (void) strncpy(dpx.orientation.filename,value,
1723 sizeof(dpx.orientation.filename)-1);
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=GetImageArtifact(image,"dpx:orientation.device");
1729 if (value != (const char *) NULL)
1730 (void) strncpy(dpx.orientation.device,value,
1731 sizeof(dpx.orientation.device)-1);
1732 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1733 dpx.orientation.device);
1734 value=GetImageArtifact(image,"dpx:orientation.serial");
1735 if (value != (const char *) NULL)
1736 (void) strncpy(dpx.orientation.serial,value,
1737 sizeof(dpx.orientation.serial)-1);
1738 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1739 dpx.orientation.serial);
1740 for (i=0; i < 4; i++)
1741 dpx.orientation.border[i]=0;
1742 value=GetImageArtifact(image,"dpx:orientation.border");
1743 if (value != (const char *) NULL)
1745 flags=ParseGeometry(value,&geometry_info);
1746 if ((flags & SigmaValue) == 0)
1747 geometry_info.sigma=geometry_info.rho;
1748 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1749 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1750 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1751 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1753 for (i=0; i < 4; i++)
1754 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1755 for (i=0; i < 2; i++)
1756 dpx.orientation.aspect_ratio[i]=0U;
1757 value=GetImageArtifact(image,"dpx:orientation.aspect_ratio");
1758 if (value != (const char *) NULL)
1760 flags=ParseGeometry(value,&geometry_info);
1761 if ((flags & SigmaValue) == 0)
1762 geometry_info.sigma=geometry_info.rho;
1763 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1764 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1766 for (i=0; i < 2; i++)
1767 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1768 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1769 dpx.orientation.reserve);
1773 (void) ResetMagickMemory(dpx.film.id,0,sizeof(dpx.film.id));
1774 value=GetImageArtifact(image,"dpx:film.id");
1775 if (value != (const char *) NULL)
1776 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id)-1);
1777 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1778 (void) ResetMagickMemory(dpx.film.type,0,sizeof(dpx.film.type));
1779 value=GetImageArtifact(image,"dpx:film.type");
1780 if (value != (const char *) NULL)
1781 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type)-1);
1782 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1784 (void) ResetMagickMemory(dpx.film.offset,0,sizeof(dpx.film.offset));
1785 value=GetImageArtifact(image,"dpx:film.offset");
1786 if (value != (const char *) NULL)
1787 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset)-1);
1788 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1790 (void) ResetMagickMemory(dpx.film.prefix,0,sizeof(dpx.film.prefix));
1791 value=GetImageArtifact(image,"dpx:film.prefix");
1792 if (value != (const char *) NULL)
1793 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix)-1);
1794 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1796 (void) ResetMagickMemory(dpx.film.count,0,sizeof(dpx.film.count));
1797 value=GetImageArtifact(image,"dpx:film.count");
1798 if (value != (const char *) NULL)
1799 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count)-1);
1800 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1802 (void) ResetMagickMemory(dpx.film.format,0,sizeof(dpx.film.format));
1803 value=GetImageArtifact(image,"dpx:film.format");
1804 if (value != (const char *) NULL)
1805 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format)-1);
1806 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1808 dpx.film.frame_position=0U;
1809 value=GetImageArtifact(image,"dpx:film.frame_position");
1810 if (value != (const char *) NULL)
1811 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1812 offset+=WriteBlobLong(image,dpx.film.frame_position);
1813 dpx.film.sequence_extent=0U;
1814 value=GetImageArtifact(image,"dpx:film.sequence_extent");
1815 if (value != (const char *) NULL)
1816 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1817 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1818 dpx.film.held_count=0U;
1819 value=GetImageArtifact(image,"dpx:film.held_count");
1820 if (value != (const char *) NULL)
1821 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1822 offset+=WriteBlobLong(image,dpx.film.held_count);
1823 dpx.film.frame_rate=0.0f;
1824 value=GetImageArtifact(image,"dpx:film.frame_rate");
1825 if (value != (const char *) NULL)
1826 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
1827 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1828 dpx.film.shutter_angle=0.0f;
1829 value=GetImageArtifact(image,"dpx:film.shutter_angle");
1830 if (value != (const char *) NULL)
1831 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
1832 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1833 (void) ResetMagickMemory(dpx.film.frame_id,0,sizeof(dpx.film.frame_id));
1834 value=GetImageArtifact(image,"dpx:film.frame_id");
1835 if (value != (const char *) NULL)
1836 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id)-1);
1837 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1839 value=GetImageArtifact(image,"dpx:film.slate");
1840 if (value != (const char *) NULL)
1841 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate)-1);
1842 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1844 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1847 Write television header.
1849 value=GetImageArtifact(image,"dpx:television.time.code");
1850 if (value != (const char *) NULL)
1851 dpx.television.time_code=StringToTimeCode(value);
1852 offset+=WriteBlobLong(image,dpx.television.time_code);
1853 value=GetImageArtifact(image,"dpx:television.user.bits");
1854 if (value != (const char *) NULL)
1855 dpx.television.user_bits=StringToTimeCode(value);
1856 offset+=WriteBlobLong(image,dpx.television.user_bits);
1857 value=GetImageArtifact(image,"dpx:television.interlace");
1858 if (value != (const char *) NULL)
1859 dpx.television.interlace=(unsigned char) StringToLong(value);
1860 offset+=WriteBlobByte(image,dpx.television.interlace);
1861 value=GetImageArtifact(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=GetImageArtifact(image,"dpx:television.video_signal");
1867 if (value != (const char *) NULL)
1868 dpx.television.video_signal=(unsigned char) StringToLong(value);
1869 offset+=WriteBlobByte(image,dpx.television.video_signal);
1870 dpx.television.padding=0;
1871 value=GetImageArtifact(image,"dpx:television.padding");
1872 if (value != (const char *) NULL)
1873 dpx.television.padding=(unsigned char) StringToLong(value);
1874 offset+=WriteBlobByte(image,dpx.television.padding);
1875 dpx.television.horizontal_sample_rate=0.0f;
1876 value=GetImageArtifact(image,"dpx:television.horizontal_sample_rate");
1877 if (value != (const char *) NULL)
1878 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
1879 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1880 dpx.television.vertical_sample_rate=0.0f;
1881 value=GetImageArtifact(image,"dpx:television.vertical_sample_rate");
1882 if (value != (const char *) NULL)
1883 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
1884 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1885 dpx.television.frame_rate=0.0f;
1886 value=GetImageArtifact(image,"dpx:television.frame_rate");
1887 if (value != (const char *) NULL)
1888 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
1889 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1890 dpx.television.time_offset=0.0f;
1891 value=GetImageArtifact(image,"dpx:television.time_offset");
1892 if (value != (const char *) NULL)
1893 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
1894 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1895 dpx.television.gamma=0.0f;
1896 value=GetImageArtifact(image,"dpx:television.gamma");
1897 if (value != (const char *) NULL)
1898 dpx.television.gamma=StringToDouble(value,(char **) NULL);
1899 offset+=WriteBlobFloat(image,dpx.television.gamma);
1900 dpx.television.black_level=0.0f;
1901 value=GetImageArtifact(image,"dpx:television.black_level");
1902 if (value != (const char *) NULL)
1903 dpx.television.black_level=StringToDouble(value,(char **) NULL);
1904 offset+=WriteBlobFloat(image,dpx.television.black_level);
1905 dpx.television.black_gain=0.0f;
1906 value=GetImageArtifact(image,"dpx:television.black_gain");
1907 if (value != (const char *) NULL)
1908 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
1909 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1910 dpx.television.break_point=0.0f;
1911 value=GetImageArtifact(image,"dpx:television.break_point");
1912 if (value != (const char *) NULL)
1913 dpx.television.break_point=StringToDouble(value,(char **) NULL);
1914 offset+=WriteBlobFloat(image,dpx.television.break_point);
1915 dpx.television.white_level=0.0f;
1916 value=GetImageArtifact(image,"dpx:television.white_level");
1917 if (value != (const char *) NULL)
1918 dpx.television.white_level=StringToDouble(value,(char **) NULL);
1919 offset+=WriteBlobFloat(image,dpx.television.white_level);
1920 dpx.television.integration_times=0.0f;
1921 value=GetImageArtifact(image,"dpx:television.integration_times");
1922 if (value != (const char *) NULL)
1923 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
1924 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1925 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1926 dpx.television.reserve);
1930 value=GetImageArtifact(image,"dpx:user.id");
1931 if (value != (const char *) NULL)
1932 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id)-1);
1933 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1934 if (profile != (StringInfo *) NULL)
1935 offset+=WriteBlob(image,GetStringInfoLength(profile),
1936 GetStringInfoDatum(profile));
1937 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1939 count=WriteBlobByte(image,0x00);
1942 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
1949 Convert pixel packets to DPX raster image.
1951 quantum_info=AcquireQuantumInfo(image_info,image);
1952 SetQuantumQuantum(quantum_info,32);
1953 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1954 MagickTrue : MagickFalse);
1955 quantum_type=RGBQuantum;
1956 if (image->alpha_trait != UndefinedPixelTrait)
1957 quantum_type=RGBAQuantum;
1958 if (image->colorspace == YCbCrColorspace)
1960 quantum_type=CbYCrQuantum;
1961 if (image->alpha_trait != UndefinedPixelTrait)
1962 quantum_type=CbYCrAQuantum;
1963 if ((horizontal_factor == 2) || (vertical_factor == 2))
1964 quantum_type=CbYCrYQuantum;
1966 extent=GetBytesPerRow(image->columns,image->alpha_trait != UndefinedPixelTrait ?
1967 4UL : 3UL,image->depth,MagickTrue);
1968 if ((image_info->type != TrueColorType) &&
1969 (image->alpha_trait == UndefinedPixelTrait) &&
1970 (IsImageGray(image,exception) != MagickFalse))
1972 quantum_type=GrayQuantum;
1973 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
1975 pixels=GetQuantumPixels(quantum_info);
1976 for (y=0; y < (ssize_t) image->rows; y++)
1978 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1979 if (p == (const Quantum *) NULL)
1981 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1982 quantum_type,pixels,exception);
1983 count=WriteBlob(image,extent,pixels);
1984 if (count != (ssize_t) extent)
1986 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1988 if (status == MagickFalse)
1991 quantum_info=DestroyQuantumInfo(quantum_info);
1992 (void) CloseBlob(image);