Mercurial > hg > orthanc
changeset 3546:460ba650be6f
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 21 Oct 2019 10:14:08 +0200 |
parents | 551945086617 (diff) bf6a61b918ef (current diff) |
children | dabe17e23e23 |
files | |
diffstat | 2 files changed, 82 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 <typename PixelType> + 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<PixelType*>(image.GetRow(y)); + + for (unsigned int x = 0; x < width; x++, p++) + { + *p = *p >> shift; + } + } + } + + template <typename PixelType> + 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<PixelType*>(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<uint8_t>(image, shift); + break; + } + + case PixelFormat_Grayscale16: + { + ShiftRightInternal<uint16_t>(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<uint8_t>(image, shift); + break; + } + + case PixelFormat_Grayscale16: + { + ShiftLeftInternal<uint16_t>(image, shift); + break; + } + default: + throw OrthancException(ErrorCode_NotImplemented); + } + } void ImageProcessing::GetMinMaxIntegerValue(int64_t& minValue, int64_t& maxValue,
--- 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);