Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libdpx/DPXHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ dpx::U32 dpx::IndustryHeader::TCFromString(const char *str) const
for (i = 0; i < 8; i++)
{
// determine string index skipping :
idx = i + ((i + 1) / 3);
idx = i + (i / 2);
ch = str[idx];

// error check
Expand Down
6 changes: 3 additions & 3 deletions libdpx/DPXHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1604,13 +1604,13 @@ namespace dpx

inline void GenericHeader::Creator(char *creat) const
{
::strncpy(creat, this->creator, 200);
creat[200] = '\0';
::strncpy(creat, this->creator, 100);
creat[100] = '\0';
}

inline void GenericHeader::SetCreator(const char *creat)
{
::strncpy(this->creator, creat, 200);
::strncpy(this->creator, creat, 100);
}

inline void GenericHeader::Project(char *prj) const
Expand Down
18 changes: 10 additions & 8 deletions libdpx/ReaderInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ namespace dpx
readSize += (block.x1 * numberOfComponents * dataSize % 32); // add the bits left over from the beginning of the line
readSize = ((readSize + 31) / 32) * sizeof(U32);

fd->Read(dpxHeader, element, offset, readBuf, readSize);

// calculate buffer offset
int bufoff = line * dpxHeader.Width() * numberOfComponents;

fd->Read(dpxHeader, element, offset, readBuf, readSize);

// unpack the words in the buffer
int count = (block.x2 - block.x1 + 1) * numberOfComponents;
UnPackPacked<BUF, MASK, MULTIPLIER, REMAIN, REVERSE>(readBuf, dataSize, data, count, bufoff);
Expand Down Expand Up @@ -367,8 +367,8 @@ namespace dpx
}


