# HG changeset patch # User Benjamin Golinvaux # Date 1586948281 -7200 # Node ID 159708a38af4c80da741a0037f6d5102cca19417 # Parent 1b8e37770d784f2304a8057067ed7f3397b3542d Enforce alignment when using PamReader to retrieve REST images, only in __EMSCRIPTEN__ diff -r 1b8e37770d78 -r 159708a38af4 Framework/Oracle/GetOrthancImageCommand.cpp --- a/Framework/Oracle/GetOrthancImageCommand.cpp Wed Apr 15 12:57:36 2020 +0200 +++ b/Framework/Oracle/GetOrthancImageCommand.cpp Wed Apr 15 12:58:01 2020 +0200 @@ -125,7 +125,16 @@ case Orthanc::MimeType_Pam: { +#ifdef __EMSCRIPTEN__ + // "true" means we ask the PamReader to make an extra copy so that + // the resulting Orthanc::ImageAccessor is aligned (as malloc is). + // Indeed, even though alignment is not required in Web Assembly, + // Emscripten seems to check it and bail out if addresses are "odd" + image.reset(new Orthanc::PamReader(true)); +#else + // potentially unaligned, with is faster and consumes less heap memory image.reset(new Orthanc::PamReader); +#endif dynamic_cast(*image).ReadFromMemory(answer); break; } @@ -157,6 +166,23 @@ } } + //{ + // // DEBUG DISPLAY IMAGE PROPERTIES BGO 2020-04-11 + // const Orthanc::ImageAccessor& source = *image; + // const void* sourceBuffer = source.GetConstBuffer(); + // intptr_t sourceBufferInt = reinterpret_cast(sourceBuffer); + // int sourceWidth = source.GetWidth(); + // int sourceHeight = source.GetHeight(); + // int sourcePitch = source.GetPitch(); + + // // TODO: turn error into trace below + // LOG(ERROR) << "GetOrthancImageCommand::ProcessHttpAnswer | source:" + // << " W = " << sourceWidth << " H = " << sourceHeight + // << " P = " << sourcePitch << " B = " << sourceBufferInt + // << " B % 4 == " << sourceBufferInt % 4; + //} + + SuccessMessage message(*this, *image, contentType); emitter.EmitMessage(receiver, message); }