# HG changeset patch # User Sebastien Jodogne # Date 1745578366 -7200 # Node ID 639b4960bb5175282fdeecd64db1956999402ade # Parent a943ce01ce0abbbe18a725bfad71f1c07967c7b0# Parent bdb28e2d2767240631077d0cb73ab17339f452fa merge diff -r a943ce01ce0a -r 639b4960bb51 OrthancStone/Sources/Toolbox/ImageToolbox.cpp --- a/OrthancStone/Sources/Toolbox/ImageToolbox.cpp Thu Apr 24 18:11:55 2025 +0200 +++ b/OrthancStone/Sources/Toolbox/ImageToolbox.cpp Fri Apr 25 12:52:46 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 a943ce01ce0a -r 639b4960bb51 OrthancStone/Sources/Toolbox/ImageToolbox.h --- a/OrthancStone/Sources/Toolbox/ImageToolbox.h Thu Apr 24 18:11:55 2025 +0200 +++ b/OrthancStone/Sources/Toolbox/ImageToolbox.h Fri Apr 25 12:52:46 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); +}; }