Skip to content

AVIF transcode does not handle XYZ color primaries #266

@Kaldaien

Description

@Kaldaien

lilliput/avif.cpp

Lines 166 to 182 in e0bc154

if (primaries == AVIF_COLOR_PRIMARIES_BT2020) {
cv::Matx33f bt2020_to_bt709(
1.6605f, -0.5876f, -0.0728f, -0.1246f, 1.1329f, -0.0083f, -0.0182f, -0.1006f, 1.1187f);
cv::transform(tonemapped, converted, bt2020_to_bt709);
}
else if (primaries == AVIF_COLOR_PRIMARIES_SMPTE432 ||
primaries == AVIF_COLOR_PRIMARIES_DCI_P3) {
cv::Matx33f p3_to_bt709(
1.2249f, -0.2247f, -0.0002f, -0.0420f, 1.0419f, 0.0001f, -0.0197f, 0.0754f, 0.9443f);
cv::transform(tonemapped, converted, p3_to_bt709);
}
else if (primaries == AVIF_COLOR_PRIMARIES_BT601) {
cv::Matx33f bt601_to_bt709(
1.0440f, -0.0440f, 0.0000f, -0.0000f, 1.0000f, 0.0000f, 0.0000f, 0.0000f, 1.0000f);
cv::transform(tonemapped, converted, bt601_to_bt709);
}
else {

There needs to be an additional case here to handle XYZ (i.e.):

constexpr DirectX::XMMATRIX c_fromXYZto709 = // Transposed
{
  {  3.2409698963165283203125f,    -0.96924364566802978515625f,       0.055630080401897430419921875f, 0.0f },
  { -1.53738319873809814453125f,    1.875967502593994140625f,        -0.2039769589900970458984375f,   0.0f },
  { -0.4986107647418975830078125f,  0.0415550582110881805419921875f,  1.05697154998779296875f,        0.0f },
  {  0.0f,                          0.0f,                             0.0f,                           1.0f }
};

xyz_hdr.zip

Attached is a 12-bit HDR image w/ XYZ primaries for testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions