diff --git a/CMakeLists.txt b/CMakeLists.txt index e55cc4b..b216804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,15 @@ set(TENMON_SRC stretchtoolbar.cpp ) +option(COLOR_MANAGMENT "Enable sRGB framebuffer support for gamma correct images and color profiles support" ON) +if(${Qt5Core_VERSION_STRING} VERSION_LESS "5.14") + set(COLOR_MANAGMENT OFF) +endif(${Qt5Core_VERSION_STRING} VERSION_LESS "5.14") + +if(COLOR_MANAGMENT) + add_compile_definitions("COLOR_MANAGMENT") +endif(COLOR_MANAGMENT) + qt5_add_resources(TENMON_SRC resources.qrc) if(WIN32) list(APPEND TENMON_SRC icon.rc) diff --git a/imagescrollareagl.cpp b/imagescrollareagl.cpp index d030ba5..97a1496 100644 --- a/imagescrollareagl.cpp +++ b/imagescrollareagl.cpp @@ -24,8 +24,13 @@ const RawImageType rawImageTypes[] = { {QOpenGLTexture::Red, QOpenGLTexture::R8_UNorm, QOpenGLTexture::UInt8, true}, {QOpenGLTexture::Red, QOpenGLTexture::R16_UNorm, QOpenGLTexture::UInt16, true}, {QOpenGLTexture::Red, QOpenGLTexture::R32F, QOpenGLTexture::Float32, true}, +#ifdef COLOR_MANAGMENT {QOpenGLTexture::RGB, QOpenGLTexture::SRGB8, QOpenGLTexture::UInt8, false}, - {QOpenGLTexture::RGBA,QOpenGLTexture::SRGB8_Alpha8, QOpenGLTexture::UInt8, false}, + {QOpenGLTexture::RGBA,QOpenGLTexture::SRGB8, QOpenGLTexture::UInt8, false}, +#else + {QOpenGLTexture::RGB, QOpenGLTexture::RGB8_UNorm, QOpenGLTexture::UInt8, false}, + {QOpenGLTexture::RGBA,QOpenGLTexture::RGB8_UNorm, QOpenGLTexture::UInt8, false}, +#endif {QOpenGLTexture::RGB, QOpenGLTexture::RGB16_UNorm, QOpenGLTexture::UInt16, false}, {QOpenGLTexture::RGBA, QOpenGLTexture::RGB16_UNorm, QOpenGLTexture::UInt16, false}, {QOpenGLTexture::RGB, QOpenGLTexture::RGB32F, QOpenGLTexture::Float32, false} @@ -79,7 +84,9 @@ ImageWidget::ImageWidget(Database *database, QWidget *parent) : QOpenGLWidget(pa }); setMouseTracking(true); +#ifdef COLOR_MANAGMENT setTextureFormat(GL_SRGB8_ALPHA8); +#endif } ImageWidget::~ImageWidget() @@ -290,7 +297,9 @@ void ImageWidget::paintGL() } else { +#ifdef COLOR_MANAGMENT if(m_srgb)f->glEnable(GL_FRAMEBUFFER_SRGB); +#endif m_vao->bind(); m_image->bind(0); m_program->bind(); @@ -301,7 +310,9 @@ void ImageWidget::paintGL() m_program->setUniformValue("bw", m_bwImg); m_program->setUniformValue("invert", m_invert); f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +#ifdef COLOR_MANAGMENT if(m_srgb)f->glDisable(GL_FRAMEBUFFER_SRGB); +#endif } } diff --git a/loadrunable.cpp b/loadrunable.cpp index 466e714..e56f1b0 100644 --- a/loadrunable.cpp +++ b/loadrunable.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -15,7 +14,10 @@ #include "starfit.h" #include "wcslib/wcshdr.h" +#ifdef COLOR_MANAGMENT +#include static pcl::ICCProfile sRgbIccProfile((void*)QColorSpace(QColorSpace::SRgb).iccProfile().data()); +#endif LoadRunable::LoadRunable(const QString &file, Image *receiver, AnalyzeLevel level, bool thumbnail) : m_file(file), @@ -293,6 +295,7 @@ bool loadPCLImage(pcl::XISFReader &xisf, RawImage **image) xisf.ReadImage(pclImage); pclImage.Status().DisableInitialization(); +#ifdef COLOR_MANAGMENT pcl::ICCProfile iccProfile = xisf.ReadICCProfile(); if(iccProfile.IsProfile()) { @@ -302,6 +305,7 @@ bool loadPCLImage(pcl::XISFReader &xisf, RawImage **image) iccTran.Add(sRgbIccProfile); iccTran >> pclImage; } +#endif int numChannels = pclImage.NumberOfChannels(); cv::Mat cvImg[numChannels]; @@ -401,8 +405,10 @@ void LoadRunable::run() else { QImage img(m_file); +#ifdef COLOR_MANAGMENT if(img.colorSpace().isValid()) img.convertToColorSpace(QColorSpace::SRgb); +#endif ExifData *exif = exif_data_new_from_file(m_file.toLocal8Bit().constData()); info.info.append({QObject::tr("Width"), QString::number(img.width())}); diff --git a/main.cpp b/main.cpp index 18a0e3c..1b784e5 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,9 @@ int main(int argc, char *argv[]) format.setMinorVersion(3); format.setOption(QSurfaceFormat::DebugContext); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); +#ifdef COLOR_MANAGMENT format.setColorSpace(QSurfaceFormat::sRGBColorSpace); +#endif QSurfaceFormat::setDefaultFormat(format); QApplication a(argc, argv);