diff --git a/debian/patches/0007-add-bt2390-eetf-and-code-refactor-to-opencl-tonemap.patch b/debian/patches/0007-add-bt2390-eetf-and-code-refactor-to-opencl-tonemap.patch index f931d4a64ea..1b411fbf915 100644 --- a/debian/patches/0007-add-bt2390-eetf-and-code-refactor-to-opencl-tonemap.patch +++ b/debian/patches/0007-add-bt2390-eetf-and-code-refactor-to-opencl-tonemap.patch @@ -65,7 +65,7 @@ Index: FFmpeg/libavfilter/opencl/colorspace_common.cl =================================================================== --- FFmpeg.orig/libavfilter/opencl/colorspace_common.cl +++ FFmpeg/libavfilter/opencl/colorspace_common.cl -@@ -17,7 +17,17 @@ +@@ -17,7 +17,21 @@ */ #define ST2084_MAX_LUMINANCE 10000.0f @@ -80,11 +80,15 @@ Index: FFmpeg/libavfilter/opencl/colorspace_common.cl +#define ARIB_B67_B 0.28466892f +#define ARIB_B67_C 0.55991073f + ++#define LIMITED_BLACK 0.06256109482f ++#define LIMITED_WHITE 0.9188660802f ++#define LIMITED_RANGE 0.8563049854f ++ +#define FLOAT_EPS 1e-6f #if chroma_loc == 1 #define chroma_sample(a,b,c,d) (((a) + (c)) * 0.5f) -@@ -33,81 +43,124 @@ +@@ -33,92 +47,134 @@ #define chroma_sample(a,b,c,d) (((a) + (b) + (c) + (d)) * 0.25f) #endif @@ -183,21 +187,33 @@ Index: FFmpeg/libavfilter/opencl/colorspace_common.cl + float den = 1.0f + ST2084_C3 * xpow; + return native_powr(1.0f + num / den, ST2084_M2); +#endif -+} -+ + } + +-float inverse_eotf_bt1886(float c) { +- return c < 0.0f ? 0.0f : powr(c, 1.0f / 2.4f); +float inverse_eotf_st2084(float x) { + x *= ref_white_div_pq_max_lum; + return inverse_eotf_st2084_common(x); -+} -+ + } + +-float oetf_bt709(float c) { +- c = c < 0.0f ? 0.0f : c; +- float r1 = 4.5f * c; +- float r2 = 1.099f * powr(c, 0.45f) - 0.099f; +- return c < 0.018f ? r1 : r2; +-} +-float inverse_oetf_bt709(float c) { +- float r1 = c / 4.5f; +- float r2 = powr((c + 0.099f) / 1.099f, 1.0f / 0.45f); +- return c < 0.081f ? r1 : r2; +float4 eotf_st2084x4(float4 x) { + x.x = eotf_st2084_common(x.x); + x.y = eotf_st2084_common(x.y); + x.z = eotf_st2084_common(x.z); + x.w = eotf_st2084_common(x.w); + return x * pq_max_lum_div_ref_white; -+} -+ + } + +float4 inverse_eotf_st2084x4(float4 x) { + x *= ref_white_div_pq_max_lum; + x.x = inverse_eotf_st2084_common(x.x); @@ -213,34 +229,22 @@ Index: FFmpeg/libavfilter/opencl/colorspace_common.cl + +float inverse_ootf_1_2(float x) { + return x > 0.0f ? native_powr(x, 1.0f / 1.2f) : x; - } - --float inverse_eotf_bt1886(float c) { -- return c < 0.0f ? 0.0f : powr(c, 1.0f / 2.4f); ++} ++ +float oetf_arib_b67(float x) { + x = fmax(x, 0.0f); + return x <= (1.0f / 12.0f) + ? native_sqrt(3.0f * x) + : (ARIB_B67_A * native_log(12.0f * x - ARIB_B67_B) + ARIB_B67_C); - } - --float oetf_bt709(float c) { -- c = c < 0.0f ? 0.0f : c; -- float r1 = 4.5f * c; -- float r2 = 1.099f * powr(c, 0.45f) - 0.099f; -- return c < 0.018f ? r1 : r2; --} --float inverse_oetf_bt709(float c) { -- float r1 = c / 4.5f; -- float r2 = powr((c + 0.099f) / 1.099f, 1.0f / 0.45f); -- return c < 0.081f ? r1 : r2; ++} ++ +float inverse_oetf_arib_b67(float x) { + x = fmax(x, 0.0f); + return x <= 0.5f + ? (x * x) * (1.0f / 3.0f) + : (native_exp((x - ARIB_B67_C) / ARIB_B67_A) + ARIB_B67_B) * (1.0f / 12.0f); - } - ++} ++ +// linearizer for HLG/ARIB-B67 +float eotf_arib_b67(float x) { + return ootf_1_2(inverse_oetf_arib_b67(x)) * 5.0f; @@ -263,19 +267,58 @@ Index: FFmpeg/libavfilter/opencl/colorspace_common.cl +#endif + float3 yuv2rgb(float y, float u, float v) { - #ifdef FULL_RANGE_IN +-#ifdef FULL_RANGE_IN u -= 0.5f; v -= 0.5f; -@@ -150,7 +203,9 @@ float3 rgb2yuv(float r, float g, float b +-#else +- y = (y * 255.0f - 16.0f) / 219.0f; +- u = (u * 255.0f - 128.0f) / 224.0f; +- v = (v * 255.0f - 128.0f) / 224.0f; +-#endif + float r = y * rgb_matrix[0] + u * rgb_matrix[1] + v * rgb_matrix[2]; + float g = y * rgb_matrix[3] + u * rgb_matrix[4] + v * rgb_matrix[5]; + float b = y * rgb_matrix[6] + u * rgb_matrix[7] + v * rgb_matrix[8]; ++#ifndef FULL_RANGE_IN ++ r = (r - LIMITED_BLACK) / LIMITED_RANGE; ++ g = (g - LIMITED_BLACK) / LIMITED_RANGE; ++ b = (b - LIMITED_BLACK) / LIMITED_RANGE; ++#endif + return (float3)(r, g, b); + } - float rgb2y(float r, float g, float b) { +@@ -135,22 +191,25 @@ float3 yuv2lrgb(float3 yuv) { + } + + float3 rgb2yuv(float r, float g, float b) { ++#ifndef FULL_RANGE_OUT ++ r = r * LIMITED_RANGE + LIMITED_BLACK; ++ g = g * LIMITED_RANGE + LIMITED_BLACK; ++ b = b * LIMITED_RANGE + LIMITED_BLACK; ++#endif float y = r*yuv_matrix[0] + g*yuv_matrix[1] + b*yuv_matrix[2]; + float u = r*yuv_matrix[3] + g*yuv_matrix[4] + b*yuv_matrix[5]; + float v = r*yuv_matrix[6] + g*yuv_matrix[7] + b*yuv_matrix[8]; +-#ifdef FULL_RANGE_OUT + u += 0.5f; v += 0.5f; +-#else +- y = (219.0f * y + 16.0f) / 255.0f; +- u = (224.0f * u + 128.0f) / 255.0f; +- v = (224.0f * v + 128.0f) / 255.0f; +-#endif + return (float3)(y, u, v); + } + + float rgb2y(float r, float g, float b) { +#ifndef FULL_RANGE_OUT - y = (219.0f * y + 16.0f) / 255.0f; ++ r = r * LIMITED_RANGE + LIMITED_BLACK; ++ g = g * LIMITED_RANGE + LIMITED_BLACK; ++ b = b * LIMITED_RANGE + LIMITED_BLACK; +#endif + float y = r*yuv_matrix[0] + g*yuv_matrix[1] + b*yuv_matrix[2]; +- y = (219.0f * y + 16.0f) / 255.0f; return y; } -@@ -188,18 +243,101 @@ float3 lrgb2lrgb(float3 c) { +@@ -188,18 +247,101 @@ float3 lrgb2lrgb(float3 c) { #endif }