Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/rawtoaces/acesrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <rawtoaces/rta.h>

#include <unordered_map>
#include <libraw/libraw.h>

using namespace rta;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion is to remove this namespace and replace those instances of core::Idt with rta::core::Idt here and in .cpp file

to avoid polluting consumers’ namespaces from a public header. Public headers should not inject namespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this is unrelated to the change. Trying to keep the scope of each PR limited.
I generally dislike the using namespace thing, we should get rid of those in a separate PR, at least in the public headers.


Expand Down Expand Up @@ -72,7 +73,7 @@ class AcesRender
const AcesRender &operator=( const AcesRender &acesrender );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion is to move impl. bit of LibRawAces into .cpp
so lines 17-24 replace with class LibRawAces; and move all this into .cpp instead

char *_pathToRaw;
Idt *_idt;
core::Idt *_idt;
libraw_processed_image_t *_image;
LibRawAces *_rawProcessor;

Expand Down
77 changes: 55 additions & 22 deletions include/rawtoaces/rta.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the rawtoaces Project.

#ifndef _RTA_h__
#define _RTA_h__
#pragma once

#include "define.h"

#include <stdint.h>
#include <libraw/libraw.h>

using namespace std;

namespace rta
{
struct CIEXYZ
namespace core
{
CIEXYZ(){};
CIEXYZ( double X, double Y, double Z ) : _Xt( X ), _Yt( Y ), _Zt( Z ){};
double _Xt;
double _Yt;
double _Zt;
};

struct trainSpec
{
Expand Down Expand Up @@ -171,12 +163,61 @@ class Idt
vector<vector<double>> _idt;
};

struct Metadata
{
struct Calibration
{
unsigned short illuminant = 0;
std::vector<double> cameraCalibrationMatrix;
std::vector<double> xyz2rgbMatrix;

friend bool operator==( const Calibration &c1, const Calibration &c2 )
{
if ( c1.illuminant != c2.illuminant )
return false;
if ( c1.cameraCalibrationMatrix != c2.cameraCalibrationMatrix )
return false;
if ( c1.xyz2rgbMatrix != c2.xyz2rgbMatrix )
return false;

return true;
}

friend bool operator!=( const Calibration &c1, const Calibration &c2 )
{
return !( c1 == c2 );
}
} calibration[2];

std::vector<double> neutralRGB;
double baselineExposure = 0.0;

friend bool operator==( const Metadata &m1, const Metadata &m2 )
{
if ( m1.calibration[0] != m2.calibration[0] )
return false;
if ( m1.calibration[1] != m2.calibration[1] )
return false;
if ( m1.baselineExposure != m2.baselineExposure )
return false;
if ( m1.neutralRGB != m2.neutralRGB )
return false;

return true;
}

friend bool operator!=( const Metadata &m1, const Metadata &m2 )
{
return !( m1 == m2 );
}
};

class DNGIdt
{
core::Metadata _metadata;

public:
DNGIdt();
DNGIdt( libraw_rawdata_t R );
virtual ~DNGIdt();
DNGIdt( const core::Metadata &metadata );

double ccttoMired( const double cct ) const;
double robertsonLength(
Expand All @@ -196,16 +237,8 @@ class DNGIdt
void getCameraXYZMtxAndWhitePoint();

private:
vector<double> _cameraCalibration1DNG;
vector<double> _cameraCalibration2DNG;
vector<double> _cameraToXYZMtx;
vector<double> _xyz2rgbMatrix1DNG;
vector<double> _xyz2rgbMatrix2DNG;
vector<double> _analogBalanceDNG;
vector<double> _neutralRGBDNG;
vector<double> _cameraXYZWhitePoint;
vector<double> _calibrateIllum;
double _baseExpo;
};

struct Objfun
Expand All @@ -222,5 +255,5 @@ struct Objfun
const vector<vector<double>> _outLAB;
};

} // namespace core
} // namespace rta
#endif
8 changes: 0 additions & 8 deletions src/rawtoaces_idt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ else ()
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC ${CERES_LIBRARIES})
endif ()

if ( LIBRAW_CONFIG_FOUND )
target_link_libraries ( ${RAWTOACESIDTLIB} PUBLIC libraw::raw )
else ()
target_include_directories(${RAWTOACESIDTLIB} PUBLIC ${libraw_INCLUDE_DIR} )
target_link_directories(${RAWTOACESIDTLIB} PUBLIC ${libraw_LIBRARY_DIRS} )
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC ${libraw_LIBRARIES} ${libraw_LDFLAGS_OTHER} )
endif ()

