Skip to content

Commit

Permalink
Implement OIIO-based version of the tool
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Dukhovnikov <[email protected]>
  • Loading branch information
antond-weta committed Sep 1, 2024
1 parent f0b601d commit 21d5461
Show file tree
Hide file tree
Showing 18 changed files with 1,512 additions and 141 deletions.
31 changes: 19 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
CC: ${{matrix.cc_compiler}}
CMAKE_CXX_STANDARD: ${{matrix.cxx_std}}
OPENEXR_VERSION: ${{matrix.openexr_ver}}
CMAKE_CXX_FLAGS: "-lstdc++fs"
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -83,40 +84,46 @@ jobs:
fail-fast: false

matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
title: [ubuntu, windows, macos]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
- title: windows
os: windows-latest
c_compiler: cl
cpp_compiler: cl
install_deps: install_deps_windows
toolchain_file: "C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
build_shared_libs: OFF
- os: ubuntu-latest
- title: ubuntu
os: ubuntu-24.04
c_compiler: gcc
cpp_compiler: g++
install_deps: install_deps_linux
- os: ubuntu-latest
c_compiler: clang
- title: ubuntu
os: ubuntu-24.04
cpp_compiler: clang++
install_deps: install_deps_linux
- os: macos-latest
- title: macos
os: macos-latest
c_compiler: clang
cpp_compiler: clang++
install_deps: install_deps_mac
exclude:
- os: windows-latest
- title: windows
c_compiler: gcc
- os: windows-latest
- title: windows
c_compiler: clang
- os: ubuntu-latest
- title: ubuntu
c_compiler: cl
- os: macos-latest
- title: macos
c_compiler: cl
- os: macos-latest
- title: macos
c_compiler: gcc

env:
CMAKE_CXX_FLAGS: "-lstdc++fs"

steps:
- uses: actions/checkout@v4

Expand All @@ -140,7 +147,7 @@ jobs:
cmake
-B ${{ steps.strings.outputs.build-output-dir }}
-S ${{ github.workspace }}
-DCXX_STANDARD=C++14
-DCXX_STANDARD=C++17
-DCMAKE_TOOLCHAIN_FILE="${{ matrix.toolchain_file }}"
-DENABLE_SHARED="${{ matrix.build_shared_libs }}"
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ set(RAWTOACESLIB "rawtoaces_util")
set( CMAKE_MACOSX_RPATH 1 )

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# set(warnings "/W4 /WX /EHsc")
add_compile_options ( /W0 )
add_compile_definitions( NOMINMAX )
add_compile_options ( $<$<COMPILE_LANGUAGE:CXX>:/utf-8> )
endif()

if (NOT CONFIGURED_ONCE)
Expand Down Expand Up @@ -76,6 +76,8 @@ add_subdirectory("src/${RAWTOACESIDTLIB}")
add_subdirectory("src/${RAWTOACESLIB}")
add_subdirectory("src/rawtoaces")

add_subdirectory("src/rawtoaces_util2")
add_subdirectory("src/rawtoaces2")

# Create a RAWTOACESBuildTreeSettings.cmake file for the use from the build tree
file(RELATIVE_PATH CONF_REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
Expand Down
1 change: 1 addition & 0 deletions build_scripts/install_deps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ time sudo apt-get update

time sudo apt-get -q -f install -y \
libunwind-dev libilmbase-dev libopenexr-dev \
libopenimageio-dev \
libboost-dev libboost-thread-dev libboost-filesystem-dev \
libboost-test-dev \
libraw-dev libceres-dev
8 changes: 6 additions & 2 deletions build_scripts/install_deps_linux.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ set -ex
time sudo apt-get update

time sudo apt-get -q -f install -y \
libunwind-dev libimath-dev \
libunwind-dev \
libimath-dev libopenexr-dev \
libboost-dev libboost-filesystem-dev \
libboost-test-dev \
libraw-dev libceres-dev
libraw-dev libceres-dev \
libopencv-dev \
openimageio-tools \
libopenimageio-dev
2 changes: 1 addition & 1 deletion build_scripts/install_deps_mac.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -ex

brew install ceres-solver imath openexr libraw boost
brew install ceres-solver imath openexr libraw boost openimageio
1 change: 1 addition & 0 deletions build_scripts/install_deps_windows.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ vcpkg install \
libraw:x64-windows \
ceres:x64-windows \
imath:x64-windows \
openimageio:x64-windows \
boost-system:x64-windows \
boost-foreach:x64-windows \
boost-filesystem:x64-windows \
Expand Down
1 change: 1 addition & 0 deletions configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_INSTALL_PREFIX}/share/CMake")


