From c5f8d745e4dc42404409a2c166181d85bc87934b Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 6 Oct 2016 19:51:29 +0100 Subject: Correct maths error in painters. As part of the blending calculations, we do: dst = src * mask_alpha + dst * (1-mask_alpha.src_alpha) We calculate mask_alpha as ma, and 1-mask_alpha.src_alpha as masa. In full accuracy, we should never have ma + masa >= 1. Unfortunately, with the formulation used in the painters at the moment, we can. We therefore rejig the calculations slightly. --- include/mupdf/fitz/math.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/mupdf/fitz/math.h b/include/mupdf/fitz/math.h index 9ba79697..5e25f871 100644 --- a/include/mupdf/fitz/math.h +++ b/include/mupdf/fitz/math.h @@ -19,6 +19,11 @@ static inline int fz_mul255(int a, int b) * to give a single value in the same range as A was. */ #define FZ_COMBINE(A,B) (((A)*(B))>>8) +/* Combine values A (in the 0..255 range) and B (in the 0..256 range), + * then reverse it within that range to give a single value in the + * 0..256 range. */ +#define FZ_REVERSE_COMBINE(A,B) ((0xFF00 - (A)*(B))>>8) + /* Combine values A and C (in the same (any) range) and B and D (in the * 0..256 range), to give a single value in the same range as A and C were. */ #define FZ_COMBINE2(A,B,C,D) (FZ_COMBINE((A), (B)) + FZ_COMBINE((C), (D))) -- cgit v1.2.3