[FFmpeg-devel] [PATCH v2 2/2] swscale/input: clamp rgbf32 values between 0, 1 before scaling

mindmark at gmail.com mindmark at gmail.com
Mon Nov 8 04:27:04 EET 2021


From: Mark Reid <mindmark at gmail.com>

if the float pixel * 65535.0f > 2147483647.0f
lrintf may overfow and return negative values, depending on implementation.
nan and +/-inf values may also be implementation defined

clamp the values between 0,1 before scaling, so lrintf
always works.

values <=0.0f, -inf, nan = 0.0f
values >=1.0f, +inf      = 1.0f
---
 libswscale/input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libswscale/input.c b/libswscale/input.c
index 90efdd2ffc..fc8242a758 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -964,7 +964,7 @@ static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
 }
 #undef rdpx
 
-#define rdpx(src) (is_be ? av_int2float(AV_RB32(src)): av_int2float(AV_RL32(src)))
+#define rdpx(src) (FFMIN(FFMAX(is_be ? av_int2float(AV_RB32(src)): av_int2float(AV_RL32(src)), 0.0f), 1.0f))
 
 static av_always_inline void planar_rgbf32_to_a(uint8_t *_dst, const uint8_t *_src[4], int width, int is_be, int32_t *rgb2yuv)
 {
-- 
2.31.1.windows.1



More information about the ffmpeg-devel mailing list