From 68c2bf1a1ab9a9764658860827ffa4b5eacd0833 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 24 Aug 2016 15:19:43 +0200 Subject: Correct use of qt_div_255 qt_div_255 does a fast rounded division, the form of rounding is however only valid for positive integers. Correct one case where it was used incorrectly and add it one place it would be valid, and adds a comment to the function. We were using the optimization (x*a + y*(255-a))/255 == (x-y)*a/255 + y but that makes the division by 255 potentially negative. Change-Id: Ie53aa82b66ef801f5d43f8d2ec48880cb4972f69 Reviewed-by: Marc Mutz --- src/gui/painting/qdrawhelper_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui/painting/qdrawhelper_p.h') diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index ff98d186c5..d636eabe3f 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -705,6 +705,7 @@ static Q_ALWAYS_INLINE uint BYTE_MUL_RGB16_32(uint x, uint a) { return t; } +// qt_div_255 is a fast rounded division by 255 using an approximation that is accurate for all positive 16-bit integers static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; } static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_div_65535(uint x) { return (x + (x>>16) + 0x8000U) >> 16; } -- cgit v1.2.3