# HG changeset patch # User Sebastien Jodogne # Date 1474298561 -7200 # Node ID 7a969f235adf9b6a80cabf1177c0fd08b1f1a910 # Parent b9428d5f7eafe409c36302e4255753f5a4fe2dfc PixelFormat_BGRA32 diff -r b9428d5f7eaf -r 7a969f235adf Core/Enumerations.cpp --- a/Core/Enumerations.cpp Fri Sep 16 12:22:30 2016 +0200 +++ b/Core/Enumerations.cpp Mon Sep 19 17:22:41 2016 +0200 @@ -733,6 +733,9 @@ case PixelFormat_RGBA32: return "RGBA32"; + case PixelFormat_BGRA32: + return "BGRA32"; + case PixelFormat_Grayscale8: return "Grayscale (unsigned 8bpp)"; @@ -1061,6 +1064,7 @@ return 3; case PixelFormat_RGBA32: + case PixelFormat_BGRA32: return 4; case PixelFormat_Float32: diff -r b9428d5f7eaf -r 7a969f235adf Core/Enumerations.h --- a/Core/Enumerations.h Fri Sep 16 12:22:30 2016 +0200 +++ b/Core/Enumerations.h Mon Sep 19 17:22:41 2016 +0200 @@ -195,7 +195,10 @@ * {summary}{Graylevel, floating-point image.} * {description}{The image is graylevel. Each pixel is floating-point and stored in 4 bytes.} **/ - PixelFormat_Float32 = 6 + PixelFormat_Float32 = 6, + + // This is the memory layout for Cairo + PixelFormat_BGRA32 = 7 }; diff -r b9428d5f7eaf -r 7a969f235adf Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Fri Sep 16 12:22:30 2016 +0200 +++ b/Core/Images/ImageProcessing.cpp Mon Sep 19 17:22:41 2016 +0200 @@ -552,6 +552,61 @@ } + void ImageProcessing::Set(ImageAccessor& image, + uint8_t red, + uint8_t green, + uint8_t blue, + uint8_t alpha) + { + uint8_t p[4]; + unsigned int size; + + switch (image.GetFormat()) + { + case PixelFormat_RGBA32: + p[0] = red; + p[1] = green; + p[2] = blue; + p[3] = alpha; + size = 4; + break; + + case PixelFormat_BGRA32: + p[0] = blue; + p[1] = green; + p[2] = red; + p[3] = alpha; + size = 4; + break; + + case PixelFormat_RGB24: + p[0] = red; + p[1] = green; + p[2] = blue; + size = 3; + break; + + default: + throw OrthancException(ErrorCode_NotImplemented); + } + + for (unsigned int y = 0; y < image.GetHeight(); y++) + { + uint8_t* q = reinterpret_cast(image.GetRow(y)); + + for (unsigned int x = 0; x < image.GetWidth(); x++) + { + for (unsigned int i = 0; i < size; i++) + { + q[i] = p[i]; + } + + q += size; + } + } + } + + void ImageProcessing::ShiftRight(ImageAccessor& image, unsigned int shift) { diff -r b9428d5f7eaf -r 7a969f235adf Core/Images/ImageProcessing.h --- a/Core/Images/ImageProcessing.h Fri Sep 16 12:22:30 2016 +0200 +++ b/Core/Images/ImageProcessing.h Mon Sep 19 17:22:41 2016 +0200 @@ -50,6 +50,12 @@ static void Set(ImageAccessor& image, int64_t value); + static void Set(ImageAccessor& image, + uint8_t red, + uint8_t green, + uint8_t blue, + uint8_t alpha); + static void ShiftRight(ImageAccessor& target, unsigned int shift);