Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range
@ 2022-11-02 21:02 Michael Niedermayer
  2022-11-02 21:02 ` [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32 Michael Niedermayer
  2022-11-03 14:07 ` [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Drew Dunne
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Niedermayer @ 2022-11-02 21:02 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Fixes: integer overflow
Fixes: ./ffmpeg   -f rawvideo -video_size 66x64 -pixel_format yuva420p10le   -i ~/videos/overflow_input_w66h64.yuva420p10le   -filter_complex "scale=flags=bicubic+full_chroma_int+full_chroma_inp+bitexact+accurate_rnd:in_color_matrix=bt2020:out_color_matrix=bt2020:in_range=full:out_range=full,format=rgba64[out]"   -pixel_format rgba64 -map '[out]'   -y overflow_w66h64.png

Found-by: Drew Dunne <asdunne@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libswscale/output.c | 120 ++++++++++++++++++++++----------------------
 1 file changed, 60 insertions(+), 60 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 0e1c1225a0..df4647adde 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -1100,8 +1100,8 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
         Y2 -= c->yuv2rgb_y_offset;
         Y1 *= c->yuv2rgb_y_coeff;
         Y2 *= c->yuv2rgb_y_coeff;
-        Y1 += 1 << 13; // 21
-        Y2 += 1 << 13;
+        Y1 += (1 << 13) - (1 << 29); // 21
+        Y2 += (1 << 13) - (1 << 29);
         // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
 
         R = V * c->yuv2rgb_v2r_coeff;
@@ -1109,20 +1109,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
+        output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
+        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
             dest += 6;
         }
     }
@@ -1160,8 +1160,8 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
         Y2 -= c->yuv2rgb_y_offset;
         Y1 *= c->yuv2rgb_y_coeff;
         Y2 *= c->yuv2rgb_y_coeff;
-        Y1 += 1 << 13;
-        Y2 += 1 << 13;
+        Y1 += (1 << 13) - (1 << 29);
+        Y2 += (1 << 13) - (1 << 29);
 
         R = V * c->yuv2rgb_v2r_coeff;
         G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
@@ -1175,20 +1175,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
             A2 += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
+        output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
+        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
             dest += 6;
         }
     }
@@ -1217,8 +1217,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             Y2 -= c->yuv2rgb_y_offset;
             Y1 *= c->yuv2rgb_y_coeff;
             Y2 *= c->yuv2rgb_y_coeff;
-            Y1 += 1 << 13;
-            Y2 += 1 << 13;
+            Y1 += (1 << 13) - (1 << 29);
+            Y2 += (1 << 13) - (1 << 29);
 
             if (hasAlpha) {
                 A1 = abuf0[i * 2    ] << 11;
@@ -1232,20 +1232,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
+            output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
+            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
                 dest += 6;
             }
         }
@@ -1263,8 +1263,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             Y2 -= c->yuv2rgb_y_offset;
             Y1 *= c->yuv2rgb_y_coeff;
             Y2 *= c->yuv2rgb_y_coeff;
-            Y1 += 1 << 13;
-            Y2 += 1 << 13;
+            Y1 += (1 << 13) - (1 << 29);
+            Y2 += (1 << 13) - (1 << 29);
 
             if (hasAlpha) {
                 A1 = abuf0[i * 2    ] << 11;
@@ -1278,20 +1278,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
+            output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
+            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
                 dest += 6;
             }
         }
@@ -1343,7 +1343,7 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
         // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
         Y -= c->yuv2rgb_y_offset;
         Y *= c->yuv2rgb_y_coeff;
-        Y += 1 << 13; // 21
+        Y += (1 << 13) - (1<<29); // 21
         // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
 
         R = V * c->yuv2rgb_v2r_coeff;
@@ -1351,9 +1351,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y)>>14) + (1<<15), 16));
+        output_pixel(&dest[1], av_clip_uintp2(((  G + Y)>>14) + (1<<15), 16));
+        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y)>>14) + (1<<15), 16));
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1392,7 +1392,7 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
 
         Y -= c->yuv2rgb_y_offset;
         Y *= c->yuv2rgb_y_coeff;
-        Y += 1 << 13;
+        Y += (1 << 13) - (1 << 29);
 
         R = V * c->yuv2rgb_v2r_coeff;
         G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
@@ -1404,9 +1404,9 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
             A += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
+        output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) + (1<<15), 16));
+        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1436,7 +1436,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
 
             Y -= c->yuv2rgb_y_offset;
             Y *= c->yuv2rgb_y_coeff;
