diff --git a/libdpx/DPXHeader.cpp b/libdpx/DPXHeader.cpp index 2c172bf..aba7873 100755 --- a/libdpx/DPXHeader.cpp +++ b/libdpx/DPXHeader.cpp @@ -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 diff --git a/libdpx/DPXHeader.h b/libdpx/DPXHeader.h index 33965c6..5aeb9b5 100755 --- a/libdpx/DPXHeader.h +++ b/libdpx/DPXHeader.h @@ -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 diff --git a/libdpx/ReaderInternal.h b/libdpx/ReaderInternal.h index 8fb1685..89b087d 100755 --- a/libdpx/ReaderInternal.h +++ b/libdpx/ReaderInternal.h @@ -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(readBuf, dataSize, data, count, bufoff); @@ -367,8 +367,8 @@ namespace dpx } - template - bool Read12bitFilledMethodB(const Header &dpxHeader, U16 *readBuf, IR *fd, const int element, const Block &block, BUF *data) + template + 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); @@ -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]); } @@ -458,11 +460,11 @@ namespace dpx else if (packing == kFilledMethodB) // filled method B // 12 bits fill LSB of 16 bits - return Read12bitFilledMethodB(dpxHeader, reinterpret_cast(readBuf), fd, element, block, reinterpret_cast(data)); + return Read12bitFilled(dpxHeader, reinterpret_cast(readBuf), fd, element, block, reinterpret_cast(data)); else // filled method A // 12 bits fill MSB of 16 bits - return ReadBlockTypes(dpxHeader, reinterpret_cast(readBuf), fd, element, block, reinterpret_cast(data)); + return Read12bitFilled(dpxHeader, reinterpret_cast(readBuf), fd, element, block, reinterpret_cast(data)); } else if (size == dpx::kByte) return ReadBlockTypes(dpxHeader, reinterpret_cast(readBuf), fd, element, block, reinterpret_cast(data)); diff --git a/libdpx/Writer.cpp b/libdpx/Writer.cpp index c7242d4..49aa398 100755 --- a/libdpx/Writer.cpp +++ b/libdpx/Writer.cpp @@ -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) @@ -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))) @@ -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(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); else - this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteBuffer(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(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); else - this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); break; case 12: - if (size == dpx::kWord) - this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + if (size == dpx::kWord && !swapEndian) + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); else - this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); break; case 16: - if (size == dpx::kWord) - this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + if (size == dpx::kWord && !swapEndian) + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); else - this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteBuffer(this->fd, size, data, width, height, noc, packing, rle, reverse, eolnPad, blank, status, swapEndian); break; case 32: - if (size == dpx::kFloat) - this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap()); + if (size == dpx::kFloat && !swapEndian) + this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian); else - this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian); break; case 64: - if (size == dpx::kDouble) - this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap()); + if (size == dpx::kDouble && !swapEndian) + this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian); else - this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, this->header.RequiresByteSwap()); + this->fileLoc += WriteFloatBuffer(this->fd, size, data, width, height, noc, packing, rle, eolnPad, blank, status, swapEndian); break; } } diff --git a/libdpx/WriterInternal.h b/libdpx/WriterInternal.h index 6805a80..e17d4b9 100755 --- a/libdpx/WriterInternal.h +++ b/libdpx/WriterInternal.h @@ -320,17 +320,20 @@ namespace dpx { WritePackedMethod(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