@@ -13,6 +13,9 @@ using namespace ceres;
1313
1414namespace rta
1515{
16+ namespace core
17+ {
18+
1619Illum::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
15601501double 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>
16511593DNGIdt::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
17891729void 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
0 commit comments