-            Y += 1 << 13;
+            Y += (1 << 13) - (1 << 29);
 
             if (hasAlpha) {
                 A = abuf0[i] << 11;
@@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
+            output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) + (1<<15), 16));
+            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
@@ -1469,7 +1469,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
 
             Y -= c->yuv2rgb_y_offset;
             Y *= c->yuv2rgb_y_coeff;
-            Y += 1 << 13;
+            Y += (1 << 13) - (1 << 29);
 
             if (hasAlpha) {
                 A = abuf0[i] << 11;
@@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
+            output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) + (1<<15), 16));
+            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:02 [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Michael Niedermayer
@ 2022-11-02 21:02 ` Michael Niedermayer
  2022-11-02 21:07   ` Michael Niedermayer
  2022-11-02 22:52   ` Mark Reid
  2022-11-03 14:07 ` [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Drew Dunne
  1 sibling, 2 replies; 11+ messages in thread
From: Michael Niedermayer @ 2022-11-02 21:02 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Fixes: integer overflow
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libswscale/output.c       | 25 +++++++++++--------------
 libswscale/x86/output.asm | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index df4647adde..5c85bff971 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2372,18 +2372,15 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
 
         Y -= c->yuv2rgb_y_offset;
         Y *= c->yuv2rgb_y_coeff;
-        Y += 1 << 13;
+        Y += (1 << 13) - (1 << 29);
         R = V * c->yuv2rgb_v2r_coeff;
         G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
         B =                            U * c->yuv2rgb_u2b_coeff;
 
-        R = av_clip_uintp2(Y + R, 30);
-        G = av_clip_uintp2(Y + G, 30);
-        B = av_clip_uintp2(Y + B, 30);
+        dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
+        dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
+        dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
 
-        dest16[0][i] = G >> 14;
-        dest16[1][i] = B >> 14;
-        dest16[2][i] = R >> 14;
         if (hasAlpha)
             dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
     }
@@ -2448,18 +2445,18 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
 
         Y -= c->yuv2rgb_y_offset;
         Y *= c->yuv2rgb_y_coeff;
-        Y += 1 << 13;
+        Y += (1 << 13) - (1 << 29);
         R = V * c->yuv2rgb_v2r_coeff;
         G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
         B =                            U * c->yuv2rgb_u2b_coeff;
 
-        R = av_clip_uintp2(Y + R, 30);
-        G = av_clip_uintp2(Y + G, 30);
-        B = av_clip_uintp2(Y + B, 30);
+        R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
+        G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
+        B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
 
-        dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
-        dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
-        dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
+        dest32[0][i] = av_float2int(float_mult * (float)G);
+        dest32[1][i] = av_float2int(float_mult * (float)B);
+        dest32[2][i] = av_float2int(float_mult * (float)R);
         if (hasAlpha)
             dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
     }
diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm
index 84e94baaf6..f943a27534 100644
--- a/libswscale/x86/output.asm
+++ b/libswscale/x86/output.asm
@@ -44,11 +44,13 @@ pd_yuv2gbrp_y_start:       times 8 dd  (1 << 9)
 pd_yuv2gbrp_uv_start:      times 8 dd  ((1 << 9) - (128 << 19))
 pd_yuv2gbrp_a_start:       times 8 dd  (1 << 18)
 pd_yuv2gbrp16_offset:      times 8 dd  0x10000  ;(1 << 16)
-pd_yuv2gbrp16_round13:     times 8 dd  0x02000  ;(1 << 13)
+pd_yuv2gbrp16_round13:     times 8 dd  0xE0002000  ;(1 << 13) - (1 << 29)
 pd_yuv2gbrp16_a_offset:    times 8 dd  0x20002000
 pd_yuv2gbrp16_upper30:     times 8 dd  0x3FFFFFFF ;(1<<30) - 1
 pd_yuv2gbrp16_upper27:     times 8 dd  0x07FFFFFF ;(1<<27) - 1
+pd_yuv2gbrp16_upper16:     times 8 dd  0x0000FFFF ;(1<<16) - 1
 pd_yuv2gbrp16_upperC:      times 8 dd  0xC0000000
+pd_yuv2gbrp_debias:        times 8 dd  0x00008000 ;(1 << 29 - 14)
 pb_pack_shuffle8:       db  0,  4,  8, 12, \
                            -1, -1, -1, -1, \
                            -1, -1, -1, -1, \