find_package ( OpenImageIO CONFIG REQUIRED )
find_package ( AcesContainer CONFIG REQUIRED )
find_package ( Eigen3 CONFIG REQUIRED )
find_package ( Imath CONFIG REQUIRED )
Expand Down
18 changes: 16 additions & 2 deletions include/rawtoaces/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ static const double XYZ_acesrgb_4[4][4] = {
{ 0.0, 0.0, 0.0, 1.0 }
};

static const float XYZ_acesrgb_float_4[4][4] = {
{ 1.0498110175, 0.0000000000, -0.0000974845, 0.0 },
{ -0.4959030231, 1.3733130458, 0.0982400361, 0.0 },
{ 0.0000000000, 0.0000000000, 0.9912520182, 0.0 },
{ 0.0, 0.0, 0.0, 1.0 }
};

static const float XYZ_acesrgb_transposed_4[4][4] = {
{ 1.0498110175, -0.4959030231, 0.0000000000, 0.0 },
{ 0.0000000000, 1.3733130458, 0.0000000000, 0.0 },
{ -0.0000974845, 0.0982400361, 0.9912520182, 0.0 },
{ 0.0000000000, 0.0000000000, 0.0000000000, 1.0 }
};

static const double acesrgb_XYZ_3[3][3] = {
{ 0.952552395938186, 0.0, 9.36786316604686e-05 },
{ 0.343966449765075, 0.728166096613485, -0.0721325463785608 },
Expand Down Expand Up @@ -390,8 +404,8 @@ inline bool isCTLetterDigit( const char c )
// to represent color temperature(s) (e.g., D60, 3200K)
inline bool isValidCT( string str )
{
int i = 0;
int length = str.length();
int i = 0;
size_t length = str.length();

if ( length == 0 )
return false;
Expand Down
29 changes: 29 additions & 0 deletions include/rawtoaces/metadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Contributors to the rawtoaces project.
// SPDX-License-Identifier: Apache-2.0
// https://github.com/AcademySoftwareFoundation/rawtoaces

#ifndef RTA_METADATA_H_
#define RTA_METADATA_H_

namespace rta
{

struct Metadata
{
// Colorimetry
std::vector<double> cameraCalibration1;
std::vector<double> cameraCalibration2;
std::vector<double> xyz2rgbMatrix1;
std::vector<double> xyz2rgbMatrix2;
double calibrationIlluminant1;
double calibrationIlluminant2;

std::vector<double> analogBalance;
std::vector<double> neutralRGB;

double baselineExposure;
};

} // namespace rta

#endif // RTA_METADATA_H_
167 changes: 167 additions & 0 deletions include/rawtoaces/rawtoaces_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright Contributors to the rawtoaces project.
// SPDX-License-Identifier: Apache-2.0
// https://github.com/AcademySoftwareFoundation/rawtoaces

#ifndef _RAWTOACES_UTIL_H_
#define _RAWTOACES_UTIL_H_

#include <OpenImageIO/argparse.h>
#include <OpenImageIO/imageio.h>
#include <OpenImageIO/imagebuf.h>

namespace rta
{

/// An image converter converts an image read from a camera raw image file
/// into an ACESContainer compatible image.
class ImageConverter
{
public:
ImageConverter();

/// The white balancing method to use for conversion can be specified
///
enum class WBMethod
{
/// Use the metadata provided in the image file. This mode is mostly
/// usable with DNG files, as the information needed for conversion
/// is mandatory in the DNG format.
Metadata,
/// White balance to a specified illuminant. See the `illuminant`
/// property for more information on the supported illuminants. This
/// mode can only be used if spectral sensitivities are available for
/// the camera.
Illuminant,
/// Calculate white balance by averaging over a specified region of
/// the image. See `wbBox`. In this mode if an empty box if provided,
/// white balancing is done by averaging over the whole image.
Box,
/// Use custom white balancing multipliers. This mode is useful if
/// the white balancing coefficients are calculated by an external
/// tool.
Custom
} wbMethod = WBMethod::Metadata;

enum class MatrixMethod
{
/// Use the camera spectral sensitivity curves to solve for the colour
/// conversion matrix. In this mode the illuminant is either provided
/// directly in `illuminant` if `wbMethod` ==
/// `WBMethod::Illuminant`, or the best illuminant is derived from the
/// white balancing multipliers.
Spectral,
/// Use the metadata provided in the image file. This mode is mostly
/// usable with DNG files, as the information needed for conversion
/// is mandatory in the DNG format.
Metadata,
/// Use the Adobe colour matrix for the camera supplied in LibRaw.
Adobe,
/// Specify a custom matrix in `colourMatrix`. This mode is useful if
/// the matrix is calculated by an external tool.
Custom
} matrixMethod = MatrixMethod::Spectral;

/// An illuminant to use for white balancing and/or colour matrix
/// calculation. Only used when `wbMethod` ==
/// `WBMethod::Illuminant` or `matrixMethod` == `MatrixMethod::Spectral`.
/// An illuminant can be provided as a black body correlated colour
/// temperature, like `3200K`; or a D-series illuminant, like `D56`;
/// or any other illuminant, in such case it must be present in the data
/// folder.
std::string illuminant;

float headroom = 6.0;
int wbBox[4] = { 0 };
float customWB[4] = { 1.0, 1.0, 1.0, 1.0 };
float customMatrix[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };

bool no_auto_bright = false;
float adjust_maximum_threshold = 0.75;
int black_level = -1;
int saturation_level = -1;
bool half_size = false;
int highlight_mode = 0;
int flip = 0;
int cropbox[4] = { 0, 0, 0, 0 };

int verbosity;

/// Returns a class which will be used for parsing the command line
/// parameters. Can be used to add additional parameters before calling
/// `parse()`. The additional parameters will be parsed by ignored by this
/// class.
/// @result A non-const reference to an
/// initialised OIIO::ArgParse class.
OIIO::ArgParse &argParse();

/// Returns an image buffer, containing the image in the current state
/// after the previous step of processing. The image can be modified before
/// executing the next step if needed.
/// @result A non-const reference to the image buffer.
OIIO::ImageBuf &imageBuffer();

/// Parse the command line parameters. This method can be used to
/// configure the converter instead of modifying each conversion parameter
/// individually. Additional command line parameters can be added by
/// modifying the structure returned by `argParse()`.
/// @param argc
/// number of parameters
/// @param argv
/// list of parameters
/// @result
/// `true` if parsed successfully
bool parse( int argc, const char *argv[] );

/// Configures the converter using the requested white balance and colour
/// matrix method, and the metadata of the file provided in `input_file`.
/// @param input_filename
/// A file name of the raw image file to read the metadata from.
/// @result
/// `true` if configured successfully.
bool configure( const std::string &input_filename );

/// Loads an image to convert. Note that the image file name in
/// `input_filename` can be differnt from the one used in `configure()`.
/// This is useful for configuring the converter using one image, and
/// applying the conversion to a different one, or multiple images.
/// @param input_filename
/// A file name of the raw image file to read the pixels from.
/// @result
/// `true` if loaded successfully.
bool load( const std::string &input_filename );

/// Converts the image from raw camera colour space to ACES.
/// @result
/// `true` if converted successfully.
bool process();

/// Saves the image into ACES Container.
/// @result
/// `true` if saved successfully.
bool save( const std::string &output_filename );

private:
void initArgParse();
void prepareIDT_DNG();
void prepareIDT_nonDNG();
void prepareIDT_spectral( bool calc_white_balance, bool calc_matrix );
void applyMatrix( const std::vector<std::vector<double>> &matrix );

bool _is_DNG;
std::string _configFilename;
std::string _cameraMake;
std::string _cameraModel;

OIIO::ArgParse _argParse;
OIIO::ImageSpec _inputHint;
OIIO::ImageSpec _inputFull;
OIIO::ImageBuf _imageBuffer;

std::vector<double> _WB_mults;
std::vector<std::vector<double>> _IDT_matrix;
std::vector<std::vector<double>> _CAT_matrix;
};

} // namespace rta

#endif // _RAWTOACES_UTIL_H_
Loading

0 comments on commit 21d5461

Please sign in to comment.