% March 2001 %
% %
% %
-% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/option.h"
+#include "MagickCore/pixel-accessor.h"
#include "MagickCore/profile.h"
#include "MagickCore/property.h"
#include "MagickCore/quantum-private.h"
UserDef8ElementComponentType = 156
} DPXComponentType;
+typedef enum
+{
+ TransferCharacteristicUserDefined = 0,
+ TransferCharacteristicPrintingDensity = 1,
+ TransferCharacteristicLinear = 2,
+ TransferCharacteristicLogarithmic = 3,
+ TransferCharacteristicUnspecifiedVideo = 4,
+ TransferCharacteristicSMTPE274M = 5, /* 1920x1080 TV */
+ TransferCharacteristicITU_R709 = 6, /* ITU R709 */
+ TransferCharacteristicITU_R601_625L = 7, /* 625 Line */
+ TransferCharacteristicITU_R601_525L = 8, /* 525 Line */
+ TransferCharacteristicNTSCCompositeVideo = 9,
+ TransferCharacteristicPALCompositeVideo = 10,
+ TransferCharacteristicZDepthLinear = 11,
+ TransferCharacteristicZDepthHomogeneous = 12
+} DPXTransferCharacteristic;
+
typedef struct _DPXFileInfo
{
unsigned int
unsigned char
descriptor,
- transfer,
+ transfer_characteristic,
colorimetric,
bit_size;
%
*/
-static size_t GetBytesPerRow(size_t columns,
- size_t samples_per_pixel,size_t bits_per_pixel,
- MagickBooleanType pad)
+static size_t GetBytesPerRow(const size_t columns,
+ const size_t samples_per_pixel,const size_t bits_per_pixel,
+ const MagickBooleanType pad)
{
size_t
bytes_per_row;
{
case 1:
{
- bytes_per_row=4*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+31)/32);
+ bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
+ 32);
break;
}
case 8:
default:
{
- bytes_per_row=4*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+31)/32);
+ bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
+ 32);
break;
}
case 10:
{
if (pad == MagickFalse)
{
- bytes_per_row=4*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+31)/32);
+ bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
+ 31)/32);
break;
}
bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
{
if (pad == MagickFalse)
{
- bytes_per_row=4*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+31)/32);
+ bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
+ 31)/32);
break;
}
bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
}
case 16:
{
- bytes_per_row=2*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+8)/16);
+ bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+8)/
+ 16);
break;
}
case 32:
{
- bytes_per_row=4*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+31)/32);
+ bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
+ 32);
break;
}
case 64:
{
- bytes_per_row=8*(((size_t) samples_per_pixel*columns*
- bits_per_pixel+63)/64);
+ bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
+ 64);
break;
}
}
return(bytes_per_row);
}
+static const char *GetImageTransferCharacteristic(
+ const DPXTransferCharacteristic characteristic)
+{
+ const char
+ *transfer;
+
+ /*
+ Get the element transfer characteristic.
+ */
+ switch(characteristic)
+ {
+ case TransferCharacteristicUserDefined:
+ {
+ transfer="UserDefined";
+ break;
+ }
+ case TransferCharacteristicPrintingDensity:
+ {
+ transfer="PrintingDensity";
+ break;
+ }
+ case TransferCharacteristicLinear:
+ {
+ transfer="Linear";
+ break;
+ }
+ case TransferCharacteristicLogarithmic:
+ {
+ transfer="Logarithmic";
+ break;
+ }
+ case TransferCharacteristicUnspecifiedVideo:
+ {
+ transfer="UnspecifiedVideo";
+ break;
+ }
+ case TransferCharacteristicSMTPE274M:
+ {
+ transfer="SMTPE274M";
+ break;
+ }
+ case TransferCharacteristicITU_R709:
+ {
+ transfer="ITU-R709";
+ break;
+ }
+ case TransferCharacteristicITU_R601_625L:
+ {
+ transfer="ITU-R601-625L";
+ break;
+ }
+ case TransferCharacteristicITU_R601_525L:
+ {
+ transfer="ITU-R601-525L";
+ break;
+ }
+ case TransferCharacteristicNTSCCompositeVideo:
+ {
+ transfer="NTSCCompositeVideo";
+ break;
+ }
+ case TransferCharacteristicPALCompositeVideo:
+ {
+ transfer="PALCompositeVideo";
+ break;
+ }
+ case TransferCharacteristicZDepthLinear:
+ {
+ transfer="ZDepthLinear";
+ break;
+ }
+ case TransferCharacteristicZDepthHomogeneous:
+ {
+ transfer="ZDepthHomogeneous";
+ break;
+ }
+ default:
+ transfer="Reserved";
+ }
+ return(transfer);
+}
+
static inline MagickBooleanType IsFloatDefined(const float value)
{
union
ssize_t
count,
+ n,
row,
y;
image->rows=dpx.image.lines_per_element;
for (i=0; i < 8; i++)
{
+ char
+ property[MaxTextExtent];
+
dpx.image.image_element[i].data_sign=ReadBlobLong(image);
offset+=4;
dpx.image.image_element[i].low_data=ReadBlobLong(image);
offset+=4;
dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
offset++;
- dpx.image.image_element[i].transfer=(unsigned char) ReadBlobByte(image);
+ dpx.image.image_element[i].transfer_characteristic=(unsigned char)
+ ReadBlobByte(image);
+ (void) FormatLocaleString(property,MaxTextExtent,
+ "dpx:image.element[%lu].transfer-characteristic",(long) i);
+ (void) FormatImageProperty(image,property,"%s",
+ GetImageTransferCharacteristic((DPXTransferCharacteristic)
+ dpx.image.image_element[i].transfer_characteristic));
offset++;
dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
offset++;
offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
(unsigned char *) dpx.image.image_element[i].description);
}
- SetPrimaryChromaticity((DPXColorimetric)
- dpx.image.image_element[0].colorimetric,&image->chromaticity);
+ SetImageColorspace(image,RGBColorspace,exception);
offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
dpx.image.reserve);
- component_type=dpx.image.image_element[0].descriptor;
- image->depth=dpx.image.image_element[0].bit_size;
if (dpx.file.image_offset >= 1664U)
{
/*
}
for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
(void) ReadBlobByte(image);
- /*
- Read DPX image header.
- */
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
- /*
- Convert DPX raster image to pixel packets.
- */
- samples_per_pixel=1;
- quantum_type=GrayQuantum;
- switch (component_type)
+ for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
{
- case CbYCrY422ComponentType:
- {
- samples_per_pixel=2;
- quantum_type=CbYCrYQuantum;
- break;
- }
- case CbYACrYA4224ComponentType:
- case CbYCr444ComponentType:
- {
- samples_per_pixel=3;
- quantum_type=CbYCrQuantum;
- break;
- }
- case RGBComponentType:
- {
- samples_per_pixel=3;
- quantum_type=RGBQuantum;
- break;
- }
- case ABGRComponentType:
- case RGBAComponentType:
- {
- image->matte=MagickTrue;
- samples_per_pixel=4;
- quantum_type=RGBAQuantum;
- break;
- }
- default:
- break;
- }
- switch (component_type)
- {
- case CbYCrY422ComponentType:
- case CbYACrYA4224ComponentType:
- case CbYCr444ComponentType:
+ /*
+ Convert DPX raster image to pixel packets.
+ */
+ if ((dpx.image.image_element[n].data_offset != (unsigned int) (~0U)) &&
+ (dpx.image.image_element[n].data_offset != 0U))
+ {
+ MagickOffsetType
+ data_offset;
+
+ data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
+ if (data_offset < offset)
+ offset=SeekBlob(image,data_offset,SEEK_SET);
+ else
+ for ( ; offset < data_offset; offset++)
+ (void) ReadBlobByte(image);
+ if (offset != data_offset)
+ ThrowReaderException(CorruptImageError,"UnableToReadImageData");
+ }
+ SetPrimaryChromaticity((DPXColorimetric)
+ dpx.image.image_element[n].colorimetric,&image->chromaticity);
+ image->depth=dpx.image.image_element[n].bit_size;
+ samples_per_pixel=1;
+ quantum_type=GrayQuantum;
+ component_type=dpx.image.image_element[n].descriptor;
+ switch (component_type)
{
- image->colorspace=Rec709YCbCrColorspace;
- break;
+ case CbYCrY422ComponentType:
+ {
+ samples_per_pixel=2;
+ quantum_type=CbYCrYQuantum;
+ break;
+ }
+ case CbYACrYA4224ComponentType:
+ case CbYCr444ComponentType:
+ {
+ samples_per_pixel=3;
+ quantum_type=CbYCrQuantum;
+ break;
+ }
+ case RGBComponentType:
+ {
+ samples_per_pixel=3;
+ quantum_type=RGBQuantum;
+ break;
+ }
+ case ABGRComponentType:
+ case RGBAComponentType:
+ {
+ image->alpha_trait=BlendPixelTrait;
+ samples_per_pixel=4;
+ quantum_type=RGBAQuantum;
+ break;
+ }
+ default:
+ break;
}
- case LumaComponentType:
+ switch (component_type)
{
- image->colorspace=RGBColorspace;
- break;
+ case CbYCrY422ComponentType:
+ case CbYACrYA4224ComponentType:
+ case CbYCr444ComponentType:
+ {
+ SetImageColorspace(image,Rec709YCbCrColorspace,exception);
+ break;
+ }
+ case LumaComponentType:
+ {
+ SetImageColorspace(image,GRAYColorspace,exception);
+ break;
+ }
+ default:
+ {
+ SetImageColorspace(image,sRGBColorspace,exception);
+ if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
+ SetImageColorspace(image,LogColorspace,exception);
+ if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
+ SetImageColorspace(image,LogColorspace,exception);
+ break;
+ }
}
- default:
+ extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
+ dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
+ /*
+ DPX any-bit pixel format.
+ */
+ status=MagickTrue;
+ row=0;
+ quantum_info=AcquireQuantumInfo(image_info,image);
+ if (quantum_info == (QuantumInfo *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ SetQuantumQuantum(quantum_info,32);
+ SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
+ MagickTrue : MagickFalse);
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- image->colorspace=RGBColorspace;
- if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
- image->colorspace=LogColorspace;
- if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
- image->colorspace=LogColorspace;
- break;
- }
- }
- extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
- dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
- /*
- DPX any-bit pixel format.
- */
- status=MagickTrue;
- row=0;
- quantum_info=AcquireQuantumInfo(image_info,image);
- if (quantum_info == (QuantumInfo *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- SetQuantumQuantum(quantum_info,32);
- SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
- MagickTrue : MagickFalse);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- MagickBooleanType
- sync;
+ MagickBooleanType
+ sync;
- register Quantum
- *q;
+ register Quantum
+ *q;
- size_t
- length;
+ size_t
+ length;
- ssize_t
- count,
- offset;
+ ssize_t
+ count,
+ offset;
- unsigned char
- *pixels;
+ unsigned char
+ *pixels;
- if (status == MagickFalse)
- continue;
- pixels=GetQuantumPixels(quantum_info);
- {
- count=ReadBlob(image,extent,pixels);
- if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
- (image->previous == (Image *) NULL))
+ if (status == MagickFalse)
+ continue;
+ pixels=GetQuantumPixels(quantum_info);
+ {
+ count=ReadBlob(image,extent,pixels);
+ if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
+ (image->previous == (Image *) NULL))
+ {
+ MagickBooleanType
+ proceed;
+
+ proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
+ image->rows);
+ if (proceed == MagickFalse)
+ status=MagickFalse;
+ }
+ offset=row++;
+ }
+ if (count != (ssize_t) extent)
+ status=MagickFalse;
+ q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
+ if (q == (Quantum *) NULL)
{
- MagickBooleanType
- proceed;
-
- proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
- image->rows);
- if (proceed == MagickFalse)
- status=MagickFalse;
+ status=MagickFalse;
+ continue;
}
- offset=row++;
+ length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+ quantum_type,pixels,exception);
+ (void) length;
+ sync=SyncAuthenticPixels(image,exception);
+ if (sync == MagickFalse)
+ status=MagickFalse;
}
- if (count != (ssize_t) extent)
- status=MagickFalse;
- q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception);
- if (q == (Quantum *) NULL)
+ quantum_info=DestroyQuantumInfo(quantum_info);
+ if (status == MagickFalse)
+ ThrowReaderException(CorruptImageError,"UnableToReadImageData");
+ SetQuantumImageType(image,quantum_type);
+ if (EOFBlob(image) != MagickFalse)
+ ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
+ image->filename);
+ if ((i+1) < (ssize_t) dpx.image.number_elements)
{
- status=MagickFalse;
- continue;
+ /*
+ Allocate next image structure.
+ */
+ AcquireNextImage(image_info,image,exception);
+ if (GetNextImageInList(image) == (Image *) NULL)
+ {
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
+ image=SyncNextImageInList(image);
+ status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
+ GetBlobSize(image));
+ if (status == MagickFalse)
+ break;
}
- length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- quantum_type,pixels,exception);
- (void) length;
- sync=SyncAuthenticPixels(image,exception);
- if (sync == MagickFalse)
- status=MagickFalse;
}
- quantum_info=DestroyQuantumInfo(quantum_info);
- if (status == MagickFalse)
- ThrowReaderException(CorruptImageError,"UnableToReadImageData");
- SetQuantumImageType(image,quantum_type);
- if (EOFBlob(image) != MagickFalse)
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
entry->encoder=(EncodeImageHandler *) WriteDPXImage;
entry->magick=(IsImageFormatHandler *) IsDPX;
entry->adjoin=MagickFalse;
+ entry->seekable_stream=MagickTrue;
entry->description=ConstantString("SMPTE 268M-2003 (DPX 2.0)");
entry->note=ConstantString(DPXNote);
entry->module=ConstantString("DPX");
DPXInfo
dpx;
+ GeometryInfo
+ geometry_info;
+
MagickBooleanType
status;
MagickStatusType
flags;
- GeometryInfo
- geometry_info;
-
QuantumInfo
*quantum_info;
/*
Write image header.
*/
- dpx.image.orientation=0x00; /* left-to-right; top-to-bottom */
+ switch (image->orientation)
+ {
+ default:
+ case TopLeftOrientation: dpx.image.orientation=0; break;
+ case TopRightOrientation: dpx.image.orientation=1; break;
+ case BottomLeftOrientation: dpx.image.orientation=2; break;
+ case BottomRightOrientation: dpx.image.orientation=3; break;
+ case LeftTopOrientation: dpx.image.orientation=4; break;
+ case RightTopOrientation: dpx.image.orientation=5; break;
+ case LeftBottomOrientation: dpx.image.orientation=6; break;
+ case RightBottomOrientation: dpx.image.orientation=7; break;
+ }
offset+=WriteBlobShort(image,dpx.image.orientation);
dpx.image.number_elements=1;
offset+=WriteBlobShort(image,dpx.image.number_elements);
case YCbCrColorspace:
{
dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
break;
}
default:
{
dpx.image.image_element[i].descriptor=RGBComponentType;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
dpx.image.image_element[i].descriptor=RGBAComponentType;
if ((image_info->type != TrueColorType) &&
- (image->matte == MagickFalse) &&
+ (image->alpha_trait != BlendPixelTrait) &&
(IsImageGray(image,exception) != MagickFalse))
dpx.image.image_element[i].descriptor=LumaComponentType;
break;
}
}
offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
- dpx.image.image_element[i].transfer=0;
+ dpx.image.image_element[i].transfer_characteristic=0;
if (image->colorspace == LogColorspace)
- dpx.image.image_element[0].transfer=PrintingDensityColorimetric;
- offset+=WriteBlobByte(image,dpx.image.image_element[i].transfer);
+ dpx.image.image_element[0].transfer_characteristic=
+ PrintingDensityColorimetric;
+ offset+=WriteBlobByte(image,
+ dpx.image.image_element[i].transfer_characteristic);
dpx.image.image_element[i].colorimetric=0;
offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
dpx.image.image_element[i].bit_size=0;
dpx.television.field_number=(unsigned char) StringToLong(value);
offset+=WriteBlobByte(image,dpx.television.field_number);
dpx.television.video_signal=0;
- value=GetDPXProperty(image_info,image,"dpx:television.video_signal",exception);
+ value=GetDPXProperty(image_info,image,"dpx:television.video_signal",
+ exception);
if (value != (const char *) NULL)
dpx.television.video_signal=(unsigned char) StringToLong(value);
offset+=WriteBlobByte(image,dpx.television.video_signal);
dpx.television.padding=(unsigned char) StringToLong(value);
offset+=WriteBlobByte(image,dpx.television.padding);
dpx.television.horizontal_sample_rate=0.0f;
- value=GetDPXProperty(image_info,image,
- "dpx:television.horizontal_sample_rate",exception);
+ value=GetDPXProperty(image_info,image,"dpx:television.horizontal_sample_rate", exception);
if (value != (const char *) NULL)
- dpx.television.horizontal_sample_rate=StringToDouble(value,
- (char **) NULL);
+ dpx.television.horizontal_sample_rate=StringToDouble(value,(char **) NULL);
offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
dpx.television.vertical_sample_rate=0.0f;
value=GetDPXProperty(image_info,image,"dpx:television.vertical_sample_rate",
exception);
if (value != (const char *) NULL)
- dpx.television.vertical_sample_rate=StringToDouble(value,
- (char **) NULL);
+ dpx.television.vertical_sample_rate=StringToDouble(value,(char **) NULL);
offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
dpx.television.frame_rate=0.0f;
value=GetDPXProperty(image_info,image,"dpx:television.frame_rate",exception);
SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
MagickTrue : MagickFalse);
quantum_type=RGBQuantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
quantum_type=RGBAQuantum;
if (image->colorspace == YCbCrColorspace)
{
quantum_type=CbYCrQuantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
quantum_type=CbYCrAQuantum;
if ((horizontal_factor == 2) || (vertical_factor == 2))
quantum_type=CbYCrYQuantum;
}
- extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL,
- image->depth,MagickTrue);
- if ((image_info->type != UndefinedType) &&
- (image_info->type != TrueColorType) && (image->matte == MagickFalse) &&
+ extent=GetBytesPerRow(image->columns,image->alpha_trait == BlendPixelTrait ?
+ 4UL : 3UL,image->depth,MagickTrue);
+ if ((image_info->type != TrueColorType) &&
+ (image->alpha_trait != BlendPixelTrait) &&
(IsImageGray(image,exception) != MagickFalse))
{
quantum_type=GrayQuantum;