Use lcms2 for color profiles
This commit is contained in:
+28
-7
@@ -14,9 +14,12 @@
|
||||
#include <QFileInfo>
|
||||
#include <cmath>
|
||||
#include <QElapsedTimer>
|
||||
#include <QFloat16>
|
||||
#include <lcms2.h>
|
||||
|
||||
int FILTERING = 1;
|
||||
bool OpenGLES = false;
|
||||
const int LUT_SIZE = 32;
|
||||
|
||||
struct RawImageType
|
||||
{
|
||||
@@ -32,7 +35,7 @@ RawImageType getRawImageType(const RawImage *img)
|
||||
{
|
||||
case RawImage::UINT8:
|
||||
if(img->channels() >= 3)
|
||||
type.textureFormat = QOpenGLTexture::SRGB8_Alpha8;
|
||||
type.textureFormat = QOpenGLTexture::RGBA8_UNorm;
|
||||
else
|
||||
type.textureFormat = QOpenGLTexture::R8_UNorm;
|
||||
type.dataType = QOpenGLTexture::UInt8;
|
||||
@@ -123,9 +126,14 @@ void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index)
|
||||
if(!m_image)return;
|
||||
|
||||
RawImageType rawImageType = getRawImageType(image.get());
|
||||
m_srgb = rawImageType.textureFormat == QOpenGLTexture::SRGB8_Alpha8;
|
||||
m_srgb = image->getLUT().size() > 0;
|
||||
m_bwImg = image->channels() == 1;
|
||||
|
||||
if(m_srgb)
|
||||
{
|
||||
m_lut->setData(0, 0, 0, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, QOpenGLTexture::RGBA, QOpenGLTexture::RGBA, QOpenGLTexture::Float16, image->getLUT().data());
|
||||
}
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
m_image->destroy();
|
||||
@@ -216,6 +224,7 @@ void ImageWidget::allocateThumbnails(const QStringList &paths)
|
||||
m_thumbnailTexture->setFormat(QOpenGLTexture::RGBA16F);
|
||||
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
|
||||
m_thumbnailTexture->setLayers(std::min((int)paths.size(), m_maxArrayLayers));
|
||||
m_thumbnailTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
|
||||
m_thumbnailTexture->allocateStorage();
|
||||
}
|
||||
|
||||
@@ -364,14 +373,16 @@ void ImageWidget::paintGL()
|
||||
QMatrix4x4 mvp;
|
||||
mvp.ortho(rect());
|
||||
m_thumbnailProgram->setUniformValue("mvp", mvp);
|
||||
fx->glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_thumbnailCount);
|
||||
m_vaoThumb->release();
|
||||
|
||||
QPainter painter(this);
|
||||
const int w = width()/THUMB_SIZE_BORDER;
|
||||
const int off = (THUMB_SIZE_BORDER - THUMB_SIZE) / 2;
|
||||
int start = std::max((int)(m_dy / THUMB_SIZE_BORDER_Y * w - w), 0);
|
||||
int end = std::min((int)(m_dy + m_height) / THUMB_SIZE_BORDER_Y * w + w, m_thumbnailCount);
|
||||
|
||||
fx->glDrawArraysInstanced(GL_TRIANGLE_STRIP, start*4, 4, (end - start) * 4);
|
||||
m_vaoThumb->release();
|
||||
|
||||
QPainter painter(this);
|
||||
for(int i=start; i < end; i++)
|
||||
{
|
||||
float x = (i % w) * THUMB_SIZE_BORDER;
|
||||
@@ -424,9 +435,8 @@ void ImageWidget::paintGL()
|
||||
m_program->setUniformValue("false_color", m_falseColor && m_bwImg);
|
||||
m_program->setUniformValue("invert", m_invert);
|
||||
m_program->setUniformValue("filtering", m_scale > 1.0f ? FILTERING : 1);
|
||||
#ifdef COLOR_MANAGMENT
|
||||
m_program->setUniformValue("lut_table", 2);
|
||||
m_program->setUniformValue("srgb", m_srgb);
|
||||
#endif
|
||||
f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
m_vao->release();
|
||||
}
|
||||
@@ -462,7 +472,9 @@ void ImageWidget::initializeGL()
|
||||
{
|
||||
src = "#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"precision highp sampler2D;\n"
|
||||
"precision highp sampler2DArray;\n"
|
||||
"precision highp sampler3D;\n"
|
||||
"#line 1\n";
|
||||
}
|
||||
else
|
||||
@@ -525,6 +537,7 @@ void ImageWidget::initializeGL()
|
||||
m_program->enableAttributeArray("qt_MultiTexCoord0");
|
||||
m_program->setAttributeBuffer("qt_MultiTexCoord0", GL_FLOAT, sizeof(float)*2, 2, sizeof(float)*4);
|
||||
m_program->setUniformValue("qt_Texture0", (GLuint)0);
|
||||
m_program->setUniformValue("lut_table", (GLuint)2);
|
||||
m_program->setUniformValue("scale", 1.0f, 0.0f);
|
||||
|
||||
m_debayerProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
|
||||
@@ -588,6 +601,14 @@ void ImageWidget::initializeGL()
|
||||
m_transferOptions = std::unique_ptr<QOpenGLPixelTransferOptions>(new QOpenGLPixelTransferOptions);
|
||||
m_transferOptions->setAlignment(1);
|
||||
|
||||
m_lut = std::make_unique<QOpenGLTexture>(QOpenGLTexture::Target3D);
|
||||
m_lut->setSize(LUT_SIZE, LUT_SIZE, LUT_SIZE);
|
||||
m_lut->setMipLevelRange(0, 0);
|
||||
m_lut->setFormat(QOpenGLTexture::TextureFormat::RGBA16F);
|
||||
m_lut->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
|
||||
m_lut->allocateStorage();
|
||||
m_lut->bind(2);
|
||||
|
||||
if(m_rawImage)
|
||||
setImage(m_rawImage, m_currentImg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user