Skip to content

Commit

Permalink
Update gray glyph blending logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachNagengast committed Nov 7, 2023
1 parent e1aaec3 commit fdecfca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Binary file modified Tests/images/bitmap_font_stroke_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/bitmap_font_stroke_raqm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/default_font_freetype.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,19 +1092,26 @@ font_render(FontObject *self, PyObject *args) {
if (color) {
unsigned char *ink = (unsigned char *)&foreground_ink;
for (k = x0; k < x1; k++) {
v = source[k] * convert_scale;
if (target[k * 4 + 3] < v) {
target[k * 4 + 0] = ink[0];
target[k * 4 + 1] = ink[1];
target[k * 4 + 2] = ink[2];
target[k * 4 + 3] = v;
int src_alpha = source[k] * convert_scale;
if (src_alpha > 0) {
if (target[k * 4 + 3] > 0) {
target[k * 4 + 0] = BLEND(src_alpha, target[k * 4 + 0], ink[0], tmp);
target[k * 4 + 1] = BLEND(src_alpha, target[k * 4 + 1], ink[1], tmp);
target[k * 4 + 2] = BLEND(src_alpha, target[k * 4 + 2], ink[2], tmp);
target[k * 4 + 3] = CLIP8(src_alpha + MULDIV255(target[k * 4 + 3], (255 - src_alpha), tmp));
} else {
target[k * 4 + 0] = ink[0];
target[k * 4 + 1] = ink[1];
target[k * 4 + 2] = ink[2];
target[k * 4 + 3] = src_alpha;
}
}
}
} else {
for (k = x0; k < x1; k++) {
v = source[k] * convert_scale;
if (target[k] < v) {
target[k] = v;
int src_alpha = source[k] * convert_scale;
if (src_alpha > 0) {
target[k] = target[k] > 0 ? CLIP8(src_alpha + MULDIV255(target[k], (255 - src_alpha), tmp)) : src_alpha;
}
}
}
Expand Down

0 comments on commit fdecfca

Please sign in to comment.