# HG changeset patch # User Alain Mazy # Date 1571645648 -7200 # Node ID 460ba650be6f62b872ff883bb62c8953671a33a8 # Parent 5519450866171b1e386cf04f7bafe8487a9b7655# Parent bf6a61b918eff80b56c84aed28752b385c48dc42 merge diff -r bf6a61b918ef -r 460ba650be6f Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Thu Oct 17 21:42:01 2019 +0200 +++ b/Core/Images/ImageProcessing.cpp Mon Oct 21 10:14:08 2019 +0200 @@ -413,6 +413,41 @@ } } + template + static void ShiftRightInternal(ImageAccessor& image, + unsigned int shift) + { + const unsigned int height = image.GetHeight(); + const unsigned int width = image.GetWidth(); + + for (unsigned int y = 0; y < height; y++) + { + PixelType* p = reinterpret_cast(image.GetRow(y)); + + for (unsigned int x = 0; x < width; x++, p++) + { + *p = *p >> shift; + } + } + } + + template + static void ShiftLeftInternal(ImageAccessor& image, + unsigned int shift) + { + const unsigned int height = image.GetHeight(); + const unsigned int width = image.GetWidth(); + + for (unsigned int y = 0; y < height; y++) + { + PixelType* p = reinterpret_cast(image.GetRow(y)); + + for (unsigned int x = 0; x < width; x++, p++) + { + *p = *p << shift; + } + } + } void ImageProcessing::Copy(ImageAccessor& target, const ImageAccessor& source) @@ -921,9 +956,52 @@ return; } - throw OrthancException(ErrorCode_NotImplemented); + switch (image.GetFormat()) + { + case PixelFormat_Grayscale8: + { + ShiftRightInternal(image, shift); + break; + } + + case PixelFormat_Grayscale16: + { + ShiftRightInternal(image, shift); + break; + } + default: + throw OrthancException(ErrorCode_NotImplemented); + } } + void ImageProcessing::ShiftLeft(ImageAccessor& image, + unsigned int shift) + { + if (image.GetWidth() == 0 || + image.GetHeight() == 0 || + shift == 0) + { + // Nothing to do + return; + } + + switch (image.GetFormat()) + { + case PixelFormat_Grayscale8: + { + ShiftLeftInternal(image, shift); + break; + } + + case PixelFormat_Grayscale16: + { + ShiftLeftInternal(image, shift); + break; + } + default: + throw OrthancException(ErrorCode_NotImplemented); + } + } void ImageProcessing::GetMinMaxIntegerValue(int64_t& minValue, int64_t& maxValue, diff -r bf6a61b918ef -r 460ba650be6f Core/Images/ImageProcessing.h --- a/Core/Images/ImageProcessing.h Thu Oct 17 21:42:01 2019 +0200 +++ b/Core/Images/ImageProcessing.h Mon Oct 21 10:14:08 2019 +0200 @@ -92,6 +92,9 @@ void ShiftRight(ImageAccessor& target, unsigned int shift); + void ShiftLeft(ImageAccessor& target, + unsigned int shift); + void GetMinMaxIntegerValue(int64_t& minValue, int64_t& maxValue, const ImageAccessor& image);