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 "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/colorspace.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/geometry.h"
51 #include "MagickCore/image.h"
52 #include "MagickCore/image-private.h"
53 #include "MagickCore/list.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/module.h"
57 #include "MagickCore/monitor.h"
58 #include "MagickCore/monitor-private.h"
59 #include "MagickCore/option.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/profile.h"
62 #include "MagickCore/property.h"
63 #include "MagickCore/quantum-private.h"
64 #include "MagickCore/static.h"
65 #include "MagickCore/string_.h"
66 #include "MagickCore/string-private.h"
73 UserDefinedColorimetric = 0,
74 PrintingDensityColorimetric = 1,
75 LinearColorimetric = 2,
76 LogarithmicColorimetric = 3,
77 UnspecifiedVideoColorimetric = 4,
78 SMTPE_274MColorimetric = 5,
79 ITU_R709Colorimetric = 6,
80 ITU_R601_625LColorimetric = 7,
81 ITU_R601_525LColorimetric = 8,
82 NTSCCompositeVideoColorimetric = 9,
83 PALCompositeVideoColorimetric = 10,
84 ZDepthLinearColorimetric = 11,
85 DepthHomogeneousColorimetric = 12
90 UndefinedComponentType = 0,
92 GreenComponentType = 2,
93 BlueComponentType = 3,
94 AlphaComponentType = 4,
95 LumaComponentType = 6,
96 ColorDifferenceCbCrComponentType = 7,
97 DepthComponentType = 8,
98 CompositeVideoComponentType = 9,
99 RGBComponentType = 50,
100 RGBAComponentType = 51,
101 ABGRComponentType = 52,
102 CbYCrY422ComponentType = 100,
103 CbYACrYA4224ComponentType = 101,
104 CbYCr444ComponentType = 102,
105 CbYCrA4444ComponentType = 103,
106 UserDef2ElementComponentType = 150,
107 UserDef3ElementComponentType = 151,
108 UserDef4ElementComponentType = 152,
109 UserDef5ElementComponentType = 153,
110 UserDef6ElementComponentType = 154,
111 UserDef7ElementComponentType = 155,
112 UserDef8ElementComponentType = 156
115 typedef struct _DPXFileInfo
145 typedef struct _DPXFilmInfo
170 typedef struct _DPXImageElement
198 end_of_image_padding;
204 typedef struct _DPXImageInfo
221 typedef struct _DPXOrientationInfo
249 } DPXOrientationInfo;
251 typedef struct _DPXTelevisionInfo
264 horizontal_sample_rate,
265 vertical_sample_rate,
279 typedef struct _DPXUserInfo
285 typedef struct DPXInfo
307 Forward declaractions.
309 static MagickBooleanType
310 WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 % IsDPX() returns MagickTrue if the image format type, identified by the
324 % magick string, is DPX.
326 % The format of the IsDPX method is:
328 % MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
330 % A description of each parameter follows:
332 % o magick: compare image format pattern against these bytes.
334 % o extent: Specifies the extent of the magick string.
337 static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
341 if (memcmp(magick,"SDPX",4) == 0)
343 if (memcmp(magick,"XPDS",4) == 0)
349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % R e a d D P X I m a g e %
357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359 % ReadDPXImage() reads an DPX X image file and returns it. It
360 % allocates the memory necessary for the new Image structure and returns a
361 % pointer to the new image.
363 % The format of the ReadDPXImage method is:
365 % Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
367 % A description of each parameter follows:
369 % o image_info: the image info.
371 % o exception: return any errors or warnings in this structure.
375 static size_t GetBytesPerRow(size_t columns,
376 size_t samples_per_pixel,size_t bits_per_pixel,
377 MagickBooleanType pad)
382 switch (bits_per_pixel)
386 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
387 bits_per_pixel+31)/32);
393 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
394 bits_per_pixel+31)/32);
399 if (pad == MagickFalse)
401 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
402 bits_per_pixel+31)/32);
405 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
410 if (pad == MagickFalse)
412 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
413 bits_per_pixel+31)/32);
416 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
421 bytes_per_row=2*(((size_t) samples_per_pixel*columns*
422 bits_per_pixel+8)/16);
427 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
428 bits_per_pixel+31)/32);
433 bytes_per_row=8*(((size_t) samples_per_pixel*columns*
434 bits_per_pixel+63)/64);
438 return(bytes_per_row);
441 static inline MagickBooleanType IsFloatDefined(const float value)
452 quantum.unsigned_value=0U;
453 quantum.float_value=(double) value;
454 if (quantum.unsigned_value == 0U)
459 static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
460 ChromaticityInfo *chromaticity_info)
464 case SMTPE_274MColorimetric:
465 case ITU_R709Colorimetric:
467 chromaticity_info->red_primary.x=0.640;
468 chromaticity_info->red_primary.y=0.330;
469 chromaticity_info->red_primary.z=0.030;
470 chromaticity_info->green_primary.x=0.300;
471 chromaticity_info->green_primary.y=0.600;
472 chromaticity_info->green_primary.z=0.100;
473 chromaticity_info->blue_primary.x=0.150;
474 chromaticity_info->blue_primary.y=0.060;
475 chromaticity_info->blue_primary.z=0.790;
476 chromaticity_info->white_point.x=0.3127;
477 chromaticity_info->white_point.y=0.3290;
478 chromaticity_info->white_point.z=0.3582;
481 case NTSCCompositeVideoColorimetric:
483 chromaticity_info->red_primary.x=0.67;
484 chromaticity_info->red_primary.y=0.33;
485 chromaticity_info->red_primary.z=0.00;
486 chromaticity_info->green_primary.x=0.21;
487 chromaticity_info->green_primary.y=0.71;
488 chromaticity_info->green_primary.z=0.08;
489 chromaticity_info->blue_primary.x=0.14;
490 chromaticity_info->blue_primary.y=0.08;
491 chromaticity_info->blue_primary.z=0.78;
492 chromaticity_info->white_point.x=0.310;
493 chromaticity_info->white_point.y=0.316;
494 chromaticity_info->white_point.z=0.374;
497 case PALCompositeVideoColorimetric:
499 chromaticity_info->red_primary.x=0.640;
500 chromaticity_info->red_primary.y=0.330;
501 chromaticity_info->red_primary.z=0.030;
502 chromaticity_info->green_primary.x=0.290;
503 chromaticity_info->green_primary.y=0.600;
504 chromaticity_info->green_primary.z=0.110;
505 chromaticity_info->blue_primary.x=0.150;
506 chromaticity_info->blue_primary.y=0.060;
507 chromaticity_info->blue_primary.z=0.790;
508 chromaticity_info->white_point.x=0.3127;
509 chromaticity_info->white_point.y=0.3290;
510 chromaticity_info->white_point.z=0.3582;
518 static void TimeCodeToString(const size_t timestamp,char *code)
530 for (i=0; i <= TimeFields; i++)
532 (void) FormatLocaleString(code,MaxTextExtent-strlen(code),"%x",
533 (unsigned int) ((timestamp >> shift) & 0x0fU));
535 if (((i % 2) != 0) && (i < TimeFields))
542 static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
546 value[MaxTextExtent];
584 assert(image_info != (const ImageInfo *) NULL);
585 assert(image_info->signature == MagickSignature);
586 if (image_info->debug != MagickFalse)
587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
588 image_info->filename);
589 assert(exception != (ExceptionInfo *) NULL);
590 assert(exception->signature == MagickSignature);
591 image=AcquireImage(image_info,exception);
592 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
593 if (status == MagickFalse)
595 image=DestroyImageList(image);
596 return((Image *) NULL);
599 Read DPX file header.
602 count=ReadBlob(image,4,(unsigned char *) magick);
604 if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
605 (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
606 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
607 image->endian=LSBEndian;
608 if (LocaleNCompare(magick,"SDPX",4) == 0)
609 image->endian=MSBEndian;
610 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
611 dpx.file.image_offset=ReadBlobLong(image);
613 offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
615 (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
616 dpx.file.file_size=ReadBlobLong(image);
618 dpx.file.ditto_key=ReadBlobLong(image);
620 if (dpx.file.ditto_key != ~0U)
621 (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
623 dpx.file.generic_size=ReadBlobLong(image);
625 dpx.file.industry_size=ReadBlobLong(image);
627 dpx.file.user_size=ReadBlobLong(image);
629 offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
631 (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
633 (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
634 offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
636 if (*dpx.file.timestamp != '\0')
637 (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
639 offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
641 if (*dpx.file.creator != '\0')
643 (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
645 (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
647 offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
649 if (*dpx.file.project != '\0')
651 (void) FormatImageProperty(image,"dpx:file.project","%.200s",
653 (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
655 offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
657 if (*dpx.file.copyright != '\0')
659 (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
661 (void) FormatImageProperty(image,"copyright","%.100s",
664 dpx.file.encrypt_key=ReadBlobLong(image);
666 if (dpx.file.encrypt_key != ~0U)
667 (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
668 dpx.file.encrypt_key);
669 offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
672 Read DPX image header.
674 dpx.image.orientation=ReadBlobShort(image);
676 if (dpx.image.orientation != (unsigned short) (~0U))
677 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
678 dpx.image.orientation);
679 switch (dpx.image.orientation)
682 case 0: image->orientation=TopLeftOrientation; break;
683 case 1: image->orientation=TopRightOrientation; break;
684 case 2: image->orientation=BottomLeftOrientation; break;
685 case 3: image->orientation=BottomRightOrientation; break;
686 case 4: image->orientation=LeftTopOrientation; break;
687 case 5: image->orientation=RightTopOrientation; break;
688 case 6: image->orientation=LeftBottomOrientation; break;
689 case 7: image->orientation=RightBottomOrientation; break;
691 dpx.image.number_elements=ReadBlobShort(image);
693 dpx.image.pixels_per_line=ReadBlobLong(image);
695 image->columns=dpx.image.pixels_per_line;
696 dpx.image.lines_per_element=ReadBlobLong(image);
698 image->rows=dpx.image.lines_per_element;
699 for (i=0; i < 8; i++)
701 dpx.image.image_element[i].data_sign=ReadBlobLong(image);
703 dpx.image.image_element[i].low_data=ReadBlobLong(image);
705 dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
707 dpx.image.image_element[i].high_data=ReadBlobLong(image);
709 dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
711 dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
713 dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
715 dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
717 dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
719 dpx.image.image_element[i].packing=ReadBlobShort(image);
721 dpx.image.image_element[i].encoding=ReadBlobShort(image);
723 dpx.image.image_element[i].data_offset=ReadBlobLong(image);
725 dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
727 dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
729 offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
730 (unsigned char *) dpx.image.image_element[i].description);
732 SetImageColorspace(image,RGBColorspace,exception);
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,exception);
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,exception);
899 dpx.television.interlace=(unsigned char) ReadBlobByte(image);
901 if (dpx.television.interlace != 0)
902 (void) FormatImageProperty(image,"dpx:television.interlace","%.20g",
903 (double) 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","%.20g",
908 (double) 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","%.20g",
913 (double) 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=BlobToStringInfo((const void *) NULL,
988 dpx.file.user_size-sizeof(dpx.user.id));
989 if (profile == (StringInfo *) NULL)
990 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
991 offset+=ReadBlob(image,GetStringInfoLength(profile),
992 GetStringInfoDatum(profile));
993 (void) SetImageProfile(image,"dpx",profile,exception);
994 profile=DestroyStringInfo(profile);
997 for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
998 (void) ReadBlobByte(image);
1000 Read DPX image header.
1002 if (image_info->ping != MagickFalse)
1004 (void) CloseBlob(image);
1005 return(GetFirstImageInList(image));
1008 Convert DPX raster image to pixel packets.
1010 samples_per_pixel=1;
1011 quantum_type=GrayQuantum;
1012 switch (component_type)
1014 case CbYCrY422ComponentType:
1016 samples_per_pixel=2;
1017 quantum_type=CbYCrYQuantum;
1020 case CbYACrYA4224ComponentType:
1021 case CbYCr444ComponentType:
1023 samples_per_pixel=3;
1024 quantum_type=CbYCrQuantum;
1027 case RGBComponentType:
1029 samples_per_pixel=3;
1030 quantum_type=RGBQuantum;
1033 case ABGRComponentType:
1034 case RGBAComponentType:
1036 image->matte=MagickTrue;
1037 samples_per_pixel=4;
1038 quantum_type=RGBAQuantum;
1044 switch (component_type)
1046 case CbYCrY422ComponentType:
1047 case CbYACrYA4224ComponentType:
1048 case CbYCr444ComponentType:
1050 SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1053 case LumaComponentType:
1055 SetImageColorspace(image,sRGBColorspace,exception);
1060 SetImageColorspace(image,sRGBColorspace,exception);
1061 if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
1062 SetImageColorspace(image,LogColorspace,exception);
1063 if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
1064 SetImageColorspace(image,LogColorspace,exception);
1068 extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1069 dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1071 DPX any-bit pixel format.
1075 quantum_info=AcquireQuantumInfo(image_info,image);
1076 if (quantum_info == (QuantumInfo *) NULL)
1077 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1078 SetQuantumQuantum(quantum_info,32);
1079 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1080 MagickTrue : MagickFalse);
1081 for (y=0; y < (ssize_t) image->rows; y++)
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 == (Quantum *) NULL)
1125 length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1126 quantum_type,pixels,exception);
1128 sync=SyncAuthenticPixels(image,exception);
1129 if (sync == MagickFalse)
1132 quantum_info=DestroyQuantumInfo(quantum_info);
1133 if (status == MagickFalse)
1134 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1135 SetQuantumImageType(image,quantum_type);
1136 if (EOFBlob(image) != MagickFalse)
1137 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1139 (void) CloseBlob(image);
1140 return(GetFirstImageInList(image));
1144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 % R e g i s t e r D P X I m a g e %
1152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154 % RegisterDPXImage() adds properties for the DPX image format to
1155 % the list of supported formats. The properties include the image format
1156 % tag, a method to read and/or write the format, whether the format
1157 % supports the saving of more than one frame to the same file or blob,
1158 % whether the format supports native in-memory I/O, and a brief
1159 % description of the format.
1161 % The format of the RegisterDPXImage method is:
1163 % size_t RegisterDPXImage(void)
1166 ModuleExport size_t RegisterDPXImage(void)
1174 "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1175 "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1178 entry=SetMagickInfo("DPX");
1179 entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1180 entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1181 entry->magick=(IsImageFormatHandler *) IsDPX;
1182 entry->adjoin=MagickFalse;
1183 entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
1184 entry->note=ConstantString(DPXNote);
1185 entry->module=ConstantString("DPX");
1186 (void) RegisterMagickInfo(entry);
1187 return(MagickImageCoderSignature);
1191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1195 % U n r e g i s t e r D P X I m a g e %
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1201 % UnregisterDPXImage() removes format registrations made by the
1202 % DPX module from the list of supported formats.
1204 % The format of the UnregisterDPXImage method is:
1206 % UnregisterDPXImage(void)
1209 ModuleExport void UnregisterDPXImage(void)
1211 (void) UnregisterMagickInfo("DPX");
1215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1219 % W r i t e D P X I m a g e %
1223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1225 % WriteDPXImage() writes an image in DPX encoded image format.
1227 % The format of the WriteDPXImage method is:
1229 % MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1230 % Image *image,ExceptionInfo *exception)
1232 % A description of each parameter follows.
1234 % o image_info: the image info.
1236 % o image: The image.
1238 % o exception: return any errors or warnings in this structure.
1242 static inline const char *GetDPXProperty(const ImageInfo *image_info,
1243 const Image *image,const char *property,ExceptionInfo *exception)
1248 value=GetImageOption(image_info,property);
1249 if (value != (const char *) NULL)
1251 return(GetImageProperty(image,property,exception));
1254 static unsigned int StringToTimeCode(const char *key)
1269 for (i=0; (*key != 0) && (i < 11); i++)
1271 if (isxdigit((int) ((unsigned char) *key)) == 0)
1277 value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1283 static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1284 ExceptionInfo *exception)
1313 register const Quantum
1335 Open output image file.
1337 assert(image_info != (const ImageInfo *) NULL);
1338 assert(image_info->signature == MagickSignature);
1339 assert(image != (Image *) NULL);
1340 assert(image->signature == MagickSignature);
1341 if (image->debug != MagickFalse)
1342 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1343 horizontal_factor=4;
1345 if (image_info->sampling_factor != (char *) NULL)
1353 flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1354 horizontal_factor=(ssize_t) geometry_info.rho;
1355 vertical_factor=(ssize_t) geometry_info.sigma;
1356 if ((flags & SigmaValue) == 0)
1357 vertical_factor=horizontal_factor;
1358 if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1359 (horizontal_factor != 4) && (vertical_factor != 1) &&
1360 (vertical_factor != 2) && (vertical_factor != 4))
1361 ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1363 if ((image->colorspace == YCbCrColorspace) &&
1364 ((horizontal_factor == 2) || (vertical_factor == 2)))
1365 if ((image->columns % 2) != 0)
1367 assert(exception != (ExceptionInfo *) NULL);
1368 assert(exception->signature == MagickSignature);
1369 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1370 if (status == MagickFalse)
1375 (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1377 dpx.file.magic=0x53445058U;
1378 offset+=WriteBlobLong(image,dpx.file.magic);
1379 dpx.file.image_offset=0x2000U;
1380 profile=GetImageProfile(image,"dpx");
1381 if (profile != (StringInfo *) NULL)
1383 if (GetStringInfoLength(profile) > 1048576)
1384 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1385 dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1386 dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1388 offset+=WriteBlobLong(image,dpx.file.image_offset);
1389 (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1390 offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1391 dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
1392 dpx.file.image_offset);
1393 offset+=WriteBlobLong(image,dpx.file.file_size);
1394 dpx.file.ditto_key=1U; /* new frame */
1395 offset+=WriteBlobLong(image,dpx.file.ditto_key);
1396 dpx.file.generic_size=0x00000680U;
1397 offset+=WriteBlobLong(image,dpx.file.generic_size);
1398 dpx.file.industry_size=0x00000180U;
1399 offset+=WriteBlobLong(image,dpx.file.industry_size);
1400 dpx.file.user_size=0;
1401 if (profile != (StringInfo *) NULL)
1403 dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1404 dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1406 offset+=WriteBlobLong(image,dpx.file.user_size);
1407 value=GetDPXProperty(image_info,image,"dpx:file.filename",exception);
1408 if (value != (const char *) NULL)
1409 (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1410 offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1412 seconds=time((time_t *) NULL);
1413 (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1414 dpx.file.timestamp);
1415 offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1416 dpx.file.timestamp);
1417 (void) strncpy(dpx.file.creator,GetMagickVersion((size_t *) NULL),
1418 sizeof(dpx.file.creator));
1419 value=GetDPXProperty(image_info,image,"dpx:file.creator",exception);
1420 if (value != (const char *) NULL)
1421 (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1422 offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1424 value=GetDPXProperty(image_info,image,"dpx:file.project",exception);
1425 if (value != (const char *) NULL)
1426 (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1427 offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1429 value=GetDPXProperty(image_info,image,"dpx:file.copyright",exception);
1430 if (value != (const char *) NULL)
1431 (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright));
1432 offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1433 dpx.file.copyright);
1434 dpx.file.encrypt_key=(~0U);
1435 offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1436 offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1441 dpx.image.orientation=0x00; /* left-to-right; top-to-bottom */
1442 offset+=WriteBlobShort(image,dpx.image.orientation);
1443 dpx.image.number_elements=1;
1444 offset+=WriteBlobShort(image,dpx.image.number_elements);
1445 if ((image->columns != (unsigned int) image->columns) ||
1446 (image->rows != (unsigned int) image->rows))
1447 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1448 offset+=WriteBlobLong(image,(unsigned int) image->columns);
1449 offset+=WriteBlobLong(image,(unsigned int) image->rows);
1450 for (i=0; i < 8; i++)
1452 dpx.image.image_element[i].data_sign=0U;
1453 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1454 dpx.image.image_element[i].low_data=0U;
1455 offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1456 dpx.image.image_element[i].low_quantity=0.0f;
1457 offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1458 dpx.image.image_element[i].high_data=0U;
1459 offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1460 dpx.image.image_element[i].high_quantity=0.0f;
1461 offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1462 dpx.image.image_element[i].descriptor=0;
1464 switch (image->colorspace)
1466 case Rec601YCbCrColorspace:
1467 case Rec709YCbCrColorspace:
1468 case YCbCrColorspace:
1470 dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1471 if (image->matte != MagickFalse)
1472 dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1477 dpx.image.image_element[i].descriptor=RGBComponentType;
1478 if (image->matte != MagickFalse)
1479 dpx.image.image_element[i].descriptor=RGBAComponentType;
1480 if ((image_info->type != TrueColorType) &&
1481 (image->matte == MagickFalse) &&
1482 (IsImageGray(image,exception) != MagickFalse))
1483 dpx.image.image_element[i].descriptor=LumaComponentType;
1487 offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1488 dpx.image.image_element[i].transfer=0;
1489 if (image->colorspace == LogColorspace)
1490 dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
1491 offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
1492 dpx.image.image_element[i].colorimetric=0;
1493 offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1494 dpx.image.image_element[i].bit_size=0;
1496 dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1497 offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1498 dpx.image.image_element[i].packing=0;
1499 if ((image->depth == 10) || (image->depth == 12))
1500 dpx.image.image_element[i].packing=1;
1501 offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1502 dpx.image.image_element[i].encoding=0;
1503 offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1504 dpx.image.image_element[i].data_offset=0U;
1506 dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1507 offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1508 dpx.image.image_element[i].end_of_line_padding=0U;
1509 offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1510 offset+=WriteBlobLong(image,
1511 dpx.image.image_element[i].end_of_image_padding);
1512 offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1513 (unsigned char *) dpx.image.image_element[i].description);
1515 offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1518 Write orientation header.
1520 if ((image->rows != image->magick_rows) ||
1521 (image->columns != image->magick_columns))
1524 These properties are not valid if image size changed.
1526 (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1527 (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1528 (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1529 (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1530 (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1531 (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1533 dpx.orientation.x_offset=0U;
1534 value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset",exception);
1535 if (value != (const char *) NULL)
1536 dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1537 offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1538 dpx.orientation.y_offset=0U;
1539 value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset",exception);
1540 if (value != (const char *) NULL)
1541 dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1542 offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1543 dpx.orientation.x_center=0.0f;
1544 value=GetDPXProperty(image_info,image,"dpx:orientation.x_center",exception);
1545 if (value != (const char *) NULL)
1546 dpx.orientation.x_center=StringToDouble(value,(char **) NULL);
1547 offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1548 dpx.orientation.y_center=0.0f;
1549 value=GetDPXProperty(image_info,image,"dpx:orientation.y_center",exception);
1550 if (value != (const char *) NULL)
1551 dpx.orientation.y_center=StringToDouble(value,(char **) NULL);
1552 offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1553 dpx.orientation.x_size=0U;
1554 value=GetDPXProperty(image_info,image,"dpx:orientation.x_size",exception);
1555 if (value != (const char *) NULL)
1556 dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1557 offset+=WriteBlobLong(image,dpx.orientation.x_size);
1558 dpx.orientation.y_size=0U;
1559 value=GetDPXProperty(image_info,image,"dpx:orientation.y_size",exception);
1560 if (value != (const char *) NULL)
1561 dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1562 offset+=WriteBlobLong(image,dpx.orientation.y_size);
1563 value=GetDPXProperty(image_info,image,"dpx:orientation.filename",exception);
1564 if (value != (const char *) NULL)
1565 (void) strncpy(dpx.orientation.filename,value,
1566 sizeof(dpx.orientation.filename));
1567 offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1568 dpx.orientation.filename);
1569 offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1570 dpx.orientation.timestamp);
1571 value=GetDPXProperty(image_info,image,"dpx:orientation.device",exception);
1572 if (value != (const char *) NULL)
1573 (void) strncpy(dpx.orientation.device,value,sizeof(dpx.orientation.device));
1574 offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1575 dpx.orientation.device);
1576 value=GetDPXProperty(image_info,image,"dpx:orientation.serial",exception);
1577 if (value != (const char *) NULL)
1578 (void) strncpy(dpx.orientation.serial,value,sizeof(dpx.orientation.serial));
1579 offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1580 dpx.orientation.serial);
1581 for (i=0; i < 4; i++)
1582 dpx.orientation.border[i]=0;
1583 value=GetDPXProperty(image_info,image,"dpx:orientation.border",exception);
1584 if (value != (const char *) NULL)
1586 flags=ParseGeometry(value,&geometry_info);
1587 if ((flags & SigmaValue) == 0)
1588 geometry_info.sigma=geometry_info.rho;
1589 dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1590 dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1591 dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1592 dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1594 for (i=0; i < 4; i++)
1595 offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1596 for (i=0; i < 2; i++)
1597 dpx.orientation.aspect_ratio[i]=0U;
1598 value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio",
1600 if (value != (const char *) NULL)
1602 flags=ParseGeometry(value,&geometry_info);
1603 if ((flags & SigmaValue) == 0)
1604 geometry_info.sigma=geometry_info.rho;
1605 dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1606 dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1608 for (i=0; i < 2; i++)
1609 offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1610 offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1611 dpx.orientation.reserve);
1616 value=GetDPXProperty(image_info,image,"dpx:film.id",exception);
1617 if (value != (const char *) NULL)
1618 (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1619 offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1620 *dpx.film.type='\0';
1621 value=GetDPXProperty(image_info,image,"dpx:film.type",exception);
1622 if (value != (const char *) NULL)
1623 (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
1624 offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1626 *dpx.film.offset='\0';
1627 value=GetDPXProperty(image_info,image,"dpx:film.offset",exception);
1628 if (value != (const char *) NULL)
1629 (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1630 offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1632 *dpx.film.prefix='\0';
1633 value=GetDPXProperty(image_info,image,"dpx:film.prefix",exception);
1634 if (value != (const char *) NULL)
1635 (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1636 offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1638 *dpx.film.count='\0';
1639 value=GetDPXProperty(image_info,image,"dpx:film.count",exception);
1640 if (value != (const char *) NULL)
1641 (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1642 offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1644 *dpx.film.format='\0';
1645 value=GetDPXProperty(image_info,image,"dpx:film.format",exception);
1646 if (value != (const char *) NULL)
1647 (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1648 offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1650 dpx.film.frame_position=0U;
1651 value=GetDPXProperty(image_info,image,"dpx:film.frame_position",exception);
1652 if (value != (const char *) NULL)
1653 dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1654 offset+=WriteBlobLong(image,dpx.film.frame_position);
1655 dpx.film.sequence_extent=0U;
1656 value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent",exception);
1657 if (value != (const char *) NULL)
1658 dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1659 offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1660 dpx.film.held_count=0U;
1661 value=GetDPXProperty(image_info,image,"dpx:film.held_count",exception);
1662 if (value != (const char *) NULL)
1663 dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1664 offset+=WriteBlobLong(image,dpx.film.held_count);
1665 dpx.film.frame_rate=0.0f;
1666 value=GetDPXProperty(image_info,image,"dpx:film.frame_rate",exception);
1667 if (value != (const char *) NULL)
1668 dpx.film.frame_rate=StringToDouble(value,(char **) NULL);
1669 offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1670 dpx.film.shutter_angle=0.0f;
1671 value=GetDPXProperty(image_info,image,"dpx:film.shutter_angle",exception);
1672 if (value != (const char *) NULL)
1673 dpx.film.shutter_angle=StringToDouble(value,(char **) NULL);
1674 offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1675 *dpx.film.frame_id='\0';
1676 value=GetDPXProperty(image_info,image,"dpx:film.frame_id",exception);
1677 if (value != (const char *) NULL)
1678 (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1679 offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1681 value=GetDPXProperty(image_info,image,"dpx:film.slate",exception);
1682 if (value != (const char *) NULL)
1683 (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1684 offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1686 offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1689 Write television header.
1691 value=GetDPXProperty(image_info,image,"dpx:television.time.code",exception);
1692 if (value != (const char *) NULL)
1693 dpx.television.time_code=StringToTimeCode(value);
1694 offset+=WriteBlobLong(image,dpx.television.time_code);
1695 value=GetDPXProperty(image_info,image,"dpx:television.user.bits",exception);
1696 if (value != (const char *) NULL)
1697 dpx.television.user_bits=StringToTimeCode(value);
1698 offset+=WriteBlobLong(image,dpx.television.user_bits);
1699 value=GetDPXProperty(image_info,image,"dpx:television.interlace",exception);
1700 if (value != (const char *) NULL)
1701 dpx.television.interlace=(unsigned char) StringToLong(value);
1702 offset+=WriteBlobByte(image,dpx.television.interlace);
1703 value=GetDPXProperty(image_info,image,"dpx:television.field_number",
1705 if (value != (const char *) NULL)
1706 dpx.television.field_number=(unsigned char) StringToLong(value);
1707 offset+=WriteBlobByte(image,dpx.television.field_number);
1708 dpx.television.video_signal=0;
1709 value=GetDPXProperty(image_info,image,"dpx:television.video_signal",
1711 if (value != (const char *) NULL)
1712 dpx.television.video_signal=(unsigned char) StringToLong(value);
1713 offset+=WriteBlobByte(image,dpx.television.video_signal);
1714 dpx.television.padding=0;
1715 value=GetDPXProperty(image_info,image,"dpx:television.padding",exception);
1716 if (value != (const char *) NULL)
1717 dpx.television.padding=(unsigned char) StringToLong(value);
1718 offset+=WriteBlobByte(image,dpx.television.padding);
1719 dpx.television.horizontal_sample_rate=0.0f;
1720 value=GetDPXProperty(image_info,image,"dpx:television.horizontal_sample_rate", exception);
1721 if (value != (const char *) NULL)
1722 dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
1723 offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1724 dpx.television.vertical_sample_rate=0.0f;
1725 value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate",
1727 if (value != (const char *) NULL)
1728 dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
1729 offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1730 dpx.television.frame_rate=0.0f;
1731 value=GetDPXProperty(image_info,image,"dpx:television.frame_rate",exception);
1732 if (value != (const char *) NULL)
1733 dpx.television.frame_rate=StringToDouble(value,(char **) NULL);
1734 offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1735 dpx.television.time_offset=0.0f;
1736 value=GetDPXProperty(image_info,image,"dpx:television.time_offset",exception);
1737 if (value != (const char *) NULL)
1738 dpx.television.time_offset=StringToDouble(value,(char **) NULL);
1739 offset+=WriteBlobFloat(image,dpx.television.time_offset);
1740 dpx.television.gamma=0.0f;
1741 value=GetDPXProperty(image_info,image,"dpx:television.gamma",exception);
1742 if (value != (const char *) NULL)
1743 dpx.television.gamma=StringToDouble(value,(char **) NULL);
1744 offset+=WriteBlobFloat(image,dpx.television.gamma);
1745 dpx.television.black_level=0.0f;
1746 value=GetDPXProperty(image_info,image,"dpx:television.black_level",exception);
1747 if (value != (const char *) NULL)
1748 dpx.television.black_level=StringToDouble(value,(char **) NULL);
1749 offset+=WriteBlobFloat(image,dpx.television.black_level);
1750 dpx.television.black_gain=0.0f;
1751 value=GetDPXProperty(image_info,image,"dpx:television.black_gain",exception);
1752 if (value != (const char *) NULL)
1753 dpx.television.black_gain=StringToDouble(value,(char **) NULL);
1754 offset+=WriteBlobFloat(image,dpx.television.black_gain);
1755 dpx.television.break_point=0.0f;
1756 value=GetDPXProperty(image_info,image,"dpx:television.break_point",exception);
1757 if (value != (const char *) NULL)
1758 dpx.television.break_point=StringToDouble(value,(char **) NULL);
1759 offset+=WriteBlobFloat(image,dpx.television.break_point);
1760 dpx.television.white_level=0.0f;
1761 value=GetDPXProperty(image_info,image,"dpx:television.white_level",exception);
1762 if (value != (const char *) NULL)
1763 dpx.television.white_level=StringToDouble(value,(char **) NULL);
1764 offset+=WriteBlobFloat(image,dpx.television.white_level);
1765 dpx.television.integration_times=0.0f;
1766 value=GetDPXProperty(image_info,image,"dpx:television.integration_times",
1768 if (value != (const char *) NULL)
1769 dpx.television.integration_times=StringToDouble(value,(char **) NULL);
1770 offset+=WriteBlobFloat(image,dpx.television.integration_times);
1771 offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1772 dpx.television.reserve);
1776 value=GetDPXProperty(image_info,image,"dpx:user.id",exception);
1777 if (value != (const char *) NULL)
1778 (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1779 offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1780 if (profile != (StringInfo *) NULL)
1781 offset+=WriteBlob(image,GetStringInfoLength(profile),
1782 GetStringInfoDatum(profile));
1783 while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1785 count=WriteBlobByte(image,0x00);
1788 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
1795 Convert pixel packets to DPX raster image.
1797 quantum_info=AcquireQuantumInfo(image_info,image);
1798 SetQuantumQuantum(quantum_info,32);
1799 SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
1800 MagickTrue : MagickFalse);
1801 quantum_type=RGBQuantum;
1802 if (image->matte != MagickFalse)
1803 quantum_type=RGBAQuantum;
1804 if (image->colorspace == YCbCrColorspace)
1806 quantum_type=CbYCrQuantum;
1807 if (image->matte != MagickFalse)
1808 quantum_type=CbYCrAQuantum;
1809 if ((horizontal_factor == 2) || (vertical_factor == 2))
1810 quantum_type=CbYCrYQuantum;
1812 extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
1813 image->depth,MagickTrue);
1814 if ((image_info->type != TrueColorType) && (image->matte == MagickFalse) &&
1815 (IsImageGray(image,exception) != MagickFalse))
1817 quantum_type=GrayQuantum;
1818 extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue);
1820 pixels=GetQuantumPixels(quantum_info);
1821 for (y=0; y < (ssize_t) image->rows; y++)
1823 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1824 if (p == (const Quantum *) NULL)
1826 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1827 quantum_type,pixels,exception);
1828 count=WriteBlob(image,extent,pixels);
1829 if (count != (ssize_t) extent)
1831 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1833 if (status == MagickFalse)
1836 quantum_info=DestroyQuantumInfo(quantum_info);
1837 (void) CloseBlob(image);