2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write SMTPE DPX Image Format %
20 % Copyright 1999-2017 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 if (pad == MagickFalse)
446 bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+
450 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
456 bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
462 bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
467 return(bytes_per_row);
470 static const char *GetImageTransferCharacteristic(
471 const DPXTransferCharacteristic characteristic)
477 Get the element transfer characteristic.
479 switch(characteristic)
481 case TransferCharacteristicUserDefined:
483 transfer="UserDefined";
486 case TransferCharacteristicPrintingDensity:
488 transfer="PrintingDensity";
491 case TransferCharacteristicLinear:
496 case TransferCharacteristicLogarithmic:
498 transfer="Logarithmic";
501 case TransferCharacteristicUnspecifiedVideo:
503 transfer="UnspecifiedVideo";
506 case TransferCharacteristicSMTPE274M:
508 transfer="SMTPE274M";
511 case TransferCharacteristicITU_R709:
516 case TransferCharacteristicITU_R601_625L:
518 transfer="ITU-R601-625L";
521 case TransferCharacteristicITU_R601_525L:
523 transfer="ITU-R601-525L";
526 case TransferCharacteristicNTSCCompositeVideo:
528 transfer="NTSCCompositeVideo";
531 case TransferCharacteristicPALCompositeVideo:
533 transfer="PALCompositeVideo";
536 case TransferCharacteristicZDepthLinear:
538 transfer="ZDepthLinear";
541 case TransferCharacteristicZDepthHomogeneous:
543 transfer="ZDepthHomogeneous";
552 static inline MagickBooleanType IsFloatDefined(const float value)
563 quantum.unsigned_value=0U;
564 quantum.float_value=(float) value;
565 if (quantum.unsigned_value == 0U)
570 static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
571 ChromaticityInfo *chromaticity_info)
575 case SMTPE_274MColorimetric:
576 case ITU_R709Colorimetric:
578 chromaticity_info->red_primary.x=0.640;
579 chromaticity_info->red_primary.y=0.330;
580 chromaticity_info->red_primary.z=0.030;
581 chromaticity_info->green_primary.x=0.300;
582 chromaticity_info->green_primary.y=0.600;
583 chromaticity_info->green_primary.z=0.100;
584 chromaticity_info->blue_primary.x=0.150;
585 chromaticity_info->blue_primary.y=0.060;
586 chromaticity_info->blue_primary.z=0.790;
587 chromaticity_info->white_point.x=0.3127;
588 chromaticity_info->white_point.y=0.3290;
589 chromaticity_info->white_point.z=0.3582;
592 case NTSCCompositeVideoColorimetric:
594 chromaticity_info->red_primary.x=0.67;
595 chromaticity_info->red_primary.y=0.33;
596 chromaticity_info->red_primary.z=0.00;
597 chromaticity_info->green_primary.x=0.21;
598 chromaticity_info->green_primary.y=0.71;
599 chromaticity_info->green_primary.z=0.08;
600 chromaticity_info->blue_primary.x=0.14;
601 chromaticity_info->blue_primary.y=0.08;
602 chromaticity_info->blue_primary.z=0.78;
603 chromaticity_info->white_point.x=0.310;
604 chromaticity_info->white_point.y=0.316;
605 chromaticity_info->white_point.z=0.374;
608 case PALCompositeVideoColorimetric:
610 chromaticity_info->red_primary.x=0.640;
611 chromaticity_info->red_primary.y=0.330;
612 chromaticity_info->red_primary.z=0.030;
613 chromaticity_info->green_primary.x=0.290;
614 chromaticity_info->green_primary.y=0.600;
615 chromaticity_info->green_primary.z=0.110;
616 chromaticity_info->blue_primary.x=0.150;
617 chromaticity_info->blue_primary.y=0.060;
618 chromaticity_info->blue_primary.z=0.790;
619 chromaticity_info->white_point.x=0.3127;
620 chromaticity_info->white_point.y=0.3290;
621 chromaticity_info->white_point.z=0.3582;
629 static void TimeCodeToString(const size_t timestamp,char *code)
641 for (i=0; i <= TimeFields; i++)
643 (void) FormatLocaleString(code,MagickPathExtent-strlen(code),"%x",
644 (unsigned int) ((timestamp >> shift) & 0x0fU));
646 if (((i % 2) != 0) && (i < TimeFields))
653 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
657 value[MagickPathExtent];
696 assert(image_info != (const ImageInfo *) NULL);
697 assert(image_info->signature == MagickCoreSignature);
698 if (image_info->debug != MagickFalse)
699 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
700 image_info->filename);
701 assert(exception != (ExceptionInfo *) NULL);
702 assert(exception->signature == MagickCoreSignature);
703 image=AcquireImage(image_info,exception);
704 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
705 if (status == MagickFalse)
707 image=DestroyImageList(image);
708 return((Image *) NULL);
711 Read DPX file header.
714 count=ReadBlob(image,4,(unsigned char *) magick);
716 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
717 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
718 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
719 image->endian=LSBEndian;
720 if (LocaleNCompare(magick,"SDPX",4) == 0)
721 image->endian=MSBEndian;
722 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
723 dpx.file.image_offset=ReadBlobLong(image);
725 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
727 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
728 dpx.file.file_size=ReadBlobLong(image);
730 dpx.file.ditto_key=ReadBlobLong(image);
732 if (dpx.file.ditto_key != ~0U)
733 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
735 dpx.file.generic_size=ReadBlobLong(image);
737 dpx.file.industry_size=ReadBlobLong(image);
739 dpx.file.user_size=ReadBlobLong(image);
741 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
743 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
745 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
746 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
748 if (*dpx.file.timestamp != '\0')
749 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
751 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
753 if (*dpx.file.creator != '\0')
755 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
757 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
759 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
761 if (*dpx.file.project != '\0')
763 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
765 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
767 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
769 if (*dpx.file.copyright != '\0')
771 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
773 (void) FormatImageProperty(image,"copyright","%.100s",
776 dpx.file.encrypt_key=ReadBlobLong(image);
778 if (dpx.file.encrypt_key != ~0U)
779 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
780 dpx.file.encrypt_key);
781 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
784 Read DPX image header.
786 dpx.image.orientation=ReadBlobShort(image);
787 if (dpx.image.orientation > 7)
788 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
790 if (dpx.image.orientation != (unsigned short) ~0)
791 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
792 dpx.image.orientation);
793 switch (dpx.image.orientation)
796 case 0: image->orientation=TopLeftOrientation; break;
797 case 1: image->orientation=TopRightOrientation; break;
798 case 2: image->orientation=BottomLeftOrientation; break;
799 case 3: image->orientation=BottomRightOrientation; break;
800 case 4: image->orientation=LeftTopOrientation; break;
801 case 5: image->orientation=RightTopOrientation; break;
802 case 6: image->orientation=LeftBottomOrientation; break;
803 case 7: image->orientation=RightBottomOrientation; break;
805 dpx.image.number_elements=ReadBlobShort(image);
806 if (dpx.image.number_elements > MaxNumberImageElements)
807 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
809 dpx.image.pixels_per_line=ReadBlobLong(image);
811 image->columns=dpx.image.pixels_per_line;
812 dpx.image.lines_per_element=ReadBlobLong(image);
814 image->rows=dpx.image.lines_per_element;
815 for (i=0; i < 8; i++)
818 property[MagickPathExtent];
820 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
822 dpx.image.image_element[i].low_data=ReadBlobLong(image);
824 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
826 dpx.image.image_element[i].high_data=ReadBlobLong(image);
828 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
830 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
832 dpx.image.image_element[i].transfer_characteristic=(unsigned char)
834 (void) FormatLocaleString(property,MagickPathExtent,
835 "dpx:image.element[%lu].transfer-characteristic",(long) i);
836 (void) FormatImageProperty(image,property,"%s",
837 GetImageTransferCharacteristic((DPXTransferCharacteristic)
838 dpx.image.image_element[i].transfer_characteristic));
840 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
842 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
844 dpx.image.image_element[i].packing=ReadBlobShort(image);
846 dpx.image.image_element[i].encoding=ReadBlobShort(image);
848 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
850 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
852 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
854 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
855 (unsigned char *) dpx.image.image_element[i].description);
857 SetImageColorspace(image,RGBColorspace,exception);
858 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
860 if (dpx.file.image_offset >= 1664U)
863 Read DPX orientation header.
865 dpx.orientation.x_offset=ReadBlobLong(image);
867 if (dpx.orientation.x_offset != ~0U)
868 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
869 dpx.orientation.x_offset);
870 dpx.orientation.y_offset=ReadBlobLong(image);
872 if (dpx.orientation.y_offset != ~0U)
873 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
874 dpx.orientation.y_offset);
875 dpx.orientation.x_center=ReadBlobFloat(image);
877 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
878 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
879 dpx.orientation.x_center);
880 dpx.orientation.y_center=ReadBlobFloat(image);
882 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
883 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
884 dpx.orientation.y_center);
885 dpx.orientation.x_size=ReadBlobLong(image);
887 if (dpx.orientation.x_size != ~0U)
888 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
889 dpx.orientation.x_size);
890 dpx.orientation.y_size=ReadBlobLong(image);
892 if (dpx.orientation.y_size != ~0U)
893 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
894 dpx.orientation.y_size);
895 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
896 dpx.orientation.filename);
897 if (*dpx.orientation.filename != '\0')
898 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
899 dpx.orientation.filename);
900 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
901 dpx.orientation.timestamp);
902 if (*dpx.orientation.timestamp != '\0')
903 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
904 dpx.orientation.timestamp);
905 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
906 dpx.orientation.device);
907 if (*dpx.orientation.device != '\0')
908 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
909 dpx.orientation.device);
910 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
911 dpx.orientation.serial);
912 if (*dpx.orientation.serial != '\0')
913 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
914 dpx.orientation.serial);
915 for (i=0; i < 4; i++)
917 dpx.orientation.border[i]=ReadBlobShort(image);
920 if ((dpx.orientation.border[0] != (unsigned short) (~0)) &&
921 (dpx.orientation.border[1] != (unsigned short) (~0)))
922 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d",
923 dpx.orientation.border[0],dpx.orientation.border[1],
924 dpx.orientation.border[2],dpx.orientation.border[3]);
925 for (i=0; i < 2; i++)
927 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
930 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
931 (dpx.orientation.aspect_ratio[1] != ~0U))
932 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
933 "%ux%u",dpx.orientation.aspect_ratio[0],
934 dpx.orientation.aspect_ratio[1]);
935 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
936 dpx.orientation.reserve);
938 if (dpx.file.image_offset >= 1920U)
941 Read DPX film header.
943 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
944 if (*dpx.film.id != '\0')
945 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
946 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
948 if (*dpx.film.type != '\0')
949 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
950 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
952 if (*dpx.film.offset != '\0')
953 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
955 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
957 if (*dpx.film.prefix != '\0')
958 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
960 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
962 if (*dpx.film.count != '\0')
963 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
965 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
967 if (*dpx.film.format != '\0')
968 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
970 dpx.film.frame_position=ReadBlobLong(image);
972 if (dpx.film.frame_position != ~0U)
973 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
974 dpx.film.frame_position);
975 dpx.film.sequence_extent=ReadBlobLong(image);
977 if (dpx.film.sequence_extent != ~0U)
978 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
979 dpx.film.sequence_extent);
980 dpx.film.held_count=ReadBlobLong(image);
982 if (dpx.film.held_count != ~0U)
983 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
984 dpx.film.held_count);
985 dpx.film.frame_rate=ReadBlobFloat(image);
987 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
988 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
989 dpx.film.frame_rate);
990 dpx.film.shutter_angle=ReadBlobFloat(image);
992 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
993 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
994 dpx.film.shutter_angle);
995 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
997 if (*dpx.film.frame_id != '\0')
998 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
1000 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1002 if (*dpx.film.slate != '\0')
1003 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
1005 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1008 if (dpx.file.image_offset >= 2048U)
1011 Read DPX television header.
1013 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
1015 TimeCodeToString(dpx.television.time_code,value);
1016 (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
1017 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
1019 TimeCodeToString(dpx.television.user_bits,value);
1020 (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
1021 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
1023 if (dpx.television.interlace != 0)
1024 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
1025 (double) dpx.television.interlace);
1026 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
1028 if (dpx.television.field_number != 0)
1029 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
1030 (double) dpx.television.field_number);
1031 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
1033 if (dpx.television.video_signal != 0)
1034 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
1035 (double) dpx.television.video_signal);
1036 dpx.television.padding=(unsigned char) ReadBlobByte(image);
1038 if (dpx.television.padding != 0)
1039 (void) FormatImageProperty(image,"dpx:television.padding","%d",
1040 dpx.television.padding);
1041 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
1043 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
1044 (void) FormatImageProperty(image,
1045 "dpx:television.horizontal_sample_rate","%g",
1046 dpx.television.horizontal_sample_rate);
1047 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
1049 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
1050 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
1051 "%g",dpx.television.vertical_sample_rate);
1052 dpx.television.frame_rate=ReadBlobFloat(image);
1054 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
1055 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
1056 dpx.television.frame_rate);
1057 dpx.television.time_offset=ReadBlobFloat(image);
1059 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
1060 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
1061 dpx.television.time_offset);
1062 dpx.television.gamma=ReadBlobFloat(image);
1064 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
1065 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
1066 dpx.television.gamma);
1067 dpx.television.black_level=ReadBlobFloat(image);
1069 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
1070 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
1071 dpx.television.black_level);
1072 dpx.television.black_gain=ReadBlobFloat(image);
1074 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
1075 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
1076 dpx.television.black_gain);
1077 dpx.television.break_point=ReadBlobFloat(image);
1079 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
1080 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
1081 dpx.television.break_point);
1082 dpx.television.white_level=ReadBlobFloat(image);
1084 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
1085 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
1086 dpx.television.white_level);
1087 dpx.television.integration_times=ReadBlobFloat(image);
1089 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
1090 (void) FormatImageProperty(image,"dpx:television.integration_times",
1091 "%g",dpx.television.integration_times);
1092 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1093 dpx.television.reserve);
1095 if (dpx.file.image_offset > 2080U)
1098 Read DPX user header.
1100 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1101 if (*dpx.user.id != '\0')
1102 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
1103 if ((dpx.file.user_size != ~0U) &&
1104 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
1109 profile=BlobToStringInfo((const unsigned char *) NULL,
1110 dpx.file.user_size-sizeof(dpx.user.id));
1111 if (profile == (StringInfo *) NULL)
1112 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1113 offset+=ReadBlob(image,GetStringInfoLength(profile),
1114 GetStringInfoDatum(profile));
1115 (void) SetImageProfile(image,"dpx:user-data",profile,exception);
1116 profile=DestroyStringInfo(profile);
1119 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
1120 (void) ReadBlobByte(image);
1121 if (image_info->ping != MagickFalse)
1123 (void) CloseBlob(image);
1124 return(GetFirstImageInList(image));
1126 status=SetImageExtent(image,image->columns,image->rows,exception);
1127 if (status == MagickFalse)
1128 return(DestroyImageList(image));
1129 for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
1132 Convert DPX raster image to pixel packets.
1134 if ((dpx.image.image_element[n].data_offset != ~0U) &&
1135 (dpx.image.image_element[n].data_offset != 0U))
1140 data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
1141 if (data_offset < offset)
1142 offset=SeekBlob(image,data_offset,SEEK_SET);
1144 for ( ; offset < data_offset; offset++)
1145 (void) ReadBlobByte(image);
1146 if (offset != data_offset)
1147 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1149 SetPrimaryChromaticity((DPXColorimetric)
1150 dpx.image.image_element[n].colorimetric,&image->chromaticity);
1151 image->depth=dpx.image.image_element[n].bit_size;
1152 samples_per_pixel=1;
1153 quantum_type=GrayQuantum;
1154 component_type=dpx.image.image_element[n].descriptor;
1155 switch (component_type)
1157 case CbYCrY422ComponentType:
1159 samples_per_pixel=2;
1160 quantum_type=CbYCrYQuantum;
1163 case CbYACrYA4224ComponentType:
1164 case CbYCr444ComponentType:
1166 samples_per_pixel=3;
1167 quantum_type=CbYCrQuantum;
1170 case RGBComponentType:
1172 samples_per_pixel=3;
1173 quantum_type=RGBQuantum;
1176 case ABGRComponentType:
1177 case RGBAComponentType:
1179 image->alpha_trait=BlendPixelTrait;
1180 samples_per_pixel=4;
1181 quantum_type=RGBAQuantum;
1187 switch (component_type)
1189 case CbYCrY422ComponentType:
1190 case CbYACrYA4224ComponentType:
1191 case CbYCr444ComponentType:
1193 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1196 case LumaComponentType:
1198 SetImageColorspace(image,GRAYColorspace,exception);
1203 SetImageColorspace(image,sRGBColorspace,exception);
1204 if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
1205 SetImageColorspace(image,LogColorspace,exception);
1206 if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
1207 SetImageColorspace(image,LogColorspace,exception);
1211 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1212 dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
1214 DPX any-bit pixel format.
1218 quantum_info=AcquireQuantumInfo(image_info,image);
1219 if (quantum_info == (QuantumInfo *) NULL)
1220 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1221 SetQuantumQuantum(quantum_info,32);
1222 SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
1223 MagickTrue : MagickFalse);
1224 for (y=0; y < (ssize_t) image->rows; y++)
1241 if (status == MagickFalse)
1243 pixels=(const unsigned char *) ReadBlobStream(image,extent,
1244 GetQuantumPixels(quantum_info),&count);
1245 if (count != (ssize_t) extent)
1247 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1248 (image->previous == (Image *) NULL))
1253 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1255 if (proceed == MagickFalse)
1259 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
1260 if (q == (Quantum *) NULL)
1265 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1266 quantum_type,pixels,exception);
1268 sync=SyncAuthenticPixels(image,exception);
1269 if (sync == MagickFalse)
1272 quantum_info=DestroyQuantumInfo(quantum_info);
1273 if (status == MagickFalse)
1274 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1275 SetQuantumImageType(image,quantum_type);
1276 if (EOFBlob(image) != MagickFalse)
1277 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1279 if ((i+1) < (ssize_t) dpx.image.number_elements)
1282 Allocate next image structure.
1284 AcquireNextImage(image_info,image,exception);
1285 if (GetNextImageInList(image) == (Image *) NULL)
1287 image=DestroyImageList(image);
1288 return((Image *) NULL);
1290 image=SyncNextImageInList(image);
1291 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1292 GetBlobSize(image));
1293 if (status == MagickFalse)
1297 (void) CloseBlob(image);
1298 return(GetFirstImageInList(image));
1302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1306 % R e g i s t e r D P X I m a g e %
1310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1312 % RegisterDPXImage() adds properties for the DPX image format to
1313 % the list of supported formats. The properties include the image format
1314 % tag, a method to read and/or write the format, whether the format
1315 % supports the saving of more than one frame to the same file or blob,
1316 % whether the format supports native in-memory I/O, and a brief
1317 % description of the format.
1319 % The format of the RegisterDPXImage method is:
1321 % size_t RegisterDPXImage(void)
1324 ModuleExport size_t RegisterDPXImage(void)
1332 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1333 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1336 entry=AcquireMagickInfo("DPX","DPX","SMPTE 268M-2003 (DPX 2.0)");
1337 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1338 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1339 entry->magick=(IsImageFormatHandler *) IsDPX;
1340 entry->flags^=CoderAdjoinFlag;
1341 entry->flags|=CoderDecoderSeekableStreamFlag;
1342 entry->note=ConstantString(DPXNote);
1343 (void) RegisterMagickInfo(entry);
1344 return(MagickImageCoderSignature);
1348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1352 % U n r e g i s t e r D P X I m a g e %
1356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1358 % UnregisterDPXImage() removes format registrations made by the
1359 % DPX module from the list of supported formats.
1361 % The format of the UnregisterDPXImage method is:
1363 % UnregisterDPXImage(void)
1366 ModuleExport void UnregisterDPXImage(void)
1368 (void) UnregisterMagickInfo("DPX");
1372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376 % W r i t e D P X I m a g e %
1380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1382 % WriteDPXImage() writes an image in DPX encoded image format.
1384 % The format of the WriteDPXImage method is:
1386 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1387 % Image *image,ExceptionInfo *exception)
1389 % A description of each parameter follows.
1391 % o image_info: the image info.
1393 % o image: The image.
1395 % o exception: return any errors or warnings in this structure.
1399 static unsigned int StringToTimeCode(const char *key)
1414 for (i=0; (*key != 0) && (i < 11); i++)
1416 if (isxdigit((int) ((unsigned char) *key)) == 0)
1422 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1428 static inline const char *GetDPXProperty(const Image *image,
1429 const char *property,ExceptionInfo *exception)
1434 value=GetImageArtifact(image,property);
1435 if (value != (const char *) NULL)
1437 return(GetImageProperty(image,property,exception));
1440 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1441 ExceptionInfo *exception)
1473 register const Quantum
1495 Open output image file.
1497 assert(image_info != (const ImageInfo *) NULL);
1498 assert(image_info->signature == MagickCoreSignature);
1499 assert(image != (Image *) NULL);
1500 assert(image->signature == MagickCoreSignature);
1501 if (image->debug != MagickFalse)
1502 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1503 horizontal_factor=4;
1505 if (image_info->sampling_factor != (char *) NULL)
1507 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1508 horizontal_factor=(ssize_t) geometry_info.rho;
1509 vertical_factor=(ssize_t) geometry_info.sigma;
1510 if ((flags & SigmaValue) == 0)
1511 vertical_factor=horizontal_factor;
1512 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1513 (horizontal_factor != 4) && (vertical_factor != 1) &&
1514 (vertical_factor != 2) && (vertical_factor != 4))
1515 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1517 if ((image->colorspace == YCbCrColorspace) &&
1518 ((horizontal_factor == 2) || (vertical_factor == 2)))
1519 if ((image->columns % 2) != 0)
1521 assert(exception != (ExceptionInfo *) NULL);
1522 assert(exception->signature == MagickCoreSignature);
1523 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1524 if (status == MagickFalse)
1529 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1531 dpx.file.magic=0x53445058U;
1532 offset+=WriteBlobLong(image,dpx.file.magic);
1533 dpx.file.image_offset=0x2000U;
1534 profile=GetImageProfile(image,"dpx:user-data");
1535 if (profile != (StringInfo *) NULL)
1537 if (GetStringInfoLength(profile) > 1048576)
1538 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1539 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1540 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1542 offset+=WriteBlobLong(image,dpx.file.image_offset);
1543 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version)-1);
1544 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1545 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1546 dpx.file.image_offset);
1547 offset+=WriteBlobLong(image,dpx.file.file_size);
1548 dpx.file.ditto_key=1U; /* new frame */
1549 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1550 dpx.file.generic_size=0x00000680U;
1551 offset+=WriteBlobLong(image,dpx.file.generic_size);
1552 dpx.file.industry_size=0x00000180U;
1553 offset+=WriteBlobLong(image,dpx.file.industry_size);
1554 dpx.file.user_size=0;
1555 if (profile != (StringInfo *) NULL)
1557 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1558 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1560 offset+=WriteBlobLong(image,dpx.file.user_size);
1561 value=GetDPXProperty(image,"dpx:file.filename",exception);
1562 if (value != (const char *) NULL)
1563 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename)-1);
1564 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1566 seconds=time((time_t *) NULL);
1567 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1568 dpx.file.timestamp);
1569 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1570 dpx.file.timestamp);
1571 url=GetMagickHomeURL();
1572 (void) strncpy(dpx.file.creator,url,sizeof(dpx.file.creator)-1);
1573 url=DestroyString(url);
1574 value=GetDPXProperty(image,"dpx:file.creator",exception);
1575 if (value != (const char *) NULL)
1576 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator)-1);
1577 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1579 value=GetDPXProperty(image,"dpx:file.project",exception);
1580 if (value != (const char *) NULL)
1581 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project)-1);
1582 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1584 value=GetDPXProperty(image,"dpx:file.copyright",exception);
1585 if (value != (const char *) NULL)
1586 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright)-1);
1587 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1588 dpx.file.copyright);
1589 dpx.file.encrypt_key=(~0U);
1590 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1591 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1596 switch (image->orientation)
1599 case TopLeftOrientation: dpx.image.orientation=0; break;
1600 case TopRightOrientation: dpx.image.orientation=1; break;
1601 case BottomLeftOrientation: dpx.image.orientation=2; break;
1602 case BottomRightOrientation: dpx.image.orientation=3; break;
1603 case LeftTopOrientation: dpx.image.orientation=4; break;
1604 case RightTopOrientation: dpx.image.orientation=5; break;
1605 case LeftBottomOrientation: dpx.image.orientation=6; break;
1606 case RightBottomOrientation: dpx.image.orientation=7; break;
1608 offset+=WriteBlobShort(image,dpx.image.orientation);
1609 dpx.image.number_elements=1;
1610 offset+=WriteBlobShort(image,dpx.image.number_elements);
1611 if ((image->columns != (unsigned int) image->columns) ||
1612 (image->rows != (unsigned int) image->rows))
1613 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1614 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1615 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1616 for (i=0; i < 8; i++)
1618 dpx.image.image_element[i].data_sign=0U;
1619 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1620 dpx.image.image_element[i].low_data=0U;
1621 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1622 dpx.image.image_element[i].low_quantity=0.0f;
1623 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1624 dpx.image.image_element[i].high_data=0U;
1625 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1626 dpx.image.image_element[i].high_quantity=0.0f;
1627 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1628 dpx.image.image_element[i].descriptor=0;
1630 switch (image->colorspace)
1632 case Rec601YCbCrColorspace:
1633 case Rec709YCbCrColorspace:
1634 case YCbCrColorspace:
1636 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1637 if (image->alpha_trait != UndefinedPixelTrait)
1638 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1643 dpx.image.image_element[i].descriptor=RGBComponentType;
1644 if (image->alpha_trait != UndefinedPixelTrait)
1645 dpx.image.image_element[i].descriptor=RGBAComponentType;
1646 if ((image_info->type != TrueColorType) &&
1647 (image->alpha_trait == UndefinedPixelTrait) &&
1648 (SetImageGray(image,exception) != MagickFalse))
1649 dpx.image.image_element[i].descriptor=LumaComponentType;
1653 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1654 dpx.image.image_element[i].transfer_characteristic=0;
1655 if (image->colorspace == LogColorspace)
1656 dpx.image.image_element[0].transfer_characteristic=
1657 PrintingDensityColorimetric;
1658 offset+=WriteBlobByte(image,
1659 dpx.image.image_element[i].transfer_characteristic);
1660 dpx.image.image_element[i].colorimetric=0;
1661 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1662 dpx.image.image_element[i].bit_size=0;
1664 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1665 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1666 dpx.image.image_element[i].packing=0;
1667 if ((image->depth == 10) || (image->depth == 12))
1668 dpx.image.image_element[i].packing=1;
1669 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1670 dpx.image.image_element[i].encoding=0;
1671 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1672 dpx.image.image_element[i].data_offset=0U;
1674 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1675 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1676 dpx.image.image_element[i].end_of_line_padding=0U;
1677 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1678 offset+=WriteBlobLong(image,
1679 dpx.image.image_element[i].end_of_image_padding);
1680 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1681 (unsigned char *) dpx.image.image_element[i].description);
1683 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1686 Write orientation header.
1688 if ((image->rows != image->magick_rows) ||
1689 (image->columns != image->magick_columns))
1692 These properties are not valid if image size changed.
1694 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1695 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1696 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1697 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1698 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1699 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1701 dpx.orientation.x_offset=0U;
1702 value=GetDPXProperty(image,"dpx:orientation.x_offset",exception);
1703 if (value != (const char *) NULL)
1704 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1705 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1706 dpx.orientation.y_offset=0U;
1707 value=GetDPXProperty(image,"dpx:orientation.y_offset",exception);
1708 if (value != (const char *) NULL)
1709 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1710 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1711 dpx.orientation.x_center=0.0f;
1712 value=GetDPXProperty(image,"dpx:orientation.x_center",exception);
1713 if (value != (const char *) NULL)
1714 dpx.orientation.x_center=StringToDouble(value,(char **) NULL);
1715 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1716 dpx.orientation.y_center=0.0f;
1717 value=GetDPXProperty(image,"dpx:orientation.y_center",exception);
1718 if (value != (const char *) NULL)
1719 dpx.orientation.y_center=StringToDouble(value,(char **) NULL);
1720 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1721 dpx.orientation.x_size=0U;
1722 value=GetDPXProperty(image,"dpx:orientation.x_size",exception);
1723 if (value != (const char *) NULL)
1724 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1725 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1726 dpx.orientation.y_size=0U;
1727 value=GetDPXProperty(image,"dpx:orientation.y_size",exception);
1728 if (value != (const char *) NULL)
1729 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1730 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1731 value=GetDPXProperty(image,"dpx:orientation.filename",exception);
1732 if (value != (const char *) NULL)
1733 (void) strncpy(dpx.orientation.filename,value,
1734 sizeof(dpx.orientation.filename)-1);
1735 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1736 dpx.orientation.filename);
1737 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1738 dpx.orientation.timestamp);
1739 value=GetDPXProperty(image,"dpx:orientation.device",exception);
1740 if (value != (const char *) NULL)
1741 (void) strncpy(dpx.orientation.device,value,
1742 sizeof(dpx.orientation.device)-1);
1743 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1744 dpx.orientation.device);
1745 value=GetDPXProperty(image,"dpx:orientation.serial",exception);
1746 if (value != (const char *) NULL)
1747 (void) strncpy(dpx.orientation.serial,value,
1748 sizeof(dpx.orientation.serial)-1);
1749 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1750 dpx.orientation.serial);
1751 for (i=0; i < 4; i++)
1752 dpx.orientation.border[i]=0;
1753 value=GetDPXProperty(image,"dpx:orientation.border",exception);
1754 if (value != (const char *) NULL)
1756 flags=ParseGeometry(value,&geometry_info);
1757 if ((flags & SigmaValue) == 0)
1758 geometry_info.sigma=geometry_info.rho;
1759 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1760 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1761 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1762 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1764 for (i=0; i < 4; i++)
1765 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1766 for (i=0; i < 2; i++)
1767 dpx.orientation.aspect_ratio[i]=0U;
1768 value=GetDPXProperty(image,"dpx:orientation.aspect_ratio",exception);
1769 if (value != (const char *) NULL)
1771 flags=ParseGeometry(value,&geometry_info);
1772 if ((flags & SigmaValue) == 0)
1773 geometry_info.sigma=geometry_info.rho;
1774 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1775 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1777 for (i=0; i < 2; i++)
1778 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1779 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1780 dpx.orientation.reserve);
1784 (void) ResetMagickMemory(dpx.film.id,0,sizeof(dpx.film.id));
1785 value=GetDPXProperty(image,"dpx:film.id",exception);
1786 if (value != (const char *) NULL)
1787 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id)-1);
1788 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1789 (void) ResetMagickMemory(dpx.film.type,0,sizeof(dpx.film.type));
1790 value=GetDPXProperty(image,"dpx:film.type",exception);
1791 if (value != (const char *) NULL)
1792 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type)-1);
1793 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1795 (void) ResetMagickMemory(dpx.film.offset,0,sizeof(dpx.film.offset));
1796 value=GetDPXProperty(image,"dpx:film.offset",exception);
1797 if (value != (const char *) NULL)
1798 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset)-1);
1799 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1801 (void) ResetMagickMemory(dpx.film.prefix,0,sizeof(dpx.film.prefix));
1802 value=GetDPXProperty(image,"dpx:film.prefix",exception);
1803 if (value != (const char *) NULL)
1804 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix)-1);
1805 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1807 (void) ResetMagickMemory(dpx.film.count,0,sizeof(dpx.film.count));
1808 value=GetDPXProperty(image,"dpx:film.count",exception);
1809 if (value != (const char *) NULL)
1810 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count)-1);
1811 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1813 (void) ResetMagickMemory(dpx.film.format,0,sizeof(dpx.film.format));
1814 value=GetDPXProperty(image,"dpx:film.format",exception);
1815 if (value != (const char *) NULL)
1816 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format)-1);
1817 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1819 dpx.film.frame_position=0U;
1820 value=GetDPXProperty(image,"dpx:film.frame_position",exception);
1821 if (value != (const char *) NULL)
1822 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1823 offset+=WriteBlobLong(image,dpx.film.frame_position);
1824 dpx.film.sequence_extent=0U;
1825 value=GetDPXProperty(image,"dpx:film.sequence_extent",exception);
1826 if (value != (const char *) NULL)
1827 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1828 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1829 dpx.film.held_count=0U;
1830 value=GetDPXProperty(image,"dpx:film.held_count",exception);
1831 if (value != (const char *) NULL)
1832 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1833 offset+=WriteBlobLong(image,dpx.film.held_count);
1834 dpx.film.frame_rate=0.0f;
1835 value=GetDPXProperty(image,"dpx:film.frame_rate",exception);
1836 if (value != (const char *) NULL)
1837 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
1838 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1839 dpx.film.shutter_angle=0.0f;
1840 value=GetDPXProperty(image,"dpx:film.shutter_angle",exception);
1841 if (value != (const char *) NULL)
1842 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
1843 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1844 (void) ResetMagickMemory(dpx.film.frame_id,0,sizeof(dpx.film.frame_id));
1845 value=GetDPXProperty(image,"dpx:film.frame_id",exception);
1846 if (value != (const char *) NULL)
1847 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id)-1);
1848 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1850 value=GetDPXProperty(image,"dpx:film.slate",exception);
1851 if (value != (const char *) NULL)
1852 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate)-1);
1853 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1855 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1858 Write television header.
1860 value=GetDPXProperty(image,"dpx:television.time.code",exception);
1861 if (value != (const char *) NULL)
1862 dpx.television.time_code=StringToTimeCode(value);
1863 offset+=WriteBlobLong(image,dpx.television.time_code);
1864 value=GetDPXProperty(image,"dpx:television.user.bits",exception);
1865 if (value != (const char *) NULL)
1866 dpx.television.user_bits=StringToTimeCode(value);
1867 offset+=WriteBlobLong(image,dpx.television.user_bits);
1868 value=GetDPXProperty(image,"dpx:television.interlace",exception);
1869 if (value != (const char *) NULL)
1870 dpx.television.interlace=(unsigned char) StringToLong(value);
1871 offset+=WriteBlobByte(image,dpx.television.interlace);
1872 value=GetDPXProperty(image,"dpx:television.field_number",exception);
1873 if (value != (const char *) NULL)
1874 dpx.television.field_number=(unsigned char) StringToLong(value);
1875 offset+=WriteBlobByte(image,dpx.television.field_number);
1876 dpx.television.video_signal=0;
1877 value=GetDPXProperty(image,"dpx:television.video_signal",exception);
1878 if (value != (const char *) NULL)
1879 dpx.television.video_signal=(unsigned char) StringToLong(value);
1880 offset+=WriteBlobByte(image,dpx.television.video_signal);
1881 dpx.television.padding=0;
1882 value=GetDPXProperty(image,"dpx:television.padding",exception);
1883 if (value != (const char *) NULL)
1884 dpx.television.padding=(unsigned char) StringToLong(value);
1885 offset+=WriteBlobByte(image,dpx.television.padding);
1886 dpx.television.horizontal_sample_rate=0.0f;
1887 value=GetDPXProperty(image,"dpx:television.horizontal_sample_rate",
1889 if (value != (const char *) NULL)
1890 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
1891 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1892 dpx.television.vertical_sample_rate=0.0f;
1893 value=GetDPXProperty(image,"dpx:television.vertical_sample_rate",exception);
1894 if (value != (const char *) NULL)
1895 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
1896 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1897 dpx.television.frame_rate=0.0f;
1898 value=GetDPXProperty(image,"dpx:television.frame_rate",exception);
1899 if (value != (const char *) NULL)
1900 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
1901 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1902 dpx.television.time_offset=0.0f;
1903 value=GetDPXProperty(image,"dpx:television.time_offset",exception);
1904 if (value != (const char *) NULL)
1905 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
1906 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1907 dpx.television.gamma=0.0f;
1908 value=GetDPXProperty(image,"dpx:television.gamma",exception);
1909 if (value != (const char *) NULL)
1910 dpx.television.gamma=StringToDouble(value,(char **) NULL);
1911 offset+=WriteBlobFloat(image,dpx.television.gamma);
1912 dpx.television.black_level=0.0f;
1913 value=GetDPXProperty(image,"dpx:television.black_level",exception);
1914 if (value != (const char *) NULL)
1915 dpx.television.black_level=StringToDouble(value,(char **) NULL);
1916 offset+=WriteBlobFloat(image,dpx.television.black_level);
1917 dpx.television.black_gain=0.0f;
1918 value=GetDPXProperty(image,"dpx:television.black_gain",exception);
1919 if (value != (const char *) NULL)
1920 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
1921 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1922 dpx.television.break_point=0.0f;
1923 value=GetDPXProperty(image,"dpx:television.break_point",exception);
1924 if (value != (const char *) NULL)
1925 dpx.television.break_point=StringToDouble(value,(char **) NULL);
1926 offset+=WriteBlobFloat(image,dpx.television.break_point);
1927 dpx.television.white_level=0.0f;
1928 value=GetDPXProperty(image,"dpx:television.white_level",exception);
1929 if (value != (const char *) NULL)
1930 dpx.television.white_level=StringToDouble(value,(char **) NULL);
1931 offset+=WriteBlobFloat(image,dpx.television.white_level);
1932 dpx.television.integration_times=0.0f;
1933 value=GetDPXProperty(image,"dpx:television.integration_times",exception);
1934 if (value != (const char *) NULL)
1935 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
1936 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1937 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1938 dpx.television.reserve);
1942 value=GetDPXProperty(image,"dpx:user.id",exception);
1943 if (value != (const char *) NULL)
1944 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id)-1);
1945 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1946 if (profile != (StringInfo *) NULL)
1947 offset+=WriteBlob(image,GetStringInfoLength(profile),
1948 GetStringInfoDatum(profile));
1949 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1951 count=WriteBlobByte(image,0x00);
1954 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
1961 Convert pixel packets to DPX raster image.
1963 quantum_info=AcquireQuantumInfo(image_info,image);
1964 SetQuantumQuantum(quantum_info,32);
1965 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1966 MagickTrue : MagickFalse);
1967 quantum_type=RGBQuantum;
1968 if (image->alpha_trait != UndefinedPixelTrait)
1969 quantum_type=RGBAQuantum;
1970 if (image->colorspace == YCbCrColorspace)
1972 quantum_type=CbYCrQuantum;
1973 if (image->alpha_trait != UndefinedPixelTrait)
1974 quantum_type=CbYCrAQuantum;
1975 if ((horizontal_factor == 2) || (vertical_factor == 2))
1976 quantum_type=CbYCrYQuantum;
1978 extent=GetBytesPerRow(image->columns,
1979 image->alpha_trait != UndefinedPixelTrait ? 4UL : 3UL,image->depth,
1980 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1981 if ((image_info->type != TrueColorType) &&
1982 (image->alpha_trait == UndefinedPixelTrait) &&
1983 (SetImageGray(image,exception) != MagickFalse))
1985 quantum_type=GrayQuantum;
1986 extent=GetBytesPerRow(image->columns,1UL,image->depth,
1987 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1989 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
1990 for (y=0; y < (ssize_t) image->rows; y++)
1992 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1993 if (p == (const Quantum *) NULL)
1995 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1996 quantum_type,pixels,exception);
1997 count=WriteBlob(image,extent,pixels);
1998 if (count != (ssize_t) extent)
2000 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
2002 if (status == MagickFalse)
2005 quantum_info=DestroyQuantumInfo(quantum_info);
2006 (void) CloseBlob(image);