# HG changeset patch # User Sebastien Jodogne # Date 1610556056 -3600 # Node ID d9bd12e3747a0a1f3d0e49044fe4de66ad57a9bf # Parent c6e7dda9ac141ce1e43494cc764a40b65e079f14 use Orthanc::ImageProcessing::Halve() instead of ImageToolbox::Halve() diff -r c6e7dda9ac14 -r d9bd12e3747a Framework/Algorithms/ReconstructPyramidCommand.cpp --- 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 #include #include +#include #include @@ -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); } diff -r c6e7dda9ac14 -r d9bd12e3747a Framework/ImageToolbox.cpp --- 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(x) + offsetX < 0) - { - x = 0; - } - else - { - x += offsetX; - if (x >= source.GetWidth()) - { - x = source.GetWidth() - 1; - } - } - - if (static_cast(y) + offsetY < 0) - { - y = 0; - } - else - { - y += offsetY; - if (y >= source.GetHeight()) - { - y = source.GetHeight() - 1; - } - } - - return *(reinterpret_cast(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(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 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(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) { diff -r c6e7dda9ac14 -r d9bd12e3747a Framework/ImageToolbox.h --- 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);