Mercurial > hg > orthanc-wsi
changeset 229:d9bd12e3747a
use Orthanc::ImageProcessing::Halve() instead of ImageToolbox::Halve()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 13 Jan 2021 17:40:56 +0100 |
parents | c6e7dda9ac14 |
children | fad22529c309 |
files | Framework/Algorithms/ReconstructPyramidCommand.cpp Framework/ImageToolbox.cpp Framework/ImageToolbox.h |
diffstat | 3 files changed, 7 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Algorithms/ReconstructPyramidCommand.cpp Wed Jan 13 17:21:31 2021 +0100 +++ b/Framework/Algorithms/ReconstructPyramidCommand.cpp Wed Jan 13 17:40:56 2021 +0100 @@ -28,6 +28,7 @@ #include <Logging.h> #include <OrthancException.h> #include <Images/Image.h> +#include <Images/ImageProcessing.h> #include <cassert> @@ -111,7 +112,12 @@ } } - result.reset(ImageToolbox::Halve(*mosaic, source_.GetParameters().IsSmoothEnabled())); + if (source_.GetParameters().IsSmoothEnabled()) + { + Orthanc::ImageProcessing::SmoothGaussian5x5(*mosaic, false /* don't use accurate rounding */); + } + + result.reset(Orthanc::ImageProcessing::Halve(*mosaic, false /* don't force minimal pitch */)); target_.EncodeTile(*result, level + shiftTargetLevel_, x, y); }
--- a/Framework/ImageToolbox.cpp Wed Jan 13 17:21:31 2021 +0100 +++ b/Framework/ImageToolbox.cpp Wed Jan 13 17:40:56 2021 +0100 @@ -221,127 +221,6 @@ } - static uint8_t GetPixelValue(const Orthanc::ImageAccessor& source, - unsigned int x, - unsigned int y, - unsigned int channel, - int offsetX, - int offsetY, - unsigned int bytesPerPixel) - { - assert(bytesPerPixel == source.GetBytesPerPixel()); - assert(channel < bytesPerPixel); - assert(source.GetFormat() == Orthanc::PixelFormat_Grayscale8 || - source.GetFormat() == Orthanc::PixelFormat_RGB24 || - source.GetFormat() == Orthanc::PixelFormat_RGBA32); // 16bpp is unsupported - - if (static_cast<int>(x) + offsetX < 0) - { - x = 0; - } - else - { - x += offsetX; - if (x >= source.GetWidth()) - { - x = source.GetWidth() - 1; - } - } - - if (static_cast<int>(y) + offsetY < 0) - { - y = 0; - } - else - { - y += offsetY; - if (y >= source.GetHeight()) - { - y = source.GetHeight() - 1; - } - } - - return *(reinterpret_cast<const uint8_t*>(source.GetConstBuffer()) + - y * source.GetPitch() + x * bytesPerPixel + channel); - } - - - static uint8_t SmoothPixelValue(const Orthanc::ImageAccessor& source, - unsigned int x, - unsigned int y, - unsigned int channel, - unsigned int bytesPerPixel) - { - static const uint32_t kernel[5] = { 1, 4, 6, 4, 1 }; - static const uint32_t normalization = 2 * (1 + 4 + 6 + 4 + 1); - - uint32_t accumulator = 0; - - // Horizontal smoothing - for (int offset = -2; offset <= 2; offset++) - { - accumulator += kernel[offset + 2] * GetPixelValue(source, x, y, channel, offset, 0, bytesPerPixel); - } - - // Vertical smoothing - for (int offset = -2; offset <= 2; offset++) - { - accumulator += kernel[offset + 2] * GetPixelValue(source, x, y, channel, 0, offset, bytesPerPixel); - } - - return static_cast<uint8_t>(accumulator / normalization); - } - - - Orthanc::ImageAccessor* Halve(const Orthanc::ImageAccessor& source, - bool smooth) - { - if (source.GetWidth() % 2 == 1 || - source.GetHeight() % 2 == 1) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); - } - - if (source.GetFormat() != Orthanc::PixelFormat_Grayscale8 && - source.GetFormat() != Orthanc::PixelFormat_RGB24 && - source.GetFormat() != Orthanc::PixelFormat_RGBA32) // 16bpp is not supported (*) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); - } - - const unsigned int bytesPerPixel = source.GetBytesPerPixel(); // Corresponds to the number of channels tx (*) - - std::unique_ptr<Orthanc::ImageAccessor> target(Allocate(source.GetFormat(), - source.GetWidth() / 2, - source.GetHeight() / 2)); - - const unsigned int width = target->GetWidth(); - const unsigned int height = target->GetHeight(); - - for (unsigned int y = 0; y < height; y++) - { - uint8_t* q = reinterpret_cast<uint8_t*>(target->GetRow(y)); - - for (unsigned int x = 0; x < width; x++, q += bytesPerPixel) - { - for (unsigned int c = 0; c < bytesPerPixel; c++) - { - if (smooth) - { - q[c] = SmoothPixelValue(source, 2 * x, 2 * y, c, bytesPerPixel); - } - else - { - q[c] = GetPixelValue(source, 2 * x, 2 * y, c, 0, 0, bytesPerPixel); - } - } - } - } - - return target.release(); - } - - Orthanc::ImageAccessor* Render(ITiledPyramid& pyramid, unsigned int level) {
--- a/Framework/ImageToolbox.h Wed Jan 13 17:21:31 2021 +0100 +++ b/Framework/ImageToolbox.h Wed Jan 13 17:40:56 2021 +0100 @@ -64,9 +64,6 @@ ImageCompression targetCompression, uint8_t quality); // Only for JPEG compression - Orthanc::ImageAccessor* Halve(const Orthanc::ImageAccessor& source, - bool smooth); - Orthanc::ImageAccessor* Render(ITiledPyramid& pyramid, unsigned int level);