Skip to content

Commit 35efa4a

Browse files
committed
Implement OIIO-based version of the tool
Signed-off-by: Anton Dukhovnikov <[email protected]>
1 parent f0b601d commit 35efa4a

File tree

18 files changed

+1520
-141
lines changed

18 files changed

+1520
-141
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
CC: ${{matrix.cc_compiler}}
4141
CMAKE_CXX_STANDARD: ${{matrix.cxx_std}}
4242
OPENEXR_VERSION: ${{matrix.openexr_ver}}
43+
CMAKE_CXX_FLAGS: "-lstdc++fs"
4344
steps:
4445
- uses: actions/checkout@v4
4546

@@ -83,40 +84,46 @@ jobs:
8384
fail-fast: false
8485

8586
matrix:
86-
os: [ubuntu-latest, windows-latest, macos-latest]
87+
title: [ubuntu, windows, macos]
8788
build_type: [Release]
8889
c_compiler: [gcc, clang, cl]
8990
include:
90-
- os: windows-latest
91+
- title: windows
92+
os: windows-latest
9193
c_compiler: cl
9294
cpp_compiler: cl
9395
install_deps: install_deps_windows
9496
toolchain_file: "C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
9597
build_shared_libs: OFF
96-
- os: ubuntu-latest
98+
- title: ubuntu
99+
os: ubuntu-24.04
97100
c_compiler: gcc
98101
cpp_compiler: g++
99102
install_deps: install_deps_linux
100-
- os: ubuntu-latest
101-
c_compiler: clang
103+
- title: ubuntu
104+
os: ubuntu-24.04
102105
cpp_compiler: clang++
103106
install_deps: install_deps_linux
104-
- os: macos-latest
107+
- title: macos
108+
os: macos-latest
105109
c_compiler: clang
106110
cpp_compiler: clang++
107111
install_deps: install_deps_mac
108112
exclude:
109-
- os: windows-latest
113+
- title: windows
110114
c_compiler: gcc
111-
- os: windows-latest
115+
- title: windows
112116
c_compiler: clang
113-
- os: ubuntu-latest
117+
- title: ubuntu
114118
c_compiler: cl
115-
- os: macos-latest
119+
- title: macos
116120
c_compiler: cl
117-
- os: macos-latest
121+
- title: macos
118122
c_compiler: gcc
119123

124+
env:
125+
CMAKE_CXX_FLAGS: "-lstdc++fs"
126+
120127
steps:
121128
- uses: actions/checkout@v4
122129

@@ -140,7 +147,7 @@ jobs:
140147
cmake
141148
-B ${{ steps.strings.outputs.build-output-dir }}
142149
-S ${{ github.workspace }}
143-
-DCXX_STANDARD=C++14
150+
-DCXX_STANDARD=C++17
144151
-DCMAKE_TOOLCHAIN_FILE="${{ matrix.toolchain_file }}"
145152
-DENABLE_SHARED="${{ matrix.build_shared_libs }}"
146153

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ set(RAWTOACESLIB "rawtoaces_util")
1212
set( CMAKE_MACOSX_RPATH 1 )
1313

1414
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
15-
# set(warnings "/W4 /WX /EHsc")
1615
add_compile_options ( /W0 )
1716
add_compile_definitions( NOMINMAX )
17+
add_compile_options ( $<$<COMPILE_LANGUAGE:CXX>:/utf-8> )
1818
endif()
1919

2020
if (NOT CONFIGURED_ONCE)
@@ -76,6 +76,8 @@ add_subdirectory("src/${RAWTOACESIDTLIB}")
7676
add_subdirectory("src/${RAWTOACESLIB}")
7777
add_subdirectory("src/rawtoaces")
7878

79+
add_subdirectory("src/rawtoaces_util2")
80+
add_subdirectory("src/rawtoaces2")
7981

8082
# Create a RAWTOACESBuildTreeSettings.cmake file for the use from the build tree
8183
file(RELATIVE_PATH CONF_REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")

build_scripts/install_deps.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ time sudo apt-get update
88

99
time sudo apt-get -q -f install -y \
1010
libunwind-dev libilmbase-dev libopenexr-dev \
11+
libopenimageio-dev \
1112
libboost-dev libboost-thread-dev libboost-filesystem-dev \
1213
libboost-test-dev \
1314
libraw-dev libceres-dev

build_scripts/install_deps_linux.bash

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ set -ex
55
time sudo apt-get update
66

77
time sudo apt-get -q -f install -y \
8-
libunwind-dev libimath-dev \
8+
libunwind-dev \
9+
libimath-dev libopenexr-dev \
910
libboost-dev libboost-filesystem-dev \
1011
libboost-test-dev \
11-
libraw-dev libceres-dev
12+
libraw-dev libceres-dev \
13+
libopencv-dev \
14+
openimageio-tools \
15+
libopenimageio-dev

build_scripts/install_deps_mac.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -ex
44

5-
brew install ceres-solver imath openexr libraw boost
5+
brew install ceres-solver imath openexr libraw boost openimageio

build_scripts/install_deps_windows.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ vcpkg install \
66
libraw:x64-windows \
77
ceres:x64-windows \
88
imath:x64-windows \
9+
openimageio:x64-windows \
910
boost-system:x64-windows \
1011
boost-foreach:x64-windows \
1112
boost-filesystem:x64-windows \

configure.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
33
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_INSTALL_PREFIX}/share/CMake")
44