@@ -883,14 +885,26 @@ cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter, lumSrcx, lumFilterSize, chrFi
         paddd G, Y
         paddd B, Y
 
+%if  DEPTH < 16
         CLIPP2 R, 30
         CLIPP2 G, 30
         CLIPP2 B, 30
+%endif
 
         psrad R, RGB_SHIFT
         psrad G, RGB_SHIFT
         psrad B, RGB_SHIFT
 
+%if  DEPTH >= 16
+        paddd R, [pd_yuv2gbrp_debias]
+        paddd G, [pd_yuv2gbrp_debias]
+        paddd B, [pd_yuv2gbrp_debias]
+
+        CLIPP2 R, 16
+        CLIPP2 G, 16
+        CLIPP2 B, 16
+%endif
+
 %if FLOAT
         cvtdq2ps R, R
         cvtdq2ps G, G
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:02 ` [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32 Michael Niedermayer
@ 2022-11-02 21:07   ` Michael Niedermayer
  2022-11-02 21:16     ` Andreas Rheinhardt
  2022-11-02 22:52   ` Mark Reid
  1 sibling, 1 reply; 11+ messages in thread
From: Michael Niedermayer @ 2022-11-02 21:07 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 694 bytes --]

On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:
> Fixes: integer overflow
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libswscale/output.c       | 25 +++++++++++--------------
>  libswscale/x86/output.asm | 16 +++++++++++++++-
>  2 files changed, 26 insertions(+), 15 deletions(-)

Note, these corner case overflows could affect some of the similary
implemented cases that are not depth 16 too

ill fix them if issues are replicated

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:07   ` Michael Niedermayer
@ 2022-11-02 21:16     ` Andreas Rheinhardt
  2022-11-02 21:31       ` Michael Niedermayer
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-11-02 21:16 UTC (permalink / raw)
  To: ffmpeg-devel

Michael Niedermayer:
> On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:
>> Fixes: integer overflow
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>>  libswscale/output.c       | 25 +++++++++++--------------
>>  libswscale/x86/output.asm | 16 +++++++++++++++-
>>  2 files changed, 26 insertions(+), 15 deletions(-)
> 
> Note, these corner case overflows could affect some of the similary
> implemented cases that are not depth 16 too
> 
> ill fix them if issues are replicated
> 

The checkasm-sw_gbrp runs into many overflows (when run under UBSan);
e.g. fate.ffmpeg.org tells me of an issue in line 2289. Said line is not
touched in your commits.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:16     ` Andreas Rheinhardt
@ 2022-11-02 21:31       ` Michael Niedermayer
  2022-11-02 21:36         ` Martin Storsjö
  2022-11-02 21:42         ` Michael Niedermayer
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Niedermayer @ 2022-11-02 21:31 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1344 bytes --]

On Wed, Nov 02, 2022 at 10:16:57PM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:
> >> Fixes: integer overflow
> >> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >> ---
> >>  libswscale/output.c       | 25 +++++++++++--------------
> >>  libswscale/x86/output.asm | 16 +++++++++++++++-
> >>  2 files changed, 26 insertions(+), 15 deletions(-)
> > 
> > Note, these corner case overflows could affect some of the similary
> > implemented cases that are not depth 16 too
> > 
> > ill fix them if issues are replicated
> > 
> 
> The checkasm-sw_gbrp runs into many overflows (when run under UBSan);
> e.g. fate.ffmpeg.org tells me of an issue in line 2289. Said line is not
> touched in your commits.

checkasm-sw_gbrp feeds random data widely outside sane ranges in.
the test certainly makes no sense for testing asm. There is no point
in matching C for widely invalid cases. Of cousre we shouldnt overflow
if any of this can be triggered with valid and real input (which probably
can be done in some cases)

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:31       ` Michael Niedermayer
@ 2022-11-02 21:36         ` Martin Storsjö
  2022-11-02 21:42         ` Michael Niedermayer
  1 sibling, 0 replies; 11+ messages in thread
From: Martin Storsjö @ 2022-11-02 21:36 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Wed, 2 Nov 2022, Michael Niedermayer wrote:

