From b2809280847d63cb616fc363e0fcc5bbd3c1b22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 5 May 2021 15:31:57 +0200 Subject: [PATCH] =?UTF-8?q?box-drawing:=20draw=20shades=20as=20=E2=80=9Can?= =?UTF-8?q?tialiased=E2=80=9D=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- box-drawing.c | 54 ++++++++++++++++++++++++++++++++++----------------- 1 file 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