From 1ca86849112b6fec869318438a4f3760de49da0e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 11 Aug 2014 17:37:56 +0600 Subject: [PATCH] Fix T40744: MIP Map is generating strange noise in texture, Blender Internal --- source/blender/imbuf/intern/scaling.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index e066443769d..6452e9fa310 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -33,6 +33,7 @@ #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "BLI_math_color.h" #include "BLI_math_interp.h" #include "MEM_guardedalloc.h" @@ -309,18 +310,18 @@ MINLINE void straight_uchar_to_premul_ushort(unsigned short result[4], const uns MINLINE void premul_ushort_to_straight_uchar(unsigned char *result, const unsigned short color[4]) { if (color[3] <= 255) { - result[0] = color[0] / 255; - result[1] = color[1] / 255; - result[2] = color[2] / 255; - result[3] = color[3] / 255; + result[0] = USHORTTOUCHAR(color[0]); + result[1] = USHORTTOUCHAR(color[1]); + result[2] = USHORTTOUCHAR(color[2]); + result[3] = USHORTTOUCHAR(color[3]); } else { unsigned short alpha = color[3] / 255; - result[0] = color[0] / alpha; - result[1] = color[1] / alpha; - result[2] = color[2] / alpha; - result[3] = alpha; + result[0] = USHORTTOUCHAR(color[0] / alpha * 255); + result[1] = USHORTTOUCHAR(color[1] / alpha * 255); + result[2] = USHORTTOUCHAR(color[2] / alpha * 255); + result[3] = USHORTTOUCHAR(color[3]); } }