Commit 115c1ebc authored by Rahix's avatar Rahix
Browse files

fix(display): Fix lines with odd linewidth

Previously, such lines would be drawn as a fuzzy two-pixel wide line
instead of a sharp one-pixel one.  This is because the coordinate grid
is aligned _between_ pixels instead of on the pixel centers.  More
information in this cairo FAQ:

For odd linewidths, add 0.5 to all coordinates to offset the line
perfectly onto the pixel grid.  This makes them look sharp, as with the
previous gfx code.
Suggested-by: Øyvind Kolås's avatarØyvind Kolås <>
parent d42ae56f
......@@ -211,13 +211,26 @@ int epic_disp_line(
return cl;
float xstartf = xstart, ystartf = ystart, xendf = xend, yendf = yend;
* For odd line widths, shift the line by half a pixel so it aligns
* perfectly with the pixel grid.
if (pixelsize % 2 == 1) {
xstartf += 0.5f;
ystartf += 0.5f;
yendf += 0.5f;
xendf += 0.5f;
uint8_t r, g, b;
rgb565_to_rgb888(color, &r, &g, &b);
ctx_rgba8_stroke(epicardium_ctx, r, g, b, 255);
ctx_line_width(epicardium_ctx, pixelsize);
ctx_move_to(epicardium_ctx, xstart, ystart);
ctx_line_to(epicardium_ctx, xend, yend);
ctx_move_to(epicardium_ctx, xstartf, ystartf);
ctx_line_to(epicardium_ctx, xendf, yendf);
return 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment