Add support for FLOAT16 image downscale
This commit is contained in:
@@ -117,7 +117,11 @@ void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index)
|
|||||||
makeCurrent();
|
makeCurrent();
|
||||||
m_rawImage = image;
|
m_rawImage = image;
|
||||||
if((int)image->width() > m_maxTextureSize || (int)image->height() > m_maxTextureSize)
|
if((int)image->width() > m_maxTextureSize || (int)image->height() > m_maxTextureSize)
|
||||||
m_rawImage->resize(std::min(m_maxTextureSize, (int)image->width()), std::min(m_maxTextureSize, (int)image->height()));
|
{
|
||||||
|
uint32_t newW = std::min(image->width() * m_maxTextureSize / image->width(), image->width() * m_maxTextureSize / image->height());
|
||||||
|
uint32_t newH = std::min(image->height() * m_maxTextureSize / image->width(), image->height() * m_maxTextureSize / image->height());
|
||||||
|
m_rawImage->resize(newW, newH);
|
||||||
|
}
|
||||||
|
|
||||||
m_imgWidth = image->width();
|
m_imgWidth = image->width();
|
||||||
m_imgHeight = image->height();
|
m_imgHeight = image->height();
|
||||||
|
|||||||
+20
-4
@@ -4,6 +4,7 @@
|
|||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QFloat16>
|
#include <QFloat16>
|
||||||
#include <lcms2.h>
|
#include <lcms2.h>
|
||||||
|
//#include <libstellarsolver/stellarsolver.h>
|
||||||
|
|
||||||
using F16 = qfloat16;
|
using F16 = qfloat16;
|
||||||
|
|
||||||
@@ -394,7 +395,11 @@ const void *RawImage::origData() const
|
|||||||
const void *RawImage::origData(uint32_t row, uint32_t col) const
|
const void *RawImage::origData(uint32_t row, uint32_t col) const
|
||||||
{
|
{
|
||||||
if(m_original)
|
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
|
else
|
||||||
return m_pixels.get() + (m_width * row * m_ch + col * m_ch) * typeSize(m_type);
|
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;
|
size_t s = size() * m_ch;
|
||||||
if(m_type == UINT32)
|
if(m_type == UINT32)
|
||||||
{
|
{
|
||||||
|
m_origWidth = m_width;
|
||||||
|
m_origHeight = m_height;
|
||||||
m_original = std::move(m_pixels);
|
m_original = std::move(m_pixels);
|
||||||
allocate(m_width, m_height, m_channels, FLOAT32);
|
allocate(m_width, m_height, m_channels, FLOAT32);
|
||||||
m_origType = UINT32;
|
m_origType = UINT32;
|
||||||
@@ -484,6 +491,8 @@ void RawImage::convertToGLFormat()
|
|||||||
}
|
}
|
||||||
else if(m_type == FLOAT64)
|
else if(m_type == FLOAT64)
|
||||||
{
|
{
|
||||||
|
m_origWidth = m_width;
|
||||||
|
m_origHeight = m_height;
|
||||||
m_original = std::move(m_pixels);
|
m_original = std::move(m_pixels);
|
||||||
allocate(m_width, m_height, m_channels, FLOAT32);
|
allocate(m_width, m_height, m_channels, FLOAT32);
|
||||||
m_origType = FLOAT64;
|
m_origType = FLOAT64;
|
||||||
@@ -495,6 +504,8 @@ void RawImage::convertToGLFormat()
|
|||||||
}
|
}
|
||||||
else if(OpenGLES && m_type == UINT16)
|
else if(OpenGLES && m_type == UINT16)
|
||||||
{
|
{
|
||||||
|
m_origWidth = m_width;
|
||||||
|
m_origHeight = m_height;
|
||||||
m_original = std::move(m_pixels);
|
m_original = std::move(m_pixels);
|
||||||
allocate(m_width, m_height, m_channels, FLOAT16);
|
allocate(m_width, m_height, m_channels, FLOAT16);
|
||||||
m_origType = UINT16;
|
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_);
|
const T *in = reinterpret_cast<const T*>(in_);
|
||||||
T *out = reinterpret_cast<T*>(out_);
|
T *out = reinterpret_cast<T*>(out_);
|
||||||
float max = 255.0f;
|
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;
|
max = UINT16_MAX;
|
||||||
|
|
||||||
float sx = (float)w / oldw;
|
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++)
|
for(uint32_t z = 0; z < ch; z++)
|
||||||
if constexpr(std::is_floating_point<T>::value)
|
if constexpr(std::is_floating_point_v<T> || std::is_same_v<T, F16>)
|
||||||
out[(y * w + x) * ch + z] = p[z];
|
out[(y * w + x) * ch + z] = (T)p[z];
|
||||||
else
|
else
|
||||||
out[(y * w + x) * ch + z] = std::clamp(std::round(p[z]), 0.0f, max);
|
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;
|
uint32_t oldh = m_height;
|
||||||
m_thumbAspect = (float)m_width / m_height;
|
m_thumbAspect = (float)m_width / m_height;
|
||||||
|
|
||||||
|
DataType origType = m_origType;
|
||||||
allocate(w, h, m_channels, m_type);
|
allocate(w, h, m_channels, m_type);
|
||||||
|
m_origType = origType;
|
||||||
|
|
||||||
switch(m_type)
|
switch(m_type)
|
||||||
{
|
{
|
||||||
@@ -682,6 +695,9 @@ void RawImage::resize(uint32_t w, uint32_t h)
|
|||||||
case RawImage::FLOAT32:
|
case RawImage::FLOAT32:
|
||||||
boxResample<float>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
boxResample<float>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
||||||
break;
|
break;
|
||||||
|
case RawImage::FLOAT16:
|
||||||
|
boxResample<F16>(w, h, m_ch, oldw, oldh, old_pixels.get(), m_pixels.get());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qWarning() << "Resizing format not supported";
|
qWarning() << "Resizing format not supported";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ protected:
|
|||||||
std::unique_ptr<PixelType[]> m_original;
|
std::unique_ptr<PixelType[]> m_original;
|
||||||
uint32_t m_width = 0;
|
uint32_t m_width = 0;
|
||||||
uint32_t m_height = 0;
|
uint32_t m_height = 0;
|
||||||
|
uint32_t m_origWidth = 0;
|
||||||
|
uint32_t m_origHeight = 0;
|
||||||
uint32_t m_channels = 0;
|
uint32_t m_channels = 0;
|
||||||
uint32_t m_ch = 0;
|
uint32_t m_ch = 0;
|
||||||
DataType m_type = UINT8;
|
DataType m_type = UINT8;
|
||||||
|
|||||||
Reference in New Issue
Block a user