# HG changeset patch # User am@osimis.io # Date 1550223497 -3600 # Node ID 6055bea6a6dc8d6f16391aaa1246c87d19d99654 # Parent 3ca924140de6c98fb91199db9a00adac294d6fe7# Parent 47fbb0467a6299bc10ba12e83450192548a878f9 merge diff -r 47fbb0467a62 -r 6055bea6a6dc Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Fri Feb 15 10:26:32 2019 +0100 +++ b/Core/Images/ImageProcessing.cpp Fri Feb 15 10:38:17 2019 +0100 @@ -1086,7 +1086,7 @@ { case PixelFormat_Grayscale16: { - uint16_t maxValueUint16 = (uint16_t)maxValue; + uint16_t maxValueUint16 = (uint16_t)(std::min(maxValue, static_cast(std::numeric_limits::max()))); for (unsigned int y = 0; y < height; y++) { @@ -1100,6 +1100,22 @@ return; } + case PixelFormat_Grayscale8: + { + uint8_t maxValueUint8 = (uint8_t)(std::min(maxValue, static_cast(std::numeric_limits::max()))); + + for (unsigned int y = 0; y < height; y++) + { + uint8_t* p = reinterpret_cast(image.GetRow(y)); + + for (unsigned int x = 0; x < width; x++, p++) + { + *p = maxValueUint8 - (*p); + } + } + + return; + } default: throw OrthancException(ErrorCode_NotImplemented); @@ -1109,28 +1125,12 @@ void ImageProcessing::Invert(ImageAccessor& image) { - const unsigned int width = image.GetWidth(); - const unsigned int height = image.GetHeight(); - switch (image.GetFormat()) { case PixelFormat_Grayscale8: - { - for (unsigned int y = 0; y < height; y++) - { - uint8_t* p = reinterpret_cast(image.GetRow(y)); - - for (unsigned int x = 0; x < width; x++, p++) - { - *p = 255 - (*p); - } - } - - return; - } - + return Invert(image, 255); default: - throw OrthancException(ErrorCode_NotImplemented); + throw OrthancException(ErrorCode_NotImplemented); // you should use the Invert(image, maxValue) overload } }