diff options
author | Richard Antalik <richardantalik@gmail.com> | 2021-04-22 09:16:16 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2021-04-22 09:16:16 +0300 |
commit | 6944521d7e3711e6f055e12427aec9d3618979ec (patch) | |
tree | 15772ed6f604e96754a5d8aac8d74aedc1721958 /source/blender/blenfont | |
parent | 4554f27adf1e66f05de66e7d6f0a61025f28862b (diff) |
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
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 38 |
1 files changed, 13 insertions, 25 deletions
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); } } |