Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nclx: use default values that match sRGB #1015

Merged
merged 2 commits into from
Oct 30, 2023
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
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
Loading