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
4 changes: 1 addition & 3 deletions src/rawtoaces_core/rawtoaces_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ double XYZ_to_color_temperature( const vector<double> &XYZ )
distance_prev = distance_this;
}

if ( i <= 0 )
if ( i == 0 )
mired = robertson_mired_table[0];
else if ( i >= num_robertson_table )
mired = robertson_mired_table[num_robertson_table - 1];
Expand Down Expand Up @@ -1159,8 +1159,6 @@ void get_camera_XYZ_matrix_and_white_point(
scaleVector(
out_camera_XYZ_white_point, 1.0 / out_camera_XYZ_white_point[1] );
assert( sumVector( out_camera_XYZ_white_point ) != 0 );

return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps that line is unreachable because of the return, can we try removing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeap. that was it.


vector<vector<double>> MetadataSolver::calculate_CAT_matrix()
Expand Down
14 changes: 7 additions & 7 deletions src/rawtoaces_core/spectral_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ static Val_or_Ref op( Val_or_Ref lhs, const Spectrum &rhs, F func )
Spectrum operator+( Spectrum lhs, const Spectrum &rhs )
{
return op<Spectrum>( lhs, rhs, std::plus<double>() );
}
} // LCOV_EXCL_LINE - bug in coverage tool

Spectrum operator-( Spectrum lhs, const Spectrum &rhs )
{
return op<Spectrum>( lhs, rhs, std::minus<double>() );
}
} // LCOV_EXCL_LINE - bug in coverage tool

Spectrum operator*( Spectrum lhs, const Spectrum &rhs )
{
return op<Spectrum>( lhs, rhs, std::multiplies<double>() );
}
} // LCOV_EXCL_LINE - bug in coverage tool

Spectrum operator/( Spectrum lhs, const Spectrum &rhs )
{
return op<Spectrum>( lhs, rhs, std::divides<double>() );
}
} // LCOV_EXCL_LINE - bug in coverage tool

Spectrum &Spectrum::operator+=( const Spectrum &rhs )
{
Expand Down Expand Up @@ -359,7 +359,7 @@ Spectrum &SpectralData::get( std::string set_name, std::string channel_name )
"' of spectral data." );
}
return it->second;
}
} // LCOV_EXCL_LINE - bug in coverage tool

const Spectrum &
SpectralData::get( std::string set_name, std::string channel_name ) const
Expand All @@ -379,12 +379,12 @@ SpectralData::get( std::string set_name, std::string channel_name ) const
Spectrum &SpectralData::operator[]( std::string name )
{
return get( "main", name );
}
} // LCOV_EXCL_LINE - bug in coverage tool

const Spectrum &SpectralData::operator[]( std::string name ) const
{
return get( "main", name );
}
} // LCOV_EXCL_LINE - bug in coverage tool

} // namespace core
} // namespace rta
5 changes: 4 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_test ( NAME Test_SpectralData COMMAND Test_SpectralData )
add_executable (
Test_IDT
testIDT.cpp
test_utils.cpp
)

