Skip to content

Commit

Permalink
Merge pull request #1015 from kleisauke/srgb-default
Browse files Browse the repository at this point in the history
nclx: use default values that match sRGB
  • Loading branch information
farindk authored Oct 30, 2023
2 parents 9700634 + 89ddc1c commit 8cacd4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
17 changes: 8 additions & 9 deletions libheif/color-conversion/colorconversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ std::shared_ptr<HeifPixelImage> ColorConversionPipeline::convert_image(const std

// --- pass the color profiles to the new image

auto output_nclx = std::make_shared<color_profile_nclx>();
*output_nclx = step.output_state.nclx_profile;
auto output_nclx = std::make_shared<color_profile_nclx>(step.output_state.nclx_profile);
out->set_color_profile_nclx(output_nclx);
out->set_color_profile_icc(in->get_color_profile_icc());

Expand Down Expand Up @@ -521,18 +520,18 @@ std::shared_ptr<HeifPixelImage> convert_colorspace(const std::shared_ptr<HeifPix
input_state.nclx_profile = *input->get_color_profile_nclx();
}

// If some input nclx values are unspecified, use CCIR-601 values as default.
// If some input nclx values are unspecified, use values that match sRGB as default.

if (input_state.nclx_profile.get_matrix_coefficients() == heif_matrix_coefficients_unspecified) {
input_state.nclx_profile.set_matrix_coefficients(heif_matrix_coefficients_ITU_R_BT_601_6);
input_state.nclx_profile.set_matrix_coefficients(heif_matrix_coefficients_ITU_R_BT_709_5);
}

if (input_state.nclx_profile.get_colour_primaries() == heif_color_primaries_unspecified) {
input_state.nclx_profile.set_colour_primaries(heif_color_primaries_ITU_R_BT_601_6);
input_state.nclx_profile.set_colour_primaries(heif_color_primaries_ITU_R_BT_709_5);
}

if (input_state.nclx_profile.get_transfer_characteristics() == heif_color_primaries_unspecified) {
input_state.nclx_profile.set_transfer_characteristics(heif_transfer_characteristic_ITU_R_BT_601_6);
if (input_state.nclx_profile.get_transfer_characteristics() == heif_transfer_characteristic_unspecified) {
input_state.nclx_profile.set_transfer_characteristics(heif_transfer_characteristic_IEC_61966_2_1);
}

std::set<enum heif_channel> channels = input->get_channel_set();
Expand All @@ -546,7 +545,7 @@ std::shared_ptr<HeifPixelImage> convert_colorspace(const std::shared_ptr<HeifPix
output_state.nclx_profile = *target_profile;
}

// If some output nclx values are unspecified, set the to the same as the input.
// If some output nclx values are unspecified, set them to the same as the input.

if (output_state.nclx_profile.get_matrix_coefficients() == heif_matrix_coefficients_unspecified) {
output_state.nclx_profile.set_matrix_coefficients(input_state.nclx_profile.get_matrix_coefficients());
Expand All @@ -556,7 +555,7 @@ std::shared_ptr<HeifPixelImage> convert_colorspace(const std::shared_ptr<HeifPix
output_state.nclx_profile.set_colour_primaries(input_state.nclx_profile.get_colour_primaries());
}

if (output_state.nclx_profile.get_transfer_characteristics() == heif_color_primaries_unspecified) {
if (output_state.nclx_profile.get_transfer_characteristics() == heif_transfer_characteristic_unspecified) {
output_state.nclx_profile.set_transfer_characteristics(input_state.nclx_profile.get_transfer_characteristics());
}

Expand Down
12 changes: 6 additions & 6 deletions libheif/nclx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ struct heif_color_profile_nclx* color_profile_nclx::alloc_nclx_color_profile()

if (profile) {
profile->version = 1;
profile->color_primaries = heif_color_primaries_unspecified;
profile->transfer_characteristics = heif_transfer_characteristic_unspecified;
profile->matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_601_6;
profile->color_primaries = heif_color_primaries_ITU_R_BT_709_5;
profile->transfer_characteristics = heif_transfer_characteristic_IEC_61966_2_1;
profile->matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_709_5;
profile->full_range_flag = true;
}

Expand All @@ -312,9 +312,9 @@ void color_profile_nclx::free_nclx_color_profile(struct heif_color_profile_nclx*

void color_profile_nclx::set_default()
{
m_colour_primaries = 2;
m_transfer_characteristics = 2;
m_matrix_coefficients = 6;
m_colour_primaries = 1;
m_transfer_characteristics = 13;
m_matrix_coefficients = 1;
m_full_range_flag = true;
}

Expand Down

0 comments on commit 8cacd4d

Please sign in to comment.