Jacek Caban : gdiplus: Introduce absdiff helper.

Alexandre Julliard julliard at winehq.org
Mon Jun 1 15:14:55 CDT 2020


Module: wine
Branch: master
Commit: cca639fa641f01f42840042f17c1499785562f17
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=cca639fa641f01f42840042f17c1499785562f17

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed May 27 23:55:18 2020 +0200

gdiplus: Introduce absdiff helper.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Esme Povirk <vincent at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdiplus/image.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index cafe69d8f4..39f717b5b3 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -380,6 +380,11 @@ GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
     return Ok;
 }
 
+static unsigned int absdiff(unsigned int x, unsigned int y)
+{
+    return x > y ? x - y : y - x;
+}
+
 static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, ColorPalette *palette)
 {
     BYTE index = 0;
@@ -399,7 +404,7 @@ static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, ColorPalett
     */
     for(i=0;i<palette->Count;i++) {
         ARGB color=palette->Entries[i];
-        distance=abs(b-(color & 0xff)) + abs(g-(color>>8 & 0xff)) + abs(r-(color>>16 & 0xff)) + abs(a-(color>>24 & 0xff));
+        distance=absdiff(b, color & 0xff) + absdiff(g, color>>8 & 0xff) + absdiff(r, color>>16 & 0xff) + absdiff(a, color>>24 & 0xff);
         if (distance<best_distance) {
             best_distance=distance;
             index=i;




More information about the wine-cvs mailing list