changeset 1352:159708a38af4 broker

Enforce alignment when using PamReader to retrieve REST images, only in __EMSCRIPTEN__
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 15 Apr 2020 12:58:01 +0200
parents 1b8e37770d78
children af65bce18951
files Framework/Oracle/GetOrthancImageCommand.cpp
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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<Orthanc::PamReader&>(*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<intptr_t>(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);
   }