Mercurial > hg > orthanc
comparison Plugins/Samples/GdcmDecoder/GdcmImageDecoder.cpp @ 3915:7e33516965f8 transcoding
merging sample GDCM decoder and Orthanc Web viewer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 May 2020 15:13:16 +0200 |
parents | 6110a4995ace |
children |
comparison
equal
deleted
inserted
replaced
3914:e14b5a7a0f75 | 3915:7e33516965f8 |
---|---|
20 | 20 |
21 | 21 |
22 #include "GdcmImageDecoder.h" | 22 #include "GdcmImageDecoder.h" |
23 | 23 |
24 #include "../../../Core/Compatibility.h" | 24 #include "../../../Core/Compatibility.h" |
25 #include "OrthancImageWrapper.h" | |
26 | 25 |
27 #include <gdcmImageReader.h> | 26 #include <gdcmImageReader.h> |
28 #include <gdcmImageApplyLookupTable.h> | 27 #include <gdcmImageApplyLookupTable.h> |
29 #include <gdcmImageChangePlanarConfiguration.h> | 28 #include <gdcmImageChangePlanarConfiguration.h> |
30 #include <gdcmImageChangePhotometricInterpretation.h> | 29 #include <gdcmImageChangePhotometricInterpretation.h> |
296 } | 295 } |
297 } | 296 } |
298 } | 297 } |
299 | 298 |
300 | 299 |
301 static void FixPhotometricInterpretation(OrthancImageWrapper& image, | 300 static void FixPhotometricInterpretation(OrthancImage& image, |
302 gdcm::PhotometricInterpretation interpretation) | 301 gdcm::PhotometricInterpretation interpretation) |
303 { | 302 { |
304 switch (interpretation) | 303 switch (interpretation) |
305 { | 304 { |
306 case gdcm::PhotometricInterpretation::MONOCHROME1: | 305 case gdcm::PhotometricInterpretation::MONOCHROME1: |
315 uint32_t width = image.GetWidth(); | 314 uint32_t width = image.GetWidth(); |
316 uint32_t height = image.GetHeight(); | 315 uint32_t height = image.GetHeight(); |
317 uint32_t pitch = image.GetPitch(); | 316 uint32_t pitch = image.GetPitch(); |
318 uint8_t* buffer = reinterpret_cast<uint8_t*>(image.GetBuffer()); | 317 uint8_t* buffer = reinterpret_cast<uint8_t*>(image.GetBuffer()); |
319 | 318 |
320 if (image.GetFormat() != OrthancPluginPixelFormat_RGB24 || | 319 if (image.GetPixelFormat() != OrthancPluginPixelFormat_RGB24 || |
321 pitch < 3 * width) | 320 pitch < 3 * width) |
322 { | 321 { |
323 throw std::runtime_error("Internal error"); | 322 throw std::runtime_error("Internal error"); |
324 } | 323 } |
325 | 324 |
344 throw std::runtime_error("Unsupported output photometric interpretation"); | 343 throw std::runtime_error("Unsupported output photometric interpretation"); |
345 } | 344 } |
346 } | 345 } |
347 | 346 |
348 | 347 |
349 OrthancPluginImage* GdcmImageDecoder::Decode(OrthancPluginContext* context, | 348 OrthancPluginImage* GdcmImageDecoder::Decode(unsigned int frameIndex) const |
350 unsigned int frameIndex) const | |
351 { | 349 { |
352 unsigned int frames = GetFramesCount(); | 350 unsigned int frames = GetFramesCount(); |
353 unsigned int width = GetWidth(); | 351 unsigned int width = GetWidth(); |
354 unsigned int height = GetHeight(); | 352 unsigned int height = GetHeight(); |
355 OrthancPluginPixelFormat format = GetFormat(); | 353 OrthancPluginPixelFormat format = GetFormat(); |
359 { | 357 { |
360 throw std::runtime_error("Inexistent frame index"); | 358 throw std::runtime_error("Inexistent frame index"); |
361 } | 359 } |
362 | 360 |
363 std::string& decoded = pimpl_->decoded_; | 361 std::string& decoded = pimpl_->decoded_; |
364 OrthancImageWrapper target(context, format, width, height); | 362 OrthancImage target(format, width, height); |
365 | 363 |
366 if (width == 0 || | 364 if (width == 0 || |
367 height == 0) | 365 height == 0) |
368 { | 366 { |
369 return target.Release(); | 367 return target.Release(); |
389 else | 387 else |
390 { | 388 { |
391 size_t targetPitch = target.GetPitch(); | 389 size_t targetPitch = target.GetPitch(); |
392 size_t sourcePitch = width * bpp; | 390 size_t sourcePitch = width * bpp; |
393 | 391 |
394 const char* a = &decoded[sourcePitch * height * frameIndex]; | 392 const uint8_t* a = (reinterpret_cast<const uint8_t*>(decoded.c_str()) + |
395 char* b = target.GetBuffer(); | 393 sourcePitch * height * frameIndex); |
394 uint8_t* b = reinterpret_cast<uint8_t*>(target.GetBuffer()); | |
396 | 395 |
397 for (uint32_t y = 0; y < height; y++) | 396 for (uint32_t y = 0; y < height; y++) |
398 { | 397 { |
399 memcpy(b, a, sourcePitch); | 398 memcpy(b, a, sourcePitch); |
400 a += sourcePitch; | 399 a += sourcePitch; |