Skip to content

Commit

Permalink
[ColorSpace] Add rec709 color space definition based on ACES ODT.
Browse files Browse the repository at this point in the history
  • Loading branch information
demoulinv committed Apr 13, 2023
1 parent e97ba3a commit 511a59a
Show file tree
Hide file tree
Showing 8 changed files with 553,409 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/aliceVision/image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ alicevision_add_library(aliceVision_image

# Install config.ocio
install(FILES ./share/aliceVision/config.ocio DESTINATION ${CMAKE_INSTALL_DATADIR}/aliceVision)
install(DIRECTORY ./share/aliceVision/luts DESTINATION ${CMAKE_INSTALL_DATADIR}/aliceVision)

# Unit tests
alicevision_add_test(image_test.cpp NAME "image" LINKS aliceVision_image)
Expand Down
11 changes: 10 additions & 1 deletion src/aliceVision/image/colorspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ std::string EImageColorSpace_informations()
EImageColorSpace_enumToString(EImageColorSpace::SRGB) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::ACES2065_1) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::ACEScg) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::REC709) + " (ODT.Academy.Rec709_100nits), " +
EImageColorSpace_enumToString(EImageColorSpace::LAB) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::XYZ) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::NO_CONVERSION);
Expand All @@ -168,8 +169,10 @@ EImageColorSpace EImageColorSpace_stringToEnum(const std::string& dataType)
return EImageColorSpace::SRGB;
if(type == "aces2065-1")
return EImageColorSpace::ACES2065_1;
if(type == "acescg")
if (type == "acescg")
return EImageColorSpace::ACEScg;
if ((type == "aces_lut") || (type == "rec709"))
return EImageColorSpace::REC709;
if(type == "lab")
return EImageColorSpace::LAB;
if(type == "xyz")
Expand All @@ -194,6 +197,8 @@ std::string EImageColorSpace_enumToString(const EImageColorSpace dataType)
return "aces2065-1";
case EImageColorSpace::ACEScg:
return "acescg";
case EImageColorSpace::REC709:
return "rec709";
case EImageColorSpace::LAB:
return "lab";
case EImageColorSpace::XYZ:
Expand All @@ -212,6 +217,7 @@ std::string EImageColorSpace_enumToOIIOString(const EImageColorSpace colorSpace)
case EImageColorSpace::LINEAR: return "Linear";
case EImageColorSpace::ACES2065_1: return "aces2065-1";
case EImageColorSpace::ACEScg: return "ACEScg";
case EImageColorSpace::REC709: return "rec709";
default: ;
}
throw std::out_of_range("No string defined for EImageColorSpace to OIIO conversion: " +
Expand All @@ -224,6 +230,7 @@ EImageColorSpace EImageColorSpace_OIIOstringToEnum(const std::string& colorspace
if (colorspace == "sRGB") return EImageColorSpace::SRGB;
if (colorspace == "aces2065-1") return EImageColorSpace::ACES2065_1;
if (colorspace == "ACEScg") return EImageColorSpace::ACEScg;
if ((colorspace == "REC709") || (colorspace == "ACES_LUT")) return EImageColorSpace::REC709;

throw std::out_of_range("No EImageColorSpace defined for string: " + colorspace);
}
Expand All @@ -236,6 +243,7 @@ bool EImageColorSpace_isSupportedOIIOEnum(const EImageColorSpace& colorspace)
case EImageColorSpace::LINEAR: return true;
case EImageColorSpace::ACES2065_1: return true;
case EImageColorSpace::ACEScg: return true;
case EImageColorSpace::REC709: return true;
default: return false;
}
}
Expand All @@ -246,6 +254,7 @@ bool EImageColorSpace_isSupportedOIIOstring(const std::string& colorspace)
if (colorspace == "sRGB") return true;
if (colorspace == "aces2065-1") return true;
if (colorspace == "ACEScg") return true;
if (colorspace == "REC709") return true;
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/aliceVision/image/colorspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum class EImageColorSpace
SRGB,
ACES2065_1,
ACEScg,
REC709,
LAB,
XYZ,
NO_CONVERSION
Expand Down
27 changes: 14 additions & 13 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ void readImage(const std::string& path,
// even if no conversion is needed.
}
else if ((imageReadOptions.workingColorSpace == EImageColorSpace::ACES2065_1) || (imageReadOptions.workingColorSpace == EImageColorSpace::ACEScg) ||
(EImageColorSpace_stringToEnum(fromColorSpaceName) == EImageColorSpace::ACES2065_1) || (EImageColorSpace_stringToEnum(fromColorSpaceName) == EImageColorSpace::ACEScg))
(EImageColorSpace_stringToEnum(fromColorSpaceName) == EImageColorSpace::ACES2065_1) || (EImageColorSpace_stringToEnum(fromColorSpaceName) == EImageColorSpace::ACEScg) ||
(EImageColorSpace_stringToEnum(fromColorSpaceName) == EImageColorSpace::REC709))
{
const auto colorConfigPath = getAliceVisionOCIOConfig();
if (colorConfigPath.empty())
Expand Down Expand Up @@ -829,19 +830,18 @@ void writeImage(const std::string& path,
oiio::ImageSpec imageSpec(image.Width(), image.Height(), nchannels, typeDesc);
imageSpec.extra_attribs = metadata; // add custom metadata

imageSpec.attribute("jpeg:subsampling", "4:4:4"); // if possible, always subsampling 4:4:4 for jpeg
imageSpec.attribute("compression", isEXR ? "zips" : "none"); // if possible, set compression (zips for EXR, none for the other)

if(displayRoi.defined() && isEXR)
{
imageSpec.set_roi_full(displayRoi);
}
imageSpec.attribute("jpeg:subsampling", "4:4:4"); // if possible, always subsampling 4:4:4 for jpeg
imageSpec.attribute("compression", isEXR ? "zips" : "none"); // if possible, set compression (zips for EXR, none for the other)

if(pixelRoi.defined() && isEXR)
{
imageSpec.set_roi(pixelRoi);
}
if(displayRoi.defined() && isEXR)
{
imageSpec.set_roi_full(displayRoi);
}

if(pixelRoi.defined() && isEXR)
{
imageSpec.set_roi(pixelRoi);
}

imageSpec.attribute("AliceVision:ColorSpace",
(toColorSpace == EImageColorSpace::NO_CONVERSION)
Expand All @@ -857,7 +857,8 @@ void writeImage(const std::string& path,
// even if no conversion is needed.
}
else if ((toColorSpace == EImageColorSpace::ACES2065_1) || (toColorSpace == EImageColorSpace::ACEScg) ||
(fromColorSpace == EImageColorSpace::ACES2065_1) || (fromColorSpace == EImageColorSpace::ACEScg))
(fromColorSpace == EImageColorSpace::ACES2065_1) || (fromColorSpace == EImageColorSpace::ACEScg) ||
(fromColorSpace == EImageColorSpace::REC709))
{
const auto colorConfigPath = getAliceVisionOCIOConfig();
if (colorConfigPath.empty())
Expand Down
35 changes: 25 additions & 10 deletions src/aliceVision/image/share/aliceVision/config.ocio
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
ocio_profile_version: 2

#
# Note: this is not intended to be a complete production-ready config, its purpose is to
# introduce many of the new features in OCIO v2.
#

description: A config to convert color space in AliceVision.
name: OCIOv2-AliceVision

#
# This config does not require any external files.
#
search_path: ""
search_path: luts

#
# Defining the environment (even if empty) in the config can be a performance boost.
Expand Down Expand Up @@ -68,7 +60,8 @@ displays:
- !<View> {name: Lin, colorspace: ACEScg}
log:
- !<View> {name: Log, colorspace: sRGB}

ACES:
- !<View> {name: Rec.709, colorspace: Rec709}
#
# The next config section is the traditional section for colorspaces that are defined relative to a
# scene-referred connection space. This section may be placed either before or after the display
Expand Down Expand Up @@ -142,3 +135,25 @@ colorspaces:
children:
- !<MatrixTransform> {matrix: [2.52140088857822, -1.13399574938275, -0.387561856768867, 0, -0.276214061561748, 1.37259556630409, -0.0962823557364663, 0, -0.0153202000774786, -0.152992561800699, 1.16838719961932, 0, 0, 0, 0, 1]}
- !<ExponentWithLinearTransform> {gamma: 2.4, offset: 0.055, direction: inverse}

- !<ColorSpace>
name: Rec709
family: Output
equalitygroup: ""
bitdepth: 32f
description: |
ACES 1.0 Output - Rec.709 Output Transform

ACES Transform ID : urn:ampas:aces:transformId:v1.5:ODT.Academy.Rec709_100nits_dim.a1.0.3
isdata: false
allocation: uniform
allocationvars: [0, 1]
to_reference: !<GroupTransform>
children:
- !<FileTransform> {src: InvRRT.Rec.709.Log2_48_nits_Shaper.spi3d, interpolation: tetrahedral}
- !<FileTransform> {src: Log2_48_nits_Shaper_to_linear.spi1d, interpolation: linear}
from_reference: !<GroupTransform>
children:
- !<FileTransform> {src: Log2_48_nits_Shaper_to_linear.spi1d, interpolation: linear, direction: inverse}
- !<FileTransform> {src: Log2_48_nits_Shaper.RRT.Rec.709.spi3d, interpolation: tetrahedral}

Loading

0 comments on commit 511a59a

Please sign in to comment.