Commit da6647b
committed
Fix alpha compositing in ft2font's draw_bitmap.
The old formula (`*dst |= *src`) works fine when either dst or src is
full transparent or fully opaque, but not for compositing intermediate
values. Fix that (while keeping a fast-path for the common case of
writing on an empty buffer).
Example (note the more uniform gray zone between the two letters):
```
from matplotlib import pyplot as plt, ft2font as f, cbook
import numpy as np
font = f.FT2Font(str(cbook._get_data_path("fonts/ttf/DejaVuSans.ttf")))
font.set_size(24, 72)
im = f.FT2Image(30, 30)
ga = font.load_char(ord("A"))
gv = font.load_char(ord("V"))
font.draw_glyph_to_bitmap(im, 2, 2, ga)
font.draw_glyph_to_bitmap(im, 12, 2, gv)
(plt.figure(layout="constrained", figsize=(3, 3))
.add_subplot(xticks=[], yticks=[])
.imshow(np.asarray(im), cmap="gray"))
plt.show()
```1 parent de00c49 commit da6647b
1 file changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
| |||
124 | 134 | | |
125 | 135 | | |
126 | 136 | | |
127 | | - | |
| 137 | + | |
| 138 | + | |
128 | 139 | | |
129 | 140 | | |
130 | 141 | | |
| |||
0 commit comments