2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write SMTPE DPX Image Format %
20 % Copyright 1999-2019 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 % https://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"
68 #include "MagickCore/timer-private.h"
73 #define MaxNumberImageElements 8
80 UserDefinedColorimetric = 0,
81 PrintingDensityColorimetric = 1,
82 LinearColorimetric = 2,
83 LogarithmicColorimetric = 3,
84 UnspecifiedVideoColorimetric = 4,
85 SMTPE_274MColorimetric = 5,
86 ITU_R709Colorimetric = 6,
87 ITU_R601_625LColorimetric = 7,
88 ITU_R601_525LColorimetric = 8,
89 NTSCCompositeVideoColorimetric = 9,
90 PALCompositeVideoColorimetric = 10,
91 ZDepthLinearColorimetric = 11,
92 DepthHomogeneousColorimetric = 12
97 UndefinedComponentType = 0,
99 GreenComponentType = 2,
100 BlueComponentType = 3,
101 AlphaComponentType = 4,
102 LumaComponentType = 6,
103 ColorDifferenceCbCrComponentType = 7,
104 DepthComponentType = 8,
105 CompositeVideoComponentType = 9,
106 RGBComponentType = 50,
107 RGBAComponentType = 51,
108 ABGRComponentType = 52,
109 CbYCrY422ComponentType = 100,
110 CbYACrYA4224ComponentType = 101,
111 CbYCr444ComponentType = 102,
112 CbYCrA4444ComponentType = 103,
113 UserDef2ElementComponentType = 150,
114 UserDef3ElementComponentType = 151,
115 UserDef4ElementComponentType = 152,
116 UserDef5ElementComponentType = 153,
117 UserDef6ElementComponentType = 154,
118 UserDef7ElementComponentType = 155,
119 UserDef8ElementComponentType = 156
124 TransferCharacteristicUserDefined = 0,
125 TransferCharacteristicPrintingDensity = 1,
126 TransferCharacteristicLinear = 2,
127 TransferCharacteristicLogarithmic = 3,
128 TransferCharacteristicUnspecifiedVideo = 4,
129 TransferCharacteristicSMTPE274M = 5, /* 1920x1080 TV */
130 TransferCharacteristicITU_R709 = 6, /* ITU R709 */
131 TransferCharacteristicITU_R601_625L = 7, /* 625 Line */
132 TransferCharacteristicITU_R601_525L = 8, /* 525 Line */
133 TransferCharacteristicNTSCCompositeVideo = 9,
134 TransferCharacteristicPALCompositeVideo = 10,
135 TransferCharacteristicZDepthLinear = 11,
136 TransferCharacteristicZDepthHomogeneous = 12
137 } DPXTransferCharacteristic;
139 typedef struct _DPXFileInfo
169 typedef struct _DPXFilmInfo
194 typedef struct _DPXImageElement
211 transfer_characteristic,
222 end_of_image_padding;
228 typedef struct _DPXImageInfo
239 image_element[MaxNumberImageElements];
245 typedef struct _DPXOrientationInfo
273 } DPXOrientationInfo;
275 typedef struct _DPXTelevisionInfo
288 horizontal_sample_rate,
289 vertical_sample_rate,
303 typedef struct _DPXUserInfo
309 typedef struct DPXInfo
331 Forward declaractions.
333 static MagickBooleanType
334 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 % IsDPX() returns MagickTrue if the image format type, identified by the
348 % magick string, is DPX.
350 % The format of the IsDPX method is:
352 % MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
354 % A description of each parameter follows:
356 % o magick: compare image format pattern against these bytes.
358 % o extent: Specifies the extent of the magick string.
361 static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
365 if (memcmp(magick,"SDPX",4) == 0)
367 if (memcmp(magick,"XPDS",4) == 0)
373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 % R e a d D P X I m a g e %
381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 % ReadDPXImage() reads an DPX X image file and returns it. It
384 % allocates the memory necessary for the new Image structure and returns a
385 % pointer to the new image.
387 % The format of the ReadDPXImage method is:
389 % Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
391 % A description of each parameter follows:
393 % o image_info: the image info.
395 % o exception: return any errors or warnings in this structure.
399 static size_t GetBytesPerRow(const size_t columns,
400 const size_t samples_per_pixel,const size_t bits_per_pixel,
401 const MagickBooleanType pad)
406 switch (bits_per_pixel)
410 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
417 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
423 if (pad == MagickFalse)
425 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
429 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
434 if (pad == MagickFalse)
436 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
440 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
445 if (pad == MagickFalse)
447 bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+
451 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
457 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
463 bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
468 return(bytes_per_row);
471 static const char *GetImageTransferCharacteristic(
472 const DPXTransferCharacteristic characteristic)
478 Get the element transfer characteristic.
480 switch(characteristic)
482 case TransferCharacteristicUserDefined:
484 transfer="UserDefined";
487 case TransferCharacteristicPrintingDensity:
489 transfer="PrintingDensity";
492 case TransferCharacteristicLinear:
497 case TransferCharacteristicLogarithmic:
499 transfer="Logarithmic";
502 case TransferCharacteristicUnspecifiedVideo:
504 transfer="UnspecifiedVideo";
507 case TransferCharacteristicSMTPE274M:
509 transfer="SMTPE274M";
512 case TransferCharacteristicITU_R709:
517 case TransferCharacteristicITU_R601_625L:
519 transfer="ITU-R601-625L";
522 case TransferCharacteristicITU_R601_525L:
524 transfer="ITU-R601-525L";
527 case TransferCharacteristicNTSCCompositeVideo:
529 transfer="NTSCCompositeVideo";
532 case TransferCharacteristicPALCompositeVideo:
534 transfer="PALCompositeVideo";
537 case TransferCharacteristicZDepthLinear:
539 transfer="ZDepthLinear";
542 case TransferCharacteristicZDepthHomogeneous:
544 transfer="ZDepthHomogeneous";
553 static inline MagickBooleanType IsFloatDefined(const float value)
564 quantum.unsigned_value=0U;
565 quantum.float_value=(float) value;
566 if (quantum.unsigned_value == 0U)
571 static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
572 ChromaticityInfo *chromaticity_info)
576 case SMTPE_274MColorimetric:
577 case ITU_R709Colorimetric:
579 chromaticity_info->red_primary.x=0.640;
580 chromaticity_info->red_primary.y=0.330;
581 chromaticity_info->red_primary.z=0.030;
582 chromaticity_info->green_primary.x=0.300;
583 chromaticity_info->green_primary.y=0.600;
584 chromaticity_info->green_primary.z=0.100;
585 chromaticity_info->blue_primary.x=0.150;
586 chromaticity_info->blue_primary.y=0.060;
587 chromaticity_info->blue_primary.z=0.790;
588 chromaticity_info->white_point.x=0.3127;
589 chromaticity_info->white_point.y=0.3290;
590 chromaticity_info->white_point.z=0.3582;
593 case NTSCCompositeVideoColorimetric:
595 chromaticity_info->red_primary.x=0.67;
596 chromaticity_info->red_primary.y=0.33;
597 chromaticity_info->red_primary.z=0.00;
598 chromaticity_info->green_primary.x=0.21;
599 chromaticity_info->green_primary.y=0.71;
600 chromaticity_info->green_primary.z=0.08;
601 chromaticity_info->blue_primary.x=0.14;
602 chromaticity_info->blue_primary.y=0.08;
603 chromaticity_info->blue_primary.z=0.78;
604 chromaticity_info->white_point.x=0.310;
605 chromaticity_info->white_point.y=0.316;
606 chromaticity_info->white_point.z=0.374;
609 case PALCompositeVideoColorimetric:
611 chromaticity_info->red_primary.x=0.640;
612 chromaticity_info->red_primary.y=0.330;
613 chromaticity_info->red_primary.z=0.030;
614 chromaticity_info->green_primary.x=0.290;
615 chromaticity_info->green_primary.y=0.600;
616 chromaticity_info->green_primary.z=0.110;
617 chromaticity_info->blue_primary.x=0.150;
618 chromaticity_info->blue_primary.y=0.060;
619 chromaticity_info->blue_primary.z=0.790;
620 chromaticity_info->white_point.x=0.3127;
621 chromaticity_info->white_point.y=0.3290;
622 chromaticity_info->white_point.z=0.3582;
630 static void TimeCodeToString(const size_t timestamp,char *code)
642 for (i=0; i <= TimeFields; i++)
644 (void) FormatLocaleString(code,MagickPathExtent-strlen(code),"%x",
645 (unsigned int) ((timestamp >> shift) & 0x0fU));
647 if (((i % 2) != 0) && (i < TimeFields))
654 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
658 value[MagickPathExtent];
697 assert(image_info != (const ImageInfo *) NULL);
698 assert(image_info->signature == MagickCoreSignature);
699 if (image_info->debug != MagickFalse)
700 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
701 image_info->filename);
702 assert(exception != (ExceptionInfo *) NULL);
703 assert(exception->signature == MagickCoreSignature);
704 image=AcquireImage(image_info,exception);
705 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
706 if (status == MagickFalse)
708 image=DestroyImageList(image);
709 return((Image *) NULL);
712 Read DPX file header.
715 count=ReadBlob(image,4,(unsigned char *) magick);
717 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
718 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
719 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
720 image->endian=LSBEndian;
721 if (LocaleNCompare(magick,"SDPX",4) == 0)
722 image->endian=MSBEndian;
723 (void) memset(&dpx,0,sizeof(dpx));
724 dpx.file.image_offset=ReadBlobLong(image);
726 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
728 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
729 dpx.file.file_size=ReadBlobLong(image);
730 if (0 && dpx.file.file_size > GetBlobSize(image))
731 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
733 dpx.file.ditto_key=ReadBlobLong(image);
735 if (dpx.file.ditto_key != ~0U)
736 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
738 dpx.file.generic_size=ReadBlobLong(image);
740 dpx.file.industry_size=ReadBlobLong(image);
742 dpx.file.user_size=ReadBlobLong(image);
744 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
746 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
748 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
749 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
751 if (*dpx.file.timestamp != '\0')
752 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
754 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
756 if (*dpx.file.creator != '\0')
758 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
760 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
762 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
764 if (*dpx.file.project != '\0')
766 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
768 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
770 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
772 if (*dpx.file.copyright != '\0')
774 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
776 (void) FormatImageProperty(image,"copyright","%.100s",
779 dpx.file.encrypt_key=ReadBlobLong(image);
781 if (dpx.file.encrypt_key != ~0U)
782 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
783 dpx.file.encrypt_key);
784 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
787 Read DPX image header.
789 dpx.image.orientation=ReadBlobShort(image);
790 if (dpx.image.orientation > 7)
791 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
793 if (dpx.image.orientation != (unsigned short) ~0)
794 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
795 dpx.image.orientation);
796 switch (dpx.image.orientation)
799 case 0: image->orientation=TopLeftOrientation; break;
800 case 1: image->orientation=TopRightOrientation; break;
801 case 2: image->orientation=BottomLeftOrientation; break;
802 case 3: image->orientation=BottomRightOrientation; break;
803 case 4: image->orientation=LeftTopOrientation; break;
804 case 5: image->orientation=RightTopOrientation; break;
805 case 6: image->orientation=LeftBottomOrientation; break;
806 case 7: image->orientation=RightBottomOrientation; break;
808 dpx.image.number_elements=ReadBlobShort(image);
809 if ((dpx.image.number_elements < 1) ||
810 (dpx.image.number_elements > MaxNumberImageElements))
811 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
813 dpx.image.pixels_per_line=ReadBlobLong(image);
815 image->columns=dpx.image.pixels_per_line;
816 dpx.image.lines_per_element=ReadBlobLong(image);
818 image->rows=dpx.image.lines_per_element;
819 for (i=0; i < 8; i++)
822 property[MagickPathExtent];
824 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
826 dpx.image.image_element[i].low_data=ReadBlobLong(image);
828 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
830 dpx.image.image_element[i].high_data=ReadBlobLong(image);
832 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
834 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
836 dpx.image.image_element[i].transfer_characteristic=(unsigned char)
838 (void) FormatLocaleString(property,MagickPathExtent,
839 "dpx:image.element[%lu].transfer-characteristic",(long) i);
840 (void) FormatImageProperty(image,property,"%s",
841 GetImageTransferCharacteristic((DPXTransferCharacteristic)
842 dpx.image.image_element[i].transfer_characteristic));
844 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
846 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
848 dpx.image.image_element[i].packing=ReadBlobShort(image);
850 dpx.image.image_element[i].encoding=ReadBlobShort(image);
852 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
854 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
856 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
858 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
859 (unsigned char *) dpx.image.image_element[i].description);
861 SetImageColorspace(image,RGBColorspace,exception);
862 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
864 if (dpx.file.image_offset >= 1664U)
867 Read DPX orientation header.
869 dpx.orientation.x_offset=ReadBlobLong(image);
871 if (dpx.orientation.x_offset != ~0U)
872 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
873 dpx.orientation.x_offset);
874 dpx.orientation.y_offset=ReadBlobLong(image);
876 if (dpx.orientation.y_offset != ~0U)
877 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
878 dpx.orientation.y_offset);
879 dpx.orientation.x_center=ReadBlobFloat(image);
881 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
882 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
883 dpx.orientation.x_center);
884 dpx.orientation.y_center=ReadBlobFloat(image);
886 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
887 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
888 dpx.orientation.y_center);
889 dpx.orientation.x_size=ReadBlobLong(image);
891 if (dpx.orientation.x_size != ~0U)
892 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
893 dpx.orientation.x_size);
894 dpx.orientation.y_size=ReadBlobLong(image);
896 if (dpx.orientation.y_size != ~0U)
897 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
898 dpx.orientation.y_size);
899 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
900 dpx.orientation.filename);
901 if (*dpx.orientation.filename != '\0')
902 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
903 dpx.orientation.filename);
904 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
905 dpx.orientation.timestamp);
906 if (*dpx.orientation.timestamp != '\0')
907 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
908 dpx.orientation.timestamp);
909 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
910 dpx.orientation.device);
911 if (*dpx.orientation.device != '\0')
912 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
913 dpx.orientation.device);
914 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
915 dpx.orientation.serial);
916 if (*dpx.orientation.serial != '\0')
917 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
918 dpx.orientation.serial);
919 for (i=0; i < 4; i++)
921 dpx.orientation.border[i]=ReadBlobShort(image);
924 if ((dpx.orientation.border[0] != (unsigned short) (~0)) &&
925 (dpx.orientation.border[1] != (unsigned short) (~0)))
926 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d",
927 dpx.orientation.border[0],dpx.orientation.border[1],
928 dpx.orientation.border[2],dpx.orientation.border[3]);
929 for (i=0; i < 2; i++)
931 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
934 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
935 (dpx.orientation.aspect_ratio[1] != ~0U))
936 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
937 "%ux%u",dpx.orientation.aspect_ratio[0],
938 dpx.orientation.aspect_ratio[1]);
939 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
940 dpx.orientation.reserve);
942 if (dpx.file.image_offset >= 1920U)
945 Read DPX film header.
947 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
948 if (*dpx.film.id != '\0')
949 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
950 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
952 if (*dpx.film.type != '\0')
953 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
954 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
956 if (*dpx.film.offset != '\0')
957 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
959 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
961 if (*dpx.film.prefix != '\0')
962 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
964 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
966 if (*dpx.film.count != '\0')
967 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
969 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
971 if (*dpx.film.format != '\0')
972 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
974 dpx.film.frame_position=ReadBlobLong(image);
976 if (dpx.film.frame_position != ~0U)
977 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
978 dpx.film.frame_position);
979 dpx.film.sequence_extent=ReadBlobLong(image);
981 if (dpx.film.sequence_extent != ~0U)
982 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
983 dpx.film.sequence_extent);
984 dpx.film.held_count=ReadBlobLong(image);
986 if (dpx.film.held_count != ~0U)
987 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
988 dpx.film.held_count);
989 dpx.film.frame_rate=ReadBlobFloat(image);
991 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
992 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
993 dpx.film.frame_rate);
994 dpx.film.shutter_angle=ReadBlobFloat(image);
996 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
997 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
998 dpx.film.shutter_angle);
999 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1001 if (*dpx.film.frame_id != '\0')
1002 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
1004 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1006 if (*dpx.film.slate != '\0')
1007 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
1009 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1012 if (dpx.file.image_offset >= 2048U)
1015 Read DPX television header.
1017 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
1019 TimeCodeToString(dpx.television.time_code,value);
1020 (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
1021 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
1023 TimeCodeToString(dpx.television.user_bits,value);
1024 (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
1025 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
1027 if (dpx.television.interlace != 0)
1028 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
1029 (double) dpx.television.interlace);
1030 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
1032 if (dpx.television.field_number != 0)
1033 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
1034 (double) dpx.television.field_number);
1035 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
1037 if (dpx.television.video_signal != 0)
1038 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
1039 (double) dpx.television.video_signal);
1040 dpx.television.padding=(unsigned char) ReadBlobByte(image);
1042 if (dpx.television.padding != 0)
1043 (void) FormatImageProperty(image,"dpx:television.padding","%d",
1044 dpx.television.padding);
1045 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
1047 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
1048 (void) FormatImageProperty(image,
1049 "dpx:television.horizontal_sample_rate","%g",
1050 dpx.television.horizontal_sample_rate);
1051 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
1053 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
1054 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
1055 "%g",dpx.television.vertical_sample_rate);
1056 dpx.television.frame_rate=ReadBlobFloat(image);
1058 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
1059 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
1060 dpx.television.frame_rate);
1061 dpx.television.time_offset=ReadBlobFloat(image);
1063 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
1064 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
1065 dpx.television.time_offset);
1066 dpx.television.gamma=ReadBlobFloat(image);
1068 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
1069 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
1070 dpx.television.gamma);
1071 dpx.television.black_level=ReadBlobFloat(image);
1073 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
1074 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
1075 dpx.television.black_level);
1076 dpx.television.black_gain=ReadBlobFloat(image);
1078 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
1079 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
1080 dpx.television.black_gain);
1081 dpx.television.break_point=ReadBlobFloat(image);
1083 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
1084 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
1085 dpx.television.break_point);
1086 dpx.television.white_level=ReadBlobFloat(image);
1088 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
1089 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
1090 dpx.television.white_level);
1091 dpx.television.integration_times=ReadBlobFloat(image);
1093 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
1094 (void) FormatImageProperty(image,"dpx:television.integration_times",
1095 "%g",dpx.television.integration_times);
1096 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1097 dpx.television.reserve);
1099 if (dpx.file.image_offset > 2080U)
1102 Read DPX user header.
1104 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1105 if (*dpx.user.id != '\0')
1106 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
1107 if ((dpx.file.user_size != ~0U) &&
1108 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
1113 if (dpx.file.user_size > GetBlobSize(image))
1114 ThrowReaderException(CorruptImageError,
1115 "InsufficientImageDataInFile");
1116 profile=BlobToStringInfo((const unsigned char *) NULL,
1117 dpx.file.user_size-sizeof(dpx.user.id));
1118 if (profile == (StringInfo *) NULL)
1119 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1120 offset+=ReadBlob(image,GetStringInfoLength(profile),
1121 GetStringInfoDatum(profile));
1122 if (EOFBlob(image) != MagickFalse)
1123 (void) SetImageProfile(image,"dpx:user-data",profile,exception);
1124 profile=DestroyStringInfo(profile);
1127 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
1128 if (ReadBlobByte(image) == EOF)
1130 if (EOFBlob(image) != MagickFalse)
1131 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1133 if (image_info->ping != MagickFalse)
1135 (void) CloseBlob(image);
1136 return(GetFirstImageInList(image));
1138 status=SetImageExtent(image,image->columns,image->rows,exception);
1139 if (status == MagickFalse)
1140 return(DestroyImageList(image));
1141 status=ResetImagePixels(image,exception);
1142 if (status == MagickFalse)
1143 return(DestroyImageList(image));
1144 for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
1147 Convert DPX raster image to pixel packets.
1149 if ((dpx.image.image_element[n].data_offset != ~0U) &&
1150 (dpx.image.image_element[n].data_offset != 0U))
1155 data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
1156 if (data_offset < offset)
1157 offset=SeekBlob(image,data_offset,SEEK_SET);
1159 for ( ; offset < data_offset; offset++)
1160 if (ReadBlobByte(image) == EOF)
1162 if (offset != data_offset)
1163 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1165 SetPrimaryChromaticity((DPXColorimetric)
1166 dpx.image.image_element[n].colorimetric,&image->chromaticity);
1167 image->depth=dpx.image.image_element[n].bit_size;
1168 if ((image->depth == 0) || (image->depth > 32))
1169 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
1170 samples_per_pixel=1;
1171 quantum_type=GrayQuantum;
1172 component_type=dpx.image.image_element[n].descriptor;
1173 switch (component_type)
1175 case CbYCrY422ComponentType:
1177 samples_per_pixel=2;
1178 quantum_type=CbYCrYQuantum;
1181 case CbYACrYA4224ComponentType:
1182 case CbYCr444ComponentType:
1184 samples_per_pixel=3;
1185 quantum_type=CbYCrQuantum;
1188 case RGBComponentType:
1190 samples_per_pixel=3;
1191 quantum_type=RGBQuantum;
1194 case ABGRComponentType:
1195 case RGBAComponentType:
1197 image->alpha_trait=BlendPixelTrait;
1198 samples_per_pixel=4;
1199 quantum_type=RGBAQuantum;
1205 switch (component_type)
1207 case CbYCrY422ComponentType:
1208 case CbYACrYA4224ComponentType:
1209 case CbYCr444ComponentType:
1211 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1214 case LumaComponentType:
1216 SetImageColorspace(image,GRAYColorspace,exception);
1221 SetImageColorspace(image,sRGBColorspace,exception);
1222 if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
1223 SetImageColorspace(image,LogColorspace,exception);
1224 if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
1225 SetImageColorspace(image,LogColorspace,exception);
1229 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1230 dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
1232 DPX any-bit pixel format.
1235 quantum_info=AcquireQuantumInfo(image_info,image);
1236 if (quantum_info == (QuantumInfo *) NULL)
1237 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1238 SetQuantumQuantum(quantum_info,32);
1239 SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
1240 MagickTrue : MagickFalse);
1241 for (y=0; y < (ssize_t) image->rows; y++)
1258 pixels=(const unsigned char *) ReadBlobStream(image,extent,
1259 GetQuantumPixels(quantum_info),&count);
1260 if (count != (ssize_t) extent)
1262 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1263 (image->previous == (Image *) NULL))
1268 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1270 if (proceed == MagickFalse)
1274 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
1275 if (q == (Quantum *) NULL)
1277 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1278 quantum_type,pixels,exception);
1280 sync=SyncAuthenticPixels(image,exception);
1281 if (sync == MagickFalse)
1284 quantum_info=DestroyQuantumInfo(quantum_info);
1285 if (y < (ssize_t) image->rows)
1286 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1287 SetQuantumImageType(image,quantum_type);
1288 if (EOFBlob(image) != MagickFalse)
1289 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1291 if ((i+1) < (ssize_t) dpx.image.number_elements)
1294 Allocate next image structure.
1296 AcquireNextImage(image_info,image,exception);
1297 if (GetNextImageInList(image) == (Image *) NULL)
1302 image=SyncNextImageInList(image);
1303 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1304 GetBlobSize(image));
1305 if (status == MagickFalse)
1309 (void) CloseBlob(image);
1310 if (status == MagickFalse)
1311 return(DestroyImageList(image));
1312 return(GetFirstImageInList(image));
1316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1320 % R e g i s t e r D P X I m a g e %
1324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1326 % RegisterDPXImage() adds properties for the DPX image format to
1327 % the list of supported formats. The properties include the image format
1328 % tag, a method to read and/or write the format, whether the format
1329 % supports the saving of more than one frame to the same file or blob,
1330 % whether the format supports native in-memory I/O, and a brief
1331 % description of the format.
1333 % The format of the RegisterDPXImage method is:
1335 % size_t RegisterDPXImage(void)
1338 ModuleExport size_t RegisterDPXImage(void)
1346 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1347 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1350 entry=AcquireMagickInfo("DPX","DPX","SMPTE 268M-2003 (DPX 2.0)");
1351 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1352 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1353 entry->magick=(IsImageFormatHandler *) IsDPX;
1354 entry->flags^=CoderAdjoinFlag;
1355 entry->flags|=CoderDecoderSeekableStreamFlag;
1356 entry->note=ConstantString(DPXNote);
1357 (void) RegisterMagickInfo(entry);
1358 return(MagickImageCoderSignature);
1362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1366 % U n r e g i s t e r D P X I m a g e %
1370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1372 % UnregisterDPXImage() removes format registrations made by the
1373 % DPX module from the list of supported formats.
1375 % The format of the UnregisterDPXImage method is:
1377 % UnregisterDPXImage(void)
1380 ModuleExport void UnregisterDPXImage(void)
1382 (void) UnregisterMagickInfo("DPX");
1386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 % W r i t e D P X I m a g e %
1394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1396 % WriteDPXImage() writes an image in DPX encoded image format.
1398 % The format of the WriteDPXImage method is:
1400 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1401 % Image *image,ExceptionInfo *exception)
1403 % A description of each parameter follows.
1405 % o image_info: the image info.
1407 % o image: The image.
1409 % o exception: return any errors or warnings in this structure.
1413 static unsigned int StringToTimeCode(const char *key)
1428 for (i=0; (*key != 0) && (i < 11); i++)
1430 if (isxdigit((int) ((unsigned char) *key)) == 0)
1436 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1442 static inline const char *GetDPXProperty(const Image *image,
1443 const char *property,ExceptionInfo *exception)
1448 value=GetImageArtifact(image,property);
1449 if (value != (const char *) NULL)
1451 return(GetImageProperty(image,property,exception));
1454 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1455 ExceptionInfo *exception)
1484 register const Quantum
1507 Open output image file.
1509 assert(image_info != (const ImageInfo *) NULL);
1510 assert(image_info->signature == MagickCoreSignature);
1511 assert(image != (Image *) NULL);
1512 assert(image->signature == MagickCoreSignature);
1513 if (image->debug != MagickFalse)
1514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1515 horizontal_factor=4;
1517 if (image_info->sampling_factor != (char *) NULL)
1519 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1520 horizontal_factor=(ssize_t) geometry_info.rho;
1521 vertical_factor=(ssize_t) geometry_info.sigma;
1522 if ((flags & SigmaValue) == 0)
1523 vertical_factor=horizontal_factor;
1524 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1525 (horizontal_factor != 4) && (vertical_factor != 1) &&
1526 (vertical_factor != 2) && (vertical_factor != 4))
1527 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1529 if ((image->colorspace == YCbCrColorspace) &&
1530 ((horizontal_factor == 2) || (vertical_factor == 2)))
1531 if ((image->columns % 2) != 0)
1533 assert(exception != (ExceptionInfo *) NULL);
1534 assert(exception->signature == MagickCoreSignature);
1535 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1536 if (status == MagickFalse)
1541 (void) memset(&dpx,0,sizeof(dpx));
1543 dpx.file.magic=0x53445058U;
1544 offset+=WriteBlobLong(image,dpx.file.magic);
1545 dpx.file.image_offset=0x2000U;
1546 profile=GetImageProfile(image,"dpx:user-data");
1547 if (profile != (StringInfo *) NULL)
1549 if (GetStringInfoLength(profile) > 1048576)
1550 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1551 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1552 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1554 offset+=WriteBlobLong(image,dpx.file.image_offset);
1555 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version)-1);
1556 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1558 if (IsImageGray(image) == MagickFalse)
1560 if (image->alpha_trait != UndefinedPixelTrait)
1562 dpx.file.file_size=(unsigned int) (channels*image->columns*image->rows+
1563 dpx.file.image_offset);
1564 offset+=WriteBlobLong(image,dpx.file.file_size);
1565 dpx.file.ditto_key=1U; /* new frame */
1566 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1567 dpx.file.generic_size=0x00000680U;
1568 offset+=WriteBlobLong(image,dpx.file.generic_size);
1569 dpx.file.industry_size=0x00000180U;
1570 offset+=WriteBlobLong(image,dpx.file.industry_size);
1571 dpx.file.user_size=0;
1572 if (profile != (StringInfo *) NULL)
1574 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1575 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1577 offset+=WriteBlobLong(image,dpx.file.user_size);
1578 value=GetDPXProperty(image,"dpx:file.filename",exception);
1579 if (value != (const char *) NULL)
1580 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename)-1);
1581 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1583 seconds=GetMagickTime();
1584 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1585 dpx.file.timestamp);
1586 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1587 dpx.file.timestamp);
1588 (void) strncpy(dpx.file.creator,MagickAuthoritativeURL,
1589 sizeof(dpx.file.creator)-1);
1590 value=GetDPXProperty(image,"dpx:file.creator",exception);
1591 if (value != (const char *) NULL)
1592 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator)-1);
1593 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1595 value=GetDPXProperty(image,"dpx:file.project",exception);
1596 if (value != (const char *) NULL)
1597 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project)-1);
1598 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1600 value=GetDPXProperty(image,"dpx:file.copyright",exception);
1601 if (value != (const char *) NULL)
1602 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright)-1);
1603 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1604 dpx.file.copyright);
1605 dpx.file.encrypt_key=(~0U);
1606 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1607 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1612 switch (image->orientation)
1615 case TopLeftOrientation: dpx.image.orientation=0; break;
1616 case TopRightOrientation: dpx.image.orientation=1; break;
1617 case BottomLeftOrientation: dpx.image.orientation=2; break;
1618 case BottomRightOrientation: dpx.image.orientation=3; break;
1619 case LeftTopOrientation: dpx.image.orientation=4; break;
1620 case RightTopOrientation: dpx.image.orientation=5; break;
1621 case LeftBottomOrientation: dpx.image.orientation=6; break;
1622 case RightBottomOrientation: dpx.image.orientation=7; break;
1624 offset+=WriteBlobShort(image,dpx.image.orientation);
1625 dpx.image.number_elements=1;
1626 offset+=WriteBlobShort(image,dpx.image.number_elements);
1627 if ((image->columns != (unsigned int) image->columns) ||
1628 (image->rows != (unsigned int) image->rows))
1629 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1630 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1631 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1632 for (i=0; i < 8; i++)
1634 dpx.image.image_element[i].data_sign=0U;
1635 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1636 dpx.image.image_element[i].low_data=0U;
1637 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1638 dpx.image.image_element[i].low_quantity=0.0f;
1639 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1640 dpx.image.image_element[i].high_data=0U;
1641 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1642 dpx.image.image_element[i].high_quantity=0.0f;
1643 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1644 dpx.image.image_element[i].descriptor=0;
1646 switch (image->colorspace)
1648 case Rec601YCbCrColorspace:
1649 case Rec709YCbCrColorspace:
1650 case YCbCrColorspace:
1652 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1653 if (image->alpha_trait != UndefinedPixelTrait)
1654 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1659 dpx.image.image_element[i].descriptor=RGBComponentType;
1660 if (image->alpha_trait != UndefinedPixelTrait)
1661 dpx.image.image_element[i].descriptor=RGBAComponentType;
1662 if ((image_info->type != TrueColorType) &&
1663 (image->alpha_trait == UndefinedPixelTrait) &&
1664 (SetImageGray(image,exception) != MagickFalse))
1665 dpx.image.image_element[i].descriptor=LumaComponentType;
1669 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1670 dpx.image.image_element[i].transfer_characteristic=0;
1671 if (image->colorspace == LogColorspace)
1672 dpx.image.image_element[0].transfer_characteristic=
1673 PrintingDensityColorimetric;
1674 offset+=WriteBlobByte(image,
1675 dpx.image.image_element[i].transfer_characteristic);
1676 dpx.image.image_element[i].colorimetric=0;
1677 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1678 dpx.image.image_element[i].bit_size=0;
1680 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1681 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1682 dpx.image.image_element[i].packing=0;
1683 if ((image->depth == 10) || (image->depth == 12))
1684 dpx.image.image_element[i].packing=1;
1685 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1686 dpx.image.image_element[i].encoding=0;
1687 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1688 dpx.image.image_element[i].data_offset=0U;
1690 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1691 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1692 dpx.image.image_element[i].end_of_line_padding=0U;
1693 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1694 offset+=WriteBlobLong(image,
1695 dpx.image.image_element[i].end_of_image_padding);
1696 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1697 (unsigned char *) dpx.image.image_element[i].description);
1699 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1702 Write orientation header.
1704 if ((image->rows != image->magick_rows) ||
1705 (image->columns != image->magick_columns))
1708 These properties are not valid if image size changed.
1710 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1711 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1712 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1713 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1714 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1715 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1717 dpx.orientation.x_offset=0U;
1718 value=GetDPXProperty(image,"dpx:orientation.x_offset",exception);
1719 if (value != (const char *) NULL)
1720 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1721 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1722 dpx.orientation.y_offset=0U;
1723 value=GetDPXProperty(image,"dpx:orientation.y_offset",exception);
1724 if (value != (const char *) NULL)
1725 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1726 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1727 dpx.orientation.x_center=0.0f;
1728 value=GetDPXProperty(image,"dpx:orientation.x_center",exception);
1729 if (value != (const char *) NULL)
1730 dpx.orientation.x_center=StringToDouble(value,(char **) NULL);
1731 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1732 dpx.orientation.y_center=0.0f;
1733 value=GetDPXProperty(image,"dpx:orientation.y_center",exception);
1734 if (value != (const char *) NULL)
1735 dpx.orientation.y_center=StringToDouble(value,(char **) NULL);
1736 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1737 dpx.orientation.x_size=0U;
1738 value=GetDPXProperty(image,"dpx:orientation.x_size",exception);
1739 if (value != (const char *) NULL)
1740 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1741 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1742 dpx.orientation.y_size=0U;
1743 value=GetDPXProperty(image,"dpx:orientation.y_size",exception);
1744 if (value != (const char *) NULL)
1745 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1746 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1747 value=GetDPXProperty(image,"dpx:orientation.filename",exception);
1748 if (value != (const char *) NULL)
1749 (void) strncpy(dpx.orientation.filename,value,
1750 sizeof(dpx.orientation.filename)-1);
1751 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1752 dpx.orientation.filename);
1753 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1754 dpx.orientation.timestamp);
1755 value=GetDPXProperty(image,"dpx:orientation.device",exception);
1756 if (value != (const char *) NULL)
1757 (void) strncpy(dpx.orientation.device,value,
1758 sizeof(dpx.orientation.device)-1);
1759 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1760 dpx.orientation.device);
1761 value=GetDPXProperty(image,"dpx:orientation.serial",exception);
1762 if (value != (const char *) NULL)
1763 (void) strncpy(dpx.orientation.serial,value,
1764 sizeof(dpx.orientation.serial)-1);
1765 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1766 dpx.orientation.serial);
1767 for (i=0; i < 4; i++)
1768 dpx.orientation.border[i]=0;
1769 value=GetDPXProperty(image,"dpx:orientation.border",exception);
1770 if (value != (const char *) NULL)
1772 flags=ParseGeometry(value,&geometry_info);
1773 if ((flags & SigmaValue) == 0)
1774 geometry_info.sigma=geometry_info.rho;
1775 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1776 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1777 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1778 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1780 for (i=0; i < 4; i++)
1781 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1782 for (i=0; i < 2; i++)
1783 dpx.orientation.aspect_ratio[i]=0U;
1784 value=GetDPXProperty(image,"dpx:orientation.aspect_ratio",exception);
1785 if (value != (const char *) NULL)
1787 flags=ParseGeometry(value,&geometry_info);
1788 if ((flags & SigmaValue) == 0)
1789 geometry_info.sigma=geometry_info.rho;
1790 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1791 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1793 for (i=0; i < 2; i++)
1794 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1795 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1796 dpx.orientation.reserve);
1800 (void) memset(dpx.film.id,0,sizeof(dpx.film.id));
1801 value=GetDPXProperty(image,"dpx:film.id",exception);
1802 if (value != (const char *) NULL)
1803 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id)-1);
1804 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1805 (void) memset(dpx.film.type,0,sizeof(dpx.film.type));
1806 value=GetDPXProperty(image,"dpx:film.type",exception);
1807 if (value != (const char *) NULL)
1808 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type)-1);
1809 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1811 (void) memset(dpx.film.offset,0,sizeof(dpx.film.offset));
1812 value=GetDPXProperty(image,"dpx:film.offset",exception);
1813 if (value != (const char *) NULL)
1814 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset)-1);
1815 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1817 (void) memset(dpx.film.prefix,0,sizeof(dpx.film.prefix));
1818 value=GetDPXProperty(image,"dpx:film.prefix",exception);
1819 if (value != (const char *) NULL)
1820 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix)-1);
1821 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1823 (void) memset(dpx.film.count,0,sizeof(dpx.film.count));
1824 value=GetDPXProperty(image,"dpx:film.count",exception);
1825 if (value != (const char *) NULL)
1826 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count)-1);
1827 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1829 (void) memset(dpx.film.format,0,sizeof(dpx.film.format));
1830 value=GetDPXProperty(image,"dpx:film.format",exception);
1831 if (value != (const char *) NULL)
1832 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format)-1);
1833 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1835 dpx.film.frame_position=0U;
1836 value=GetDPXProperty(image,"dpx:film.frame_position",exception);
1837 if (value != (const char *) NULL)
1838 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1839 offset+=WriteBlobLong(image,dpx.film.frame_position);
1840 dpx.film.sequence_extent=0U;
1841 value=GetDPXProperty(image,"dpx:film.sequence_extent",exception);
1842 if (value != (const char *) NULL)
1843 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1844 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1845 dpx.film.held_count=0U;
1846 value=GetDPXProperty(image,"dpx:film.held_count",exception);
1847 if (value != (const char *) NULL)
1848 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1849 offset+=WriteBlobLong(image,dpx.film.held_count);
1850 dpx.film.frame_rate=0.0f;
1851 value=GetDPXProperty(image,"dpx:film.frame_rate",exception);
1852 if (value != (const char *) NULL)
1853 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
1854 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1855 dpx.film.shutter_angle=0.0f;
1856 value=GetDPXProperty(image,"dpx:film.shutter_angle",exception);
1857 if (value != (const char *) NULL)
1858 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
1859 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1860 (void) memset(dpx.film.frame_id,0,sizeof(dpx.film.frame_id));
1861 value=GetDPXProperty(image,"dpx:film.frame_id",exception);
1862 if (value != (const char *) NULL)
1863 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id)-1);
1864 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1866 value=GetDPXProperty(image,"dpx:film.slate",exception);
1867 if (value != (const char *) NULL)
1868 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate)-1);
1869 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1871 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1874 Write television header.
1876 value=GetDPXProperty(image,"dpx:television.time.code",exception);
1877 if (value != (const char *) NULL)
1878 dpx.television.time_code=StringToTimeCode(value);
1879 offset+=WriteBlobLong(image,dpx.television.time_code);
1880 value=GetDPXProperty(image,"dpx:television.user.bits",exception);
1881 if (value != (const char *) NULL)
1882 dpx.television.user_bits=StringToTimeCode(value);
1883 offset+=WriteBlobLong(image,dpx.television.user_bits);
1884 value=GetDPXProperty(image,"dpx:television.interlace",exception);
1885 if (value != (const char *) NULL)
1886 dpx.television.interlace=(unsigned char) StringToLong(value);
1887 offset+=WriteBlobByte(image,dpx.television.interlace);
1888 value=GetDPXProperty(image,"dpx:television.field_number",exception);
1889 if (value != (const char *) NULL)
1890 dpx.television.field_number=(unsigned char) StringToLong(value);
1891 offset+=WriteBlobByte(image,dpx.television.field_number);
1892 dpx.television.video_signal=0;
1893 value=GetDPXProperty(image,"dpx:television.video_signal",exception);
1894 if (value != (const char *) NULL)
1895 dpx.television.video_signal=(unsigned char) StringToLong(value);
1896 offset+=WriteBlobByte(image,dpx.television.video_signal);
1897 dpx.television.padding=0;
1898 value=GetDPXProperty(image,"dpx:television.padding",exception);
1899 if (value != (const char *) NULL)
1900 dpx.television.padding=(unsigned char) StringToLong(value);
1901 offset+=WriteBlobByte(image,dpx.television.padding);
1902 dpx.television.horizontal_sample_rate=0.0f;
1903 value=GetDPXProperty(image,"dpx:television.horizontal_sample_rate",
1905 if (value != (const char *) NULL)
1906 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
1907 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1908 dpx.television.vertical_sample_rate=0.0f;
1909 value=GetDPXProperty(image,"dpx:television.vertical_sample_rate",exception);
1910 if (value != (const char *) NULL)
1911 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
1912 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1913 dpx.television.frame_rate=0.0f;
1914 value=GetDPXProperty(image,"dpx:television.frame_rate",exception);
1915 if (value != (const char *) NULL)
1916 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
1917 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1918 dpx.television.time_offset=0.0f;
1919 value=GetDPXProperty(image,"dpx:television.time_offset",exception);
1920 if (value != (const char *) NULL)
1921 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
1922 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1923 dpx.television.gamma=0.0f;
1924 value=GetDPXProperty(image,"dpx:television.gamma",exception);
1925 if (value != (const char *) NULL)
1926 dpx.television.gamma=StringToDouble(value,(char **) NULL);
1927 offset+=WriteBlobFloat(image,dpx.television.gamma);
1928 dpx.television.black_level=0.0f;
1929 value=GetDPXProperty(image,"dpx:television.black_level",exception);
1930 if (value != (const char *) NULL)
1931 dpx.television.black_level=StringToDouble(value,(char **) NULL);
1932 offset+=WriteBlobFloat(image,dpx.television.black_level);
1933 dpx.television.black_gain=0.0f;
1934 value=GetDPXProperty(image,"dpx:television.black_gain",exception);
1935 if (value != (const char *) NULL)
1936 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
1937 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1938 dpx.television.break_point=0.0f;
1939 value=GetDPXProperty(image,"dpx:television.break_point",exception);
1940 if (value != (const char *) NULL)
1941 dpx.television.break_point=StringToDouble(value,(char **) NULL);
1942 offset+=WriteBlobFloat(image,dpx.television.break_point);
1943 dpx.television.white_level=0.0f;
1944 value=GetDPXProperty(image,"dpx:television.white_level",exception);
1945 if (value != (const char *) NULL)
1946 dpx.television.white_level=StringToDouble(value,(char **) NULL);
1947 offset+=WriteBlobFloat(image,dpx.television.white_level);
1948 dpx.television.integration_times=0.0f;
1949 value=GetDPXProperty(image,"dpx:television.integration_times",exception);
1950 if (value != (const char *) NULL)
1951 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
1952 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1953 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1954 dpx.television.reserve);
1958 value=GetDPXProperty(image,"dpx:user.id",exception);
1959 if (value != (const char *) NULL)
1960 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id)-1);
1961 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1962 if (profile != (StringInfo *) NULL)
1963 offset+=WriteBlob(image,GetStringInfoLength(profile),
1964 GetStringInfoDatum(profile));
1965 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1967 count=WriteBlobByte(image,0x00);
1970 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
1977 Convert pixel packets to DPX raster image.
1979 quantum_info=AcquireQuantumInfo(image_info,image);
1980 if (quantum_info == (QuantumInfo *) NULL)
1981 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1982 SetQuantumQuantum(quantum_info,32);
1983 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1984 MagickTrue : MagickFalse);
1985 quantum_type=RGBQuantum;
1986 if (image->alpha_trait != UndefinedPixelTrait)
1987 quantum_type=RGBAQuantum;
1988 if (image->colorspace == YCbCrColorspace)
1990 quantum_type=CbYCrQuantum;
1991 if (image->alpha_trait != UndefinedPixelTrait)
1992 quantum_type=CbYCrAQuantum;
1993 if ((horizontal_factor == 2) || (vertical_factor == 2))
1994 quantum_type=CbYCrYQuantum;
1996 extent=GetBytesPerRow(image->columns,
1997 image->alpha_trait != UndefinedPixelTrait ? 4UL : 3UL,image->depth,
1998 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1999 if ((image_info->type != TrueColorType) &&
2000 (image->alpha_trait == UndefinedPixelTrait) &&
2001 (SetImageGray(image,exception) != MagickFalse))
2003 quantum_type=GrayQuantum;
2004 extent=GetBytesPerRow(image->columns,1UL,image->depth,
2005 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
2007 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
2008 for (y=0; y < (ssize_t) image->rows; y++)
2013 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2014 if (p == (const Quantum *) NULL)
2016 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2017 quantum_type,pixels,exception);
2020 count=WriteBlob(image,extent,pixels);
2021 if (count != (ssize_t) extent)
2023 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
2025 if (status == MagickFalse)
2028 quantum_info=DestroyQuantumInfo(quantum_info);
2029 if (y < (ssize_t) image->rows)
2030 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
2031 (void) CloseBlob(image);