2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write SMTPE DPX Image Format %
20 % Copyright 1999-2008 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 "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/colorspace.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/geometry.h"
50 #include "magick/image.h"
51 #include "magick/image-private.h"
52 #include "magick/list.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/option.h"
58 #include "magick/profile.h"
59 #include "magick/property.h"
60 #include "magick/quantum-private.h"
61 #include "magick/static.h"
62 #include "magick/string_.h"
63 #include "magick/module.h"
64 #include "magick/module.h"
71 UserDefinedColorimetric = 0,
72 PrintingDensityColorimetric = 1,
73 LinearColorimetric = 2,
74 LogarithmicColorimetric = 3,
75 UnspecifiedVideoColorimetric = 4,
76 SMTPE_274MColorimetric = 5,
77 ITU_R709Colorimetric = 6,
78 ITU_R601_625LColorimetric = 7,
79 ITU_R601_525LColorimetric = 8,
80 NTSCCompositeVideoColorimetric = 9,
81 PALCompositeVideoColorimetric = 10,
82 ZDepthLinearColorimetric = 11,
83 DepthHomogeneousColorimetric = 12
88 UndefinedComponentType = 0,
90 GreenComponentType = 2,
91 BlueComponentType = 3,
92 AlphaComponentType = 4,
93 LumaComponentType = 6,
94 ColorDifferenceCbCrComponentType = 7,
95 DepthComponentType = 8,
96 CompositeVideoComponentType = 9,
97 RGBComponentType = 50,
98 RGBAComponentType = 51,
99 ABGRComponentType = 52,
100 CbYCrY422ComponentType = 100,
101 CbYACrYA4224ComponentType = 101,
102 CbYCr444ComponentType = 102,
103 CbYCrA4444ComponentType = 103,
104 UserDef2ElementComponentType = 150,
105 UserDef3ElementComponentType = 151,
106 UserDef4ElementComponentType = 152,
107 UserDef5ElementComponentType = 153,
108 UserDef6ElementComponentType = 154,
109 UserDef7ElementComponentType = 155,
110 UserDef8ElementComponentType = 156
113 typedef struct _DPXFileInfo
143 typedef struct _DPXFilmInfo
168 typedef struct _DPXImageElement
196 end_of_image_padding;
202 typedef struct _DPXImageInfo
219 typedef struct _DPXOrientationInfo
247 } DPXOrientationInfo;
249 typedef struct _DPXTelevisionInfo
262 horizontal_sample_rate,
263 vertical_sample_rate,
277 typedef struct _DPXUserInfo
283 typedef struct DPXInfo
305 Forward declaractions.
307 static MagickBooleanType
308 WriteDPXImage(const ImageInfo *,Image *);
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 % IsDPX() returns MagickTrue if the image format type, identified by the
322 % magick string, is DPX.
324 % The format of the IsDPX method is:
326 % MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
328 % A description of each parameter follows:
330 % o magick: compare image format pattern against these bytes.
332 % o extent: Specifies the extent of the magick string.
335 static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
339 if (memcmp(magick,"SDPX",4) == 0)
341 if (memcmp(magick,"XPDS",4) == 0)
347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351 % R e a d D P X I m a g e %
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 % ReadDPXImage() reads an DPX X image file and returns it. It
358 % allocates the memory necessary for the new Image structure and returns a
359 % pointer to the new image.
361 % The format of the ReadDPXImage method is:
363 % Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
365 % A description of each parameter follows:
367 % o image_info: the image info.
369 % o exception: return any errors or warnings in this structure.
373 static size_t GetBytesPerRow(unsigned long columns,
374 unsigned long samples_per_pixel,unsigned long bits_per_pixel,
375 MagickBooleanType pad)
380 switch (bits_per_pixel)
384 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
385 bits_per_pixel+31)/32);
391 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
392 bits_per_pixel+31)/32);
397 if (pad == MagickFalse)
399 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
400 bits_per_pixel+31)/32);
403 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns)/3))+31)/32);
408 if (pad == MagickFalse)
410 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
411 bits_per_pixel+31)/32);
414 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
419 bytes_per_row=2*(((size_t) samples_per_pixel*columns*
420 bits_per_pixel+8)/16);
425 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
426 bits_per_pixel+31)/32);
431 bytes_per_row=8*(((size_t) samples_per_pixel*columns*
432 bits_per_pixel+63)/64);
436 return(bytes_per_row);
439 static inline MagickBooleanType IsFloatDefined(const float value)
450 quantum.unsigned_value=0U;
451 quantum.float_value=(double) value;
452 if (quantum.unsigned_value == 0U)
457 static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
458 ChromaticityInfo *chromaticity_info)
462 case SMTPE_274MColorimetric:
463 case ITU_R709Colorimetric:
465 chromaticity_info->red_primary.x=0.640;
466 chromaticity_info->red_primary.y=0.330;
467 chromaticity_info->red_primary.z=0.030;
468 chromaticity_info->green_primary.x=0.300;
469 chromaticity_info->green_primary.y=0.600;
470 chromaticity_info->green_primary.z=0.100;
471 chromaticity_info->blue_primary.x=0.150;
472 chromaticity_info->blue_primary.y=0.060;
473 chromaticity_info->blue_primary.z=0.790;
474 chromaticity_info->white_point.x=0.3127;
475 chromaticity_info->white_point.y=0.3290;
476 chromaticity_info->white_point.z=0.3582;
479 case NTSCCompositeVideoColorimetric:
481 chromaticity_info->red_primary.x=0.67;
482 chromaticity_info->red_primary.y=0.33;
483 chromaticity_info->red_primary.z=0.00;
484 chromaticity_info->green_primary.x=0.21;
485 chromaticity_info->green_primary.y=0.71;
486 chromaticity_info->green_primary.z=0.08;
487 chromaticity_info->blue_primary.x=0.14;
488 chromaticity_info->blue_primary.y=0.08;
489 chromaticity_info->blue_primary.z=0.78;
490 chromaticity_info->white_point.x=0.310;
491 chromaticity_info->white_point.y=0.316;
492 chromaticity_info->white_point.z=0.374;
495 case PALCompositeVideoColorimetric:
497 chromaticity_info->red_primary.x=0.640;
498 chromaticity_info->red_primary.y=0.330;
499 chromaticity_info->red_primary.z=0.030;
500 chromaticity_info->green_primary.x=0.290;
501 chromaticity_info->green_primary.y=0.600;
502 chromaticity_info->green_primary.z=0.110;
503 chromaticity_info->blue_primary.x=0.150;
504 chromaticity_info->blue_primary.y=0.060;
505 chromaticity_info->blue_primary.z=0.790;
506 chromaticity_info->white_point.x=0.3127;
507 chromaticity_info->white_point.y=0.3290;
508 chromaticity_info->white_point.z=0.3582;
516 static void TimeCodeToString(const unsigned long timestamp,char *code)
528 for (i=0; i <= TimeFields; i++)
530 (void) FormatMagickString(code,MaxTextExtent-strlen(code),"%x",
531 (unsigned int) ((timestamp >> shift) & 0x0fU));
533 if (((i % 2) != 0) && (i < TimeFields))
540 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
544 value[MaxTextExtent];
585 assert(image_info != (const ImageInfo *) NULL);
586 assert(image_info->signature == MagickSignature);
587 if (image_info->debug != MagickFalse)
588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
589 image_info->filename);
590 assert(exception != (ExceptionInfo *) NULL);
591 assert(exception->signature == MagickSignature);
592 image=AcquireImage(image_info);
593 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
594 if (status == MagickFalse)
596 image=DestroyImageList(image);
597 return((Image *) NULL);
600 Read DPX file header.
603 count=ReadBlob(image,4,(unsigned char *) magick);
605 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
606 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
607 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
608 image->endian=LSBEndian;
609 if (LocaleNCompare(magick,"SDPX",4) == 0)
610 image->endian=MSBEndian;
611 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
612 dpx.file.image_offset=ReadBlobLong(image);
614 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
616 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
617 dpx.file.file_size=ReadBlobLong(image);
619 dpx.file.ditto_key=ReadBlobLong(image);
621 if (dpx.file.ditto_key != ~0U)
622 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
624 dpx.file.generic_size=ReadBlobLong(image);
626 dpx.file.industry_size=ReadBlobLong(image);
628 dpx.file.user_size=ReadBlobLong(image);
630 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
632 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
634 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
635 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
637 if (*dpx.file.timestamp != '\0')
638 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
640 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
642 if (*dpx.file.creator != '\0')
644 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
646 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
648 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
650 if (*dpx.file.project != '\0')
652 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
654 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
656 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
658 if (*dpx.file.copyright != '\0')
660 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
662 (void) FormatImageProperty(image,"copyright","%.100s",
665 dpx.file.encrypt_key=ReadBlobLong(image);
667 if (dpx.file.encrypt_key != ~0U)
668 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
669 dpx.file.encrypt_key);
670 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
673 Read DPX image header.
675 dpx.image.orientation=ReadBlobShort(image);
677 if (dpx.image.orientation != (unsigned short) (~0U))
678 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
679 dpx.image.orientation);
680 switch (dpx.image.orientation)
683 case 0: image->orientation=TopLeftOrientation; break;
684 case 1: image->orientation=TopRightOrientation; break;
685 case 2: image->orientation=BottomLeftOrientation; break;
686 case 3: image->orientation=BottomRightOrientation; break;
687 case 4: image->orientation=LeftTopOrientation; break;
688 case 5: image->orientation=RightTopOrientation; break;
689 case 6: image->orientation=LeftBottomOrientation; break;
690 case 7: image->orientation=RightBottomOrientation; break;
692 dpx.image.number_elements=ReadBlobShort(image);
694 dpx.image.pixels_per_line=ReadBlobLong(image);
696 image->columns=dpx.image.pixels_per_line;
697 dpx.image.lines_per_element=ReadBlobLong(image);
699 image->rows=dpx.image.lines_per_element;
700 for (i=0; i < 8; i++)
702 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
704 dpx.image.image_element[i].low_data=ReadBlobLong(image);
706 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
708 dpx.image.image_element[i].high_data=ReadBlobLong(image);
710 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
712 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
714 dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
716 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
718 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
720 dpx.image.image_element[i].packing=ReadBlobShort(image);
722 dpx.image.image_element[i].encoding=ReadBlobShort(image);
724 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
726 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
728 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
730 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
731 (unsigned char *) dpx.image.image_element[i].description);
733 SetPrimaryChromaticity((DPXColorimetric)
734 dpx.image.image_element[0].colorimetric,&image->chromaticity);
735 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
737 component_type=dpx.image.image_element[0].descriptor;
738 image->depth=dpx.image.image_element[0].bit_size;
739 if (dpx.file.image_offset >= 1664U)
742 Read DPX orientation header.
744 dpx.orientation.x_offset=ReadBlobLong(image);
746 if (dpx.orientation.x_offset != ~0U)
747 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
748 dpx.orientation.x_offset);
749 dpx.orientation.y_offset=ReadBlobLong(image);
751 if (dpx.orientation.y_offset != ~0U)
752 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
753 dpx.orientation.y_offset);
754 dpx.orientation.x_center=ReadBlobFloat(image);
756 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
757 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
758 dpx.orientation.x_center);
759 dpx.orientation.y_center=ReadBlobFloat(image);
761 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
762 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
763 dpx.orientation.y_center);
764 dpx.orientation.x_size=ReadBlobLong(image);
766 if (dpx.orientation.x_size != ~0U)
767 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
768 dpx.orientation.x_size);
769 dpx.orientation.y_size=ReadBlobLong(image);
771 if (dpx.orientation.y_size != ~0U)
772 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
773 dpx.orientation.y_size);
774 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
775 dpx.orientation.filename);
776 if (*dpx.orientation.filename != '\0')
777 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
778 dpx.orientation.filename);
779 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
780 dpx.orientation.timestamp);
781 if (*dpx.orientation.timestamp != '\0')
782 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
783 dpx.orientation.timestamp);
784 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
785 dpx.orientation.device);
786 if (*dpx.orientation.device != '\0')
787 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
788 dpx.orientation.device);
789 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
790 dpx.orientation.serial);
791 if (*dpx.orientation.serial != '\0')
792 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
793 dpx.orientation.serial);
794 for (i=0; i < 4; i++)
796 dpx.orientation.border[i]=ReadBlobShort(image);
799 if ((dpx.orientation.border[0] != (unsigned short) (~0U)) &&
800 (dpx.orientation.border[1] != (unsigned short) (~0U)))
801 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d", dpx.orientation.border[0],dpx.orientation.border[1],
802 dpx.orientation.border[2],dpx.orientation.border[3]);
803 for (i=0; i < 2; i++)
805 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
808 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
809 (dpx.orientation.aspect_ratio[1] != ~0U))
810 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
811 "%ux%u",dpx.orientation.aspect_ratio[0],
812 dpx.orientation.aspect_ratio[1]);
813 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
814 dpx.orientation.reserve);
816 if (dpx.file.image_offset >= 1920U)
819 Read DPX film header.
821 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
822 if (*dpx.film.type != '\0')
823 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
824 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
826 if (*dpx.film.type != '\0')
827 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
828 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
830 if (*dpx.film.offset != '\0')
831 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
833 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
835 if (*dpx.film.prefix != '\0')
836 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
838 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
840 if (*dpx.film.count != '\0')
841 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
843 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
845 if (*dpx.film.format != '\0')
846 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
848 dpx.film.frame_position=ReadBlobLong(image);
850 if (dpx.film.frame_position != ~0U)
851 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
852 dpx.film.frame_position);
853 dpx.film.sequence_extent=ReadBlobLong(image);
855 if (dpx.film.sequence_extent != ~0U)
856 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
857 dpx.film.sequence_extent);
858 dpx.film.held_count=ReadBlobLong(image);
860 if (dpx.film.held_count != ~0U)
861 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
862 dpx.film.held_count);
863 dpx.film.frame_rate=ReadBlobFloat(image);
865 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
866 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
867 dpx.film.frame_rate);
868 dpx.film.shutter_angle=ReadBlobFloat(image);
870 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
871 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
872 dpx.film.shutter_angle);
873 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
875 if (*dpx.film.frame_id != '\0')
876 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
878 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
880 if (*dpx.film.slate != '\0')
881 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
883 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
886 if (dpx.file.image_offset >= 2048U)
889 Read DPX television header.
891 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
893 TimeCodeToString(dpx.television.time_code,value);
894 (void) SetImageProperty(image,"dpx:television.time.code",value);
895 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
897 TimeCodeToString(dpx.television.user_bits,value);
898 (void) SetImageProperty(image,"dpx:television.user.bits",value);
899 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
901 if (dpx.television.interlace != 0)
902 (void) FormatImageProperty(image,"dpx:television.interlace","%ld",(long)
903 dpx.television.interlace);
904 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
906 if (dpx.television.field_number != 0)
907 (void) FormatImageProperty(image,"dpx:television.field_number","%ld",
908 (long) dpx.television.field_number);
909 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
911 if (dpx.television.video_signal != 0)
912 (void) FormatImageProperty(image,"dpx:television.video_signal","%ld",
913 (long) dpx.television.video_signal);
914 dpx.television.padding=(unsigned char) ReadBlobByte(image);
916 if (dpx.television.padding != 0)
917 (void) FormatImageProperty(image,"dpx:television.padding","%d",
918 dpx.television.padding);
919 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
921 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
922 (void) FormatImageProperty(image,
923 "dpx:television.horizontal_sample_rate","%g",
924 dpx.television.horizontal_sample_rate);
925 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
927 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
928 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
929 "%g",dpx.television.vertical_sample_rate);
930 dpx.television.frame_rate=ReadBlobFloat(image);
932 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
933 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
934 dpx.television.frame_rate);
935 dpx.television.time_offset=ReadBlobFloat(image);
937 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
938 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
939 dpx.television.time_offset);
940 dpx.television.gamma=ReadBlobFloat(image);
942 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
943 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
944 dpx.television.gamma);
945 dpx.television.black_level=ReadBlobFloat(image);
947 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
948 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
949 dpx.television.black_level);
950 dpx.television.black_gain=ReadBlobFloat(image);
952 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
953 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
954 dpx.television.black_gain);
955 dpx.television.break_point=ReadBlobFloat(image);
957 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
958 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
959 dpx.television.break_point);
960 dpx.television.white_level=ReadBlobFloat(image);
962 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
963 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
964 dpx.television.white_level);
965 dpx.television.integration_times=ReadBlobFloat(image);
967 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
968 (void) FormatImageProperty(image,"dpx:television.integration_times",
969 "%g",dpx.television.integration_times);
970 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
971 dpx.television.reserve);
973 if (dpx.file.image_offset > 2080U)
976 Read DPX user header.
978 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
979 if (*dpx.user.id != '\0')
980 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
981 if ((dpx.file.user_size != ~0U) &&
982 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
987 profile=AcquireStringInfo(dpx.file.user_size-sizeof(dpx.user.id));
988 offset+=ReadBlob(image,GetStringInfoLength(profile),
989 GetStringInfoDatum(profile));
990 (void) SetImageProfile(image,"dpx:user.data",profile);
991 profile=DestroyStringInfo(profile);
994 for ( ; offset < (long) dpx.file.image_offset; offset++)
995 (void) ReadBlobByte(image);
997 Read DPX image header.
999 if (image_info->ping != MagickFalse)
1001 (void) CloseBlob(image);
1002 return(GetFirstImageInList(image));
1005 Convert DPX raster image to pixel packets.
1007 samples_per_pixel=1;
1008 quantum_type=GrayQuantum;
1009 switch (component_type)
1011 case CbYCrY422ComponentType:
1013 samples_per_pixel=2;
1014 quantum_type=CbYCrYQuantum;
1017 case CbYACrYA4224ComponentType:
1018 case CbYCr444ComponentType:
1020 samples_per_pixel=3;
1021 quantum_type=CbYCrQuantum;
1024 case RGBComponentType:
1026 samples_per_pixel=3;
1027 quantum_type=RGBQuantum;
1030 case ABGRComponentType:
1031 case RGBAComponentType:
1033 image->matte=MagickTrue;
1034 samples_per_pixel=4;
1035 quantum_type=RGBAQuantum;
1041 switch (component_type)
1043 case CbYCrY422ComponentType:
1044 case CbYACrYA4224ComponentType:
1045 case CbYCr444ComponentType:
1047 image->colorspace=Rec709YCbCrColorspace;
1050 case LumaComponentType:
1052 image->colorspace=RGBColorspace;
1057 image->colorspace=RGBColorspace;
1058 if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
1059 image->colorspace=LogColorspace;
1060 if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
1061 image->colorspace=LogColorspace;
1065 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1066 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1067 if ((quantum_type == GrayQuantum) &&
1068 (dpx.image.image_element[0].packing != 0) && (image->depth == 10) &&
1069 (image->endian == MSBEndian))
1086 quantum_info=AcquireQuantumInfo(image_info,image);
1087 if (quantum_info == (QuantumInfo *) NULL)
1088 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1089 SetQuantumQuantum(quantum_info,32);
1090 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1091 MagickTrue : MagickFalse);
1092 pixels=GetQuantumPixels(quantum_info);
1095 range=GetQuantumRange(image->depth);
1096 for (y=0; y < (long) image->rows; y++)
1098 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1099 if (q == (PixelPacket *) NULL)
1101 for (x=0; x < (long) image->columns; x++)
1107 pixel=ReadBlobMSBLong(image);
1108 q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
1113 q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
1118 q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
1126 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1128 status=SetImageProgress(image,LoadImageTag,y,image->rows);
1129 if (status == MagickFalse)
1132 quantum_info=DestroyQuantumInfo(quantum_info);
1146 DPX any-bit pixel format.
1150 quantum_info=AcquireQuantumInfo(image_info,image);
1151 if (quantum_info == (QuantumInfo *) NULL)
1152 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1153 SetQuantumQuantum(quantum_info,32);
1154 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1155 MagickTrue : MagickFalse);
1156 image_view=AcquireCacheView(image);
1157 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505)
1158 #pragma omp parallel for schedule(dynamic,1) shared(row,status,quantum_type)
1160 for (y=0; y < (long) image->rows; y++)
1168 register PixelPacket
1180 if (status == MagickFalse)
1182 pixels=GetQuantumPixels(quantum_info);
1183 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505)
1184 #pragma omp critical (MagickCore_ReadDPXImage)
1187 count=ReadBlob(image,extent,pixels);
1188 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1189 (image->previous == (Image *) NULL))
1194 proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
1195 if (proceed == MagickFalse)
1200 if (count != (ssize_t) extent)
1202 q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1,
1204 if (q == (PixelPacket *) NULL)
1209 length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
1211 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1212 if (sync == MagickFalse)
1215 image_view=DestroyCacheView(image_view);
1216 quantum_info=DestroyQuantumInfo(quantum_info);
1217 if (status == MagickFalse)
1218 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1220 SetQuantumImageType(image,quantum_type);
1221 if (EOFBlob(image) != MagickFalse)
1222 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1224 (void) CloseBlob(image);
1225 return(GetFirstImageInList(image));
1229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 % R e g i s t e r D P X I m a g e %
1237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1239 % RegisterDPXImage() adds properties for the DPX image format to
1240 % the list of supported formats. The properties include the image format
1241 % tag, a method to read and/or write the format, whether the format
1242 % supports the saving of more than one frame to the same file or blob,
1243 % whether the format supports native in-memory I/O, and a brief
1244 % description of the format.
1246 % The format of the RegisterDPXImage method is:
1248 % unsigned long RegisterDPXImage(void)
1251 ModuleExport unsigned long RegisterDPXImage(void)
1259 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1260 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1263 entry=SetMagickInfo("DPX");
1264 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1265 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1266 entry->magick=(IsImageFormatHandler *) IsDPX;
1267 entry->adjoin=MagickFalse;
1268 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1269 entry->note=ConstantString(DPXNote);
1270 entry->module=ConstantString("DPX");
1271 (void) RegisterMagickInfo(entry);
1272 return(MagickImageCoderSignature);
1276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1280 % U n r e g i s t e r D P X I m a g e %
1284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1286 % UnregisterDPXImage() removes format registrations made by the
1287 % DPX module from the list of supported formats.
1289 % The format of the UnregisterDPXImage method is:
1291 % UnregisterDPXImage(void)
1294 ModuleExport void UnregisterDPXImage(void)
1296 (void) UnregisterMagickInfo("DPX");
1300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1304 % W r i t e D P X I m a g e %
1308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1310 % WriteDPXImage() writes an image in DPX encoded image format.
1312 % The format of the WriteDPXImage method is:
1314 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image)
1316 % A description of each parameter follows.
1318 % o image_info: the image info.
1320 % o image: The image.
1324 static inline const char *GetDPXProperty(const ImageInfo *image_info,
1325 const Image *image,const char *property)
1330 value=GetImageOption(image_info,property);
1331 if (value != (const char *) NULL)
1333 return(GetImageProperty(image,property));
1336 static unsigned int StringToTimeCode(const char *key)
1351 for (i=0; (*key != 0) && (i < 11); i++)
1353 if (isxdigit((int) ((unsigned char) *key)) == 0)
1359 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1365 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image)
1399 register const PixelPacket
1418 Open output image file.
1420 assert(image_info != (const ImageInfo *) NULL);
1421 assert(image_info->signature == MagickSignature);
1422 assert(image != (Image *) NULL);
1423 assert(image->signature == MagickSignature);
1424 if (image->debug != MagickFalse)
1425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1426 horizontal_factor=4;
1428 if (image_info->sampling_factor != (char *) NULL)
1436 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1437 horizontal_factor=(long) geometry_info.rho;
1438 vertical_factor=(long) geometry_info.sigma;
1439 if ((flags & SigmaValue) == 0)
1440 vertical_factor=horizontal_factor;
1441 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1442 (horizontal_factor != 4) && (vertical_factor != 1) &&
1443 (vertical_factor != 2) && (vertical_factor != 4))
1444 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1446 if ((image->colorspace == YCbCrColorspace) &&
1447 ((horizontal_factor == 2) || (vertical_factor == 2)))
1448 if ((image->columns % 2) != 0)
1450 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1451 if (status == MagickFalse)
1456 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1458 dpx.file.magic=0x53445058U;
1459 offset+=WriteBlobLong(image,dpx.file.magic);
1460 dpx.file.image_offset=0x2000U;
1461 profile=GetImageProfile(image,"dpx:user.data");
1462 if (profile != (StringInfo *) NULL)
1464 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1465 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1467 offset+=WriteBlobLong(image,dpx.file.image_offset);
1468 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1469 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1470 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1471 dpx.file.image_offset);
1472 offset+=WriteBlobLong(image,dpx.file.file_size);
1473 dpx.file.ditto_key=1U; /* new frame */
1474 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1475 dpx.file.generic_size=0x00000680U;
1476 offset+=WriteBlobLong(image,dpx.file.generic_size);
1477 dpx.file.industry_size=0x00000180U;
1478 offset+=WriteBlobLong(image,dpx.file.industry_size);
1479 dpx.file.user_size=0;
1480 if (profile != (StringInfo *) NULL)
1482 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1483 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1485 offset+=WriteBlobLong(image,dpx.file.user_size);
1486 value=GetDPXProperty(image_info,image,"dpx:file.filename");
1487 if (value != (const char *) NULL)
1488 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1489 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1491 seconds=time((time_t *) NULL);
1492 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1493 dpx.file.timestamp);
1494 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1495 dpx.file.timestamp);
1496 (void) strncpy(dpx.file.creator,GetMagickVersion((unsigned long *) NULL),
1497 sizeof(dpx.file.creator));
1498 value=GetDPXProperty(image_info,image,"dpx:file.creator");
1499 if (value != (const char *) NULL)
1500 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1501 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1503 value=GetDPXProperty(image_info,image,"dpx:file.project");
1504 if (value != (const char *) NULL)
1505 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1506 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1508 value=GetDPXProperty(image_info,image,"dpx:file.copyright");
1509 if (value != (const char *) NULL)
1510 (void) strncpy(dpx.file.copyright,value,
1511 sizeof(dpx.file.copyright));
1512 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1513 dpx.file.copyright);
1514 dpx.file.encrypt_key=(~0U);
1515 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1516 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1521 dpx.image.orientation=0x00; /* left-to-right; top-to-bottom */
1522 offset+=WriteBlobShort(image,dpx.image.orientation);
1523 dpx.image.number_elements=1;
1524 offset+=WriteBlobShort(image,dpx.image.number_elements);
1525 if ((image->columns != (unsigned int) image->columns) ||
1526 (image->rows != (unsigned int) image->rows))
1527 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1528 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1529 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1530 for (i=0; i < 8; i++)
1532 dpx.image.image_element[i].data_sign=0U;
1533 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1534 dpx.image.image_element[i].low_data=0U;
1535 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1536 dpx.image.image_element[i].low_quantity=0.0f;
1537 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1538 dpx.image.image_element[i].high_data=0U;
1539 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1540 dpx.image.image_element[i].high_quantity=0.0f;
1541 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1542 dpx.image.image_element[i].descriptor=0;
1544 switch (image->colorspace)
1546 case Rec601YCbCrColorspace:
1547 case Rec709YCbCrColorspace:
1548 case YCbCrColorspace:
1550 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1551 if (image->matte != MagickFalse)
1552 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1557 dpx.image.image_element[i].descriptor=RGBComponentType;
1558 if (image->matte != MagickFalse)
1559 dpx.image.image_element[i].descriptor=RGBAComponentType;
1563 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1564 dpx.image.image_element[i].transfer=0;
1565 if (image->colorspace == LogColorspace)
1566 dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
1567 offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
1568 dpx.image.image_element[i].colorimetric=0;
1569 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1570 dpx.image.image_element[i].bit_size=0;
1572 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1573 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1574 dpx.image.image_element[i].packing=0;
1575 if ((image->depth == 10) || (image->depth == 12))
1576 dpx.image.image_element[i].packing=1;
1577 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1578 dpx.image.image_element[i].encoding=0;
1579 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1580 dpx.image.image_element[i].data_offset=0U;
1582 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1583 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1584 dpx.image.image_element[i].end_of_line_padding=0U;
1585 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1586 offset+=WriteBlobLong(image,
1587 dpx.image.image_element[i].end_of_image_padding);
1588 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1589 (unsigned char *) dpx.image.image_element[i].description);
1591 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1594 Write orientation header.
1596 if ((image->rows != image->magick_rows) ||
1597 (image->columns != image->magick_columns))
1600 These properties are not valid if image size changed.
1602 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1603 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1604 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1605 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1606 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1607 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1609 dpx.orientation.x_offset=0U;
1610 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset");
1611 if (value != (const char *) NULL)
1612 dpx.orientation.x_offset=(unsigned int) atoi(value);
1613 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1614 dpx.orientation.y_offset=0U;
1615 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset");
1616 if (value != (const char *) NULL)
1617 dpx.orientation.y_offset=(unsigned int) atoi(value);
1618 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1619 dpx.orientation.x_center=0.0f;
1620 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center");
1621 if (value != (const char *) NULL)
1622 dpx.orientation.x_center=atof(value);
1623 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1624 dpx.orientation.y_center=0.0f;
1625 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center");
1626 if (value != (const char *) NULL)
1627 dpx.orientation.y_center=atof(value);
1628 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1629 dpx.orientation.x_size=0U;
1630 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size");
1631 if (value != (const char *) NULL)
1632 dpx.orientation.x_size=(unsigned int) atoi(value);
1633 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1634 dpx.orientation.y_size=0U;
1635 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size");
1636 if (value != (const char *) NULL)
1637 dpx.orientation.y_size=(unsigned int) atoi(value);
1638 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1639 value=GetDPXProperty(image_info,image,"dpx:orientation.filename");
1640 if (value != (const char *) NULL)
1641 (void) strncpy(dpx.orientation.filename,value,
1642 sizeof(dpx.orientation.filename));
1643 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1644 dpx.orientation.filename);
1645 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1646 dpx.orientation.timestamp);
1647 value=GetDPXProperty(image_info,image,"dpx:orientation.device");
1648 if (value != (const char *) NULL)
1649 (void) strncpy(dpx.orientation.device,value,
1650 sizeof(dpx.orientation.device));
1651 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1652 dpx.orientation.device);
1653 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1654 dpx.orientation.serial);
1655 for (i=0; i < 4; i++)
1656 dpx.orientation.border[i]=0;
1657 value=GetDPXProperty(image_info,image,"dpx:orientation.border");
1658 if (value != (const char *) NULL)
1660 flags=ParseGeometry(value,&geometry_info);
1661 if ((flags & SigmaValue) == 0)
1662 geometry_info.sigma=geometry_info.rho;
1663 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1664 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1665 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1666 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1668 for (i=0; i < 4; i++)
1669 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1670 for (i=0; i < 2; i++)
1671 dpx.orientation.aspect_ratio[i]=0U;
1672 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio");
1673 if (value != (const char *) NULL)
1675 flags=ParseGeometry(value,&geometry_info);
1676 if ((flags & SigmaValue) == 0)
1677 geometry_info.sigma=geometry_info.rho;
1678 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1679 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1681 for (i=0; i < 2; i++)
1682 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1683 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1684 dpx.orientation.reserve);
1689 value=GetDPXProperty(image_info,image,"dpx:film.id");
1690 if (value != (const char *) NULL)
1691 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1692 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1693 *dpx.film.type='\0';
1694 value=GetDPXProperty(image_info,image,"dpx:film.type");
1695 if (value != (const char *) NULL)
1696 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1697 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1699 *dpx.film.offset='\0';
1700 value=GetDPXProperty(image_info,image,"dpx:film.offset");
1701 if (value != (const char *) NULL)
1702 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1703 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1705 *dpx.film.prefix='\0';
1706 value=GetDPXProperty(image_info,image,"dpx:film.prefix");
1707 if (value != (const char *) NULL)
1708 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1709 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1711 *dpx.film.count='\0';
1712 value=GetDPXProperty(image_info,image,"dpx:film.count");
1713 if (value != (const char *) NULL)
1714 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1715 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1717 *dpx.film.format='\0';
1718 value=GetDPXProperty(image_info,image,"dpx:film.format");
1719 if (value != (const char *) NULL)
1720 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1721 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1723 dpx.film.frame_position=0U;
1724 value=GetDPXProperty(image_info,image,"dpx:film.frame_position");
1725 if (value != (const char *) NULL)
1726 dpx.film.frame_position=(unsigned int) atoi(value);
1727 offset+=WriteBlobLong(image,dpx.film.frame_position);
1728 dpx.film.sequence_extent=0U;
1729 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent");
1730 if (value != (const char *) NULL)
1731 dpx.film.sequence_extent=(unsigned int) atoi(value);
1732 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1733 dpx.film.held_count=0U;
1734 value=GetDPXProperty(image_info,image,"dpx:film.held_count");
1735 if (value != (const char *) NULL)
1736 dpx.film.held_count=(unsigned int) atoi(value);
1737 offset+=WriteBlobLong(image,dpx.film.held_count);
1738 dpx.film.frame_rate=0.0f;
1739 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate");
1740 if (value != (const char *) NULL)
1741 dpx.film.frame_rate=atof(value);
1742 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1743 dpx.film.shutter_angle=0.0f;
1744 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle");
1745 if (value != (const char *) NULL)
1746 dpx.film.shutter_angle=atof(value);
1747 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1748 *dpx.film.frame_id='\0';
1749 value=GetDPXProperty(image_info,image,"dpx:film.frame_id");
1750 if (value != (const char *) NULL)
1751 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1752 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1754 value=GetDPXProperty(image_info,image,"dpx:film.slate");
1755 if (value != (const char *) NULL)
1756 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1757 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1759 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1762 Write television header.
1764 value=GetDPXProperty(image_info,image,"dpx:television.time.code");
1765 if (value != (const char *) NULL)
1766 dpx.television.time_code=StringToTimeCode(value);
1767 offset+=WriteBlobLong(image,dpx.television.time_code);
1768 value=GetDPXProperty(image_info,image,"dpx:television.user.bits");
1769 if (value != (const char *) NULL)
1770 dpx.television.user_bits=StringToTimeCode(value);
1771 offset+=WriteBlobLong(image,dpx.television.user_bits);
1772 value=GetDPXProperty(image_info,image,"dpx:television.interlace");
1773 if (value != (const char *) NULL)
1774 dpx.television.interlace=(unsigned char) atoi(value);
1775 offset+=WriteBlobByte(image,dpx.television.interlace);
1776 value=GetDPXProperty(image_info,image,"dpx:television.field_number");
1777 if (value != (const char *) NULL)
1778 dpx.television.field_number=(unsigned char) atoi(value);
1779 offset+=WriteBlobByte(image,dpx.television.field_number);
1780 dpx.television.video_signal=0;
1781 value=GetDPXProperty(image_info,image,"dpx:television.video_signal");
1782 if (value != (const char *) NULL)
1783 dpx.television.video_signal=(unsigned char) atoi(value);
1784 offset+=WriteBlobByte(image,dpx.television.video_signal);
1785 dpx.television.padding=0;
1786 value=GetDPXProperty(image_info,image,"dpx:television.padding");
1787 if (value != (const char *) NULL)
1788 dpx.television.padding=(unsigned char) atoi(value);
1789 offset+=WriteBlobByte(image,dpx.television.padding);
1790 dpx.television.horizontal_sample_rate=0.0f;
1791 value=GetDPXProperty(image_info,image,
1792 "dpx:television.horizontal_sample_rate");
1793 if (value != (const char *) NULL)
1794 dpx.television.horizontal_sample_rate=atof(value);
1795 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1796 dpx.television.vertical_sample_rate=0.0f;
1797 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate");
1798 if (value != (const char *) NULL)
1799 dpx.television.vertical_sample_rate=atof(value);
1800 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1801 dpx.television.frame_rate=0.0f;
1802 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate");
1803 if (value != (const char *) NULL)
1804 dpx.television.frame_rate=atof(value);
1805 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1806 dpx.television.time_offset=0.0f;
1807 value=GetDPXProperty(image_info,image,"dpx:television.time_offset");
1808 if (value != (const char *) NULL)
1809 dpx.television.time_offset=atof(value);
1810 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1811 dpx.television.gamma=0.0f;
1812 value=GetDPXProperty(image_info,image,"dpx:television.gamma");
1813 if (value != (const char *) NULL)
1814 dpx.television.gamma=atof(value);
1815 offset+=WriteBlobFloat(image,dpx.television.gamma);
1816 dpx.television.black_level=0.0f;
1817 value=GetDPXProperty(image_info,image,"dpx:television.black_level");
1818 if (value != (const char *) NULL)
1819 dpx.television.black_level=atof(value);
1820 offset+=WriteBlobFloat(image,dpx.television.black_level);
1821 dpx.television.black_gain=0.0f;
1822 value=GetDPXProperty(image_info,image,"dpx:television.black_gain");
1823 if (value != (const char *) NULL)
1824 dpx.television.black_gain=atof(value);
1825 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1826 dpx.television.break_point=0.0f;
1827 value=GetDPXProperty(image_info,image,"dpx:television.break_point");
1828 if (value != (const char *) NULL)
1829 dpx.television.break_point=atof(value);
1830 offset+=WriteBlobFloat(image,dpx.television.break_point);
1831 dpx.television.white_level=0.0f;
1832 value=GetDPXProperty(image_info,image,"dpx:television.white_level");
1833 if (value != (const char *) NULL)
1834 dpx.television.white_level=atof(value);
1835 offset+=WriteBlobFloat(image,dpx.television.white_level);
1836 dpx.television.integration_times=0.0f;
1837 value=GetDPXProperty(image_info,image,"dpx:television.integration_times");
1838 if (value != (const char *) NULL)
1839 dpx.television.integration_times=atof(value);
1840 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1841 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1842 dpx.television.reserve);
1846 value=GetDPXProperty(image_info,image,"dpx:user.id");
1847 if (value != (const char *) NULL)
1848 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1849 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1850 if (profile != (StringInfo *) NULL)
1851 offset+=WriteBlob(image,GetStringInfoLength(profile),
1852 GetStringInfoDatum(profile));
1853 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1855 count=WriteBlobByte(image,0x00);
1858 ThrowFileException(&image->exception,FileOpenError,"UnableToWriteFile",
1865 Convert pixel packets to DPX raster image.
1867 quantum_info=AcquireQuantumInfo(image_info,image);
1868 quantum_info->quantum=32;
1869 quantum_info->pack=dpx.image.image_element[0].packing == 0 ? MagickTrue :
1871 quantum_type=RGBQuantum;
1872 if (image->matte != MagickFalse)
1873 quantum_type=RGBAQuantum;
1874 if (image->colorspace == YCbCrColorspace)
1876 quantum_type=CbYCrQuantum;
1877 if (image->matte != MagickFalse)
1878 quantum_type=CbYCrAQuantum;
1879 if ((horizontal_factor == 2) || (vertical_factor == 2))
1880 quantum_type=CbYCrYQuantum;
1882 extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
1883 image->depth,MagickTrue);
1886 quantum_type=GrayQuantum;
1887 extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ?
1888 4UL : 3UL,image->depth,MagickTrue);
1890 pixels=GetQuantumPixels(quantum_info);
1891 for (y=0; y < (long) image->rows; y++)
1893 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1894 if (p == (const PixelPacket *) NULL)
1896 (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
1897 quantum_type,pixels,&image->exception);
1898 count=WriteBlob(image,extent,pixels);
1899 if (count != (ssize_t) extent)
1901 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1902 if (status == MagickFalse)
1905 quantum_info=DestroyQuantumInfo(quantum_info);
1906 (void) CloseBlob(image);