From fa8d38da74946d3d08ecb4548db98eb2a855b096 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 30 Jul 2014 17:28:48 +0200 Subject: Fix T41241: VSE: cropping strips puts a transparent line through the image. --- source/blender/imbuf/intern/scaling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/imbuf/intern/scaling.c') diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index c98b39c826b..e066443769d 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -1353,7 +1353,7 @@ static ImBuf *scaleupy(struct ImBuf *ibuf, int newy) val_g += 0.5f; val_r = rect[3]; - nval_r = rect[skipx + 4]; + nval_r = rect[skipx + 3]; diff_r = nval_r - val_r; val_r += 0.5f; -- cgit v1.2.3 From 1ca86849112b6fec869318438a4f3760de49da0e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 11 Aug 2014 17:37:56 +0600 Subject: 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(-) (limited to 'source/blender/imbuf/intern/scaling.c') 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]); } } -- cgit v1.2.3 From e05567ef3e72830abb2cd23c26b0bbc6139f0e1e Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Wed, 13 Aug 2014 19:07:28 +0200 Subject: Fix out of bounds read when recalculating mipmaps, error reported by address sanitizer. This was strangely only triggered when float buffers were used. --- source/blender/imbuf/intern/scaling.c | 76 +++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 25 deletions(-) (limited to 'source/blender/imbuf/intern/scaling.c') diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 6452e9fa310..40e43224f3f 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -52,26 +52,17 @@ /************************************************************************/ -struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) +static void imb_half_x_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) { - struct ImBuf *ibuf2; uchar *p1, *_p1, *dest; short a, r, g, b; int x, y; float af, rf, gf, bf, *p1f, *_p1f, *destf; bool do_rect, do_float; - if (ibuf1 == NULL) return (NULL); - if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL); - do_rect = (ibuf1->rect != NULL); - do_float = (ibuf1->rect_float != NULL); - - if (ibuf1->x <= 1) return(IMB_dupImBuf(ibuf1)); + do_float = (ibuf1->rect_float != NULL && ibuf2->rect_float != NULL); - ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags); - if (ibuf2 == NULL) return (NULL); - _p1 = (uchar *) ibuf1->rect; dest = (uchar *) ibuf2->rect; @@ -114,9 +105,24 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) if (do_rect) _p1 += (ibuf1->x << 2); if (do_float) _p1f += (ibuf1->x << 2); } - return (ibuf2); } +struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) +{ + struct ImBuf *ibuf2; + + if (ibuf1 == NULL) return (NULL); + if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL); + + if (ibuf1->x <= 1) return(IMB_dupImBuf(ibuf1)); + + ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags); + if (ibuf2 == NULL) return (NULL); + + imb_half_x_no_alloc(ibuf2, ibuf1); + + return (ibuf2); +} struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) { @@ -171,9 +177,8 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1) } -struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) +static void imb_half_y_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) { - struct ImBuf *ibuf2; uchar *p1, *p2, *_p1, *dest; short a, r, g, b; int x, y; @@ -182,15 +187,9 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) p1 = p2 = NULL; p1f = p2f = NULL; - if (ibuf1 == NULL) return (NULL); - if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL); - if (ibuf1->y <= 1) return(IMB_dupImBuf(ibuf1)); do_rect = (ibuf1->rect != NULL); - do_float = (ibuf1->rect_float != NULL); - - ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags); - if (ibuf2 == NULL) return (NULL); + do_float = (ibuf1->rect_float != NULL && ibuf2->rect_float != NULL); _p1 = (uchar *) ibuf1->rect; dest = (uchar *) ibuf2->rect; @@ -239,6 +238,23 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) if (do_rect) _p1 += (ibuf1->x << 3); if (do_float) _p1f += (ibuf1->x << 3); } +} + + +struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) +{ + struct ImBuf *ibuf2; + + if (ibuf1 == NULL) return (NULL); + if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL); + + if (ibuf1->y <= 1) return(IMB_dupImBuf(ibuf1)); + + ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags); + if (ibuf2 == NULL) return (NULL); + + imb_half_y_no_alloc(ibuf2, ibuf1); + return (ibuf2); } @@ -336,28 +352,38 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) imb_addrectImBuf(ibuf2); } + if (ibuf1->x <= 1) { + imb_half_y_no_alloc(ibuf2, ibuf1); + return; + } + if (ibuf1->y <= 1) { + imb_half_x_no_alloc(ibuf2, ibuf1); + return; + } + if (do_rect) { unsigned char *cp1, *cp2, *dest; cp1 = (unsigned char *) ibuf1->rect; dest = (unsigned char *) ibuf2->rect; + for (y = ibuf2->y; y > 0; y--) { cp2 = cp1 + (ibuf1->x << 2); for (x = ibuf2->x; x > 0; x--) { unsigned short p1i[8], p2i[8], desti[4]; - + straight_uchar_to_premul_ushort(p1i, cp1); straight_uchar_to_premul_ushort(p2i, cp2); straight_uchar_to_premul_ushort(p1i + 4, cp1 + 4); straight_uchar_to_premul_ushort(p2i + 4, cp2 + 4); - + desti[0] = ((unsigned int) p1i[0] + p2i[0] + p1i[4] + p2i[4]) >> 2; desti[1] = ((unsigned int) p1i[1] + p2i[1] + p1i[5] + p2i[5]) >> 2; desti[2] = ((unsigned int) p1i[2] + p2i[2] + p1i[6] + p2i[6]) >> 2; desti[3] = ((unsigned int) p1i[3] + p2i[3] + p1i[7] + p2i[7]) >> 2; - + premul_ushort_to_straight_uchar(dest, desti); - + cp1 += 8; cp2 += 8; dest += 4; -- cgit v1.2.3 From dc05d817eb2d37b3d65ced0fcefa96f23548d2f3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 18 Aug 2014 18:03:56 +0600 Subject: Correction to the mipmaps generation Seem we've always were wrong with multiplying alpha by 255, other channels seems to be multiplied by 256 with the shift operations. --- source/blender/imbuf/intern/scaling.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source/blender/imbuf/intern/scaling.c') diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 40e43224f3f..e480f06da2b 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -320,7 +320,7 @@ MINLINE void straight_uchar_to_premul_ushort(unsigned short result[4], const uns result[0] = color[0] * alpha; result[1] = color[1] * alpha; result[2] = color[2] * alpha; - result[3] = alpha * 255; + result[3] = alpha * 256; } MINLINE void premul_ushort_to_straight_uchar(unsigned char *result, const unsigned short color[4]) @@ -332,11 +332,11 @@ MINLINE void premul_ushort_to_straight_uchar(unsigned char *result, const unsign result[3] = USHORTTOUCHAR(color[3]); } else { - unsigned short alpha = color[3] / 255; + unsigned short alpha = color[3] / 256; - result[0] = USHORTTOUCHAR(color[0] / alpha * 255); - result[1] = USHORTTOUCHAR(color[1] / alpha * 255); - result[2] = USHORTTOUCHAR(color[2] / alpha * 255); + result[0] = USHORTTOUCHAR(color[0] / alpha * 256); + result[1] = USHORTTOUCHAR(color[1] / alpha * 256); + result[2] = USHORTTOUCHAR(color[2] / alpha * 256); result[3] = USHORTTOUCHAR(color[3]); } } -- cgit v1.2.3