# HG changeset patch # User Sebastien Jodogne # Date 1787325647 -7200 # Node ID 205c879ba2cc0928200613bb37c0b2b41626250e # Parent b26611429f83c499e01160d65ce17874ffc20b6c added BackgroundColor::FromHexadecimalString() diff -r b26611429f83 -r 205c879ba2cc Framework/BackgroundColor.cpp --- a/Framework/BackgroundColor.cpp Fri Aug 21 17:13:23 2026 +0200 +++ b/Framework/BackgroundColor.cpp Fri Aug 21 17:20:47 2026 +0200 @@ -125,6 +125,44 @@ } + static unsigned int GetHexDigit(char c) + { + if (c >= '0' && c <= '9') + { + return c - '0'; + } + else if (c >= 'a' && c <= 'f') + { + return c - 'a' + 10; + } + else if (c >= 'A' && c <= 'F') + { + return c - 'A' + 10; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + + + BackgroundColor BackgroundColor::FromHexadecimalString(const std::string& color) + { + if (color.size() != 7 || + color[0] != '#') + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); + } + else + { + unsigned int r = GetHexDigit(color[1]) * 16 + GetHexDigit(color[2]); + unsigned int g = GetHexDigit(color[3]) * 16 + GetHexDigit(color[4]); + unsigned int b = GetHexDigit(color[5]) * 16 + GetHexDigit(color[6]); + return BackgroundColor(r, g, b); + } + } + + void BackgroundColor::Fill(Orthanc::ImageAccessor& region, uint8_t defaultRed, uint8_t defaultGreen, diff -r b26611429f83 -r 205c879ba2cc Framework/BackgroundColor.h --- a/Framework/BackgroundColor.h Fri Aug 21 17:13:23 2026 +0200 +++ b/Framework/BackgroundColor.h Fri Aug 21 17:20:47 2026 +0200 @@ -78,6 +78,8 @@ uint8_t defaultGreen, uint8_t defaultBlue) const; + static BackgroundColor FromHexadecimalString(const std::string& color); + void Fill(Orthanc::ImageAccessor& region, uint8_t defaultRed, uint8_t defaultGreen,