Downscale image to max OpenGL texture

This commit is contained in:
2023-02-10 09:11:38 +01:00
parent c47ecbedb8
commit 576df9c196
4 changed files with 20 additions and 3 deletions
+7 -3
View File
@@ -99,6 +99,7 @@ void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index)
if(image == nullptr)return;
makeCurrent();
m_rawImage = image;
m_rawImage->downscaleTo(m_maxTextureSize);
m_imgWidth = image->width();
m_imgHeight = image->height();
@@ -398,9 +399,12 @@ void ImageWidget::initializeGL()
qDebug() << message;
});
qDebug() << (char*)f->glGetString(GL_VENDOR);
qDebug() << (char*)f->glGetString(GL_RENDERER);
qDebug() << (char*)f->glGetString(GL_VERSION);
qDebug() << "Vendor:" << (char*)f->glGetString(GL_VENDOR);
qDebug() << "Renderer:" << (char*)f->glGetString(GL_RENDERER);
qDebug() << "Version:" << (char*)f->glGetString(GL_VERSION);
f->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
f->glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_maxArrayLayers);
qDebug() << "Max texture size:" << m_maxTextureSize << "max layers:" << m_maxArrayLayers;
//MANUAL_MIPMAP_GEN = QString((const char*)f->glGetString(GL_VENDOR)).startsWith("ATI Technologies Inc", Qt::CaseInsensitive);
+2
View File
@@ -62,6 +62,8 @@ class ImageWidget : public QOpenGLWidget
bool m_sizesDirty;
bool m_srgb;
int m_thumbnailCount;
int m_maxTextureSize;
int m_maxArrayLayers;
QVector<ImageThumb> m_thumnails;
Database *m_database;
public:
+10
View File
@@ -410,3 +410,13 @@ void RawImage::scaleToUnit()
}
}
}
void RawImage::downscaleTo(uint32_t size)
{
if(size < width() || size < height())
{
double s = (double)size / std::max(width(), height());
cv::Size dsize(std::floor(width() * s), std::floor(height() * s));
cv::resize(m_img, m_img, dsize, 0, 0, cv::INTER_AREA);
}
}
+1
View File
@@ -86,6 +86,7 @@ public:
const cv::Mat& mat() const;
bool pixel(int x, int y, QVector3D &rgb) const;
void scaleToUnit();
void downscaleTo(uint32_t size);
};
#endif // RAWIMAGE_H