> On Wed, Nov 02, 2022 at 10:16:57PM +0100, Andreas Rheinhardt wrote:
>> Michael Niedermayer:
>>> On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:
>>>> Fixes: integer overflow
>>>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>>>> ---
>>>>  libswscale/output.c       | 25 +++++++++++--------------
>>>>  libswscale/x86/output.asm | 16 +++++++++++++++-
>>>>  2 files changed, 26 insertions(+), 15 deletions(-)
>>>
>>> Note, these corner case overflows could affect some of the similary
>>> implemented cases that are not depth 16 too
>>>
>>> ill fix them if issues are replicated
>>>
>>
>> The checkasm-sw_gbrp runs into many overflows (when run under UBSan);
>> e.g. fate.ffmpeg.org tells me of an issue in line 2289. Said line is not
>> touched in your commits.
>
> checkasm-sw_gbrp feeds random data widely outside sane ranges in.
> the test certainly makes no sense for testing asm. There is no point
> in matching C for widely invalid cases. Of cousre we shouldnt overflow
> if any of this can be triggered with valid and real input (which probably
> can be done in some cases)

Patches for the checkasm tests, to make them produce sane input values in 
the correct ranges, are very much welcome!

// Martin

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:31       ` Michael Niedermayer
  2022-11-02 21:36         ` Martin Storsjö
