WIP: debugging stuff

This commit is contained in:
Francesco Abbate
2020-06-06 10:52:50 +02:00
parent 7b541b7de8
commit d17fde1b13
2 changed files with 67 additions and 10 deletions
+53
View File
@@ -126,6 +126,33 @@ void ren_free_coverage(RenCoverageImage *coverage) {
free(coverage);
}
void debug_bitmap_draw_rect(RenImage *image, GlyphBitmapInfo *glyph) {
const int subpixel = 3;
const int x0 = glyph->x0, x1 = glyph->x1;
const int y0 = glyph->y0, y1 = glyph->y1;
const int w = image->width;
RenColor *c = image->pixels + y0 * w;
for (int x = x0 * subpixel; x < x1 * subpixel; x++) {
c[x].g = c[x].g >> 1;
c[x].b = c[x].b >> 1;
}
c = image->pixels + x1 * subpixel;
for (int y = y0; y < y1; y++) {
c[y * w].g = c[y * w].g >> 1;
c[y * w].b = c[y * w].b >> 1;
}
c = image->pixels + y1 * w;
for (int x = x0 * subpixel; x < x1 * subpixel; x++) {
c[x].g = c[x].g >> 1;
c[x].b = c[x].b >> 1;
}
c = image->pixels + x0 * subpixel;
for (int y = y0 + 1; y < y1; y++) {
c[y * w].g = c[y * w].g >> 1;
c[y * w].b = c[y * w].b >> 1;
}
}
static GlyphSet* load_glyphset(RenFont *font, int idx) {
GlyphSet *set = check_alloc(calloc(1, sizeof(GlyphSet)));
@@ -149,6 +176,32 @@ retry:
goto retry;
}
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;
uint8_t *s = set->coverage->pixels + h * subpixel_scale * width;
for (int w = 0; w < width * subpixel_scale; w++) {
uint8_t cover = s[w];
d[w] = (RenColor) {.b = 0xff - cover, .g = 0xff - cover, .r = 0xff - cover, .a = 0xff};
}
}
for (int i = 0; i < 256; i++) {
debug_bitmap_draw_rect(debug_cov_image, &set->glyphs[i]);
}
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
debug_cov_image->pixels,
width * subpixel_scale, height, 32, width * subpixel_scale * 4,
SDL_PIXELFORMAT_RGBA32);
char img_filename[64];
sprintf(img_filename, "agg-glyphset-%03d.bmp", debug_image_index);
SDL_SaveBMP(surface, img_filename);
SDL_FreeSurface(surface);
ren_free_image(debug_cov_image);
debug_image_index++;
}
/* adjust glyph's xadvance */
for (int i = 0; i < 256; i++) {
set->glyphs[i].xadvance = floor(set->glyphs[i].xadvance + 0.5);