Fix pixel off-by-one error in subpixel font renderer hspan

This commit is contained in:
Francesco Abbate 2020-06-08 09:32:39 +02:00
parent 74de184e50
commit bddc947b99
1 changed files with 7 additions and 11 deletions

View File

@ -256,27 +256,23 @@ void blend_solid_hspan(agg::rendering_buffer& rbuf, blender_gamma_type& blender,
} }
void blend_solid_hspan_rgb_subpixel(agg::rendering_buffer& rbuf, agg::gamma_lut<>& gamma, agg::lcd_distribution_lut& lcd_lut, void blend_solid_hspan_rgb_subpixel(agg::rendering_buffer& rbuf, agg::gamma_lut<>& gamma, agg::lcd_distribution_lut& lcd_lut,
int x, int y, unsigned len, const int x, const int y, unsigned len,
const agg::rgba8& c, const agg::rgba8& c,
const agg::int8u* covers) const agg::int8u* covers)
{ {
const int x_min = x;
const int x_max = x + len / 3;
const int pixel_size = 4; const int pixel_size = 4;
const agg::int8u rgb[3] = { c.r, c.g, c.b }; const agg::int8u rgb[3] = { c.r, c.g, c.b };
agg::int8u* p = rbuf.row_ptr(y) + x_min * pixel_size; agg::int8u* p = rbuf.row_ptr(y) + x * pixel_size;
// Indexes to adress RGB colors in a BGRA32 format. // Indexes to adress RGB colors in a BGRA32 format.
const int pixel_index[3] = {2, 1, 0}; const int pixel_index[3] = {2, 1, 0};
for (int xp = x_min; xp <= x_max; xp++) for (unsigned cx = 0; cx < len; cx += 3)
{ {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
int cx = xp * 3 - x + i; const unsigned cover_value = covers[cx + i];
unsigned cover_value = covers[cx]; const unsigned alpha = (cover_value + 1) * (c.a + 1);
unsigned alpha = (cover_value + 1) * (c.a + 1); const unsigned dst_col = gamma.dir(rgb[i]);
unsigned dst_col = gamma.dir(rgb[i]); const unsigned src_col = gamma.dir(*(p + pixel_index[i]));
unsigned src_col = gamma.dir(*(p + pixel_index[i]));
*(p + pixel_index[i]) = gamma.inv((((dst_col - src_col) * alpha) + (src_col << 16)) >> 16); *(p + pixel_index[i]) = gamma.inv((((dst_col - src_col) * alpha) + (src_col << 16)) >> 16);
} }
// Leave p[3], the alpha channel value unmodified. // Leave p[3], the alpha channel value unmodified.