# HG changeset patch # User am@osimis.io # Date 1550223478 -3600 # Node ID 3ca924140de6c98fb91199db9a00adac294d6fe7 # Parent 53bb1f4b3844870f9ba99f5e416e34496bb89889 merged ImageProcessing::Invert implementations diff -r 53bb1f4b3844 -r 3ca924140de6 Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Thu Feb 14 16:22:52 2019 +0100 +++ b/Core/Images/ImageProcessing.cpp Fri Feb 15 10:37:58 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 } }