sekrit-twc / zimg

Scaling, colorspace conversion, and dithering library
Do What The F*ck You Want To Public License
405 stars 77 forks source link

AribB67InverseOperationC #170

Closed MinfengZhu closed 2 years ago

MinfengZhu commented 2 years ago

According to ITU-R BT.2390-3 (Page 8, 2nd Figure), we should apply Inverse OETF fisrt followed by OOTF, when we transform HLG signal to display linear light.

However, the implementation of AribB67InverseOperationC applys OOTF first and then Inverse OETF.

It is right when we encode linear exr files into HLG video using AribB67OperationC. Unfortunately, we may get inconsistent images if we extract exr images from HLG video using AribB67InverseOperationC.

Modify code (L135-140) https://github.com/sekrit-twc/zimg/blob/dbde7d84e421e7bf1695cd3d399da2c68335b9e6/src/zimg/colorspace/operation_impl.cpp#L135-L140 to

r = arib_b67_inverse_oetf(r);
g = arib_b67_inverse_oetf(g);
b = arib_b67_inverse_oetf(b);
float ys = std::max(m_kr * r + m_kg * g + m_kb * b, FLT_MIN);
ys = zimg_x_powf(ys, gamma - 1.0f);
r = r * ys;
g = g * ys;
b = b * ys;

might works.