swscale/swscale: force SwsDither and SwsAlphaBlend to 32 bits

The 'sws_dither' and 'alphablend' options access 'SwsDither' and
'SwsAlphaBlend' enum fields as integers. This is unsafe when the
code is compiled with -fshort-enums, as the enum size might be
smaller than an int.

Since the 'dither' and 'alpha_blend' struct members are part of the
public API, their types cannot be easily changed.

To ensure safe integer access and maintain ABI compatibility across
different compiler settings, a MAX_ENUM value is added to force the
enums to a 32-bit underlying type.
This commit is contained in:
Zhao Zhili
2026-01-26 23:50:50 +08:00
committed by Zhao Zhili
parent 36b23092f9
commit 9ebfd68096

View File

@@ -82,6 +82,7 @@ typedef enum SwsDither {
SWS_DITHER_A_DITHER, /* arithmetic addition */
SWS_DITHER_X_DITHER, /* arithmetic xor */
SWS_DITHER_NB, /* not part of the ABI */
SWS_DITHER_MAX_ENUM = 0x7FFFFFFF, /* force size to 32 bits, not a valid dither type */
} SwsDither;
typedef enum SwsAlphaBlend {
@@ -89,6 +90,7 @@ typedef enum SwsAlphaBlend {
SWS_ALPHA_BLEND_UNIFORM,
SWS_ALPHA_BLEND_CHECKERBOARD,
SWS_ALPHA_BLEND_NB, /* not part of the ABI */
SWS_ALPHA_BLEND_MAX_ENUM = 0x7FFFFFFF, /* force size to 32 bits, not a valid blend mode */
} SwsAlphaBlend;
typedef enum SwsFlags {