Add support for uint32 and double in boxResample

This commit is contained in:
2024-11-15 23:29:22 +01:00
parent 24eea573e6
commit d1344d2dc8
+12 -9
View File
@@ -643,16 +643,16 @@ bool RawImage::pixel(int x, int y, double &r, double &g, double &b) const
return true; return true;
} }
template<typename T> template<typename T, typename U = float>
void boxResample(uint32_t w, uint32_t h, uint32_t ch, uint32_t oldw, uint32_t oldh, const uint8_t *in_, uint8_t *out_) 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; if(oldw == 0 || oldh == 0)return;
const T *in = reinterpret_cast<const T*>(in_); const T *in = reinterpret_cast<const T*>(in_);
T *out = reinterpret_cast<T*>(out_); T *out = reinterpret_cast<T*>(out_);
float max = 255.0f; U max = 255.0f;
if constexpr(std::is_same_v<T, uint16_t>) if constexpr(std::is_integral_v<T>)
max = UINT16_MAX; max = (U)std::numeric_limits<T>::max();
float sx = (float)w / oldw; float sx = (float)w / oldw;
float sy = (float)h / oldh; 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 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 xx = x * oldw / w;//calculate source rect
uint32_t yy = y * oldh / h; uint32_t yy = y * oldh / h;
uint32_t xe = std::min((x + 1) * oldw / w, oldw - 1); 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: case RawImage::UINT16:
boxResample<uint16_t>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); boxResample<uint16_t>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
break; break;
case RawImage::FLOAT32: case RawImage::UINT32:
boxResample<float>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); boxResample<uint32_t>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
break; break;
case RawImage::FLOAT16: case RawImage::FLOAT16:
boxResample<F16>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get()); boxResample<F16>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
break; break;
default: case RawImage::FLOAT32:
qWarning() << "Resizing format not supported"; boxResample<float>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
break;
case RawImage::FLOAT64:
boxResample<double, double>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
break; break;
} }
} }