target_link_libraries(
Expand Down Expand Up @@ -104,6 +105,7 @@ add_test ( NAME Test_Illum COMMAND Test_Illum )
add_executable (
Test_DNGIdt
testDNGIdt.cpp
test_utils.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely happy with exposing the rawtoaces_util code in the rawtoaces_core tests as an implicit dependency.
Hopefully we'll redo the logging soon, so the stderr capturing won't be needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hopefully I got what you mean and did what asked.

)

target_link_libraries(
Expand Down Expand Up @@ -191,6 +193,7 @@ add_executable (
Test_ImageConverter
test_image_converter.cpp
test_utils.cpp
test_utils_image_converter.cpp
)

target_link_libraries(
Expand Down Expand Up @@ -235,4 +238,4 @@ if( ENABLE_COVERAGE AND COVERAGE_SUPPORTED )
add_subdirectory(config_tests/util)

generate_coverage_report()
endif()
endif()
178 changes: 167 additions & 11 deletions tests/testDNGIdt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

#include <rawtoaces/rawtoaces_core.h>
#include "../src/rawtoaces_core/define.h"
#include "../src/rawtoaces_core/mathOps.h"
#include "../src/rawtoaces_core/rawtoaces_core_priv.h"
#include "test_utils.h"

void testIDT_CcttoMired()
{
Expand All @@ -32,6 +34,48 @@ void testIDT_LightSourceToColorTemp()
OIIO_CHECK_EQUAL_THRESH( ct, 2856.0, 1e-5 );
}

void testIDT_LightSourceToColorTemp_Extended()
{
/// Test extended value (tag >= 32768): tag 32768 should return 0.0
unsigned short tag = 32768;
double ct = rta::core::light_source_to_color_temp( tag );
OIIO_CHECK_EQUAL_THRESH( ct, 0.0, 1e-5 );

/// Test extended value: tag 37768 (32768 + 5000) should return 5000.0
tag = 37768;
ct = rta::core::light_source_to_color_temp( tag );
OIIO_CHECK_EQUAL_THRESH( ct, 5000.0, 1e-5 );

/// Test extended value: tag 40000 (32768 + 7232) should return 7232.0
tag = 40000;
ct = rta::core::light_source_to_color_temp( tag );
OIIO_CHECK_EQUAL_THRESH( ct, 7232.0, 1e-5 );
}

void testIDT_LightSourceToColorTemp_Default()
{
/// Test unknown tag values fall back to daylight default (5500K).
unsigned short tag = 999;
double ct = rta::core::light_source_to_color_temp( tag );
OIIO_CHECK_EQUAL_THRESH( ct, 5500.0, 1e-5 );
}

static const std::vector<double> k_calibration_0_xyz_to_rgb = {
1.3119699954986572, -0.49678999185562134, 0.011559999547898769,
-0.41723001003265381, 1.4423700571060181, 0.045279998332262039,
0.067230001091957092, 0.21709999442100525, 0.72650998830795288
};

static const std::vector<double> k_calibration_1_xyz_to_rgb = {
1.0088499784469604, -0.27351000905036926, -0.082580000162124634,
-0.48996999859809875, 1.3444099426269531, 0.11174000054597855,
-0.064060002565383911, 0.32997000217437744, 0.5391700267791748
};

static const std::vector<double> k_identity_xyz_to_rgb = { 1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0 };

void init_metadata( rta::core::Metadata &metadata )
{
metadata.baseline_exposure = 2.4;
Expand All @@ -41,17 +85,8 @@ void init_metadata( rta::core::Metadata &metadata )
metadata.calibration[0].illuminant = 17;
metadata.calibration[1].illuminant = 21;

metadata.calibration[0].XYZ_to_RGB_matrix = {
1.3119699954986572, -0.49678999185562134, 0.011559999547898769,
-0.41723001003265381, 1.4423700571060181, 0.045279998332262039,
0.067230001091957092, 0.21709999442100525, 0.72650998830795288
};

metadata.calibration[1].XYZ_to_RGB_matrix = {
1.0088499784469604, -0.27351000905036926, -0.082580000162124634,
-0.48996999859809875, 1.3444099426269531, 0.11174000054597855,
-0.064060002565383911, 0.32997000217437744, 0.5391700267791748
};
metadata.calibration[0].XYZ_to_RGB_matrix = k_calibration_0_xyz_to_rgb;
metadata.calibration[1].XYZ_to_RGB_matrix = k_calibration_1_xyz_to_rgb;
}

void testIDT_XYZToColorTemperature()
Expand All @@ -63,6 +98,26 @@ void testIDT_XYZToColorTemperature()
OIIO_CHECK_EQUAL_THRESH( cct, 5564.6648479019, 1e-5 );
}

void testIDT_XYZToColorTemperature_UpperClamp()
{
/// UV exactly at the first Robertson entry should clamp to 50000K.
const double huge_cct = 1.0e16;
std::vector<double> XYZ = rta::core::color_temperature_to_XYZ( huge_cct );
double cct = rta::core::XYZ_to_color_temperature( XYZ );

OIIO_CHECK_EQUAL_THRESH( cct, 50000.0, 1e-5 );
}

void testIDT_XYZToColorTemperature_LowerClamp()
{
/// UV slightly above the Robertson table should clamp to 2000K.
std::vector<double> XYZ =
rta::core::uv_to_XYZ( std::vector<double>{ 0.34, 0.361 } );
double cct = rta::core::XYZ_to_color_temperature( XYZ );

OIIO_CHECK_EQUAL_THRESH( cct, 2000.0, 1e-5 );
}

void testIDT_XYZtoCameraWeightedMatrix()
{
rta::core::Metadata metadata;
Expand Down Expand Up @@ -105,6 +160,66 @@ void testIDT_FindXYZtoCameraMtx()
OIIO_CHECK_EQUAL_THRESH( result[i], matrix[i], 1e-5 );
}

void testIDT_FindXYZtoCameraMtx_NoIlluminant()
{
rta::core::Metadata metadata;
init_metadata( metadata );
metadata.calibration[0].illuminant = 0;

std::vector<double> neutralRGB = { 0.5, 0.5, 0.5 };
std::vector<double> result;
std::string stderr_output = capture_stderr( [&]() {
result = rta::core::find_XYZ_to_camera_matrix( metadata, neutralRGB );
} );

const std::vector<double> &matrix =
metadata.calibration[0].XYZ_to_RGB_matrix;
OIIO_CHECK_EQUAL(
stderr_output, "No calibration illuminants were found.\n" );
OIIO_CHECK_EQUAL( result.size(), matrix.size() );
for ( int i = 0; i < countSize( matrix ); i++ )
OIIO_CHECK_EQUAL_THRESH( result[i], matrix[i], 1e-5 );
}

void testIDT_FindXYZtoCameraMtx_EmptyNeutral()
{
rta::core::Metadata metadata;
init_metadata( metadata );

std::vector<double> result;
std::string stderr_output = capture_stderr( [&]() {
result = rta::core::find_XYZ_to_camera_matrix( metadata, {} );
} );

const std::vector<double> &matrix =
metadata.calibration[0].XYZ_to_RGB_matrix;
OIIO_CHECK_EQUAL( stderr_output, "No neutral RGB values were found.\n" );
OIIO_CHECK_EQUAL( result.size(), matrix.size() );
for ( int i = 0; i < countSize( matrix ); i++ )
OIIO_CHECK_EQUAL_THRESH( result[i], matrix[i], 1e-5 );
}

void testIDT_FindXYZtoCameraMtx_ExactMatchMired()
{
rta::core::Metadata metadata;
init_metadata( metadata );
metadata.calibration[0].XYZ_to_RGB_matrix = k_identity_xyz_to_rgb;
metadata.calibration[1].XYZ_to_RGB_matrix = k_identity_xyz_to_rgb;
metadata.calibration[1].illuminant = 32768 + 10000;

std::vector<double> neutral_RGB = { 0.97347064038736957,
1.0,
1.4953965764168315 };
std::vector<double> expected_matrix = k_identity_xyz_to_rgb;

std::vector<double> result =
rta::core::find_XYZ_to_camera_matrix( metadata, neutral_RGB );

OIIO_CHECK_EQUAL( result.size(), expected_matrix.size() );
for ( int i = 0; i < countSize( expected_matrix ); i++ )
OIIO_CHECK_EQUAL_THRESH( result[i], expected_matrix[i], 1e-5 );
}

void testIDT_ColorTemperatureToXYZ()
{
double cct = 6500.0;
Expand All @@ -115,6 +230,38 @@ void testIDT_ColorTemperatureToXYZ()
OIIO_CHECK_EQUAL_THRESH( result[i], XYZ[i], 1e-5 );
}

void testIDT_ColorTemperatureToXYZ_ClampHighMired()
{
/// Mired below the Robertson table should clamp to the last entry.
const double cct = 200.0;
std::vector<double> result = rta::core::color_temperature_to_XYZ( cct );
std::vector<double> expected =
rta::core::uv_to_XYZ( std::vector<double>{ 0.33724, 0.36051 } );

for ( int i = 0; i < countSize( expected ); i++ )
OIIO_CHECK_EQUAL_THRESH( result[i], expected[i], 1e-5 );
}

void testIDT_GetCameraXYZWhitePoint_UsesIlluminantWhenNeutralEmpty()
{
rta::core::Metadata metadata;
init_metadata( metadata );
metadata.neutral_RGB.clear();

std::vector<double> camera_to_XYZ;
std::vector<double> camera_XYZ_white_point;
std::string stderr_output = capture_stderr( [&]() {
rta::core::get_camera_XYZ_matrix_and_white_point(
metadata, camera_to_XYZ, camera_XYZ_white_point );
} );

// Expect illuminant 17 fallback (normalized Y=1.0) when neutral_RGB is empty.
std::vector<double> expected = { 1.098445424569, 1.0, 0.355920076967 };
OIIO_CHECK_EQUAL( stderr_output, "No neutral RGB values were found.\n" );
for ( int i = 0; i < countSize( expected ); i++ )
OIIO_CHECK_EQUAL_THRESH( camera_XYZ_white_point[i], expected[i], 1e-5 );
}

void testIDT_MatrixRGBtoXYZ()
{
double XYZ[9] = { 0.952552395938, 0.000000000000, 0.000093678632,
Expand Down Expand Up @@ -166,10 +313,19 @@ int main( int, char ** )
testIDT_CcttoMired();
testIDT_RobertsonLength();
testIDT_LightSourceToColorTemp();
testIDT_LightSourceToColorTemp_Extended();
testIDT_LightSourceToColorTemp_Default();
testIDT_XYZToColorTemperature();
testIDT_XYZToColorTemperature_UpperClamp();
testIDT_XYZToColorTemperature_LowerClamp();
testIDT_XYZtoCameraWeightedMatrix();
testIDT_FindXYZtoCameraMtx();
testIDT_FindXYZtoCameraMtx_NoIlluminant();
testIDT_FindXYZtoCameraMtx_EmptyNeutral();
testIDT_FindXYZtoCameraMtx_ExactMatchMired();
testIDT_ColorTemperatureToXYZ();
testIDT_ColorTemperatureToXYZ_ClampHighMired();
testIDT_GetCameraXYZWhitePoint_UsesIlluminantWhenNeutralEmpty();
testIDT_MatrixRGBtoXYZ();
testIDT_GetDNGCATMatrix();
testIDT_GetDNGIDTMatrix();
Expand Down
Loading