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/module.h"
56 #include "magick/monitor.h"
57 #include "magick/monitor-private.h"
58 #include "magick/option.h"
59 #include "magick/profile.h"
60 #include "magick/property.h"
61 #include "magick/quantum-private.h"
62 #include "magick/static.h"
63 #include "magick/string_.h"
64 #include "magick/string-private.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(size_t columns,
374 size_t samples_per_pixel,size_t 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+2)/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 size_t 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];
586 assert(image_info != (const ImageInfo *) NULL);
587 assert(image_info->signature == MagickSignature);
588 if (image_info->debug != MagickFalse)
589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
590 image_info->filename);
591 assert(exception != (ExceptionInfo *) NULL);
592 assert(exception->signature == MagickSignature);
593 image=AcquireImage(image_info);
594 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
595 if (status == MagickFalse)
597 image=DestroyImageList(image);
598 return((Image *) NULL);
601 Read DPX file header.
604 count=ReadBlob(image,4,(unsigned char *) magick);
606 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
607 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
608 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
609 image->endian=LSBEndian;
610 if (LocaleNCompare(magick,"SDPX",4) == 0)
611 image->endian=MSBEndian;
612 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
613 dpx.file.image_offset=ReadBlobLong(image);
615 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
617 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
618 dpx.file.file_size=ReadBlobLong(image);
620 dpx.file.ditto_key=ReadBlobLong(image);
622 if (dpx.file.ditto_key != ~0U)
623 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
625 dpx.file.generic_size=ReadBlobLong(image);
627 dpx.file.industry_size=ReadBlobLong(image);
629 dpx.file.user_size=ReadBlobLong(image);
631 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
633 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
635 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
636 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
638 if (*dpx.file.timestamp != '\0')
639 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
641 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
643 if (*dpx.file.creator != '\0')
645 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
647 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
649 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
651 if (*dpx.file.project != '\0')
653 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
655 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
657 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
659 if (*dpx.file.copyright != '\0')
661 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
663 (void) FormatImageProperty(image,"copyright","%.100s",
666 dpx.file.encrypt_key=ReadBlobLong(image);
668 if (dpx.file.encrypt_key != ~0U)
669 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
670 dpx.file.encrypt_key);
671 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
674 Read DPX image header.
676 dpx.image.orientation=ReadBlobShort(image);
678 if (dpx.image.orientation != (unsigned short) (~0U))
679 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
680 dpx.image.orientation);
681 switch (dpx.image.orientation)
684 case 0: image->orientation=TopLeftOrientation; break;
685 case 1: image->orientation=TopRightOrientation; break;
686 case 2: image->orientation=BottomLeftOrientation; break;
687 case 3: image->orientation=BottomRightOrientation; break;
688 case 4: image->orientation=LeftTopOrientation; break;
689 case 5: image->orientation=RightTopOrientation; break;
690 case 6: image->orientation=LeftBottomOrientation; break;
691 case 7: image->orientation=RightBottomOrientation; break;
693 dpx.image.number_elements=ReadBlobShort(image);
695 dpx.image.pixels_per_line=ReadBlobLong(image);
697 image->columns=dpx.image.pixels_per_line;
698 dpx.image.lines_per_element=ReadBlobLong(image);
700 image->rows=dpx.image.lines_per_element;
701 for (i=0; i < 8; i++)
703 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
705 dpx.image.image_element[i].low_data=ReadBlobLong(image);
707 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
709 dpx.image.image_element[i].high_data=ReadBlobLong(image);
711 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
713 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
715 dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
717 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
719 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
721 dpx.image.image_element[i].packing=ReadBlobShort(image);
723 dpx.image.image_element[i].encoding=ReadBlobShort(image);
725 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
727 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
729 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
731 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
732 (unsigned char *) dpx.image.image_element[i].description);
734 SetPrimaryChromaticity((DPXColorimetric)
735 dpx.image.image_element[0].colorimetric,&image->chromaticity);
736 offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
738 component_type=dpx.image.image_element[0].descriptor;
739 image->depth=dpx.image.image_element[0].bit_size;
740 if (dpx.file.image_offset >= 1664U)
743 Read DPX orientation header.
745 dpx.orientation.x_offset=ReadBlobLong(image);
747 if (dpx.orientation.x_offset != ~0U)
748 (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
749 dpx.orientation.x_offset);
750 dpx.orientation.y_offset=ReadBlobLong(image);
752 if (dpx.orientation.y_offset != ~0U)
753 (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
754 dpx.orientation.y_offset);
755 dpx.orientation.x_center=ReadBlobFloat(image);
757 if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
758 (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
759 dpx.orientation.x_center);
760 dpx.orientation.y_center=ReadBlobFloat(image);
762 if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
763 (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
764 dpx.orientation.y_center);
765 dpx.orientation.x_size=ReadBlobLong(image);
767 if (dpx.orientation.x_size != ~0U)
768 (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
769 dpx.orientation.x_size);
770 dpx.orientation.y_size=ReadBlobLong(image);
772 if (dpx.orientation.y_size != ~0U)
773 (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
774 dpx.orientation.y_size);
775 offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
776 dpx.orientation.filename);
777 if (*dpx.orientation.filename != '\0')
778 (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
779 dpx.orientation.filename);
780 offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
781 dpx.orientation.timestamp);
782 if (*dpx.orientation.timestamp != '\0')
783 (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
784 dpx.orientation.timestamp);
785 offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
786 dpx.orientation.device);
787 if (*dpx.orientation.device != '\0')
788 (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
789 dpx.orientation.device);
790 offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
791 dpx.orientation.serial);
792 if (*dpx.orientation.serial != '\0')
793 (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
794 dpx.orientation.serial);
795 for (i=0; i < 4; i++)
797 dpx.orientation.border[i]=ReadBlobShort(image);
800 if ((dpx.orientation.border[0] != (unsigned short) (~0U)) &&
801 (dpx.orientation.border[1] != (unsigned short) (~0U)))
802 (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d", dpx.orientation.border[0],dpx.orientation.border[1],
803 dpx.orientation.border[2],dpx.orientation.border[3]);
804 for (i=0; i < 2; i++)
806 dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
809 if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
810 (dpx.orientation.aspect_ratio[1] != ~0U))
811 (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
812 "%ux%u",dpx.orientation.aspect_ratio[0],
813 dpx.orientation.aspect_ratio[1]);
814 offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
815 dpx.orientation.reserve);
817 if (dpx.file.image_offset >= 1920U)
820 Read DPX film header.
822 offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
823 if (*dpx.film.type != '\0')
824 (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
825 offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
827 if (*dpx.film.type != '\0')
828 (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
829 offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
831 if (*dpx.film.offset != '\0')
832 (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
834 offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
836 if (*dpx.film.prefix != '\0')
837 (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
839 offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
841 if (*dpx.film.count != '\0')
842 (void) FormatImageProperty(image,"dpx:film.count","%.4s",
844 offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
846 if (*dpx.film.format != '\0')
847 (void) FormatImageProperty(image,"dpx:film.format","%.4s",
849 dpx.film.frame_position=ReadBlobLong(image);
851 if (dpx.film.frame_position != ~0U)
852 (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
853 dpx.film.frame_position);
854 dpx.film.sequence_extent=ReadBlobLong(image);
856 if (dpx.film.sequence_extent != ~0U)
857 (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
858 dpx.film.sequence_extent);
859 dpx.film.held_count=ReadBlobLong(image);
861 if (dpx.film.held_count != ~0U)
862 (void) FormatImageProperty(image,"dpx:film.held_count","%u",
863 dpx.film.held_count);
864 dpx.film.frame_rate=ReadBlobFloat(image);
866 if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
867 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
868 dpx.film.frame_rate);
869 dpx.film.shutter_angle=ReadBlobFloat(image);
871 if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
872 (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
873 dpx.film.shutter_angle);
874 offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
876 if (*dpx.film.frame_id != '\0')
877 (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
879 offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
881 if (*dpx.film.slate != '\0')
882 (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
884 offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
887 if (dpx.file.image_offset >= 2048U)
890 Read DPX television header.
892 dpx.television.time_code=(unsigned int) ReadBlobLong(image);
894 TimeCodeToString(dpx.television.time_code,value);
895 (void) SetImageProperty(image,"dpx:television.time.code",value);
896 dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
898 TimeCodeToString(dpx.television.user_bits,value);
899 (void) SetImageProperty(image,"dpx:television.user.bits",value);
900 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
902 if (dpx.television.interlace != 0)
903 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
904 (double) dpx.television.interlace);
905 dpx.television.field_number=(unsigned char) ReadBlobByte(image);
907 if (dpx.television.field_number != 0)
908 (void) FormatImageProperty(image,"dpx:television.field_number","%.20g",
909 (double) dpx.television.field_number);
910 dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
912 if (dpx.television.video_signal != 0)
913 (void) FormatImageProperty(image,"dpx:television.video_signal","%.20g",
914 (double) dpx.television.video_signal);
915 dpx.television.padding=(unsigned char) ReadBlobByte(image);
917 if (dpx.television.padding != 0)
918 (void) FormatImageProperty(image,"dpx:television.padding","%d",
919 dpx.television.padding);
920 dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
922 if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
923 (void) FormatImageProperty(image,
924 "dpx:television.horizontal_sample_rate","%g",
925 dpx.television.horizontal_sample_rate);
926 dpx.television.vertical_sample_rate=ReadBlobFloat(image);
928 if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
929 (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
930 "%g",dpx.television.vertical_sample_rate);
931 dpx.television.frame_rate=ReadBlobFloat(image);
933 if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
934 (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
935 dpx.television.frame_rate);
936 dpx.television.time_offset=ReadBlobFloat(image);
938 if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
939 (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
940 dpx.television.time_offset);
941 dpx.television.gamma=ReadBlobFloat(image);
943 if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
944 (void) FormatImageProperty(image,"dpx:television.gamma","%g",
945 dpx.television.gamma);
946 dpx.television.black_level=ReadBlobFloat(image);
948 if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
949 (void) FormatImageProperty(image,"dpx:television.black_level","%g",
950 dpx.television.black_level);
951 dpx.television.black_gain=ReadBlobFloat(image);
953 if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
954 (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
955 dpx.television.black_gain);
956 dpx.television.break_point=ReadBlobFloat(image);
958 if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
959 (void) FormatImageProperty(image,"dpx:television.break_point","%g",
960 dpx.television.break_point);
961 dpx.television.white_level=ReadBlobFloat(image);
963 if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
964 (void) FormatImageProperty(image,"dpx:television.white_level","%g",
965 dpx.television.white_level);
966 dpx.television.integration_times=ReadBlobFloat(image);
968 if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
969 (void) FormatImageProperty(image,"dpx:television.integration_times",
970 "%g",dpx.television.integration_times);
971 offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
972 dpx.television.reserve);
974 if (dpx.file.image_offset > 2080U)
977 Read DPX user header.
979 offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
980 if (*dpx.user.id != '\0')
981 (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
982 if ((dpx.file.user_size != ~0U) &&
983 ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
988 profile=AcquireStringInfo(dpx.file.user_size-sizeof(dpx.user.id));
989 offset+=ReadBlob(image,GetStringInfoLength(profile),
990 GetStringInfoDatum(profile));
991 (void) SetImageProfile(image,"dpx",profile);
992 profile=DestroyStringInfo(profile);
995 for ( ; offset < (ssize_t) dpx.file.image_offset; offset++)
996 (void) ReadBlobByte(image);
998 Read DPX image header.
1000 if (image_info->ping != MagickFalse)
1002 (void) CloseBlob(image);
1003 return(GetFirstImageInList(image));
1006 Convert DPX raster image to pixel packets.
1008 samples_per_pixel=1;
1009 quantum_type=GrayQuantum;
1010 switch (component_type)
1012 case CbYCrY422ComponentType:
1014 samples_per_pixel=2;
1015 quantum_type=CbYCrYQuantum;
1018 case CbYACrYA4224ComponentType:
1019 case CbYCr444ComponentType:
1021 samples_per_pixel=3;
1022 quantum_type=CbYCrQuantum;
1025 case RGBComponentType:
1027 samples_per_pixel=3;
1028 quantum_type=RGBQuantum;
1031 case ABGRComponentType:
1032 case RGBAComponentType:
1034 image->matte=MagickTrue;
1035 samples_per_pixel=4;
1036 quantum_type=RGBAQuantum;
1042 switch (component_type)
1044 case CbYCrY422ComponentType:
1045 case CbYACrYA4224ComponentType:
1046 case CbYCr444ComponentType:
1048 image->colorspace=Rec709YCbCrColorspace;
1051 case LumaComponentType:
1053 image->colorspace=RGBColorspace;
1058 image->colorspace=RGBColorspace;
1059 if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
1060 image->colorspace=LogColorspace;
1061 if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
1062 image->colorspace=LogColorspace;
1066 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1067 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1069 DPX any-bit pixel format.
1073 quantum_info=AcquireQuantumInfo(image_info,image);
1074 if (quantum_info == (QuantumInfo *) NULL)
1075 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1076 SetQuantumQuantum(quantum_info,32);
1077 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1078 MagickTrue : MagickFalse);
1079 for (y=0; y < (ssize_t) image->rows; y++)
1087 register PixelPacket
1099 if (status == MagickFalse)
1101 pixels=GetQuantumPixels(quantum_info);
1103 count=ReadBlob(image,extent,pixels);
1104 if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1105 (image->previous == (Image *) NULL))
1110 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1112 if (proceed == MagickFalse)
1117 if (count != (ssize_t) extent)
1119 q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
1120 if (q == (PixelPacket *) NULL)
1125 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1126 quantum_type,pixels,exception);
1127 sync=SyncAuthenticPixels(image,exception);
1128 if (sync == MagickFalse)
1131 quantum_info=DestroyQuantumInfo(quantum_info);
1132 if (status == MagickFalse)
1133 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1134 SetQuantumImageType(image,quantum_type);
1135 if (EOFBlob(image) != MagickFalse)
1136 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1138 (void) CloseBlob(image);
1139 return(GetFirstImageInList(image));
1143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 % R e g i s t e r D P X I m a g e %
1151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1153 % RegisterDPXImage() adds properties for the DPX image format to
1154 % the list of supported formats. The properties include the image format
1155 % tag, a method to read and/or write the format, whether the format
1156 % supports the saving of more than one frame to the same file or blob,
1157 % whether the format supports native in-memory I/O, and a brief
1158 % description of the format.
1160 % The format of the RegisterDPXImage method is:
1162 % size_t RegisterDPXImage(void)
1165 ModuleExport size_t RegisterDPXImage(void)
1173 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1174 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1177 entry=SetMagickInfo("DPX");
1178 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1179 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1180 entry->magick=(IsImageFormatHandler *) IsDPX;
1181 entry->adjoin=MagickFalse;
1182 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1183 entry->note=ConstantString(DPXNote);
1184 entry->module=ConstantString("DPX");
1185 (void) RegisterMagickInfo(entry);
1186 return(MagickImageCoderSignature);
1190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1194 % U n r e g i s t e r D P X I m a g e %
1198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200 % UnregisterDPXImage() removes format registrations made by the
1201 % DPX module from the list of supported formats.
1203 % The format of the UnregisterDPXImage method is:
1205 % UnregisterDPXImage(void)
1208 ModuleExport void UnregisterDPXImage(void)
1210 (void) UnregisterMagickInfo("DPX");
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1218 % W r i t e D P X I m a g e %
1222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224 % WriteDPXImage() writes an image in DPX encoded image format.
1226 % The format of the WriteDPXImage method is:
1228 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image)
1230 % A description of each parameter follows.
1232 % o image_info: the image info.
1234 % o image: The image.
1238 static inline const char *GetDPXProperty(const ImageInfo *image_info,
1239 const Image *image,const char *property)
1244 value=GetImageOption(image_info,property);
1245 if (value != (const char *) NULL)
1247 return(GetImageProperty(image,property));
1250 static unsigned int StringToTimeCode(const char *key)
1265 for (i=0; (*key != 0) && (i < 11); i++)
1267 if (isxdigit((int) ((unsigned char) *key)) == 0)
1273 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1279 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image)
1313 register const PixelPacket
1332 Open output image file.
1334 assert(image_info != (const ImageInfo *) NULL);
1335 assert(image_info->signature == MagickSignature);
1336 assert(image != (Image *) NULL);
1337 assert(image->signature == MagickSignature);
1338 if (image->debug != MagickFalse)
1339 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1340 horizontal_factor=4;
1342 if (image_info->sampling_factor != (char *) NULL)
1350 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1351 horizontal_factor=(ssize_t) geometry_info.rho;
1352 vertical_factor=(ssize_t) geometry_info.sigma;
1353 if ((flags & SigmaValue) == 0)
1354 vertical_factor=horizontal_factor;
1355 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1356 (horizontal_factor != 4) && (vertical_factor != 1) &&
1357 (vertical_factor != 2) && (vertical_factor != 4))
1358 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1360 if ((image->colorspace == YCbCrColorspace) &&
1361 ((horizontal_factor == 2) || (vertical_factor == 2)))
1362 if ((image->columns % 2) != 0)
1364 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1365 if (status == MagickFalse)
1370 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1372 dpx.file.magic=0x53445058U;
1373 offset+=WriteBlobLong(image,dpx.file.magic);
1374 dpx.file.image_offset=0x2000U;
1375 profile=GetImageProfile(image,"dpx");
1376 if (profile != (StringInfo *) NULL)
1378 if (GetStringInfoLength(profile) > 1048576)
1379 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1380 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1381 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1383 offset+=WriteBlobLong(image,dpx.file.image_offset);
1384 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1385 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1386 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1387 dpx.file.image_offset);
1388 offset+=WriteBlobLong(image,dpx.file.file_size);
1389 dpx.file.ditto_key=1U; /* new frame */
1390 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1391 dpx.file.generic_size=0x00000680U;
1392 offset+=WriteBlobLong(image,dpx.file.generic_size);
1393 dpx.file.industry_size=0x00000180U;
1394 offset+=WriteBlobLong(image,dpx.file.industry_size);
1395 dpx.file.user_size=0;
1396 if (profile != (StringInfo *) NULL)
1398 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1399 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1401 offset+=WriteBlobLong(image,dpx.file.user_size);
1402 value=GetDPXProperty(image_info,image,"dpx:file.filename");
1403 if (value != (const char *) NULL)
1404 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1405 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1407 seconds=time((time_t *) NULL);
1408 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1409 dpx.file.timestamp);
1410 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1411 dpx.file.timestamp);
1412 (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL),
1413 sizeof(dpx.file.creator));
1414 value=GetDPXProperty(image_info,image,"dpx:file.creator");
1415 if (value != (const char *) NULL)
1416 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1417 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1419 value=GetDPXProperty(image_info,image,"dpx:file.project");
1420 if (value != (const char *) NULL)
1421 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1422 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1424 value=GetDPXProperty(image_info,image,"dpx:file.copyright");
1425 if (value != (const char *) NULL)
1426 (void) strncpy(dpx.file.copyright,value,
1427 sizeof(dpx.file.copyright));
1428 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1429 dpx.file.copyright);
1430 dpx.file.encrypt_key=(~0U);
1431 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1432 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1437 dpx.image.orientation=0x00; /* left-to-right; top-to-bottom */
1438 offset+=WriteBlobShort(image,dpx.image.orientation);
1439 dpx.image.number_elements=1;
1440 offset+=WriteBlobShort(image,dpx.image.number_elements);
1441 if ((image->columns != (unsigned int) image->columns) ||
1442 (image->rows != (unsigned int) image->rows))
1443 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1444 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1445 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1446 for (i=0; i < 8; i++)
1448 dpx.image.image_element[i].data_sign=0U;
1449 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1450 dpx.image.image_element[i].low_data=0U;
1451 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1452 dpx.image.image_element[i].low_quantity=0.0f;
1453 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1454 dpx.image.image_element[i].high_data=0U;
1455 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1456 dpx.image.image_element[i].high_quantity=0.0f;
1457 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1458 dpx.image.image_element[i].descriptor=0;
1460 switch (image->colorspace)
1462 case Rec601YCbCrColorspace:
1463 case Rec709YCbCrColorspace:
1464 case YCbCrColorspace:
1466 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1467 if (image->matte != MagickFalse)
1468 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1473 dpx.image.image_element[i].descriptor=RGBComponentType;
1474 if (image->matte != MagickFalse)
1475 dpx.image.image_element[i].descriptor=RGBAComponentType;
1476 if ((image_info->type != TrueColorType) &&
1477 (image->matte == MagickFalse) &&
1478 (IsGrayImage(image,&image->exception) != MagickFalse))
1479 dpx.image.image_element[i].descriptor=LumaComponentType;
1483 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1484 dpx.image.image_element[i].transfer=0;
1485 if (image->colorspace == LogColorspace)
1486 dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
1487 offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
1488 dpx.image.image_element[i].colorimetric=0;
1489 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1490 dpx.image.image_element[i].bit_size=0;
1492 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1493 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1494 dpx.image.image_element[i].packing=0;
1495 if ((image->depth == 10) || (image->depth == 12))
1496 dpx.image.image_element[i].packing=1;
1497 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1498 dpx.image.image_element[i].encoding=0;
1499 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1500 dpx.image.image_element[i].data_offset=0U;
1502 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1503 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1504 dpx.image.image_element[i].end_of_line_padding=0U;
1505 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1506 offset+=WriteBlobLong(image,
1507 dpx.image.image_element[i].end_of_image_padding);
1508 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1509 (unsigned char *) dpx.image.image_element[i].description);
1511 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1514 Write orientation header.
1516 if ((image->rows != image->magick_rows) ||
1517 (image->columns != image->magick_columns))
1520 These properties are not valid if image size changed.
1522 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1523 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1524 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1525 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1526 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1527 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1529 dpx.orientation.x_offset=0U;
1530 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset");
1531 if (value != (const char *) NULL)
1532 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1533 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1534 dpx.orientation.y_offset=0U;
1535 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset");
1536 if (value != (const char *) NULL)
1537 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1538 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1539 dpx.orientation.x_center=0.0f;
1540 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center");
1541 if (value != (const char *) NULL)
1542 dpx.orientation.x_center=StringToDouble(value);
1543 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1544 dpx.orientation.y_center=0.0f;
1545 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center");
1546 if (value != (const char *) NULL)
1547 dpx.orientation.y_center=StringToDouble(value);
1548 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1549 dpx.orientation.x_size=0U;
1550 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size");
1551 if (value != (const char *) NULL)
1552 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1553 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1554 dpx.orientation.y_size=0U;
1555 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size");
1556 if (value != (const char *) NULL)
1557 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1558 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1559 value=GetDPXProperty(image_info,image,"dpx:orientation.filename");
1560 if (value != (const char *) NULL)
1561 (void) strncpy(dpx.orientation.filename,value,
1562 sizeof(dpx.orientation.filename));
1563 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1564 dpx.orientation.filename);
1565 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1566 dpx.orientation.timestamp);
1567 value=GetDPXProperty(image_info,image,"dpx:orientation.device");
1568 if (value != (const char *) NULL)
1569 (void) strncpy(dpx.orientation.device,value,sizeof(dpx.orientation.device));
1570 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1571 dpx.orientation.device);
1572 value=GetDPXProperty(image_info,image,"dpx:orientation.serial");
1573 if (value != (const char *) NULL)
1574 (void) strncpy(dpx.orientation.serial,value,sizeof(dpx.orientation.serial));
1575 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1576 dpx.orientation.serial);
1577 for (i=0; i < 4; i++)
1578 dpx.orientation.border[i]=0;
1579 value=GetDPXProperty(image_info,image,"dpx:orientation.border");
1580 if (value != (const char *) NULL)
1582 flags=ParseGeometry(value,&geometry_info);
1583 if ((flags & SigmaValue) == 0)
1584 geometry_info.sigma=geometry_info.rho;
1585 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1586 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1587 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1588 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1590 for (i=0; i < 4; i++)
1591 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1592 for (i=0; i < 2; i++)
1593 dpx.orientation.aspect_ratio[i]=0U;
1594 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio");
1595 if (value != (const char *) NULL)
1597 flags=ParseGeometry(value,&geometry_info);
1598 if ((flags & SigmaValue) == 0)
1599 geometry_info.sigma=geometry_info.rho;
1600 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1601 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1603 for (i=0; i < 2; i++)
1604 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1605 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1606 dpx.orientation.reserve);
1611 value=GetDPXProperty(image_info,image,"dpx:film.id");
1612 if (value != (const char *) NULL)
1613 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1614 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1615 *dpx.film.type='\0';
1616 value=GetDPXProperty(image_info,image,"dpx:film.type");
1617 if (value != (const char *) NULL)
1618 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1619 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1621 *dpx.film.offset='\0';
1622 value=GetDPXProperty(image_info,image,"dpx:film.offset");
1623 if (value != (const char *) NULL)
1624 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1625 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1627 *dpx.film.prefix='\0';
1628 value=GetDPXProperty(image_info,image,"dpx:film.prefix");
1629 if (value != (const char *) NULL)
1630 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1631 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1633 *dpx.film.count='\0';
1634 value=GetDPXProperty(image_info,image,"dpx:film.count");
1635 if (value != (const char *) NULL)
1636 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1637 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1639 *dpx.film.format='\0';
1640 value=GetDPXProperty(image_info,image,"dpx:film.format");
1641 if (value != (const char *) NULL)
1642 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1643 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1645 dpx.film.frame_position=0U;
1646 value=GetDPXProperty(image_info,image,"dpx:film.frame_position");
1647 if (value != (const char *) NULL)
1648 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1649 offset+=WriteBlobLong(image,dpx.film.frame_position);
1650 dpx.film.sequence_extent=0U;
1651 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent");
1652 if (value != (const char *) NULL)
1653 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1654 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1655 dpx.film.held_count=0U;
1656 value=GetDPXProperty(image_info,image,"dpx:film.held_count");
1657 if (value != (const char *) NULL)
1658 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1659 offset+=WriteBlobLong(image,dpx.film.held_count);
1660 dpx.film.frame_rate=0.0f;
1661 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate");
1662 if (value != (const char *) NULL)
1663 dpx.film.frame_rate=StringToDouble(value);
1664 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1665 dpx.film.shutter_angle=0.0f;
1666 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle");
1667 if (value != (const char *) NULL)
1668 dpx.film.shutter_angle=StringToDouble(value);
1669 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1670 *dpx.film.frame_id='\0';
1671 value=GetDPXProperty(image_info,image,"dpx:film.frame_id");
1672 if (value != (const char *) NULL)
1673 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1674 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1676 value=GetDPXProperty(image_info,image,"dpx:film.slate");
1677 if (value != (const char *) NULL)
1678 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1679 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1681 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1684 Write television header.
1686 value=GetDPXProperty(image_info,image,"dpx:television.time.code");
1687 if (value != (const char *) NULL)
1688 dpx.television.time_code=StringToTimeCode(value);
1689 offset+=WriteBlobLong(image,dpx.television.time_code);
1690 value=GetDPXProperty(image_info,image,"dpx:television.user.bits");
1691 if (value != (const char *) NULL)
1692 dpx.television.user_bits=StringToTimeCode(value);
1693 offset+=WriteBlobLong(image,dpx.television.user_bits);
1694 value=GetDPXProperty(image_info,image,"dpx:television.interlace");
1695 if (value != (const char *) NULL)
1696 dpx.television.interlace=(unsigned char) StringToLong(value);
1697 offset+=WriteBlobByte(image,dpx.television.interlace);
1698 value=GetDPXProperty(image_info,image,"dpx:television.field_number");
1699 if (value != (const char *) NULL)
1700 dpx.television.field_number=(unsigned char) StringToLong(value);
1701 offset+=WriteBlobByte(image,dpx.television.field_number);
1702 dpx.television.video_signal=0;
1703 value=GetDPXProperty(image_info,image,"dpx:television.video_signal");
1704 if (value != (const char *) NULL)
1705 dpx.television.video_signal=(unsigned char) StringToLong(value);
1706 offset+=WriteBlobByte(image,dpx.television.video_signal);
1707 dpx.television.padding=0;
1708 value=GetDPXProperty(image_info,image,"dpx:television.padding");
1709 if (value != (const char *) NULL)
1710 dpx.television.padding=(unsigned char) StringToLong(value);
1711 offset+=WriteBlobByte(image,dpx.television.padding);
1712 dpx.television.horizontal_sample_rate=0.0f;
1713 value=GetDPXProperty(image_info,image,
1714 "dpx:television.horizontal_sample_rate");
1715 if (value != (const char *) NULL)
1716 dpx.television.horizontal_sample_rate=StringToDouble(value);
1717 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1718 dpx.television.vertical_sample_rate=0.0f;
1719 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate");
1720 if (value != (const char *) NULL)
1721 dpx.television.vertical_sample_rate=StringToDouble(value);
1722 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1723 dpx.television.frame_rate=0.0f;
1724 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate");
1725 if (value != (const char *) NULL)
1726 dpx.television.frame_rate=StringToDouble(value);
1727 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1728 dpx.television.time_offset=0.0f;
1729 value=GetDPXProperty(image_info,image,"dpx:television.time_offset");
1730 if (value != (const char *) NULL)
1731 dpx.television.time_offset=StringToDouble(value);
1732 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1733 dpx.television.gamma=0.0f;
1734 value=GetDPXProperty(image_info,image,"dpx:television.gamma");
1735 if (value != (const char *) NULL)
1736 dpx.television.gamma=StringToDouble(value);
1737 offset+=WriteBlobFloat(image,dpx.television.gamma);
1738 dpx.television.black_level=0.0f;
1739 value=GetDPXProperty(image_info,image,"dpx:television.black_level");
1740 if (value != (const char *) NULL)
1741 dpx.television.black_level=StringToDouble(value);
1742 offset+=WriteBlobFloat(image,dpx.television.black_level);
1743 dpx.television.black_gain=0.0f;
1744 value=GetDPXProperty(image_info,image,"dpx:television.black_gain");
1745 if (value != (const char *) NULL)
1746 dpx.television.black_gain=StringToDouble(value);
1747 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1748 dpx.television.break_point=0.0f;
1749 value=GetDPXProperty(image_info,image,"dpx:television.break_point");
1750 if (value != (const char *) NULL)
1751 dpx.television.break_point=StringToDouble(value);
1752 offset+=WriteBlobFloat(image,dpx.television.break_point);
1753 dpx.television.white_level=0.0f;
1754 value=GetDPXProperty(image_info,image,"dpx:television.white_level");
1755 if (value != (const char *) NULL)
1756 dpx.television.white_level=StringToDouble(value);
1757 offset+=WriteBlobFloat(image,dpx.television.white_level);
1758 dpx.television.integration_times=0.0f;
1759 value=GetDPXProperty(image_info,image,"dpx:television.integration_times");
1760 if (value != (const char *) NULL)
1761 dpx.television.integration_times=StringToDouble(value);
1762 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1763 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1764 dpx.television.reserve);
1768 value=GetDPXProperty(image_info,image,"dpx:user.id");
1769 if (value != (const char *) NULL)
1770 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1771 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1772 if (profile != (StringInfo *) NULL)
1773 offset+=WriteBlob(image,GetStringInfoLength(profile),
1774 GetStringInfoDatum(profile));
1775 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1777 count=WriteBlobByte(image,0x00);
1780 ThrowFileException(&image->exception,FileOpenError,"UnableToWriteFile",
1787 Convert pixel packets to DPX raster image.
1789 quantum_info=AcquireQuantumInfo(image_info,image);
1790 SetQuantumQuantum(quantum_info,32);
1791 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1792 MagickTrue : MagickFalse);
1793 quantum_type=RGBQuantum;
1794 if (image->matte != MagickFalse)
1795 quantum_type=RGBAQuantum;
1796 if (image->colorspace == YCbCrColorspace)
1798 quantum_type=CbYCrQuantum;
1799 if (image->matte != MagickFalse)
1800 quantum_type=CbYCrAQuantum;
1801 if ((horizontal_factor == 2) || (vertical_factor == 2))
1802 quantum_type=CbYCrYQuantum;
1804 extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
1805 image->depth,MagickTrue);
1806 if ((image_info->type != TrueColorType) && (image->matte == MagickFalse) &&
1807 (IsGrayImage(image,&image->exception) != MagickFalse))
1809 quantum_type=GrayQuantum;
1810 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
1812 pixels=GetQuantumPixels(quantum_info);
1813 for (y=0; y < (ssize_t) image->rows; y++)
1815 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1816 if (p == (const PixelPacket *) NULL)
1818 (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
1819 quantum_type,pixels,&image->exception);
1820 count=WriteBlob(image,extent,pixels);
1821 if (count != (ssize_t) extent)
1823 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1825 if (status == MagickFalse)
1828 quantum_info=DestroyQuantumInfo(quantum_info);
1829 (void) CloseBlob(image);