Mercurial > hg > orthanc-wsi
diff Framework/ImageToolbox.cpp @ 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 | c0a554576721 |
line wrap: on
line diff
--- 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) {