Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from alicevision/fix_oiio_raw
Browse files Browse the repository at this point in the history
[imageIO] fix colorspace handling depending on OIIO version
  • Loading branch information
fabiencastan authored Jun 20, 2019
2 parents a932836 + 4c1540e commit e9798a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 29 additions & 2 deletions src/imageIOHandler/QtOIIOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,51 @@ 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);

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;
Expand Down

0 comments on commit e9798a7

Please sign in to comment.