Skip to content

Commit

Permalink
use matrix_coefficients=5 for sRGB
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 30, 2023
1 parent 36326c5 commit 2698eef
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/heif_enc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int metadata_compression = 0;
const char* encoderId = nullptr;
std::string chroma_downsampling;

uint16_t nclx_matrix_coefficients = 1;
uint16_t nclx_colour_primaries = 1;
uint16_t nclx_transfer_characteristic = 13;
uint16_t nclx_matrix_coefficients = 5;
int nclx_full_range = true;

std::string property_pitm_description;
Expand Down
2 changes: 1 addition & 1 deletion libheif/color-conversion/colorconversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ std::shared_ptr<HeifPixelImage> convert_colorspace(const std::shared_ptr<HeifPix
input_state.nclx_profile = *input->get_color_profile_nclx();
}

input_state.nclx_profile.replace_undefined_values_with_defaults();
input_state.nclx_profile.replace_undefined_values_with_sRGB_defaults();

std::set<enum heif_channel> channels = input->get_channel_set();
assert(!channels.empty());
Expand Down
2 changes: 1 addition & 1 deletion libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ static std::shared_ptr<color_profile_nclx> compute_target_nclx_profile(const std
target_nclx_profile->set_undefined();
}

target_nclx_profile->replace_undefined_values_with_defaults();
target_nclx_profile->replace_undefined_values_with_sRGB_defaults();

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

if (profile) {
profile->version = 1;
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;

// sRGB defaults
profile->color_primaries = heif_color_primaries_ITU_R_BT_709_5; // 1
profile->transfer_characteristics = heif_transfer_characteristic_IEC_61966_2_1; // 13
profile->matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_470_6_System_B_G; // 5
profile->full_range_flag = true;
}

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

void color_profile_nclx::set_default()
{
// sRGB defaults
m_colour_primaries = 1;
m_transfer_characteristics = 13;
m_matrix_coefficients = 1;
m_matrix_coefficients = 5;
m_full_range_flag = true;
}

Expand All @@ -339,10 +342,10 @@ void color_profile_nclx::set_from_heif_color_profile_nclx(const struct heif_colo
}


void color_profile_nclx::replace_undefined_values_with_defaults()
void color_profile_nclx::replace_undefined_values_with_sRGB_defaults()
{
if (m_matrix_coefficients == heif_matrix_coefficients_unspecified) {
m_matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_709_5;
m_matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_470_6_System_B_G;
}

if (m_colour_primaries == heif_color_primaries_unspecified) {
Expand Down
2 changes: 1 addition & 1 deletion libheif/nclx.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class color_profile_nclx : public color_profile

void set_from_heif_color_profile_nclx(const struct heif_color_profile_nclx* nclx);

void replace_undefined_values_with_defaults();
void replace_undefined_values_with_sRGB_defaults();

private:
uint16_t m_colour_primaries = heif_color_primaries_unspecified;
Expand Down

1 comment on commit 2698eef

@novomesk
Copy link

Choose a reason for hiding this comment

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

I know that iOS and Safari couldn't open AVIF in the past when matrix coefficients= 5.

MC = 6 is technically equal with 5 but it didn't work.

That's why I recommend to keep MC = 6 as default.

Please sign in to comment.