From 339acc57cf09fa99314625ec709ea74a1258be75 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 20 Dec 2020 12:25:12 +0100 Subject: render: fix rounding error when calculating background color with alpha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use pre-multiplied alpha color channels, but were having bad rounding errors due to the alpha divider being truncated to an integer. The algorithm for pre-multiplying a color channel is: alpha_divider = 0xffff / alpha pre_mult_color = color / alpha_divider In order to fix the rounding errors, we could turn ‘alpha_divider’ into a double. That however would introduce a performance penalty since now we’d need to do floating point math for each cell. The algorithm can be trivially converted to: pre_mult_color = color * alpha / 0xffff Since both color and alpa values are < 65536, the multiplication is “safe”; it will not overflow an uint32_t. Closes #249 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 795d395a..c25d5586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ * Missing dependencies in meson, causing heavily parallelized builds to fail. +* Background color when alpha < 1.0 being wrong + (https://codeberg.org/dnkl/foot/issues/249). ### Security -- cgit v1.3