# HG changeset patch # User Alain Mazy # Date 1571758243 -7200 # Node ID dabe17e23e231e597a06c0b778bf40c681e67ab9 # Parent 460ba650be6f62b872ff883bb62c8953671a33a8 Copy RGBA to BGRA & Set with alpha diff -r 460ba650be6f -r dabe17e23e23 Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Mon Oct 21 10:14:08 2019 +0200 +++ b/Core/Images/ImageProcessing.cpp Tue Oct 22 17:30:43 2019 +0200 @@ -803,6 +803,29 @@ return; } + if ((target.GetFormat() == PixelFormat_BGRA32 && + source.GetFormat() == PixelFormat_RGBA32) + || (target.GetFormat() == PixelFormat_RGBA32 && + source.GetFormat() == PixelFormat_BGRA32)) + { + for (unsigned int y = 0; y < height; y++) + { + const uint8_t* p = reinterpret_cast(source.GetConstRow(y)); + uint8_t* q = reinterpret_cast(target.GetRow(y)); + for (unsigned int x = 0; x < width; x++) + { + q[0] = p[2]; + q[1] = p[1]; + q[2] = p[0]; + q[3] = p[3]; + p += 4; + q += 4; + } + } + + return; + } + if (target.GetFormat() == PixelFormat_RGB24 && source.GetFormat() == PixelFormat_RGB48) { @@ -944,6 +967,63 @@ } } + void ImageProcessing::Set(ImageAccessor& image, + uint8_t red, + uint8_t green, + uint8_t blue, + ImageAccessor& alpha) + { + uint8_t p[4]; + + if (alpha.GetWidth() != image.GetWidth() || alpha.GetHeight() != image.GetHeight()) + { + throw OrthancException(ErrorCode_IncompatibleImageSize); + } + + if (alpha.GetFormat() != PixelFormat_Grayscale8) + { + throw OrthancException(ErrorCode_NotImplemented); + } + + switch (image.GetFormat()) + { + case PixelFormat_RGBA32: + p[0] = red; + p[1] = green; + p[2] = blue; + break; + + case PixelFormat_BGRA32: + p[0] = blue; + p[1] = green; + p[2] = red; + break; + + default: + throw OrthancException(ErrorCode_NotImplemented); + } + + const unsigned int width = image.GetWidth(); + const unsigned int height = image.GetHeight(); + + for (unsigned int y = 0; y < height; y++) + { + uint8_t* q = reinterpret_cast(image.GetRow(y)); + uint8_t* a = reinterpret_cast(alpha.GetRow(y)); + + for (unsigned int x = 0; x < width; x++) + { + for (unsigned int i = 0; i < 3; i++) + { + q[i] = p[i]; + } + q[3] = *a; + q += 4; + ++a; + } + } + } + void ImageProcessing::ShiftRight(ImageAccessor& image, unsigned int shift) diff -r 460ba650be6f -r dabe17e23e23 Core/Images/ImageProcessing.h --- a/Core/Images/ImageProcessing.h Mon Oct 21 10:14:08 2019 +0200 +++ b/Core/Images/ImageProcessing.h Tue Oct 22 17:30:43 2019 +0200 @@ -89,6 +89,12 @@ uint8_t blue, uint8_t alpha); + void Set(ImageAccessor& image, + uint8_t red, + uint8_t green, + uint8_t blue, + ImageAccessor& alpha); + void ShiftRight(ImageAccessor& target, unsigned int shift);