From 5eedd257575c86cd2cf85fce6553edb3553b3f17 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Mon, 17 Jun 2019 14:58:04 +0200 Subject: [PATCH 1/2] [imageIO] fix colorspace handling depending on OIIO version --- src/imageIOHandler/QtOIIOHandler.cpp | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/imageIOHandler/QtOIIOHandler.cpp b/src/imageIOHandler/QtOIIOHandler.cpp index 4ad27f4..77257f1 100644 --- a/src/imageIOHandler/QtOIIOHandler.cpp +++ b/src/imageIOHandler/QtOIIOHandler.cpp @@ -70,7 +70,12 @@ bool QtOIIOHandler::read(QImage *image) // libRAW configuration configSpec.attribute("raw:auto_bright", 0); // don't want exposure correction configSpec.attribute("raw:use_camera_wb", 1); // want white balance correction +#if OIIO_VERSION <= (10000 * 2 + 100 * 0 + 8) // OIIO_VERSION <= 2.0.8 + // In these previous versions of oiio, there was no Linear option configSpec.attribute("raw:ColorSpace", "sRGB"); // want colorspace sRGB +#else + configSpec.attribute("raw:ColorSpace", "Linear"); // want linear colorspace with sRGB primaries +#endif configSpec.attribute("raw:use_camera_matrix", 3); // want to use embeded color profile oiio::ImageBuf inBuf(path, 0, 0, NULL, &configSpec); @@ -78,16 +83,38 @@ bool QtOIIOHandler::read(QImage *image) if(!inBuf.initialized()) throw std::runtime_error("Can't find/open image file '" + path + "'."); +#if OIIO_VERSION <= (10000 * 2 + 100 * 0 + 8) // OIIO_VERSION <= 2.0.8 + // Workaround for bug in RAW colorspace management in previous versions of OIIO: + // When asking sRGB we got sRGB primaries with linear gamma, + // but oiio::ColorSpace was wrongly set to sRGB. oiio::ImageSpec inSpec = inBuf.spec(); + if(inSpec.get_string_attribute("oiio:ColorSpace", "") == "sRGB") + { + const auto in = oiio::ImageInput::open(path, nullptr); + const std::string formatStr = in->format_name(); + if(formatStr == "raw") + { + // For the RAW plugin: override colorspace as linear (as the content is linear with sRGB primaries but declared as sRGB) + inSpec.attribute("oiio:ColorSpace", "Linear"); + qDebug() << "OIIO workaround: RAW input image " << QString::fromStdString(path) << " is in Linear."; + } + } +#else + const oiio::ImageSpec& inSpec = inBuf.spec(); +#endif qDebug() << "[QtOIIO] width:" << inSpec.width << ", height:" << inSpec.height << ", nchannels:" << inSpec.nchannels; if(inSpec.nchannels >= 3) { // Color conversion to sRGB - const std::string& colorSpace = inSpec.get_string_attribute("oiio:Colorspace", "sRGB"); - if(colorSpace != "sRGB") + const std::string& colorSpace = inSpec.get_string_attribute("oiio:ColorSpace", "sRGB"); // default image color space is sRGB + + if(colorSpace != "sRGB") // color conversion to sRGB + { oiio::ImageBufAlgo::colorconvert(inBuf, inBuf, colorSpace, "sRGB"); + qDebug() << "Convert image " << QString::fromStdString(path) << " from " << QString::fromStdString(colorSpace) << " to sRGB colorspace"; + } } int nchannels = 0; From 4c1540ef04cb65d63b8a097dd6ffeeb30cfbc9e5 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Tue, 18 Jun 2019 11:22:17 +0200 Subject: [PATCH 2/2] [ci][appVeyor] update Qt version --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ec32e19..8c76e3d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,7 +9,7 @@ platform: - x64 environment: - QT5: C:\Qt\5.11.2\msvc2017_64 + QT5: C:\Qt\5.12.2\msvc2017_64 # APPVEYOR_SAVE_CACHE_ON_ERROR: true install: