Skip to content

Commit f8652f1

Browse files
committed
remove the dependency on libraw from the core library
Signed-off-by: Anton Dukhovnikov <[email protected]>
1 parent a8bad07 commit f8652f1

File tree

11 files changed

+203
-138
lines changed

11 files changed

+203
-138
lines changed

include/rawtoaces/acesrender.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <rawtoaces/rta.h>
88

99
#include <unordered_map>
10+
#include <libraw/libraw.h>
1011

1112
using namespace rta;
1213

@@ -72,7 +73,7 @@ class AcesRender
7273
const AcesRender &operator=( const AcesRender &acesrender );
7374

7475
char *_pathToRaw;
75-
Idt *_idt;
76+
core::Idt *_idt;
7677
libraw_processed_image_t *_image;
7778
LibRawAces *_rawProcessor;
7879

include/rawtoaces/rta.h

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Contributors to the rawtoaces Project.
33

4-
#ifndef _RTA_h__
5-
#define _RTA_h__
4+
#pragma once
65

76
#include "define.h"
87

98
#include <stdint.h>
10-
#include <libraw/libraw.h>
119

1210
using namespace std;
1311

1412
namespace rta
1513
{
16-
struct CIEXYZ
14+
namespace core
1715
{
18-
CIEXYZ(){};
19-
CIEXYZ( double X, double Y, double Z ) : _Xt( X ), _Yt( Y ), _Zt( Z ){};
20-
double _Xt;
21-
double _Yt;
22-
double _Zt;
23-
};
2416

2517
struct trainSpec
2618
{
@@ -171,12 +163,61 @@ class Idt
171163
vector<vector<double>> _idt;
172164
};
173165

166+
struct Metadata
167+
{
168+
struct Calibration
169+
{
170+
unsigned short illuminant = 0;
171+
std::vector<double> cameraCalibrationMatrix;
172+
std::vector<double> xyz2rgbMatrix;
173+
174+
friend bool operator==( const Calibration &c1, const Calibration &c2 )
175+
{
176+
if ( c1.illuminant != c2.illuminant )
177+
return false;
178+
if ( c1.cameraCalibrationMatrix != c2.cameraCalibrationMatrix )
179+
return false;
180+
if ( c1.xyz2rgbMatrix != c2.xyz2rgbMatrix )
181+
return false;
182+
183+
return true;
184+
}
185+
186+
friend bool operator!=( const Calibration &c1, const Calibration &c2 )
187+
{
188+
return !( c1 == c2 );
189+
}
190+
} calibration[2];
191+
192+
std::vector<double> neutralRGB;
193+
double baselineExposure = 0.0;
194+
195+
friend bool operator==( const Metadata &m1, const Metadata &m2 )
196+
{
197+
if ( m1.calibration[0] != m2.calibration[0] )
198+
return false;
199+
if ( m1.calibration[1] != m2.calibration[1] )
200+
return false;
201+
if ( m1.baselineExposure != m2.baselineExposure )
202+
return false;
203+
if ( m1.neutralRGB != m2.neutralRGB )
204+
return false;
205+
206+
return true;
207+
}
208+
209+
friend bool operator!=( const Metadata &m1, const Metadata &m2 )
210+
{
211+
return !( m1 == m2 );
212+
}
213+
};
214+
174215
class DNGIdt
175216
{
217+
core::Metadata _metadata;
218+
176219
public:
177-
DNGIdt();
178-
DNGIdt( libraw_rawdata_t R );
179-
virtual ~DNGIdt();
220+
DNGIdt( const core::Metadata &metadata );
180221

181222
double ccttoMired( const double cct ) const;
182223
double robertsonLength(
@@ -196,16 +237,8 @@ class DNGIdt
196237
void getCameraXYZMtxAndWhitePoint();
197238

198239
private:
199-
vector<double> _cameraCalibration1DNG;
200-
vector<double> _cameraCalibration2DNG;
201240
vector<double> _cameraToXYZMtx;
202-
vector<double> _xyz2rgbMatrix1DNG;
203-
vector<double> _xyz2rgbMatrix2DNG;
204-
vector<double> _analogBalanceDNG;
205-
vector<double> _neutralRGBDNG;
206241
vector<double> _cameraXYZWhitePoint;
207-
vector<double> _calibrateIllum;
208-
double _baseExpo;
209242
};
210243

211244
struct Objfun
@@ -222,5 +255,5 @@ struct Objfun
222255
const vector<vector<double>> _outLAB;
223256
};
224257

258+
} // namespace core
225259
} // namespace rta
226-
#endif

src/rawtoaces_idt/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ else ()
3131
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC ${CERES_LIBRARIES})
3232
endif ()
3333

