mirror of https://github.com/mpv-player/mpv
draw_bmp: silence another ridiculous ubsan warning
UB sanitizer complains that aval<<24 (if >=128) cannot be represented as int. Indeed, we would shift a bit into the sign of an int, which is probably UB or implementation defined (I can't even remember, but the stupidity of it burns). So technically, ubsan might be right. Change aval to uint32_t, which I don't think has a chance of getting promoted to int. Change the other *val to uint32_t too for cosmetic symmetry. So we have to obscure the intention of the code (*val can take only 8 bits) out of language stupidity. How nice. (What a shitty language.)
This commit is contained in:
parent
ab201ce042
commit
a09c7691d7
|
@ -148,10 +148,10 @@ static void unpremultiply_and_split_BGR32(struct mp_image *img,
|
||||||
uint8_t *arow = &alpha->planes[0][alpha->stride[0] * y];
|
uint8_t *arow = &alpha->planes[0][alpha->stride[0] * y];
|
||||||
for (int x = 0; x < img->w; ++x) {
|
for (int x = 0; x < img->w; ++x) {
|
||||||
uint32_t pval = irow[x];
|
uint32_t pval = irow[x];
|
||||||
uint8_t aval = (pval >> 24);
|
uint32_t aval = (pval >> 24);
|
||||||
uint8_t rval = (pval >> 16) & 0xFF;
|
uint32_t rval = (pval >> 16) & 0xFF;
|
||||||
uint8_t gval = (pval >> 8) & 0xFF;
|
uint32_t gval = (pval >> 8) & 0xFF;
|
||||||
uint8_t bval = pval & 0xFF;
|
uint32_t bval = pval & 0xFF;
|
||||||
// multiplied = separate * alpha / 255
|
// multiplied = separate * alpha / 255
|
||||||
// separate = rint(multiplied * 255 / alpha)
|
// separate = rint(multiplied * 255 / alpha)
|
||||||
// = floor(multiplied * 255 / alpha + 0.5)
|
// = floor(multiplied * 255 / alpha + 0.5)
|
||||||
|
|
Loading…
Reference in New Issue