55

6+
find_package ( OpenImageIO CONFIG REQUIRED )
67
find_package ( AcesContainer CONFIG REQUIRED )
78
find_package ( Eigen3 CONFIG REQUIRED )
89
find_package ( Imath CONFIG REQUIRED )

include/rawtoaces/define.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ static const double XYZ_acesrgb_4[4][4] = {
266266
{ 0.0, 0.0, 0.0, 1.0 }
267267
};
268268

269+
static const float XYZ_acesrgb_float_4[4][4] = {
270+
{ 1.0498110175, 0.0000000000, -0.0000974845, 0.0 },
271+
{ -0.4959030231, 1.3733130458, 0.0982400361, 0.0 },
272+
{ 0.0000000000, 0.0000000000, 0.9912520182, 0.0 },
273+
{ 0.0, 0.0, 0.0, 1.0 }
274+
};
275+
276+
static const float XYZ_acesrgb_transposed_4[4][4] = {
277+
{ 1.0498110175, -0.4959030231, 0.0000000000, 0.0 },
278+
{ 0.0000000000, 1.3733130458, 0.0000000000, 0.0 },
279+
{ -0.0000974845, 0.0982400361, 0.9912520182, 0.0 },
280+
{ 0.0000000000, 0.0000000000, 0.0000000000, 1.0 }
281+
};
282+
269283
static const double acesrgb_XYZ_3[3][3] = {
270284
{ 0.952552395938186, 0.0, 9.36786316604686e-05 },
271285
{ 0.343966449765075, 0.728166096613485, -0.0721325463785608 },
@@ -390,8 +404,8 @@ inline bool isCTLetterDigit( const char c )
390404
// to represent color temperature(s) (e.g., D60, 3200K)
391405
inline bool isValidCT( string str )
392406
{
393-
int i = 0;
394-
int length = str.length();
407+
int i = 0;
408+
size_t length = str.length();
395409

396410
if ( length == 0 )
397411
return false;

include/rawtoaces/metadata.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Contributors to the rawtoaces project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
// https://github.com/AcademySoftwareFoundation/rawtoaces
4+
5+
#ifndef RTA_METADATA_H_
6+
#define RTA_METADATA_H_
7+
8+
namespace rta
9+
{
10+
11+
struct Metadata
12+
{
13+
// Colorimetry
14+
std::vector<double> cameraCalibration1;
15+
std::vector<double> cameraCalibration2;
16+
std::vector<double> xyz2rgbMatrix1;
17+
std::vector<double> xyz2rgbMatrix2;
18+
double calibrationIlluminant1;
19+
double calibrationIlluminant2;
20+
21+
std::vector<double> analogBalance;
22+
std::vector<double> neutralRGB;
23+
24+
double baselineExposure;
25+
};
26+
27+
} // namespace rta
28+
29+
#endif // RTA_METADATA_H_

include/rawtoaces/rawtoaces_util.h

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright Contributors to the rawtoaces project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
// https://github.com/AcademySoftwareFoundation/rawtoaces
4+
5+
#ifndef _RAWTOACES_UTIL_H_
6+
#define _RAWTOACES_UTIL_H_
7+
8+
#include <OpenImageIO/argparse.h>
9+
#include <OpenImageIO/imageio.h>
10+
#include <OpenImageIO/imagebuf.h>
11+
12+
namespace rta
13+
{
14+
15+
/// An image converter converts an image read from a camera raw image file
16+
/// into an ACESContainer compatible image.
17+
class ImageConverter
18+
{
19+
public:
20+
ImageConverter();
21+
22+
/// The white balancing method to use for conversion can be specified
23+
///
24+
enum class WBMethod
25+
{
26+
/// Use the metadata provided in the image file. This mode is mostly
27+
/// usable with DNG files, as the information needed for conversion
28+
/// is mandatory in the DNG format.
29+
Metadata,
30+
/// White balance to a specified illuminant. See the `illuminant`
31+
/// property for more information on the supported illuminants. This
32+
/// mode can only be used if spectral sensitivities are available for
33+
/// the camera.
34+
Illuminant,
35+
/// Calculate white balance by averaging over a specified region of
36+
/// the image. See `wbBox`. In this mode if an empty box if provided,
37+
/// white balancing is done by averaging over the whole image.
38+
Box,
39+
/// Use custom white balancing multipliers. This mode is useful if
40+
/// the white balancing coefficients are calculated by an external
41+
/// tool.
42+
Custom
43+
} wbMethod = WBMethod::Metadata;
44+
45+
enum class MatrixMethod
46+
{
47+
/// Use the camera spectral sensitivity curves to solve for the colour
48+
/// conversion matrix. In this mode the illuminant is either provided
49+
/// directly in `illuminant` if `wbMethod` ==
50+
/// `WBMethod::Illuminant`, or the best illuminant is derived from the
51+
/// white balancing multipliers.
52+
Spectral,
53+
/// Use the metadata provided in the image file. This mode is mostly
54+
/// usable with DNG files, as the information needed for conversion
55+
/// is mandatory in the DNG format.
56+
Metadata,
57+
/// Use the Adobe colour matrix for the camera supplied in LibRaw.
58+
Adobe,
59+
/// Specify a custom matrix in `colourMatrix`. This mode is useful if
60+
/// the matrix is calculated by an external tool.
61+
Custom
62+
} matrixMethod = MatrixMethod::Spectral;
63+
64+
/// An illuminant to use for white balancing and/or colour matrix
65+
/// calculation. Only used when `wbMethod` ==
66+
/// `WBMethod::Illuminant` or `matrixMethod` == `MatrixMethod::Spectral`.
67+
/// An illuminant can be provided as a black body correlated colour
68+
/// temperature, like `3200K`; or a D-series illuminant, like `D56`;
69+
/// or any other illuminant, in such case it must be present in the data
70+
/// folder.
71+
std::string illuminant;
72+
73+
float headroom = 6.0;
74+
int wbBox[4] = { 0 };
75+
float customWB[4] = { 1.0, 1.0, 1.0, 1.0 };
76+
float customMatrix[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
77+
78+
bool no_auto_bright = false;
79+
float adjust_maximum_threshold = 0.75;
80+
int black_level = -1;
81+
int saturation_level = -1;
82+
bool half_size = false;
83+
int highlight_mode = 0;
84+
int flip = 0;
85+
int cropbox[4] = { 0, 0, 0, 0 };
86+
87+
int verbosity;
88+
89+
/// Returns a class which will be used for parsing the command line
90+
/// parameters. Can be used to add additional parameters before calling
91+
/// `parse()`. The additional parameters will be parsed by ignored by this
92+
/// class.
93+
/// @result A non-const reference to an
94+
/// initialised OIIO::ArgParse class.
95+
OIIO::ArgParse &argParse();
96+
97+
/// Returns an image buffer, containing the image in the current state
98+
/// after the previous step of processing. The image can be modified before
99+
/// executing the next step if needed.
100+
/// @result A non-const reference to the image buffer.
101+
OIIO::ImageBuf &imageBuffer();
102+
103+
/// Parse the command line parameters. This method can be used to
104+
/// configure the converter instead of modifying each conversion parameter
105+
/// individually. Additional command line parameters can be added by
106+
/// modifying the structure returned by `argParse()`.
107+
/// @param argc
108+
/// number of parameters
109+
/// @param argv
110+
/// list of parameters
111+
/// @result
112+
/// `true` if parsed successfully
113+
bool parse( int argc, const char *argv[] );
114+
115+
/// Configures the converter using the requested white balance and colour
116+
/// matrix method, and the metadata of the file provided in `input_file`.
117+
/// @param input_filename
118+
/// A file name of the raw image file to read the metadata from.
119+
/// @result
120+
/// `true` if configured successfully.
121+
bool configure( const std::string &input_filename );
122+
123+
/// Loads an image to convert. Note that the image file name in
124+
/// `input_filename` can be differnt from the one used in `configure()`.
125+
/// This is useful for configuring the converter using one image, and
126+
/// applying the conversion to a different one, or multiple images.
127+
/// @param input_filename
128+
/// A file name of the raw image file to read the pixels from.
129+
/// @result
130+
/// `true` if loaded successfully.
131+
bool load( const std::string &input_filename );
132+
133+
/// Converts the image from raw camera colour space to ACES.
134+
/// @result
135+
/// `true` if converted successfully.
136+
bool process();
137+
138+
/// Saves the image into ACES Container.
139+
/// @result
140+
/// `true` if saved successfully.
141+
bool save( const std::string &output_filename );
142+
143+
private:
144+
void initArgParse();
145+
void prepareIDT_DNG();
146+
void prepareIDT_nonDNG();
147+
void prepareIDT_spectral( bool calc_white_balance, bool calc_matrix );
148+
void applyMatrix( const std::vector<std::vector<double>> &matrix );
149+
150+
bool _is_DNG;
151+
std::string _configFilename;
152+
std::string _cameraMake;
153+
std::string _cameraModel;
154+
155+
OIIO::ArgParse _argParse;
156+
OIIO::ImageSpec _inputHint;
157+
OIIO::ImageSpec _inputFull;
158+
OIIO::ImageBuf _imageBuffer;
159+
160+
std::vector<double> _WB_mults;
161+
std::vector<std::vector<double>> _IDT_matrix;
162+
std::vector<std::vector<double>> _CAT_matrix;
163+
};
164+
165+
} // namespace rta
166+
167+
#endif // _RAWTOACES_UTIL_H_

0 commit comments

Comments
 (0)