template <typename IR, typename BUF>
bool Read12bitFilledMethodB(const Header &dpxHeader, U16 *readBuf, IR *fd, const int element, const Block &block, BUF *data)
template <typename IR, typename BUF, bool METHODB>
bool Read12bitFilled(const Header &dpxHeader, U16 *readBuf, IR *fd, const int element, const Block &block, BUF *data)
{
// get the number of components for this element descriptor
const int numberOfComponents = dpxHeader.ImageElementComponentCount(element);
Expand All @@ -393,11 +393,13 @@ namespace dpx
block.x1 * numberOfComponents * 2 + (line * eolnPad);

fd->Read(dpxHeader, element, offset, readBuf, width*2);


const int downshift = (METHODB ? 0 : 4);

// convert data
for (int i = 0; i < width; i++)
{
U16 d1 = readBuf[i];
U16 d1 = readBuf[i] >> downshift;
BaseTypeConvertU12ToU16(d1, d1);
BaseTypeConverter(d1, data[width*line+i]);
}
Expand Down Expand Up @@ -458,11 +460,11 @@ namespace dpx
else if (packing == kFilledMethodB)
// filled method B
// 12 bits fill LSB of 16 bits
return Read12bitFilledMethodB<IR, BUF>(dpxHeader, reinterpret_cast<U16 *>(readBuf), fd, element, block, reinterpret_cast<BUF *>(data));
return Read12bitFilled<IR, BUF, true>(dpxHeader, reinterpret_cast<U16 *>(readBuf), fd, element, block, reinterpret_cast<BUF *>(data));
else
// filled method A
// 12 bits fill MSB of 16 bits
return ReadBlockTypes<IR, U16, kWord, BUF, BUFTYPE>(dpxHeader, reinterpret_cast<U16 *>(readBuf), fd, element, block, reinterpret_cast<BUF *>(data));
return Read12bitFilled<IR, BUF, false>(dpxHeader, reinterpret_cast<U16 *>(readBuf), fd, element, block, reinterpret_cast<BUF *>(data));
}
else if (size == dpx::kByte)
return ReadBlockTypes<IR, U8, kByte, BUF, BUFTYPE>(dpxHeader, reinterpret_cast<U8 *>(readBuf), fd, element, block, reinterpret_cast<BUF *>(data));
Expand Down
40 changes: 20 additions & 20 deletions libdpx/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ bool dpx::Writer::WriteElement(const int element, void *data, const DataSize siz
const U32 height = this->header.Height();
const int noc = this->header.ImageElementComponentCount(element);
const Packing packing = this->header.ImagePacking(element);
const bool swapEndian = this->header.RequiresByteSwap();

// check width & height, just in case
if (width == 0 || height == 0)
Expand All @@ -262,9 +263,8 @@ bool dpx::Writer::WriteElement(const int element, void *data, const DataSize siz
}

// can we write the entire memory chunk at once without any additional processing
if (!rle &&
if (!rle && !swapEndian &&
((bitDepth == 8 && size == dpx::kByte) ||
(bitDepth == 12 && size == dpx::kWord && packing == kFilledMethodA) ||
(bitDepth == 16 && size == dpx::kWord) ||
(bitDepth == 32 && size == dpx::kFloat) ||
(bitDepth == 64 && size == dpx::kDouble)))
Expand All @@ -280,48 +280,48 @@ bool dpx::Writer::WriteElement(const int element, void *data, const DataSize siz
{
case 8:
if (size == dpx::kByte)
this->fileLoc += WriteBuffer<U8, 8, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteBuffer<U8, 8, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
else
this->fileLoc += WriteBuffer<U8, 8, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteBuffer<U8, 8, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
break;

case 10:
// are the channels stored in reverse
if (this->header.ImageDescriptor(element) == kRGB && this->header.DatumSwap(element) && bitDepth == 10)
reverse = true;
//if (this->header.ImageDescriptor(element) == kRGB && this->header.DatumSwap(element) && bitDepth == 10)
reverse = true; // seems like we would always have to "reverse" the order, although actually the normal written order appears reversed

if (size == dpx::kWord)
this->fileLoc += WriteBuffer<U16, 10, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteBuffer<U16, 10, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
else
this->fileLoc += WriteBuffer<U16, 10, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteBuffer<U16, 10, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
break;

case 12:
if (size == dpx::kWord)
this->fileLoc += WriteBuffer<U16, 12, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
if (size == dpx::kWord && !swapEndian)
this->fileLoc += WriteBuffer<U16, 12, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
else
this->fileLoc += WriteBuffer<U16, 12, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteBuffer<U16, 12, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
break;

case 16:
if (size == dpx::kWord)
this->fileLoc += WriteBuffer<U16, 16, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
if (size == dpx::kWord && !swapEndian)
this->fileLoc += WriteBuffer<U16, 16, true>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
else
this->fileLoc += WriteBuffer<U16, 16, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteBuffer<U16, 16, false>(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian);
break;

case 32:
if (size == dpx::kFloat)
this->fileLoc += WriteFloatBuffer<R32, 32, true>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap());
if (size == dpx::kFloat && !swapEndian)
this->fileLoc += WriteFloatBuffer<R32, 32, true>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian);
else
this->fileLoc += WriteFloatBuffer<R32, 32, false>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteFloatBuffer<R32, 32, false>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian);
break;

case 64:
if (size == dpx::kDouble)
this->fileLoc += WriteFloatBuffer<R64, 64, true>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap());
if (size == dpx::kDouble && !swapEndian)
this->fileLoc += WriteFloatBuffer<R64, 64, true>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian);
else
this->fileLoc += WriteFloatBuffer<R64, 64, false>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap());
this->fileLoc += WriteFloatBuffer<R64, 64, false>(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian);
break;
}
}
Expand Down
13 changes: 8 additions & 5 deletions libdpx/WriterInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,20 @@ namespace dpx
{
WritePackedMethod<IB, BITDEPTH>(src, dst, (width*noc), reverse, bufaccess);
}
else if (packing == dpx::kFilledMethodB)
else if (packing == dpx::kFilledMethodA)
{
// zero out the bottom 4 bits
for (int w = 0; w < bufaccess.length; w++)
dst[w] = src[bufaccess.offset+w] & 0xfff0;
bufaccess.offset = 0;
}
else // if (packing == dpx::kFilledMethodB)
{
// shift 4 MSB down, so 0x0f00 would become 0x00f0
for (int w = 0; w < bufaccess.length; w++)
dst[w] = src[bufaccess.offset+w] >> 4;
bufaccess.offset = 0;
}
// a bitdepth of 12 by default is packed with dpx::kFilledMethodA
// assumes that either a copy or rle was required
// otherwise this routine should not be called with:
// 12-bit Method A with the source buffer data type is kWord
}

// write line
Expand Down