Mercurial > hg > orthanc-wsi
changeset 358:9e4dcbb578e3
handling of background color depending on photometric interpretation
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 20 Dec 2024 15:28:19 +0100 (5 months ago) |
parents | 3fc2ef580095 |
children | 6b3de7a6052d |
files | ViewerPlugin/OrthancPyramidFrameFetcher.cpp ViewerPlugin/OrthancPyramidFrameFetcher.h ViewerPlugin/Plugin.cpp |
diffstat | 3 files changed, 50 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/ViewerPlugin/OrthancPyramidFrameFetcher.cpp Fri Dec 20 15:11:22 2024 +0100 +++ b/ViewerPlugin/OrthancPyramidFrameFetcher.cpp Fri Dec 20 15:28:19 2024 +0100 @@ -68,9 +68,9 @@ tileHeight_(512), paddingX_(0), paddingY_(0), - backgroundRed_(0), - backgroundGreen_(0), - backgroundBlue_(0) + defaultBackgroundRed_(0), + defaultBackgroundGreen_(0), + defaultBackgroundBlue_(0) { if (orthanc == NULL) { @@ -105,13 +105,13 @@ } - void OrthancPyramidFrameFetcher::SetBackgroundColor(uint8_t red, - uint8_t green, - uint8_t blue) + void OrthancPyramidFrameFetcher::SetDefaultBackgroundColor(uint8_t red, + uint8_t green, + uint8_t blue) { - backgroundRed_ = red; - backgroundGreen_ = green; - backgroundBlue_ = blue; + defaultBackgroundRed_ = red; + defaultBackgroundGreen_ = green; + defaultBackgroundBlue_ = blue; } @@ -123,6 +123,33 @@ OrthancPlugins::DicomInstance dicom(buffer.GetData(), buffer.GetSize()); + uint8_t backgroundRed = defaultBackgroundRed_; + uint8_t backgroundGreen = defaultBackgroundGreen_; + uint8_t backgroundBlue = defaultBackgroundBlue_; + + Json::Value tags; + dicom.GetSimplifiedJson(tags); + + static const char* const PHOTOMETRIC_INTERPRETATION = "PhotometricInterpretation"; + + if (tags.isMember(PHOTOMETRIC_INTERPRETATION) && + tags[PHOTOMETRIC_INTERPRETATION].type() == Json::stringValue) + { + std::string p = tags[PHOTOMETRIC_INTERPRETATION].asString(); + if (p == "MONOCHROME1") + { + backgroundRed = 255; + backgroundGreen = 255; + backgroundBlue = 255; + } + else if (p == "MONOCHROME2") + { + backgroundRed = 0; + backgroundGreen = 0; + backgroundBlue = 0; + } + } + std::unique_ptr<OrthancPlugins::OrthancImage> frame(dicom.GetDecodedFrame(frameNumber)); Orthanc::PixelFormat format; @@ -172,7 +199,7 @@ if (paddedWidth != source.GetWidth() || paddedHeight != source.GetHeight()) { - Orthanc::ImageProcessing::Set(*rendered, backgroundRed_, backgroundGreen_, backgroundBlue_, 255 /* alpha */); + Orthanc::ImageProcessing::Set(*rendered, backgroundRed, backgroundGreen, backgroundBlue, 255 /* alpha */); } Orthanc::ImageAccessor region; @@ -196,6 +223,9 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); } - return new OnTheFlyPyramid(rendered.release(), tileWidth_, tileHeight_, smooth_); + std::unique_ptr<DecodedTiledPyramid> result(new OnTheFlyPyramid(rendered.release(), tileWidth_, tileHeight_, smooth_)); + result->SetBackgroundColor(backgroundRed, backgroundGreen, backgroundBlue); + + return result.release(); } }
--- a/ViewerPlugin/OrthancPyramidFrameFetcher.h Fri Dec 20 15:11:22 2024 +0100 +++ b/ViewerPlugin/OrthancPyramidFrameFetcher.h Fri Dec 20 15:28:19 2024 +0100 @@ -38,9 +38,9 @@ unsigned int tileHeight_; unsigned int paddingX_; unsigned int paddingY_; - uint8_t backgroundRed_; - uint8_t backgroundGreen_; - uint8_t backgroundBlue_; + uint8_t defaultBackgroundRed_; + uint8_t defaultBackgroundGreen_; + uint8_t defaultBackgroundBlue_; static void RenderGrayscale(Orthanc::ImageAccessor& target, const Orthanc::ImageAccessor& source); @@ -85,9 +85,9 @@ paddingY_ = paddingY; } - void SetBackgroundColor(uint8_t red, - uint8_t green, - uint8_t blue); + void SetDefaultBackgroundColor(uint8_t red, + uint8_t green, + uint8_t blue); DecodedTiledPyramid* Fetch(const std::string &instanceId, unsigned frameNumber) ORTHANC_OVERRIDE;
--- a/ViewerPlugin/Plugin.cpp Fri Dec 20 15:11:22 2024 +0100 +++ b/ViewerPlugin/Plugin.cpp Fri Dec 20 15:28:19 2024 +0100 @@ -159,7 +159,7 @@ { uint8_t red, green, blue; - accessor.GetPyramid().GetBackgroundColor(red, green, blue); // TODO + accessor.GetPyramid().GetBackgroundColor(red, green, blue); char tmp[16]; sprintf(tmp, "#%02x%02x%02x", red, green, blue); @@ -453,10 +453,10 @@ { std::unique_ptr<OrthancWSI::OrthancPyramidFrameFetcher> fetcher( - new OrthancWSI::OrthancPyramidFrameFetcher(new OrthancWSI::OrthancPluginConnection(), false /* TODO PARAMETER */)); + new OrthancWSI::OrthancPyramidFrameFetcher(new OrthancWSI::OrthancPluginConnection(), false /* smooth - TODO PARAMETER */)); fetcher->SetPaddingX(64); // TODO PARAMETER fetcher->SetPaddingY(64); // TODO PARAMETER - fetcher->SetBackgroundColor(255, 255, 255); // TODO PARAMETER + fetcher->SetDefaultBackgroundColor(255, 255, 255); // TODO PARAMETER OrthancWSI::DecodedPyramidCache::InitializeInstance(fetcher.release(), 10 /* TODO - PARAMETER */,