target_include_directories( ${RAWTOACESIDTLIB} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include>
$<INSTALL_INTERFACE:./include>
Expand Down
102 changes: 22 additions & 80 deletions src/rawtoaces_idt/rta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ using namespace ceres;

namespace rta
{
namespace core
{

Illum::Illum()
{
_inc = 5;
Expand Down Expand Up @@ -1492,70 +1495,8 @@ const vector<double> Idt::getWB() const

// ------------------------------------------------------//

DNGIdt::DNGIdt()
{
_cameraCalibration1DNG = vector<double>( 9, 1.0 );
_cameraCalibration2DNG = vector<double>( 9, 1.0 );
_cameraToXYZMtx = vector<double>( 9, 1.0 );
_xyz2rgbMatrix1DNG = vector<double>( 9, 1.0 );
_xyz2rgbMatrix2DNG = vector<double>( 9, 1.0 );
_analogBalanceDNG = vector<double>( 3, 1.0 );
_neutralRGBDNG = vector<double>( 3, 1.0 );
_cameraXYZWhitePoint = vector<double>( 3, 1.0 );
_calibrateIllum = vector<double>( 2, 1.0 );
_baseExpo = 1.0;
}

DNGIdt::DNGIdt( libraw_rawdata_t R )
{
_cameraCalibration1DNG = vector<double>( 9, 1.0 );
_cameraCalibration2DNG = vector<double>( 9, 1.0 );
_cameraToXYZMtx = vector<double>( 9, 1.0 );
_xyz2rgbMatrix1DNG = vector<double>( 9, 1.0 );
_xyz2rgbMatrix2DNG = vector<double>( 9, 1.0 );
_analogBalanceDNG = vector<double>( 3, 1.0 );
_neutralRGBDNG = vector<double>( 3, 1.0 );
_cameraXYZWhitePoint = vector<double>( 3, 1.0 );
_calibrateIllum = vector<double>( 2, 1.0 );

#if LIBRAW_VERSION >= LIBRAW_MAKE_VERSION( 0, 20, 0 )
_baseExpo = static_cast<double>( R.color.dng_levels.baseline_exposure );
#else
_baseExpo = static_cast<double>( R.color.baseline_exposure );
#endif
_calibrateIllum[0] = static_cast<double>( R.color.dng_color[0].illuminant );
_calibrateIllum[1] = static_cast<double>( R.color.dng_color[1].illuminant );

FORI( 3 )
{
_neutralRGBDNG[i] = 1.0 / static_cast<double>( R.color.cam_mul[i] );
}

FORIJ( 3, 3 )
{
_xyz2rgbMatrix1DNG[i * 3 + j] =
static_cast<double>( ( R.color.dng_color[0].colormatrix )[i][j] );
_xyz2rgbMatrix2DNG[i * 3 + j] =
static_cast<double>( ( R.color.dng_color[1].colormatrix )[i][j] );
_cameraCalibration1DNG[i * 3 + j] =
static_cast<double>( ( R.color.dng_color[0].calibration )[i][j] );
_cameraCalibration2DNG[i * 3 + j] =
static_cast<double>( ( R.color.dng_color[1].calibration )[i][j] );
}
}

DNGIdt::~DNGIdt()
{
clearVM( _cameraCalibration1DNG );
clearVM( _cameraCalibration2DNG );
clearVM( _cameraToXYZMtx );
clearVM( _xyz2rgbMatrix1DNG );
clearVM( _xyz2rgbMatrix2DNG );
clearVM( _analogBalanceDNG );
clearVM( _neutralRGBDNG );
clearVM( _cameraXYZWhitePoint );
clearVM( _calibrateIllum );
}
DNGIdt::DNGIdt( const core::Metadata &metadata ) : _metadata( metadata )
{}

double DNGIdt::ccttoMired( const double cct ) const
{
Expand Down Expand Up @@ -1639,10 +1580,11 @@ vector<double> DNGIdt::XYZtoCameraWeightedMatrix(

double weight =
std::max( 0.0, std::min( 1.0, ( mir1 - mir0 ) / ( mir1 - mir2 ) ) );
vector<double> result =
subVectors( _xyz2rgbMatrix2DNG, _xyz2rgbMatrix1DNG );
vector<double> result = subVectors(
_metadata.calibration[1].xyz2rgbMatrix,
_metadata.calibration[0].xyz2rgbMatrix );
scaleVector( result, weight );
result = addVectors( result, _xyz2rgbMatrix1DNG );
result = addVectors( result, _metadata.calibration[0].xyz2rgbMatrix );

return result;
}
Expand All @@ -1651,22 +1593,20 @@ vector<double>
DNGIdt::findXYZtoCameraMtx( const vector<double> &neutralRGB ) const
{

if ( _calibrateIllum.size() == 0 )
if ( _metadata.calibration[0].illuminant == 0 )
{
fprintf( stderr, " No calibration illuminants were found. \n " );
return _xyz2rgbMatrix1DNG;
return _metadata.calibration[0].xyz2rgbMatrix;
}

if ( neutralRGB.size() == 0 )
{
fprintf( stderr, " no neutral RGB values were found. \n " );
return _xyz2rgbMatrix1DNG;
return _metadata.calibration[0].xyz2rgbMatrix;
}

double cct1 = lightSourceToColorTemp(
static_cast<const unsigned short>( _calibrateIllum[0] ) );
double cct2 = lightSourceToColorTemp(
static_cast<const unsigned short>( _calibrateIllum[1] ) );
double cct1 = lightSourceToColorTemp( _metadata.calibration[0].illuminant );
double cct2 = lightSourceToColorTemp( _metadata.calibration[1].illuminant );

double mir1 = ccttoMired( cct1 );
double mir2 = ccttoMired( cct2 );
Expand All @@ -1688,7 +1628,7 @@ DNGIdt::findXYZtoCameraMtx( const vector<double> &neutralRGB ) const
lerror =
mir - ccttoMired( XYZToColorTemperature( mulVector(
invertV( XYZtoCameraWeightedMatrix( mir, mir1, mir2 ) ),
_neutralRGBDNG ) ) );
neutralRGB ) ) );

if ( std::fabs( lerror - 0.0 ) <= 1e-09 )
{
Expand Down Expand Up @@ -1788,19 +1728,20 @@ vector<double> DNGIdt::matrixRGBtoXYZ( const double chromaticities[][2] ) const

void DNGIdt::getCameraXYZMtxAndWhitePoint()
{
_cameraToXYZMtx = invertV( findXYZtoCameraMtx( _neutralRGBDNG ) );
_cameraToXYZMtx = invertV( findXYZtoCameraMtx( _metadata.neutralRGB ) );
assert( std::fabs( sumVector( _cameraToXYZMtx ) - 0.0 ) > 1e-09 );

scaleVector( _cameraToXYZMtx, std::pow( 2.0, _baseExpo ) );
scaleVector( _cameraToXYZMtx, std::pow( 2.0, _metadata.baselineExposure ) );

if ( _neutralRGBDNG.size() > 0 )
if ( _metadata.neutralRGB.size() > 0 )
{
_cameraXYZWhitePoint = mulVector( _cameraToXYZMtx, _neutralRGBDNG );
_cameraXYZWhitePoint =
mulVector( _cameraToXYZMtx, _metadata.neutralRGB );
}
else
{
_cameraXYZWhitePoint = colorTemperatureToXYZ(
lightSourceToColorTemp( _calibrateIllum[0] ) );
lightSourceToColorTemp( _metadata.calibration[0].illuminant ) );
}

scaleVector( _cameraXYZWhitePoint, 1.0 / _cameraXYZWhitePoint[1] );
Expand Down Expand Up @@ -1866,4 +1807,5 @@ template <typename T> bool Objfun::operator()( const T *B, T *residuals ) const
return true;
}

} // namespace core
} // namespace rta
1 change: 1 addition & 0 deletions src/rawtoaces_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ target_link_libraries ( ${RAWTOACESLIB}
if ( LIBRAW_CONFIG_FOUND )
target_link_libraries ( ${RAWTOACESLIB} PUBLIC libraw::raw )
else ()
target_include_directories(${RAWTOACESLIB} PUBLIC ${libraw_INCLUDE_DIR} )
target_link_directories(${RAWTOACESLIB} PUBLIC ${libraw_LIBRARY_DIRS} )
target_link_libraries(${RAWTOACESLIB} PUBLIC ${libraw_LIBRARIES} ${libraw_LDFLAGS_OTHER} )
endif ()
Expand Down
Loading
Loading