34-
if ( LIBRAW_CONFIG_FOUND )
35-
target_link_libraries ( ${RAWTOACESIDTLIB} PUBLIC libraw::raw )
36-
else ()
37-
target_include_directories(${RAWTOACESIDTLIB} PUBLIC ${libraw_INCLUDE_DIR} )
38-
target_link_directories(${RAWTOACESIDTLIB} PUBLIC ${libraw_LIBRARY_DIRS} )
39-
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC ${libraw_LIBRARIES} ${libraw_LDFLAGS_OTHER} )
40-
endif ()
41-
4234
target_include_directories( ${RAWTOACESIDTLIB} PUBLIC
4335
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include>
4436
$<INSTALL_INTERFACE:./include>

src/rawtoaces_idt/rta.cpp

Lines changed: 22 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ using namespace ceres;
1313

1414
namespace rta
1515
{
16+
namespace core
17+
{
18+
1619
Illum::Illum()
1720
{
1821
_inc = 5;
@@ -1492,70 +1495,8 @@ const vector<double> Idt::getWB() const
14921495

14931496
// ------------------------------------------------------//
14941497

1495-
DNGIdt::DNGIdt()
1496-
{
1497-
_cameraCalibration1DNG = vector<double>( 9, 1.0 );
1498-
_cameraCalibration2DNG = vector<double>( 9, 1.0 );
1499-
_cameraToXYZMtx = vector<double>( 9, 1.0 );
1500-
_xyz2rgbMatrix1DNG = vector<double>( 9, 1.0 );
1501-
_xyz2rgbMatrix2DNG = vector<double>( 9, 1.0 );
1502-
_analogBalanceDNG = vector<double>( 3, 1.0 );
1503-
_neutralRGBDNG = vector<double>( 3, 1.0 );
1504-
_cameraXYZWhitePoint = vector<double>( 3, 1.0 );
1505-
_calibrateIllum = vector<double>( 2, 1.0 );
1506-
_baseExpo = 1.0;
1507-
}
1508-
1509-
DNGIdt::DNGIdt( libraw_rawdata_t R )
1510-
{
1511-
_cameraCalibration1DNG = vector<double>( 9, 1.0 );
1512-
_cameraCalibration2DNG = vector<double>( 9, 1.0 );
1513-
_cameraToXYZMtx = vector<double>( 9, 1.0 );
1514-
_xyz2rgbMatrix1DNG = vector<double>( 9, 1.0 );
1515-
_xyz2rgbMatrix2DNG = vector<double>( 9, 1.0 );
1516-
_analogBalanceDNG = vector<double>( 3, 1.0 );
1517-
_neutralRGBDNG = vector<double>( 3, 1.0 );
1518-
_cameraXYZWhitePoint = vector<double>( 3, 1.0 );
1519-
_calibrateIllum = vector<double>( 2, 1.0 );
1520-
1521-
#if LIBRAW_VERSION >= LIBRAW_MAKE_VERSION( 0, 20, 0 )
1522-
_baseExpo = static_cast<double>( R.color.dng_levels.baseline_exposure );
1523-
#else
1524-
_baseExpo = static_cast<double>( R.color.baseline_exposure );
1525-
#endif
1526-
_calibrateIllum[0] = static_cast<double>( R.color.dng_color[0].illuminant );
1527-
_calibrateIllum[1] = static_cast<double>( R.color.dng_color[1].illuminant );
1528-
1529-
FORI( 3 )
1530-
{
1531-
_neutralRGBDNG[i] = 1.0 / static_cast<double>( R.color.cam_mul[i] );
1532-
}
1533-
1534-
FORIJ( 3, 3 )
1535-
{
1536-
_xyz2rgbMatrix1DNG[i * 3 + j] =
1537-
static_cast<double>( ( R.color.dng_color[0].colormatrix )[i][j] );
1538-
_xyz2rgbMatrix2DNG[i * 3 + j] =
1539-
static_cast<double>( ( R.color.dng_color[1].colormatrix )[i][j] );
1540-
_cameraCalibration1DNG[i * 3 + j] =
1541-
static_cast<double>( ( R.color.dng_color[0].calibration )[i][j] );
1542-
_cameraCalibration2DNG[i * 3 + j] =
1543-
static_cast<double>( ( R.color.dng_color[1].calibration )[i][j] );
1544-
}
1545-
}
1546-
1547-
DNGIdt::~DNGIdt()
1548-
{
1549-
clearVM( _cameraCalibration1DNG );
1550-
clearVM( _cameraCalibration2DNG );
1551-
clearVM( _cameraToXYZMtx );
1552-
clearVM( _xyz2rgbMatrix1DNG );
1553-
clearVM( _xyz2rgbMatrix2DNG );
1554-
clearVM( _analogBalanceDNG );
1555-
clearVM( _neutralRGBDNG );
1556-
clearVM( _cameraXYZWhitePoint );
1557-
clearVM( _calibrateIllum );
1558-
}
1498+
DNGIdt::DNGIdt( const core::Metadata &metadata ) : _metadata( metadata )
1499+
{}
15591500

15601501
double DNGIdt::ccttoMired( const double cct ) const
15611502
{
@@ -1639,10 +1580,11 @@ vector<double> DNGIdt::XYZtoCameraWeightedMatrix(
16391580

16401581
double weight =
16411582
std::max( 0.0, std::min( 1.0, ( mir1 - mir0 ) / ( mir1 - mir2 ) ) );
1642-
vector<double> result =
1643-
subVectors( _xyz2rgbMatrix2DNG, _xyz2rgbMatrix1DNG );
1583+
vector<double> result = subVectors(
1584+
_metadata.calibration[1].xyz2rgbMatrix,
1585+
_metadata.calibration[0].xyz2rgbMatrix );
16441586
scaleVector( result, weight );
1645-
result = addVectors( result, _xyz2rgbMatrix1DNG );
1587+
result = addVectors( result, _metadata.calibration[0].xyz2rgbMatrix );
16461588

16471589
return result;
16481590
}
@@ -1651,22 +1593,20 @@ vector<double>
16511593
DNGIdt::findXYZtoCameraMtx( const vector<double> &neutralRGB ) const
16521594
{
16531595

1654-
if ( _calibrateIllum.size() == 0 )
1596+
if ( _metadata.calibration[0].illuminant == 0 )
16551597
{
16561598
fprintf( stderr, " No calibration illuminants were found. \n " );
1657-
return _xyz2rgbMatrix1DNG;
1599+
return _metadata.calibration[0].xyz2rgbMatrix;
16581600
}
16591601

16601602
if ( neutralRGB.size() == 0 )
16611603
{
16621604
fprintf( stderr, " no neutral RGB values were found. \n " );
1663-
return _xyz2rgbMatrix1DNG;
1605+
return _metadata.calibration[0].xyz2rgbMatrix;
16641606
}
16651607

1666-
double cct1 = lightSourceToColorTemp(
1667-
static_cast<const unsigned short>( _calibrateIllum[0] ) );
1668-
double cct2 = lightSourceToColorTemp(
1669-
static_cast<const unsigned short>( _calibrateIllum[1] ) );
1608+
double cct1 = lightSourceToColorTemp( _metadata.calibration[0].illuminant );
1609+
double cct2 = lightSourceToColorTemp( _metadata.calibration[1].illuminant );
16701610

16711611
double mir1 = ccttoMired( cct1 );
16721612
double mir2 = ccttoMired( cct2 );
@@ -1688,7 +1628,7 @@ DNGIdt::findXYZtoCameraMtx( const vector<double> &neutralRGB ) const
16881628
lerror =
16891629
mir - ccttoMired( XYZToColorTemperature( mulVector(
16901630
invertV( XYZtoCameraWeightedMatrix( mir, mir1, mir2 ) ),
1691-
_neutralRGBDNG ) ) );
1631+
_metadata.neutralRGB ) ) );
16921632

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

17891729
void DNGIdt::getCameraXYZMtxAndWhitePoint()
17901730
{
1791-
_cameraToXYZMtx = invertV( findXYZtoCameraMtx( _neutralRGBDNG ) );
1731+
_cameraToXYZMtx = invertV( findXYZtoCameraMtx( _metadata.neutralRGB ) );
17921732
assert( std::fabs( sumVector( _cameraToXYZMtx ) - 0.0 ) > 1e-09 );
17931733

1794-
scaleVector( _cameraToXYZMtx, std::pow( 2.0, _baseExpo ) );
1734+
scaleVector( _cameraToXYZMtx, std::pow( 2.0, _metadata.baselineExposure ) );
17951735

1796-
if ( _neutralRGBDNG.size() > 0 )
1736+
if ( _metadata.neutralRGB.size() > 0 )
17971737
{
1798-
_cameraXYZWhitePoint = mulVector( _cameraToXYZMtx, _neutralRGBDNG );
1738+
_cameraXYZWhitePoint =
1739+
mulVector( _cameraToXYZMtx, _metadata.neutralRGB );
17991740
}
18001741
else
18011742
{
18021743
_cameraXYZWhitePoint = colorTemperatureToXYZ(
1803-
lightSourceToColorTemp( _calibrateIllum[0] ) );
1744+
lightSourceToColorTemp( _metadata.calibration[0].illuminant ) );
18041745
}
18051746

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

1810+
} // namespace core
18691811
} // namespace rta

src/rawtoaces_util/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ target_link_libraries ( ${RAWTOACESLIB}
3434
if ( LIBRAW_CONFIG_FOUND )
3535
target_link_libraries ( ${RAWTOACESLIB} PUBLIC libraw::raw )
3636
else ()
37+
target_include_directories(${RAWTOACESLIB} PUBLIC ${libraw_INCLUDE_DIR} )
3738
target_link_directories(${RAWTOACESLIB} PUBLIC ${libraw_LIBRARY_DIRS} )
3839
target_link_libraries(${RAWTOACESLIB} PUBLIC ${libraw_LIBRARIES} ${libraw_LDFLAGS_OTHER} )
3940
endif ()

0 commit comments

Comments
 (0)