Fix divide by zero

This commit is contained in:
Kovid Goyal 2023-01-02 22:07:41 +05:30
parent 7237e5cf9c
commit 7c2317d301
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -169,10 +169,15 @@ func newScannerRGB(img image.Image, opaque_base NRGBColor) *scanner_rgb {
d := make([]uint8, 3) d := make([]uint8, 3)
for i := 0; i < len(img.Palette); i++ { for i := 0; i < len(img.Palette); i++ {
r, g, b, a := img.Palette[i].RGBA() r, g, b, a := img.Palette[i].RGBA()
switch a {
case 0:
s.palette[i] = opaque_base
default:
blend(d, s.opaque_base, uint8((r*0xffff/a)>>8), uint8((g*0xffff/a)>>8), uint8((b*0xffff/a)>>8), uint8(a>>8)) blend(d, s.opaque_base, uint8((r*0xffff/a)>>8), uint8((g*0xffff/a)>>8), uint8((b*0xffff/a)>>8), uint8(a>>8))
s.palette[i] = NRGBColor{d[0], d[1], d[2]} s.palette[i] = NRGBColor{d[0], d[1], d[2]}
} }
} }
}
return s return s
} }