Mercurial > hg > orthanc-stone
comparison Framework/Oracle/GetOrthancImageCommand.cpp @ 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 | 257f2c9a02ac |
children | 30deba7bc8e2 |
comparison
equal
deleted
inserted
replaced
1351:1b8e37770d78 | 1352:159708a38af4 |
---|---|
123 break; | 123 break; |
124 } | 124 } |
125 | 125 |
126 case Orthanc::MimeType_Pam: | 126 case Orthanc::MimeType_Pam: |
127 { | 127 { |
128 #ifdef __EMSCRIPTEN__ | |
129 // "true" means we ask the PamReader to make an extra copy so that | |
130 // the resulting Orthanc::ImageAccessor is aligned (as malloc is). | |
131 // Indeed, even though alignment is not required in Web Assembly, | |
132 // Emscripten seems to check it and bail out if addresses are "odd" | |
133 image.reset(new Orthanc::PamReader(true)); | |
134 #else | |
135 // potentially unaligned, with is faster and consumes less heap memory | |
128 image.reset(new Orthanc::PamReader); | 136 image.reset(new Orthanc::PamReader); |
137 #endif | |
129 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(answer); | 138 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(answer); |
130 break; | 139 break; |
131 } | 140 } |
132 | 141 |
133 case Orthanc::MimeType_Jpeg: | 142 case Orthanc::MimeType_Jpeg: |
155 { | 164 { |
156 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 165 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
157 } | 166 } |
158 } | 167 } |
159 | 168 |
169 //{ | |
170 // // DEBUG DISPLAY IMAGE PROPERTIES BGO 2020-04-11 | |
171 // const Orthanc::ImageAccessor& source = *image; | |
172 // const void* sourceBuffer = source.GetConstBuffer(); | |
173 // intptr_t sourceBufferInt = reinterpret_cast<intptr_t>(sourceBuffer); | |
174 // int sourceWidth = source.GetWidth(); | |
175 // int sourceHeight = source.GetHeight(); | |
176 // int sourcePitch = source.GetPitch(); | |
177 | |
178 // // TODO: turn error into trace below | |
179 // LOG(ERROR) << "GetOrthancImageCommand::ProcessHttpAnswer | source:" | |
180 // << " W = " << sourceWidth << " H = " << sourceHeight | |
181 // << " P = " << sourcePitch << " B = " << sourceBufferInt | |
182 // << " B % 4 == " << sourceBufferInt % 4; | |
183 //} | |
184 | |
185 | |
160 SuccessMessage message(*this, *image, contentType); | 186 SuccessMessage message(*this, *image, contentType); |
161 emitter.EmitMessage(receiver, message); | 187 emitter.EmitMessage(receiver, message); |
162 } | 188 } |
163 } | 189 } |