[Bf-blender-cvs] [6944521d7e3] blender-v2.93-release: Fix T87337: Text strip draws white outline

Richard Antalik noreply at git.blender.org
Thu Apr 22 08:25:22 CEST 2021


Commit: 6944521d7e3711e6f055e12427aec9d3618979ec
Author: Richard Antalik
Date:   Thu Apr 22 08:16:16 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rB6944521d7e3711e6f055e12427aec9d3618979ec

Fix T87337: Text strip draws white outline

Math for drawing font over byte buffer was incorrect. Effect can be seen
when target buffer is fully black and transparent - this results in font
color being effectively premultiplied, which causes problems when image
is composited further.

Use `blend_color_mix_byte()` and `blend_color_mix_float()` for blending.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D11035

===================================================================

M	source/blender/blenfont/intern/blf_font.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index f83ee409187..b7c226ada1d 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -41,6 +41,7 @@
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_math_color_blend.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
 #include "BLI_string_utf8.h"
@@ -640,18 +641,12 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
                                       (size_t)buf_info->ch);
               float *fbuf = buf_info->fbuf + buf_ofs;
 
-              if (a >= 1.0f) {
-                fbuf[0] = b_col_float[0];
-                fbuf[1] = b_col_float[1];
-                fbuf[2] = b_col_float[2];
-                fbuf[3] = 1.0f;
-              }
-              else {
-                fbuf[0] = (b_col_float[0] * a) + (fbuf[0] * (1.0f - a));
-                fbuf[1] = (b_col_float[1] * a) + (fbuf[1] * (1.0f - a));
-                fbuf[2] = (b_col_float[2] * a) + (fbuf[2] * (1.0f - a));
-                fbuf[3] = MIN2(fbuf[3] + a, 1.0f); /* clamp to 1.0 */
-              }
+              float font_pixel[4];
+              font_pixel[0] = b_col_float[0] * a;
+              font_pixel[1] = b_col_float[1] * a;
+              font_pixel[2] = b_col_float[2] * a;
+              font_pixel[3] = a;
+              blend_color_mix_float(fbuf, fbuf, font_pixel);
             }
           }
 
@@ -677,19 +672,12 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
                                       (size_t)buf_info->ch);
               unsigned char *cbuf = buf_info->cbuf + buf_ofs;
 
-              if (a >= 1.0f) {
-                cbuf[0] = b_col_char[0];
-                cbuf[1] = b_col_char[1];
-                cbuf[2] = b_col_char[2];
-                cbuf[3] = 255;
-              }
-              else {
-                cbuf[0] = (unsigned char)((b_col_char[0] * a) + (cbuf[0] * (1.0f - a)));
-                cbuf[1] = (unsigned char)((b_col_char[1] * a) + (cbuf[1] * (1.0f - a)));
-                cbuf[2] = (unsigned char)((b_col_char[2] * a) + (cbuf[2] * (1.0f - a)));
-                /* clamp to 255 */
-                cbuf[3] = (unsigned char)MIN2((int)cbuf[3] + (int)(a * 255), 255);
-              }
+              uchar font_pixel[4];
+              font_pixel[0] = b_col_char[0];
+              font_pixel[1] = b_col_char[1];
+              font_pixel[2] = b_col_char[2];
+              font_pixel[3] = unit_float_to_uchar_clamp(a);
+              blend_color_mix_byte(cbuf, cbuf, font_pixel);
             }
           }



More information about the Bf-blender-cvs mailing list