comparison 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
comparison
equal deleted inserted replaced
3831:83ea6939293d 3834:219de90c1f43
198 { 198 {
199 throw OrthancException(ErrorCode_BadFileFormat); 199 throw OrthancException(ErrorCode_BadFileFormat);
200 } 200 }
201 201
202 size_t offset = content_.size() - pitch * height; 202 size_t offset = content_.size() - pitch * height;
203 AssignWritable(format, width, height, pitch, &content_[offset]); 203
204 {
205 intptr_t bufferAddr = reinterpret_cast<intptr_t>(&content_[offset]);
206 if((bufferAddr % 8) == 0)
207 LOG(TRACE) << "PamReader::ParseContent() image address = " << bufferAddr;
208 else
209 LOG(TRACE) << "PamReader::ParseContent() image address = " << bufferAddr << " (not a multiple of 8!)";
210 }
211
212 // if we want to enforce alignment, we need to use a freshly allocated
213 // buffer, since we have no alignment guarantees on the original one
214 if (enforceAligned_)
215 {
216 if (alignedImageBuffer_ != NULL)
217 free(alignedImageBuffer_);
218 alignedImageBuffer_ = malloc(pitch * height);
219 memcpy(alignedImageBuffer_, &content_[offset], pitch* height);
220 content_ = "";
221 AssignWritable(format, width, height, pitch, alignedImageBuffer_);
222 }
223 else
224 {
225 AssignWritable(format, width, height, pitch, &content_[offset]);
226 }
204 227
205 // Byte swapping if needed 228 // Byte swapping if needed
206 if (bytesPerChannel != 1 && 229 if (bytesPerChannel != 1 &&
207 bytesPerChannel != 2) 230 bytesPerChannel != 2)
208 { 231 {
229 at abort 252 at abort
230 at alignfault 253 at alignfault
231 at SAFE_HEAP_LOAD_i32_2_2 (wasm-function[251132]:39) 254 at SAFE_HEAP_LOAD_i32_2_2 (wasm-function[251132]:39)
232 at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088) 255 at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088)
233 256
234 Web Assenmbly IS LITTLE ENDIAN! 257 Web Assembly IS LITTLE ENDIAN!
235 258
236 Perhaps in htobe16 ? 259 Perhaps in htobe16 ?
237 */ 260 */
238 uint8_t* srcdst = reinterpret_cast<uint8_t*>(pixel); 261 uint8_t* srcdst = reinterpret_cast<uint8_t*>(pixel);
239 uint8_t tmp = srcdst[0]; 262 uint8_t tmp = srcdst[0];