Mercurial > hg > orthanc
diff Core/Images/PamReader.cpp @ 3834:219de90c1f43
Added a flag to use an extra buffer in PamReader
to ensure (malloc-like) alignment of the image
buffer. This flag is NOT turned on by default and,
in Orthanc, is only used by the Unit tests.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 15 Apr 2020 16:58:28 +0200 |
parents | 94f4a18a79cc |
children | 95083d2f6819 |
line wrap: on
line diff
--- a/Core/Images/PamReader.cpp Fri Apr 10 17:56:12 2020 +0200 +++ b/Core/Images/PamReader.cpp Wed Apr 15 16:58:28 2020 +0200 @@ -200,7 +200,30 @@ } size_t offset = content_.size() - pitch * height; - AssignWritable(format, width, height, pitch, &content_[offset]); + + { + intptr_t bufferAddr = reinterpret_cast<intptr_t>(&content_[offset]); + if((bufferAddr % 8) == 0) + LOG(TRACE) << "PamReader::ParseContent() image address = " << bufferAddr; + else + LOG(TRACE) << "PamReader::ParseContent() image address = " << bufferAddr << " (not a multiple of 8!)"; + } + + // if we want to enforce alignment, we need to use a freshly allocated + // buffer, since we have no alignment guarantees on the original one + if (enforceAligned_) + { + if (alignedImageBuffer_ != NULL) + free(alignedImageBuffer_); + alignedImageBuffer_ = malloc(pitch * height); + memcpy(alignedImageBuffer_, &content_[offset], pitch* height); + content_ = ""; + AssignWritable(format, width, height, pitch, alignedImageBuffer_); + } + else + { + AssignWritable(format, width, height, pitch, &content_[offset]); + } // Byte swapping if needed if (bytesPerChannel != 1 && @@ -231,7 +254,7 @@ at SAFE_HEAP_LOAD_i32_2_2 (wasm-function[251132]:39) at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088) - Web Assenmbly IS LITTLE ENDIAN! + Web Assembly IS LITTLE ENDIAN! Perhaps in htobe16 ? */