Mercurial > hg > orthanc-wsi
changeset 516:205c879ba2cc default
added BackgroundColor::FromHexadecimalString()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 21 Aug 2026 17:20:47 +0200 |
| parents | b26611429f83 |
| children | eefdef0a313e |
| files | Framework/BackgroundColor.cpp Framework/BackgroundColor.h |
| diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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,
