From d1344d2dc80201f7c10a58210d1264d3ce746809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Fri, 15 Nov 2024 23:29:22 +0100 Subject: [PATCH] Add support for uint32 and double in boxResample --- rawimage.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/rawimage.cpp b/rawimage.cpp index c36b669..cbdda79 100644 --- a/rawimage.cpp +++ b/rawimage.cpp @@ -643,16 +643,16 @@ bool RawImage::pixel(int x, int y, double &r, double &g, double &b) const return true; } -template +template void boxResample(uint32_t w, uint32_t h, uint32_t ch, uint32_t oldw, uint32_t oldh, const uint8_t *in_, uint8_t *out_) { if(oldw == 0 || oldh == 0)return; const T *in = reinterpret_cast(in_); T *out = reinterpret_cast(out_); - float max = 255.0f; - if constexpr(std::is_same_v) - max = UINT16_MAX; + U max = 255.0f; + if constexpr(std::is_integral_v) + max = (U)std::numeric_limits::max(); float sx = (float)w / oldw; float sy = (float)h / oldh; @@ -660,7 +660,7 @@ void boxResample(uint32_t w, uint32_t h, uint32_t ch, uint32_t oldw, uint32_t ol { for(uint32_t x = 0; x < w; x++)//iterate over destination X { - float p[4] = {0.0f}; + U p[4] = {0.0f}; uint32_t xx = x * oldw / w;//calculate source rect uint32_t yy = y * oldh / h; uint32_t xe = std::min((x + 1) * oldw / w, oldw - 1); @@ -713,14 +713,17 @@ void RawImage::resize(uint32_t w, uint32_t h) case RawImage::UINT16: boxResample(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); break; - case RawImage::FLOAT32: - boxResample(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); + case RawImage::UINT32: + boxResample(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); break; case RawImage::FLOAT16: boxResample(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); break; - default: - qWarning() << "Resizing format not supported"; + case RawImage::FLOAT32: + boxResample(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); + break; + case RawImage::FLOAT64: + boxResample(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); break; } }