diff mbox series

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

Message ID 20211108022704.812-2-mindmark@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/2] swscale/input: unify grayf32 funcs with rgbf32 funcs
Related show


Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Mark Reid Nov. 8, 2021, 2:27 a.m. UTC
From: Mark Reid <mindmark@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 mbox series


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)