@ 2022-11-02 21:42         ` Michael Niedermayer
  1 sibling, 0 replies; 11+ messages in thread
From: Michael Niedermayer @ 2022-11-02 21:42 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1668 bytes --]

On Wed, Nov 02, 2022 at 10:31:27PM +0100, Michael Niedermayer wrote:
> On Wed, Nov 02, 2022 at 10:16:57PM +0100, Andreas Rheinhardt wrote:
> > Michael Niedermayer:
> > > On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:
> > >> Fixes: integer overflow
> > >> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > >> ---
> > >>  libswscale/output.c       | 25 +++++++++++--------------
> > >>  libswscale/x86/output.asm | 16 +++++++++++++++-
> > >>  2 files changed, 26 insertions(+), 15 deletions(-)
> > > 
> > > Note, these corner case overflows could affect some of the similary
> > > implemented cases that are not depth 16 too
> > > 
> > > ill fix them if issues are replicated
> > > 
> > 
> > The checkasm-sw_gbrp runs into many overflows (when run under UBSan);
> > e.g. fate.ffmpeg.org tells me of an issue in line 2289. Said line is not
> > touched in your commits.
> 
> checkasm-sw_gbrp feeds random data widely outside sane ranges in.
> the test certainly makes no sense for testing asm. There is no point
> in matching C for widely invalid cases. Of cousre we shouldnt overflow
> if any of this can be triggered with valid and real input (which probably
> can be done in some cases)

also to elaborate further, checkasm-sw_gbrp sets everything randomly
that includes yuv2rgb matrix values and bits outside the valid input sample
range and the resample filter coeffs.

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If a bugfix only changes things apparently unrelated to the bug with no
further explanation, that is a good sign that the bugfix is wrong.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 21:02 ` [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32 Michael Niedermayer
  2022-11-02 21:07   ` Michael Niedermayer
@ 2022-11-02 22:52   ` Mark Reid
  2022-11-02 22:55     ` Mark Reid
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Reid @ 2022-11-02 22:52 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Wed, Nov 2, 2022 at 2:03 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Fixes: integer overflow
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libswscale/output.c       | 25 +++++++++++--------------
>  libswscale/x86/output.asm | 16 +++++++++++++++-
>  2 files changed, 26 insertions(+), 15 deletions(-)
>
> diff --git a/libswscale/output.c b/libswscale/output.c
> index df4647adde..5c85bff971 100644
> --- a/libswscale/output.c
> +++ b/libswscale/output.c
> @@ -2372,18 +2372,15 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t
> *lumFilter,
>
>          Y -= c->yuv2rgb_y_offset;
>          Y *= c->yuv2rgb_y_coeff;
> -        Y += 1 << 13;
> +        Y += (1 << 13) - (1 << 29);
>          R = V * c->yuv2rgb_v2r_coeff;
>          G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>          B =                            U * c->yuv2rgb_u2b_coeff;
>
> -        R = av_clip_uintp2(Y + R, 30);
> -        G = av_clip_uintp2(Y + G, 30);
> -        B = av_clip_uintp2(Y + B, 30);
> +        dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
> +        dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
> +        dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>
> -        dest16[0][i] = G >> 14;
> -        dest16[1][i] = B >> 14;
> -        dest16[2][i] = R >> 14;
>          if (hasAlpha)
>              dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
>      }
> @@ -2448,18 +2445,18 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t
> *lumFilter,
>
>          Y -= c->yuv2rgb_y_offset;
>          Y *= c->yuv2rgb_y_coeff;
> -        Y += 1 << 13;
> +        Y += (1 << 13) - (1 << 29);
>          R = V * c->yuv2rgb_v2r_coeff;
>          G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>          B =                            U * c->yuv2rgb_u2b_coeff;
>
> -        R = av_clip_uintp2(Y + R, 30);
> -        G = av_clip_uintp2(Y + G, 30);
> -        B = av_clip_uintp2(Y + B, 30);
> +        R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
> +        G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
> +        B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>
> -        dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
> -        dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
> -        dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
> +        dest32[0][i] = av_float2int(float_mult * (float)G);
> +        dest32[1][i] = av_float2int(float_mult * (float)B);
> +        dest32[2][i] = av_float2int(float_mult * (float)R);
>          if (hasAlpha)
>              dest32[3][i] = av_float2int(float_mult *
> (float)(av_clip_uintp2(A, 30) >> 14));
>      }
> diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm
> index 84e94baaf6..f943a27534 100644
> --- a/libswscale/x86/output.asm
> +++ b/libswscale/x86/output.asm
> @@ -44,11 +44,13 @@ pd_yuv2gbrp_y_start:       times 8 dd  (1 << 9)
>  pd_yuv2gbrp_uv_start:      times 8 dd  ((1 << 9) - (128 << 19))
>  pd_yuv2gbrp_a_start:       times 8 dd  (1 << 18)
>  pd_yuv2gbrp16_offset:      times 8 dd  0x10000  ;(1 << 16)
> -pd_yuv2gbrp16_round13:     times 8 dd  0x02000  ;(1 << 13)
> +pd_yuv2gbrp16_round13:     times 8 dd  0xE0002000  ;(1 << 13) - (1 << 29)
>  pd_yuv2gbrp16_a_offset:    times 8 dd  0x20002000
>  pd_yuv2gbrp16_upper30:     times 8 dd  0x3FFFFFFF ;(1<<30) - 1
>  pd_yuv2gbrp16_upper27:     times 8 dd  0x07FFFFFF ;(1<<27) - 1
> +pd_yuv2gbrp16_upper16:     times 8 dd  0x0000FFFF ;(1<<16) - 1
>

pd_yuv2gbrp16_upper16 doesn't appear to be used anywhere


>  pd_yuv2gbrp16_upperC:      times 8 dd  0xC0000000
> +pd_yuv2gbrp_debias:        times 8 dd  0x00008000 ;(1 << 29 - 14)
>  pb_pack_shuffle8:       db  0,  4,  8, 12, \
>                             -1, -1, -1, -1, \
>                             -1, -1, -1, -1, \
> @@ -883,14 +885,26 @@ cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter,
> lumSrcx, lumFilterSize, chrFi
>          paddd G, Y
>          paddd B, Y
>
> +%if  DEPTH < 16
>          CLIPP2 R, 30
>          CLIPP2 G, 30
>          CLIPP2 B, 30
> +%endif
>
>          psrad R, RGB_SHIFT
>          psrad G, RGB_SHIFT
>          psrad B, RGB_SHIFT
>
> +%if  DEPTH >= 16
> +        paddd R, [pd_yuv2gbrp_debias]
> +        paddd G, [pd_yuv2gbrp_debias]
> +        paddd B, [pd_yuv2gbrp_debias]
> +
> +        CLIPP2 R, 16
> +        CLIPP2 G, 16
> +        CLIPP2 B, 16
> +%endif
> +
>  %if FLOAT
>          cvtdq2ps R, R
>          cvtdq2ps G, G
> --
> 2.17.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32
  2022-11-02 22:52   ` Mark Reid
@ 2022-11-02 22:55     ` Mark Reid
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Reid @ 2022-11-02 22:55 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Wed, Nov 2, 2022 at 3:52 PM Mark Reid <mindmark@gmail.com> wrote:

>
>
> On Wed, Nov 2, 2022 at 2:03 PM Michael Niedermayer <michael@niedermayer.cc>
> wrote:
>
>> Fixes: integer overflow
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>>  libswscale/output.c       | 25 +++++++++++--------------
>>  libswscale/x86/output.asm | 16 +++++++++++++++-
>>  2 files changed, 26 insertions(+), 15 deletions(-)
>>
>> diff --git a/libswscale/output.c b/libswscale/output.c
>> index df4647adde..5c85bff971 100644
>> --- a/libswscale/output.c
>> +++ b/libswscale/output.c
>> @@ -2372,18 +2372,15 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t
>> *lumFilter,
>>
>>          Y -= c->yuv2rgb_y_offset;
>>          Y *= c->yuv2rgb_y_coeff;
>> -        Y += 1 << 13;
>> +        Y += (1 << 13) - (1 << 29);
>>          R = V * c->yuv2rgb_v2r_coeff;
>>          G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>>          B =                            U * c->yuv2rgb_u2b_coeff;
>>
>> -        R = av_clip_uintp2(Y + R, 30);
>> -        G = av_clip_uintp2(Y + G, 30);
>> -        B = av_clip_uintp2(Y + B, 30);
>> +        dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
>> +        dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
>> +        dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>>
>> -        dest16[0][i] = G >> 14;
>> -        dest16[1][i] = B >> 14;
>> -        dest16[2][i] = R >> 14;
>>          if (hasAlpha)
>>              dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
>>      }
>> @@ -2448,18 +2445,18 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t
>> *lumFilter,
>>
>>          Y -= c->yuv2rgb_y_offset;
>>          Y *= c->yuv2rgb_y_coeff;
>> -        Y += 1 << 13;
>> +        Y += (1 << 13) - (1 << 29);
>>          R = V * c->yuv2rgb_v2r_coeff;
>>          G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>>          B =                            U * c->yuv2rgb_u2b_coeff;
>>
>> -        R = av_clip_uintp2(Y + R, 30);
>> -        G = av_clip_uintp2(Y + G, 30);
>> -        B = av_clip_uintp2(Y + B, 30);
>> +        R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
>> +        G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
>> +        B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>>
>> -        dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
>> -        dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
>> -        dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
>> +        dest32[0][i] = av_float2int(float_mult * (float)G);
>> +        dest32[1][i] = av_float2int(float_mult * (float)B);
>> +        dest32[2][i] = av_float2int(float_mult * (float)R);
>>          if (hasAlpha)
>>              dest32[3][i] = av_float2int(float_mult *
>> (float)(av_clip_uintp2(A, 30) >> 14));
>>      }
>> diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm
>> index 84e94baaf6..f943a27534 100644
>> --- a/libswscale/x86/output.asm
>> +++ b/libswscale/x86/output.asm
>> @@ -44,11 +44,13 @@ pd_yuv2gbrp_y_start:       times 8 dd  (1 << 9)
>>  pd_yuv2gbrp_uv_start:      times 8 dd  ((1 << 9) - (128 << 19))
>>  pd_yuv2gbrp_a_start:       times 8 dd  (1 << 18)
>>  pd_yuv2gbrp16_offset:      times 8 dd  0x10000  ;(1 << 16)
>> -pd_yuv2gbrp16_round13:     times 8 dd  0x02000  ;(1 << 13)
>> +pd_yuv2gbrp16_round13:     times 8 dd  0xE0002000  ;(1 << 13) - (1 << 29)
>>  pd_yuv2gbrp16_a_offset:    times 8 dd  0x20002000
>>  pd_yuv2gbrp16_upper30:     times 8 dd  0x3FFFFFFF ;(1<<30) - 1
>>  pd_yuv2gbrp16_upper27:     times 8 dd  0x07FFFFFF ;(1<<27) - 1
>> +pd_yuv2gbrp16_upper16:     times 8 dd  0x0000FFFF ;(1<<16) - 1
>>
>
> pd_yuv2gbrp16_upper16 doesn't appear to be used anywhere
>

nevermind, I see where it is used now.


>
>
>>  pd_yuv2gbrp16_upperC:      times 8 dd  0xC0000000
>> +pd_yuv2gbrp_debias:        times 8 dd  0x00008000 ;(1 << 29 - 14)
>>  pb_pack_shuffle8:       db  0,  4,  8, 12, \
>>                             -1, -1, -1, -1, \
>>                             -1, -1, -1, -1, \
>> @@ -883,14 +885,26 @@ cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter,
>> lumSrcx, lumFilterSize, chrFi
>>          paddd G, Y
>>          paddd B, Y
>>
>> +%if  DEPTH < 16
>>          CLIPP2 R, 30
>>          CLIPP2 G, 30
>>          CLIPP2 B, 30
>> +%endif
>>
>>          psrad R, RGB_SHIFT
>>          psrad G, RGB_SHIFT
>>          psrad B, RGB_SHIFT
>>
>> +%if  DEPTH >= 16
>> +        paddd R, [pd_yuv2gbrp_debias]
>> +        paddd G, [pd_yuv2gbrp_debias]
>> +        paddd B, [pd_yuv2gbrp_debias]
>> +
>> +        CLIPP2 R, 16
>> +        CLIPP2 G, 16
>> +        CLIPP2 B, 16
>> +%endif
>> +
>>  %if FLOAT
>>          cvtdq2ps R, R
>>          cvtdq2ps G, G
>> --
>> 2.17.1
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>>
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range
  2022-11-02 21:02 [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Michael Niedermayer
  2022-11-02 21:02 ` [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32 Michael Niedermayer
@ 2022-11-03 14:07 ` Drew Dunne
  2022-11-04 21:45   ` Michael Niedermayer
  1 sibling, 1 reply; 11+ messages in thread
From: Drew Dunne @ 2022-11-03 14:07 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

I verified this fixes the overflow I was encountering.

On Wed, Nov 2, 2022 at 5:02 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Fixes: integer overflow
> Fixes: ./ffmpeg   -f rawvideo -video_size 66x64 -pixel_format
> yuva420p10le   -i ~/videos/overflow_input_w66h64.yuva420p10le
>  -filter_complex
> "scale=flags=bicubic+full_chroma_int+full_chroma_inp+bitexact+accurate_rnd:in_color_matrix=bt2020:out_color_matrix=bt2020:in_range=full:out_range=full,format=rgba64[out]"
>  -pixel_format rgba64 -map '[out]'   -y overflow_w66h64.png
>
> Found-by: Drew Dunne <asdunne@google.com>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libswscale/output.c | 120 ++++++++++++++++++++++----------------------
>  1 file changed, 60 insertions(+), 60 deletions(-)
>
> diff --git a/libswscale/output.c b/libswscale/output.c
> index 0e1c1225a0..df4647adde 100644
> --- a/libswscale/output.c
> +++ b/libswscale/output.c
> @@ -1100,8 +1100,8 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t
> *lumFilter,
>          Y2 -= c->yuv2rgb_y_offset;
>          Y1 *= c->yuv2rgb_y_coeff;
>          Y2 *= c->yuv2rgb_y_coeff;
> -        Y1 += 1 << 13; // 21
> -        Y2 += 1 << 13;
> +        Y1 += (1 << 13) - (1 << 29); // 21
> +        Y2 += (1 << 13) - (1 << 29);
>          // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
>
>          R = V * c->yuv2rgb_v2r_coeff;
> @@ -1109,20 +1109,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const
> int16_t *lumFilter,
>          B =                            U * c->yuv2rgb_u2b_coeff;
>
>          // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) +
> (1<<15), 16));
> +        output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) +
> (1<<15), 16));
> +        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) +
> (1<<15), 16));
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) +
> (1<<15), 16));
>              output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
>              dest += 8;
>          } else {
> -            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) +
> (1<<15), 16));
>              dest += 6;
>          }
>      }
> @@ -1160,8 +1160,8 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t
> *buf[2],
>          Y2 -= c->yuv2rgb_y_offset;
>          Y1 *= c->yuv2rgb_y_coeff;
>          Y2 *= c->yuv2rgb_y_coeff;
> -        Y1 += 1 << 13;
> -        Y2 += 1 << 13;
> +        Y1 += (1 << 13) - (1 << 29);
> +        Y2 += (1 << 13) - (1 << 29);
>
>          R = V * c->yuv2rgb_v2r_coeff;
>          G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
> @@ -1175,20 +1175,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const
> int32_t *buf[2],
>              A2 += 1 << 13;
>          }
>
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) +
> (1<<15), 16));
> +        output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) +
> (1<<15), 16));
> +        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) +
> (1<<15), 16));
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) +
> (1<<15), 16));
>              output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
>              dest += 8;
>          } else {
> -            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) +
> (1<<15), 16));
>              dest += 6;
>          }
>      }
> @@ -1217,8 +1217,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t
> *buf0,
>              Y2 -= c->yuv2rgb_y_offset;
>              Y1 *= c->yuv2rgb_y_coeff;
>              Y2 *= c->yuv2rgb_y_coeff;
> -            Y1 += 1 << 13;
> -            Y2 += 1 << 13;
> +            Y1 += (1 << 13) - (1 << 29);
> +            Y2 += (1 << 13) - (1 << 29);
>
>              if (hasAlpha) {
>                  A1 = abuf0[i * 2    ] << 11;
> @@ -1232,20 +1232,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) +
> (1<<15), 16));
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14)
> + (1<<15), 16));
>                  output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >>
> 14);
>                  dest += 8;
>              } else {
> -                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14)
> + (1<<15), 16));
>                  dest += 6;
>              }
>          }
> @@ -1263,8 +1263,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t
> *buf0,
>              Y2 -= c->yuv2rgb_y_offset;
>              Y1 *= c->yuv2rgb_y_coeff;
>              Y2 *= c->yuv2rgb_y_coeff;
> -            Y1 += 1 << 13;
> -            Y2 += 1 << 13;
> +            Y1 += (1 << 13) - (1 << 29);
> +            Y2 += (1 << 13) - (1 << 29);
>
>              if (hasAlpha) {
>                  A1 = abuf0[i * 2    ] << 11;
> @@ -1278,20 +1278,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) +
> (1<<15), 16));
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14)
> + (1<<15), 16));
>                  output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >>
> 14);
>                  dest += 8;
>              } else {
> -                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14)
> + (1<<15), 16));
> +                output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14)
> + (1<<15), 16));
>                  dest += 6;
>              }
>          }
> @@ -1343,7 +1343,7 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const
> int16_t *lumFilter,
>          // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
>          Y -= c->yuv2rgb_y_offset;
>          Y *= c->yuv2rgb_y_coeff;
> -        Y += 1 << 13; // 21
> +        Y += (1 << 13) - (1<<29); // 21
>          // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
>
>          R = V * c->yuv2rgb_v2r_coeff;
> @@ -1351,9 +1351,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const
> int16_t *lumFilter,
>          B =                            U * c->yuv2rgb_u2b_coeff;
>
>          // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y)>>14) + (1<<15),
> 16));
> +        output_pixel(&dest[1], av_clip_uintp2(((  G + Y)>>14) + (1<<15),
> 16));
> +        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y)>>14) + (1<<15),
> 16));
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>              dest += 4;
> @@ -1392,7 +1392,7 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const
> int32_t *buf[2],
>
>          Y -= c->yuv2rgb_y_offset;
>          Y *= c->yuv2rgb_y_coeff;
> -        Y += 1 << 13;
> +        Y += (1 << 13) - (1 << 29);
>
>          R = V * c->yuv2rgb_v2r_coeff;
>          G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
> @@ -1404,9 +1404,9 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const
> int32_t *buf[2],
>              A += 1 << 13;
>          }
>
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) +
> (1<<15), 16));
> +        output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) +
> (1<<15), 16));
> +        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) +
> (1<<15), 16));
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>              dest += 4;
> @@ -1436,7 +1436,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const
> int32_t *buf0,
>
>              Y -= c->yuv2rgb_y_offset;
>              Y *= c->yuv2rgb_y_coeff;
> -            Y += 1 << 13;
> +            Y += (1 << 13) - (1 << 29);
>
>              if (hasAlpha) {
>                  A = abuf0[i] << 11;
> @@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) +
> (1<<15), 16));
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>                  dest += 4;
> @@ -1469,7 +1469,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const
> int32_t *buf0,
>
>              Y -= c->yuv2rgb_y_offset;
>              Y *= c->yuv2rgb_y_coeff;
> -            Y += 1 << 13;
> +            Y += (1 << 13) - (1 << 29);
>
>              if (hasAlpha) {
>                  A = abuf0[i] << 11;
> @@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) +
> (1<<15), 16));
> +            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) +
> (1<<15), 16));
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>                  dest += 4;
> --
> 2.17.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>


-- 
Drew Dunne
asdunne@google.com
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range
  2022-11-03 14:07 ` [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Drew Dunne
@ 2022-11-04 21:45   ` Michael Niedermayer
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Niedermayer @ 2022-11-04 21:45 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 352 bytes --]

On Thu, Nov 03, 2022 at 10:07:45AM -0400, Drew Dunne wrote:
> I verified this fixes the overflow I was encountering.

Will apply patchset

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-11-04 21:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 21:02 [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Michael Niedermayer
2022-11-02 21:02 ` [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32 Michael Niedermayer
2022-11-02 21:07   ` Michael Niedermayer
2022-11-02 21:16     ` Andreas Rheinhardt
2022-11-02 21:31       ` Michael Niedermayer
2022-11-02 21:36         ` Martin Storsjö
2022-11-02 21:42         ` Michael Niedermayer
2022-11-02 22:52   ` Mark Reid
2022-11-02 22:55     ` Mark Reid
2022-11-03 14:07 ` [FFmpeg-devel] [PATCH 1/2] swscale/output: Bias 16bps output calculations to improve non overflowing range Drew Dunne
2022-11-04 21:45   ` Michael Niedermayer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git