diff --git a/imagescrollareagl.cpp b/imagescrollareagl.cpp index 98969d7..51695e0 100644 --- a/imagescrollareagl.cpp +++ b/imagescrollareagl.cpp @@ -117,7 +117,11 @@ void ImageWidget::setImage(std::shared_ptr image, int index) makeCurrent(); m_rawImage = image; 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_imgHeight = image->height(); diff --git a/rawimage.cpp b/rawimage.cpp index 664734a..eed6fd9 100644 --- a/rawimage.cpp +++ b/rawimage.cpp @@ -4,6 +4,7 @@ #include #include #include +//#include 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(in_); T *out = reinterpret_cast(out_); float max = 255.0f; - if constexpr(std::is_same::value) + if constexpr(std::is_same_v) 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::value) - out[(y * w + x) * ch + z] = p[z]; + if constexpr(std::is_floating_point_v || std::is_same_v) + 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(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"; break; diff --git a/rawimage.h b/rawimage.h index 7482adc..6ee6ec3 100644 --- a/rawimage.h +++ b/rawimage.h @@ -67,6 +67,8 @@ protected: std::unique_ptr m_original; uint32_t m_width = 0; uint32_t m_height = 0; + uint32_t m_origWidth = 0; + uint32_t m_origHeight = 0; uint32_t m_channels = 0; uint32_t m_ch = 0; DataType m_type = UINT8;