Mercurial > hg > orthanc-stone
changeset 2224:bdb28e2d2767
added ImageToolbox::Colorize()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Apr 2025 12:12:12 +0200 |
parents | e928629d7df0 |
children | 639b4960bb51 |
files | OrthancStone/Sources/Toolbox/ImageToolbox.cpp OrthancStone/Sources/Toolbox/ImageToolbox.h |
diffstat | 2 files changed, 34 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/ImageToolbox.cpp Wed Apr 23 17:52:01 2025 +0200 +++ b/OrthancStone/Sources/Toolbox/ImageToolbox.cpp Fri Apr 25 12:12:12 2025 +0200 @@ -25,6 +25,7 @@ #include "../StoneException.h" +#include <Images/Image.h> #include <Images/ImageProcessing.h> #include <Images/PixelTraits.h> @@ -332,4 +333,32 @@ return false; } } + + + Orthanc::ImageAccessor* ImageToolbox::Colorize(const Orthanc::ImageAccessor& source, + const OrthancStone::Color& color) + { + if (source.GetFormat() != Orthanc::PixelFormat_Grayscale8) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); + } + + std::unique_ptr<Orthanc::ImageAccessor> result(new Orthanc::Image(Orthanc::PixelFormat_RGB24, source.GetWidth(), source.GetHeight(), false)); + + for (unsigned int y = 0; y < source.GetHeight(); y++) + { + uint8_t* q = reinterpret_cast<uint8_t *>(result->GetRow(y)); + const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); + for (unsigned int x = 0; x < source.GetWidth(); x++) + { + q[0] = (static_cast<uint16_t>(*p) * static_cast<uint16_t>(color.GetRed())) / static_cast<uint16_t>(255); + q[1] = (static_cast<uint16_t>(*p) * static_cast<uint16_t>(color.GetGreen())) / static_cast<uint16_t>(255); + q[2] = (static_cast<uint16_t>(*p) * static_cast<uint16_t>(color.GetBlue())) / static_cast<uint16_t>(255); + q += 3; + p ++; + } + } + + return result.release(); + } }
--- a/OrthancStone/Sources/Toolbox/ImageToolbox.h Wed Apr 23 17:52:01 2025 +0200 +++ b/OrthancStone/Sources/Toolbox/ImageToolbox.h Fri Apr 25 12:12:12 2025 +0200 @@ -25,6 +25,7 @@ #include "../StoneEnumerations.h" #include "LinearAlgebra.h" +#include "../Scene2D/Color.h" #include <Images/ImageAccessor.h> @@ -80,5 +81,8 @@ { public: static bool IsDecodingSupported(Orthanc::DicomTransferSyntax& transferSyntax); - }; + + static Orthanc::ImageAccessor* Colorize(const Orthanc::ImageAccessor& source, + const OrthancStone::Color& color); +}; }