Add support for FLOAT16 image downscale

This commit is contained in:
2024-08-27 11:28:09 +02:00
parent d6e257e201
commit 5e18c591f7
3 changed files with 27 additions and 5 deletions
+20 -4
View File
@@ -4,6 +4,7 @@
#include <QElapsedTimer>
#include <QFloat16>
#include <lcms2.h>
//#include <libstellarsolver/stellarsolver.h>
using F16 = qfloat16;
@@ -394,7 +395,11 @@ const void *RawImage::origData() const
const void *RawImage::origData(uint32_t row, uint32_t col) const
{
if(m_original)
return m_original.get() + (m_width * row * m_ch + col * m_ch) * typeSize(m_origType);
{
col = col * m_origWidth / m_width;
row = row * m_origHeight / m_height;
return m_original.get() + (m_origWidth * row * m_ch + col * m_ch) * typeSize(m_origType);
}
else
return m_pixels.get() + (m_width * row * m_ch + col * m_ch) * typeSize(m_type);
}
@@ -473,6 +478,8 @@ void RawImage::convertToGLFormat()
size_t s = size() * m_ch;
if(m_type == UINT32)
{
m_origWidth = m_width;
m_origHeight = m_height;
m_original = std::move(m_pixels);
allocate(m_width, m_height, m_channels, FLOAT32);
m_origType = UINT32;
@@ -484,6 +491,8 @@ void RawImage::convertToGLFormat()
}
else if(m_type == FLOAT64)
{
m_origWidth = m_width;
m_origHeight = m_height;
m_original = std::move(m_pixels);
allocate(m_width, m_height, m_channels, FLOAT32);
m_origType = FLOAT64;
@@ -495,6 +504,8 @@ void RawImage::convertToGLFormat()
}
else if(OpenGLES && m_type == UINT16)
{
m_origWidth = m_width;
m_origHeight = m_height;
m_original = std::move(m_pixels);
allocate(m_width, m_height, m_channels, FLOAT16);
m_origType = UINT16;
@@ -619,7 +630,7 @@ void boxResample(uint32_t w, uint32_t h, uint32_t ch, uint32_t oldw, uint32_t ol
const T *in = reinterpret_cast<const T*>(in_);
T *out = reinterpret_cast<T*>(out_);
float max = 255.0f;
if constexpr(std::is_same<T, uint16_t>::value)
if constexpr(std::is_same_v<T, uint16_t>)
max = UINT16_MAX;
float sx = (float)w / oldw;
@@ -652,8 +663,8 @@ void boxResample(uint32_t w, uint32_t h, uint32_t ch, uint32_t oldw, uint32_t ol
}
}
for(uint32_t z = 0; z < ch; z++)
if constexpr(std::is_floating_point<T>::value)
out[(y * w + x) * ch + z] = p[z];
if constexpr(std::is_floating_point_v<T> || std::is_same_v<T, F16>)
out[(y * w + x) * ch + z] = (T)p[z];
else
out[(y * w + x) * ch + z] = std::clamp(std::round(p[z]), 0.0f, max);
}
@@ -669,7 +680,9 @@ void RawImage::resize(uint32_t w, uint32_t h)
uint32_t oldh = m_height;
m_thumbAspect = (float)m_width / m_height;
DataType origType = m_origType;
allocate(w, h, m_channels, m_type);
m_origType = origType;
switch(m_type)
{
@@ -682,6 +695,9 @@ void RawImage::resize(uint32_t w, uint32_t h)
case RawImage::FLOAT32:
boxResample<float>(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";
break;