Mercurial > hg > orthanc-webviewer
comparison Plugin/DecodedImageAdapter.cpp @ 173:4f0f4f64cff3
Support of rendering RGB48 lookup tables (palette)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Oct 2017 13:26:15 +0200 |
parents | 330ecfd96aec |
children | 81f16c5667ba |
comparison
equal
deleted
inserted
replaced
172:330ecfd96aec | 173:4f0f4f64cff3 |
---|---|
155 Json::Value json; | 155 Json::Value json; |
156 if (GetCornerstoneMetadata(json, tags, *image)) | 156 if (GetCornerstoneMetadata(json, tags, *image)) |
157 { | 157 { |
158 if (type == CompressionType_Deflate) | 158 if (type == CompressionType_Deflate) |
159 { | 159 { |
160 ok = EncodeUsingDeflate(json, *image, 9); | 160 ok = EncodeUsingDeflate(json, *image); |
161 } | 161 } |
162 else if (type == CompressionType_Jpeg) | 162 else if (type == CompressionType_Jpeg) |
163 { | 163 { |
164 ok = EncodeUsingJpeg(json, *image, level); | 164 ok = EncodeUsingJpeg(json, *image, level); |
165 } | 165 } |
224 | 224 |
225 break; | 225 break; |
226 } | 226 } |
227 | 227 |
228 case PixelFormat_RGB24: | 228 case PixelFormat_RGB24: |
229 case PixelFormat_RGB48: | |
229 result["minPixelValue"] = 0; | 230 result["minPixelValue"] = 0; |
230 result["maxPixelValue"] = 255; | 231 result["maxPixelValue"] = 255; |
231 result["color"] = true; | 232 result["color"] = true; |
232 windowCenter = 127.5f; | 233 windowCenter = 127.5f; |
233 windowWidth = 256.0f; | 234 windowWidth = 256.0f; |
279 | 280 |
280 return true; | 281 return true; |
281 } | 282 } |
282 | 283 |
283 | 284 |
285 static void ConvertRGB48ToRGB24(Orthanc::ImageAccessor& target, | |
286 const Orthanc::ImageAccessor& source) | |
287 { | |
288 if (source.GetWidth() != target.GetWidth() || | |
289 source.GetHeight() != target.GetHeight()) | |
290 { | |
291 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); | |
292 } | |
293 | |
294 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
295 { | |
296 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); | |
297 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
298 | |
299 for (unsigned int x = 0; x < source.GetWidth(); x++) | |
300 { | |
301 q[0] = p[0] >> 8; | |
302 q[1] = p[1] >> 8; | |
303 q[2] = p[2] >> 8; | |
304 p += 3; | |
305 q += 3; | |
306 } | |
307 } | |
308 } | |
309 | |
284 | 310 |
285 bool DecodedImageAdapter::EncodeUsingDeflate(Json::Value& result, | 311 bool DecodedImageAdapter::EncodeUsingDeflate(Json::Value& result, |
286 OrthancImageWrapper& image, | 312 OrthancImageWrapper& image) |
287 uint8_t compressionLevel /* between 0 and 9 */) | |
288 { | 313 { |
289 Orthanc::ImageAccessor accessor; | 314 Orthanc::ImageAccessor accessor; |
290 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetFormat()), image.GetWidth(), | 315 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetFormat()), image.GetWidth(), |
291 image.GetHeight(), image.GetPitch(), image.GetBuffer()); | 316 image.GetHeight(), image.GetPitch(), image.GetBuffer()); |
292 | 317 |
296 | 321 |
297 switch (accessor.GetFormat()) | 322 switch (accessor.GetFormat()) |
298 { | 323 { |
299 case Orthanc::PixelFormat_RGB24: | 324 case Orthanc::PixelFormat_RGB24: |
300 converted = accessor; | 325 converted = accessor; |
326 break; | |
327 | |
328 case Orthanc::PixelFormat_RGB48: | |
329 buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_RGB24, | |
330 accessor.GetWidth(), | |
331 accessor.GetHeight(), false)); | |
332 converted = buffer->GetAccessor(); | |
333 ConvertRGB48ToRGB24(converted, accessor); | |
301 break; | 334 break; |
302 | 335 |
303 case Orthanc::PixelFormat_Grayscale8: | 336 case Orthanc::PixelFormat_Grayscale8: |
304 case Orthanc::PixelFormat_Grayscale16: | 337 case Orthanc::PixelFormat_Grayscale16: |
305 buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_Grayscale16, | 338 buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_Grayscale16, |
400 accessor.GetFormat() == Orthanc::PixelFormat_RGB24) | 433 accessor.GetFormat() == Orthanc::PixelFormat_RGB24) |
401 { | 434 { |
402 result["Orthanc"]["Stretched"] = false; | 435 result["Orthanc"]["Stretched"] = false; |
403 converted = accessor; | 436 converted = accessor; |
404 } | 437 } |
438 else if (accessor.GetFormat() == Orthanc::PixelFormat_RGB48) | |
439 { | |
440 result["Orthanc"]["Stretched"] = false; | |
441 | |
442 buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_RGB24, | |
443 accessor.GetWidth(), | |
444 accessor.GetHeight(), false)); | |
445 converted = buffer->GetAccessor(); | |
446 ConvertRGB48ToRGB24(converted, accessor); | |
447 } | |
405 else if (accessor.GetFormat() == Orthanc::PixelFormat_Grayscale16 || | 448 else if (accessor.GetFormat() == Orthanc::PixelFormat_Grayscale16 || |
406 accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16) | 449 accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16) |
407 { | 450 { |
408 result["Orthanc"]["Stretched"] = true; | 451 result["Orthanc"]["Stretched"] = true; |
409 | 452 |