Cleanup debug code

This commit is contained in:
Francesco Abbate 2020-06-06 13:08:39 +02:00
parent d17fde1b13
commit dcf6b06629
2 changed files with 32 additions and 43 deletions

View File

@ -146,28 +146,14 @@ static void glyph_lut_convolution(agg::rendering_buffer ren_buf, agg::lcd_distri
const int len = (x1 - x0) * subpixel;
const int height = ren_buf.height();
for (int y = y0; y < y1; y++) {
// FIXME: clarify why we do not use height - 1 below.
agg::int8u *covers = ren_buf.row_ptr(height - 1 - y) + x0 * subpixel;
memcpy(covers_buf, covers, len);
#if 0
if (len >= 24) {
debug_print_covers("BUF ", covers_buf, 0, len + 2 * subpixel, 0);
debug_print_covers("BEFORE", covers - subpixel, 0, len + 2 * subpixel, 0);
}
#endif
for (int x = x0 - 1; x < x1 + 1; x++) {
for (int i = 0; i < subpixel; i++) {
const int cx = (x - x0) * subpixel + i;
covers[cx] = lcd_lut.convolution(covers, cx, 0, len - 1);
}
}
#if 0
if (len >= 24) {
debug_print_covers("AFTER ", covers - subpixel, 0, len + 2 * subpixel, 0);
char c;
scanf("%c", &c);
}
#endif
}
gli.x0 -= 1;
gli.x1 += 1;
@ -203,7 +189,7 @@ int FontRendererBakeFontBitmap(FontRenderer *font_renderer, int font_height,
// When using subpixel font rendering it is needed to leave a padding pixel on the left and on the right.
// Since each pixel is composed by n subpixel we set below x_start to subpixel_scale instead than zero.
const int x_start = subpixel_scale;
int x = x_start, y = pixels_height - 1; // - 20; // -20 is for debug
int x = x_start, y = pixels_height - 1;
int res = 0;
const agg::alpha8 text_color(0xff);
#ifdef FONT_RENDERER_HEIGHT_HACK
@ -211,7 +197,7 @@ int FontRendererBakeFontBitmap(FontRenderer *font_renderer, int font_height,
#else
const int font_height_reduced = font_height;
#endif
fprintf(stderr, "FONT HEIGHT %d, ASCENDER: %d DESCENDER: %d\n", font_height, ascender_px, descender_px);
agg::int8u *cover_swap_buffer = new agg::int8u[pixels_width * subpixel_scale];
for (int i = 0; i < num_chars; i++) {
int codepoint = first_char + i;
if (x + font_height * subpixel_scale > pixels_width * subpixel_scale) {
@ -225,7 +211,6 @@ int FontRendererBakeFontBitmap(FontRenderer *font_renderer, int font_height,
const int y_baseline = y - pad_y - ascender_px;
double x_next = x, y_next = y_baseline;
fprintf(stderr, "GLYPH (%d, %d)\n", x, y_baseline);
renderer_alpha.render_codepoint(ren_buf, font_height_reduced, text_color, x_next, y_next, codepoint, subpixel_scale);
int x_next_i = (subpixel_scale == 1 ? int(x_next + 1.0) : ceil_to_multiple(x_next + 0.5, subpixel_scale));
@ -241,14 +226,14 @@ int FontRendererBakeFontBitmap(FontRenderer *font_renderer, int font_height,
glyph_info.xadvance = (x_next - x) / subpixel_scale;
if (glyph_info.x1 > glyph_info.x0) {
agg::int8u *covers_buf = ren_buf.row_ptr(0);
glyph_lut_convolution(ren_buf, lcd_lut, covers_buf, glyph_info);
glyph_lut_convolution(ren_buf, lcd_lut, cover_swap_buffer, glyph_info);
}
// glyph_trim_rect(ren_buf, glyph_info, subpixel_scale);
glyph_trim_rect(ren_buf, glyph_info, subpixel_scale);
// When subpixel is activated we need at least two more subpixels on the right.
// When subpixel is activated we need one padding pixel on the left and on the right.
x = x_next_i + 2 * subpixel_scale;
}
delete [] cover_swap_buffer;
return res;
}

View File

@ -126,6 +126,7 @@ void ren_free_coverage(RenCoverageImage *coverage) {
free(coverage);
}
#ifdef FONT_RENDERER_DEBUG
void debug_bitmap_draw_rect(RenImage *image, GlyphBitmapInfo *glyph) {
const int subpixel = 3;
const int x0 = glyph->x0, x1 = glyph->x1;
@ -152,6 +153,7 @@ void debug_bitmap_draw_rect(RenImage *image, GlyphBitmapInfo *glyph) {
c[y * w].b = c[y * w].b >> 1;
}
}
#endif
static GlyphSet* load_glyphset(RenFont *font, int idx) {
GlyphSet *set = check_alloc(calloc(1, sizeof(GlyphSet)));
@ -176,9 +178,9 @@ retry:
goto retry;
}
#ifdef FONT_RENDERER_DEBUG
static int debug_image_index = 1;
if (idx == 0) {
// DEBUG CODE
RenImage *debug_cov_image = ren_new_image(width * subpixel_scale, height);
for (int h = 0; h < height; h++) {
RenColor *d = debug_cov_image->pixels + h * width * subpixel_scale;
@ -202,6 +204,8 @@ retry:
ren_free_image(debug_cov_image);
debug_image_index++;
}
#endif
/* adjust glyph's xadvance */
for (int i = 0; i < 256; i++) {
set->glyphs[i].xadvance = floor(set->glyphs[i].xadvance + 0.5);