aboutsummaryrefslogtreecommitdiff
path: root/box-drawing.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-05-05 13:31:57 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-05-17 15:58:29 +0000
commitb2809280847d63cb616fc363e0fcc5bbd3c1b22b (patch)
tree2584ea5a3006b08653a527df96f9eac522c00ea7 /box-drawing.c
parentbox-drawing: use pixman_image_fill_boxes() for rect() (diff)
box-drawing: draw shades as “antialiased” blocks
When rendering to an a8 surface, render shades using “transparent” pixman rectangles. When these glyphs are composited with a color, the resulting look is the color, but darkened.
Diffstat (limited to 'box-drawing.c')
-rw-r--r--box-drawing.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/box-drawing.c b/box-drawing.c
index e196e7fb..eb486a75 100644
--- a/box-drawing.c
+++ b/box-drawing.c
@@ -1676,40 +1676,58 @@ draw_right_half_block(struct buf *buf)
rect(round(buf->width / 2.), 0, buf->width, buf->height);
}
+static void NOINLINE
+draw_pixman_shade(struct buf *buf, uint16_t v)
+{
+ pixman_color_t shade = {0, 0, 0, v};
+ pixman_image_fill_rectangles(
+ PIXMAN_OP_SRC, buf->pix, &shade, 1,
+ (pixman_rectangle16_t []){{0, 0, buf->width, buf->height}});
+}
+
static void
draw_light_shade(struct buf *buf)
{
- for (size_t row = 0; row < buf->height; row += 2) {
- for (size_t col = 0; col < buf->width; col += 2) {
- size_t idx = col / 8;
- size_t bit_no = col % 8;
- buf->data[row * buf->stride + idx] |= 1 << bit_no;
+ if (pixman_image_get_format(buf->pix) == PIXMAN_a1) {
+ for (size_t row = 0; row < buf->height; row += 2) {
+ for (size_t col = 0; col < buf->width; col += 2) {
+ size_t idx = col / 8;
+ size_t bit_no = col % 8;
+ buf->data[row * buf->stride + idx] |= 1 << bit_no;
+ }
}
- }
+ } else
+ draw_pixman_shade(buf, 0x8000);
}
static void
draw_medium_shade(struct buf *buf)
{
- for (size_t row = 0; row < buf->height; row++) {
- for (size_t col = row % 2; col < buf->width; col += 2) {
- size_t idx = col / 8;
- size_t bit_no = col % 8;
- buf->data[row * buf->stride + idx] |= 1 << bit_no;
+ if (pixman_image_get_format(buf->pix) == PIXMAN_a1) {
+ for (size_t row = 0; row < buf->height; row++) {
+ for (size_t col = row % 2; col < buf->width; col += 2) {
+ size_t idx = col / 8;
+ size_t bit_no = col % 8;
+ buf->data[row * buf->stride + idx] |= 1 << bit_no;
+ }
}
- }
+ } else
+ draw_pixman_shade(buf, 0x4000);
}
static void
draw_dark_shade(struct buf *buf)
{
- for (size_t row = 0; row < buf->height; row++) {
- for (size_t col = 0; col < buf->width; col += 1 + row % 2) {
- size_t idx = col / 8;
- size_t bit_no = col % 8;
- buf->data[row * buf->stride + idx] |= 1 << bit_no;
+ if (pixman_image_get_format(buf->pix) == PIXMAN_a1) {
+ for (size_t row = 0; row < buf->height; row++) {
+ for (size_t col = 0; col < buf->width; col += 1 + row % 2) {
+ size_t idx = col / 8;
+ size_t bit_no = col % 8;
+ buf->data[row * buf->stride + idx] |= 1 << bit_no;
+ }
}
- }
+ } else
+ draw_pixman_shade(buf, 0x2000);
}
static void