Add support for uint32 and double in boxResample
This commit is contained in:
+12
-9
@@ -643,16 +643,16 @@ bool RawImage::pixel(int x, int y, double &r, double &g, double &b) const
|
||||
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_)
|
||||
{
|
||||
if(oldw == 0 || oldh == 0)return;
|
||||
|
||||
const T *in = reinterpret_cast<const T*>(in_);
|
||||
T *out = reinterpret_cast<T*>(out_);
|
||||
float max = 255.0f;
|
||||
if constexpr(std::is_same_v<T, uint16_t>)
|
||||
max = UINT16_MAX;
|
||||
U max = 255.0f;
|
||||
if constexpr(std::is_integral_v<T>)
|
||||
max = (U)std::numeric_limits<T>::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<uint16_t>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
case RawImage::FLOAT32:
|
||||
boxResample<float>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
||||
case RawImage::UINT32:
|
||||
boxResample<uint32_t>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
case RawImage::FLOAT16:
|
||||
boxResample<F16>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Resizing format not supported";
|
||||
case RawImage::FLOAT32:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user