# HG changeset patch # User Sebastien Jodogne # Date 1745575932 -7200 # Node ID bdb28e2d2767240631077d0cb73ab17339f452fa # Parent e928629d7df009faa5dd70a28c71847ab2fe4a9e added ImageToolbox::Colorize() diff -r e928629d7df0 -r bdb28e2d2767 OrthancStone/Sources/Toolbox/ImageToolbox.cpp --- 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 #include #include @@ -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 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(result->GetRow(y)); + const uint8_t* p = reinterpret_cast(source.GetConstRow(y)); + for (unsigned int x = 0; x < source.GetWidth(); x++) + { + q[0] = (static_cast(*p) * static_cast(color.GetRed())) / static_cast(255); + q[1] = (static_cast(*p) * static_cast(color.GetGreen())) / static_cast(255); + q[2] = (static_cast(*p) * static_cast(color.GetBlue())) / static_cast(255); + q += 3; + p ++; + } + } + + return result.release(); + } } diff -r e928629d7df0 -r bdb28e2d2767 OrthancStone/Sources/Toolbox/ImageToolbox.h --- 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 @@ -80,5 +81,8 @@ { public: static bool IsDecodingSupported(Orthanc::DicomTransferSyntax& transferSyntax); - }; + + static Orthanc::ImageAccessor* Colorize(const Orthanc::ImageAccessor& source, + const OrthancStone::Color& color); +}; }