From 8d09ba5bd2f8843232d25fc93acfcccd3513f1bd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 14:59:53 +0200 Subject: box-drawing: include pixman image in the buffer we’re passing around MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box-drawing.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 5701bf46..2e387582 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -20,6 +20,7 @@ enum thickness { struct buf { uint8_t *data; + pixman_image_t *pix; int width; int height; int stride; @@ -2278,11 +2279,13 @@ box_drawing(const struct terminal *term, wchar_t wc) { int width = term->cell_width; int height = term->cell_height; - int stride = stride_for_format_and_width(PIXMAN_a1, width); + pixman_format_code_t fmt = PIXMAN_a1; /* TODO: use a8 when antialiasing=true */ + + int stride = stride_for_format_and_width(fmt, width); uint8_t *data = xcalloc(height * stride, 1); pixman_image_t *pix = pixman_image_create_bits_no_clear( - PIXMAN_a1, width, height, (uint32_t*)data, stride); + fmt, width, height, (uint32_t*)data, stride); if (pix == NULL) { errno = ENOMEM; @@ -2292,6 +2295,7 @@ box_drawing(const struct terminal *term, wchar_t wc) struct buf buf = { .data = data, + .pix = pix, .width = width, .height = height, .stride = stride, -- cgit v1.3 From e03257d3429279bc54d932a8a3d74acbb06fd07a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 15:00:17 +0200 Subject: box-drawing: U+256C - BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL: add missing corner The inner corner, where the upper/left lines meet, were missing --- box-drawing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box-drawing.c b/box-drawing.c index 2e387582..df5db54f 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1210,7 +1210,7 @@ draw_box_drawings_double_vertical_and_horizontal(struct buf *buf) hline(0, vmid, hmid + 2 * thick, thick); hline(vmid + 2 * thick, buf->width, hmid + 2 * thick, thick); - vline(0, hmid, vmid, thick); + vline(0, hmid + thick, vmid, thick); vline(0, hmid, vmid + 2 * thick, thick); vline(hmid + 2 * thick, buf->height, vmid, thick); vline(hmid + 2 * thick, buf->height, vmid + 2 * thick, thick); -- cgit v1.3 From 155537c2de346713c152199fad5b216b282ea7aa Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 15:01:57 +0200 Subject: box-drawing: {h,v}line: implement using pixman Use pixman_image_fill_rectangles() to render horizontal and vertical lines. Despite the name, this *is* the appropriate function to use, since our lines *do* have a thickness, and thus *are* rectangles. --- box-drawing.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index df5db54f..0b9d2f58 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -29,6 +29,8 @@ struct buf { float base_thickness; }; +static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff}; + static int _thickness(struct buf *buf, enum thickness thick) { @@ -42,13 +44,15 @@ _hline(struct buf *buf, int x1, int x2, int y, int thick) x1 = min(max(x1, 0), buf->width); x2 = min(max(x2, 0), buf->width); - for (size_t row = max(y, 0); row < max(min(y + thick, buf->height), 0); row++) { - for (size_t col = x1; col < x2; col++) { - size_t idx = col / 8; - size_t bit_no = col % 8; - buf->data[row * buf->stride + idx] |= 1 << bit_no; - } - } + int y1 = max(y, 0); + int y2 = min(max(y + thick, 0), buf->height); + int width = x2 - x1; + int height = y2 - y1; + + pixman_rectangle16_t rect = { + .x = x1, .y = y1, .width = width, .height = height}; + + pixman_image_fill_rectangles(PIXMAN_OP_SRC, buf->pix, &white, 1, &rect); } #define hline(x1, x2, y, thick) _hline(buf, x1, x2, y, thick) @@ -59,13 +63,15 @@ _vline(struct buf *buf, int y1, int y2, int x, int thick) y1 = min(max(y1, 0), buf->height); y2 = min(max(y2, 0), buf->height); - for (size_t row = y1; row < y2; row++) { - for (size_t col = max(x, 0); col < max(min(x + thick, buf->width), 0); col++) { - size_t idx = col / 8; - size_t bit_no = col % 8; - buf->data[row * buf->stride + idx] |= 1 << bit_no; - } - } + int x1 = max(x, 0); + int x2 = min(max(x + thick, 0), buf->width); + int width = x2 - x1; + int height = y2 - y1; + + pixman_rectangle16_t rect = { + .x = x1, .y = y1, .width = width, .height = height}; + + pixman_image_fill_rectangles(PIXMAN_OP_SRC, buf->pix, &white, 1, &rect); } #define vline(y1, y2, x, thick) _vline(buf, y1, y2, x, thick) -- cgit v1.3 From 19fa1b30b8f4d8563fffb8403700b8f7931db8d9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 15:03:04 +0200 Subject: box-drawing: rect(): implement using pixman Use pixman_image_fill_rectangles() to render rectangles. Duh! --- box-drawing.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 0b9d2f58..d820a4f1 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -79,13 +79,21 @@ _vline(struct buf *buf, int y1, int y2, int x, int thick) static void NOINLINE _rect(struct buf *buf, int x1, int y1, int x2, int y2) { - for (size_t row = max(y1, 0); row < min(y2, buf->height); row++) { - for (size_t col = max(x1, 0); col < max(min(x2, buf->width), 0); col++) { - size_t idx = col / 8; - size_t bit_no = col % 8; - buf->data[row * buf->stride + idx] |= 1 << bit_no; - } - } + x1 = min(max(x1, 0), buf->width); + y1 = min(max(y1, 0), buf->height); + x2 = min(max(x2, 0), buf->width); + y2 = min(max(y2, 0), buf->height); + + int width = x2 - x1; + int height = y2 - y1; + + assert(x1 + width <= buf->width); + assert(y1 + height <= buf->height); + + pixman_rectangle16_t rect = { + .x = x1, .y = y1, .width = width, .height = height}; + + pixman_image_fill_rectangles(PIXMAN_OP_SRC, buf->pix, &white, 1, &rect); } #define rect(x1, y1, x2, y2) _rect(buf, x1, y1, x2, y2) -- cgit v1.3 From e05a510a7c4a9584d07a729c986fc21872a80c4c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 15:03:30 +0200 Subject: box-drawing: implement LIGHT diagonal lines using pixman Use trapezoids to rasterize the diagonal lines. --- box-drawing.c | 82 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index d820a4f1..983b2e95 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1363,44 +1363,66 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) } } -static void -draw_box_drawings_light_diagonal(struct buf *buf, double k, double c) -{ -#define linear_equation(x) (k * (x) + c) - - int num_samples = buf->width * 16; - - for (int i = 0; i < num_samples; i++) { - double x = i / 16.; - int col = round(x); - int row = round(linear_equation(x)); - - if (row >= 0 && row < buf->height) { - size_t ofs = col / 8; - size_t bit_no = col % 8; - buf->data[row * buf->stride + ofs] |= 1 << bit_no; - } - } - -#undef linear_equation -} - static void draw_box_drawings_light_diagonal_upper_right_to_lower_left(struct buf *buf) { - /* y = k * x + c */ - double c = buf->height - 1; - double k = (0 - (buf->height - 1)) / (double)(buf->width - 1 - 0); - draw_box_drawings_light_diagonal(buf, k, c); + pixman_trapezoid_t trap = { + .top = pixman_int_to_fixed(0), + .bottom = pixman_int_to_fixed(buf->height), + .left = { + .p1 = { + .x = pixman_double_to_fixed(buf->width - thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(0), + }, + .p2 = { + .x = pixman_double_to_fixed(0 - thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(buf->height), + }, + }, + .right = { + .p1 = { + .x = pixman_double_to_fixed(buf->width + thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(0), + }, + .p2 = { + .x = pixman_double_to_fixed(0 + thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(buf->height), + }, + }, + }; + + pixman_rasterize_trapezoid(buf->pix, &trap, 0, 0); } static void draw_box_drawings_light_diagonal_upper_left_to_lower_right(struct buf *buf) { - /* y = k * x + c */ - double c = 0; - double k = (buf->height - 1 - 0) / (double)(buf->width - 1 - 0); - draw_box_drawings_light_diagonal(buf, k, c); + pixman_trapezoid_t trap = { + .top = pixman_int_to_fixed(0), + .bottom = pixman_int_to_fixed(buf->height), + .left = { + .p1 = { + .x = pixman_double_to_fixed(0 - thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(0), + }, + .p2 = { + .x = pixman_double_to_fixed(buf->width - thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(buf->height), + }, + }, + .right = { + .p1 = { + .x = pixman_double_to_fixed(0 + thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(0), + }, + .p2 = { + .x = pixman_double_to_fixed(buf->width + thickness(LIGHT) / 2.), + .y = pixman_int_to_fixed(buf->height), + }, + }, + }; + + pixman_rasterize_trapezoid(buf->pix, &trap, 0, 0); } static void -- cgit v1.3 From d6898dcc4233211ab20ceae9cb786ac194abe8ee Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 15:12:34 +0200 Subject: box-drawing: use pixman_image_fill_boxes() for rect() --- box-drawing.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 983b2e95..e196e7fb 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -84,16 +84,8 @@ _rect(struct buf *buf, int x1, int y1, int x2, int y2) x2 = min(max(x2, 0), buf->width); y2 = min(max(y2, 0), buf->height); - int width = x2 - x1; - int height = y2 - y1; - - assert(x1 + width <= buf->width); - assert(y1 + height <= buf->height); - - pixman_rectangle16_t rect = { - .x = x1, .y = y1, .width = width, .height = height}; - - pixman_image_fill_rectangles(PIXMAN_OP_SRC, buf->pix, &white, 1, &rect); + pixman_box32_t box = {.x1 = x1, y1 = y1, .x2 = x2, .y2 = y2}; + pixman_image_fill_boxes(PIXMAN_OP_SRC, buf->pix, &white, 1, &box); } #define rect(x1, y1, x2, y2) _rect(buf, x1, y1, x2, y2) -- cgit v1.3 From b2809280847d63cb616fc363e0fcc5bbd3c1b22b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 15:31:57 +0200 Subject: box-drawing: draw shades as “antialiased” blocks 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 -- cgit v1.3 From 5dd8a7090578d62519a2568b70989acc812c082a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 16:33:52 +0200 Subject: box-drawing: swap amount of shade for LIGHT and DARK shades The DARK shade is the one most dense, and thus the one that looks brightest. --- box-drawing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index eb486a75..ff1ccf22 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1697,7 +1697,7 @@ draw_light_shade(struct buf *buf) } } } else - draw_pixman_shade(buf, 0x8000); + draw_pixman_shade(buf, 0x2000); } static void @@ -1727,7 +1727,7 @@ draw_dark_shade(struct buf *buf) } } } else - draw_pixman_shade(buf, 0x2000); + draw_pixman_shade(buf, 0x8000); } static void -- cgit v1.3 From d495da03e1d87f25e88a0d9edc8c39ba2b74e411 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 16:34:57 +0200 Subject: box-drawing: temporary “fix” for LIGHT ARCs with a8 buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don’t have a method to draw the arcs using pixman yet. Work around this by replacing the a8 buffer with an a1 buffer, and render the arcs using our old, non-antialiased, way. --- box-drawing.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/box-drawing.c b/box-drawing.c index ff1ccf22..188aafc0 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1225,6 +1225,27 @@ draw_box_drawings_double_vertical_and_horizontal(struct buf *buf) static void draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) { + if (pixman_image_get_format(buf->pix) == PIXMAN_a8) { + /* + * Hack until we’ve implemented ARCs with pixman + * + * Replace the a8 buffer with a a1 buffer, and use our “old” + * non-antialiased technique to draw arcs. + */ + + int stride = stride_for_format_and_width(PIXMAN_a1, buf->width); + uint8_t *new_data = xcalloc(buf->height * stride, 1); + pixman_image_t *new_pix = pixman_image_create_bits_no_clear( + PIXMAN_a1, buf->width, buf->height, (uint32_t *)new_data, stride); + + pixman_image_unref(buf->pix); + free(buf->data); + + buf->data = new_data; + buf->pix = new_pix; + buf->stride = stride; + } + int thick = thickness(LIGHT); double a = (buf->width - thick) / 2; @@ -2359,7 +2380,7 @@ box_drawing(const struct terminal *term, wchar_t wc) *glyph = (struct fcft_glyph){ .wc = wc, .cols = 1, - .pix = pix, + .pix = buf.pix, .x = -term->font_x_ofs, .y = term->font_y_ofs + term->fonts[0]->ascent, .width = width, -- cgit v1.3 From 6937b1add80eaf6f1c140e89040528692270b643 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 16:45:21 +0200 Subject: box-drawing: shades can now be rendered either using solid color, or checker box For now, switching is done using a static variable. In the future, this could be a user option. --- box-drawing.c | 72 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 188aafc0..9fd68a12 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -29,8 +29,25 @@ struct buf { float base_thickness; }; +static const bool solid_shades = true; /* TODO: configurable? */ static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff}; +static void +change_buffer_format(struct buf *buf, pixman_format_code_t new_format) +{ + int stride = stride_for_format_and_width(new_format, buf->width); + uint8_t *new_data = xcalloc(buf->height * stride, 1); + pixman_image_t *new_pix = pixman_image_create_bits_no_clear( + new_format, buf->width, buf->height, (uint32_t *)new_data, stride); + + pixman_image_unref(buf->pix); + free(buf->data); + + buf->data = new_data; + buf->pix = new_pix; + buf->stride = stride; +} + static int _thickness(struct buf *buf, enum thickness thick) { @@ -1232,18 +1249,7 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) * Replace the a8 buffer with a a1 buffer, and use our “old” * non-antialiased technique to draw arcs. */ - - int stride = stride_for_format_and_width(PIXMAN_a1, buf->width); - uint8_t *new_data = xcalloc(buf->height * stride, 1); - pixman_image_t *new_pix = pixman_image_create_bits_no_clear( - PIXMAN_a1, buf->width, buf->height, (uint32_t *)new_data, stride); - - pixman_image_unref(buf->pix); - free(buf->data); - - buf->data = new_data; - buf->pix = new_pix; - buf->stride = stride; + change_buffer_format(buf, PIXMAN_a1); } int thick = thickness(LIGHT); @@ -1709,7 +1715,16 @@ draw_pixman_shade(struct buf *buf, uint16_t v) static void draw_light_shade(struct buf *buf) { - if (pixman_image_get_format(buf->pix) == PIXMAN_a1) { + pixman_format_code_t fmt = pixman_image_get_format(buf->pix); + + if (solid_shades && fmt == PIXMAN_a1) + change_buffer_format(buf, PIXMAN_a8); + else if (!solid_shades && fmt == PIXMAN_a8) + change_buffer_format(buf, PIXMAN_a1); + + if (solid_shades) + draw_pixman_shade(buf, 0x2000); + else { 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; @@ -1717,14 +1732,22 @@ draw_light_shade(struct buf *buf) buf->data[row * buf->stride + idx] |= 1 << bit_no; } } - } else - draw_pixman_shade(buf, 0x2000); + } } static void draw_medium_shade(struct buf *buf) { - if (pixman_image_get_format(buf->pix) == PIXMAN_a1) { + pixman_format_code_t fmt = pixman_image_get_format(buf->pix); + + if (solid_shades && fmt == PIXMAN_a1) + change_buffer_format(buf, PIXMAN_a8); + else if (!solid_shades && fmt == PIXMAN_a8) + change_buffer_format(buf, PIXMAN_a1); + + if (solid_shades) + draw_pixman_shade(buf, 0x4000); + else { 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; @@ -1732,14 +1755,22 @@ draw_medium_shade(struct buf *buf) buf->data[row * buf->stride + idx] |= 1 << bit_no; } } - } else - draw_pixman_shade(buf, 0x4000); + } } static void draw_dark_shade(struct buf *buf) { - if (pixman_image_get_format(buf->pix) == PIXMAN_a1) { + pixman_format_code_t fmt = pixman_image_get_format(buf->pix); + + if (solid_shades && fmt == PIXMAN_a1) + change_buffer_format(buf, PIXMAN_a8); + else if (!solid_shades && fmt == PIXMAN_a8) + change_buffer_format(buf, PIXMAN_a1); + + if (solid_shades) + draw_pixman_shade(buf, 0x8000); + else { 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; @@ -1747,8 +1778,7 @@ draw_dark_shade(struct buf *buf) buf->data[row * buf->stride + idx] |= 1 << bit_no; } } - } else - draw_pixman_shade(buf, 0x8000); + } } static void -- cgit v1.3 From 977d37396fb3859d16ef26eca3a0842cb4c9fc99 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 16:49:21 +0200 Subject: box-drawing: fix typo: missing ‘.’ in struct member initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box-drawing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box-drawing.c b/box-drawing.c index 9fd68a12..603bcb04 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -101,7 +101,7 @@ _rect(struct buf *buf, int x1, int y1, int x2, int y2) x2 = min(max(x2, 0), buf->width); y2 = min(max(y2, 0), buf->height); - pixman_box32_t box = {.x1 = x1, y1 = y1, .x2 = x2, .y2 = y2}; + pixman_box32_t box = {.x1 = x1, .y1 = y1, .x2 = x2, .y2 = y2}; pixman_image_fill_boxes(PIXMAN_OP_SRC, buf->pix, &white, 1, &box); } -- cgit v1.3 From 3d97b8c1139fbabefc7357fec3e1632cb9a0b452 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 16:55:16 +0200 Subject: box-drawing: draw_pixman_shade(): named struct initialization --- box-drawing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box-drawing.c b/box-drawing.c index 603bcb04..dfb868e8 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1706,7 +1706,7 @@ draw_right_half_block(struct buf *buf) static void NOINLINE draw_pixman_shade(struct buf *buf, uint16_t v) { - pixman_color_t shade = {0, 0, 0, v}; + pixman_color_t shade = {.red = 0, .green = 0, .blue = 0, .alpha = v}; pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix, &shade, 1, (pixman_rectangle16_t []){{0, 0, buf->width, buf->height}}); -- cgit v1.3 From 99a3b034c33bd88822fb802ee12324eb262ce172 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 20:44:46 +0200 Subject: box-drawing: apply antialiasing to LIGHT ARCs When drawing on an a8 buffer, apply antialiasing to LIGHT ARCs. This is done by supersampling; draw to a 4 times bigger buffer, then downsample, where each downsampled pixel is the average of the corresponding 4x4 pixel from the supersampled buffer. We also need to take supersampling into account while adjusting the row and col when pixel aligning the arcs with the regular horizontal/vertical lines. The shape of the ARCs can still be improved. Still, this is a much needed improvement over the current implementation. Closes #279 --- box-drawing.c | 113 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 40 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index dfb868e8..05fad40b 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1242,25 +1242,28 @@ draw_box_drawings_double_vertical_and_horizontal(struct buf *buf) static void draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) { - if (pixman_image_get_format(buf->pix) == PIXMAN_a8) { - /* - * Hack until we’ve implemented ARCs with pixman - * - * Replace the a8 buffer with a a1 buffer, and use our “old” - * non-antialiased technique to draw arcs. - */ - change_buffer_format(buf, PIXMAN_a1); - } + const pixman_format_code_t fmt = pixman_image_get_format(buf->pix); + const int supersample = fmt == PIXMAN_a8 ? 4 : 1; + const int height = buf->height * supersample; + const int width = buf->width * supersample; + const int stride = fmt == PIXMAN_a8 + ? stride_for_format_and_width(PIXMAN_a8, width) : buf->stride; + uint8_t *data = supersample > 1 ? xcalloc(height * stride, 1) : buf->data; - int thick = thickness(LIGHT); + const int thick = thickness(LIGHT) * supersample; + + const bool thick_is_odd = (thick / supersample) % 2; + const bool height_is_odd = buf->height % 2; + const bool width_is_odd = buf->width % 2; + + const double a = (width - thick) / 2; + const double b = (height - thick) / 2; - double a = (buf->width - thick) / 2; - double b = (buf->height - thick) / 2; + const double a2 = a * a; + const double b2 = b * b; - double a2 = a * a; - double b2 = b * b; + const int num_samples = height * 16; - int num_samples = buf->height * 16; for (int i = 0; i < num_samples; i++) { double y = i / 16.; double x = sqrt(a2 * (1. - y * y / b2)); @@ -1310,30 +1313,30 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) */ switch (wc) { case L'╭': - row_end = buf->height - row - (thick % 2 ^ buf->height % 2); + row_end = height - row - (thick_is_odd ^ height_is_odd); row_start = row_end - thick; - col_end = buf->width - col - (thick % 2 ^ buf->width % 2); + col_end = width - col - (thick_is_odd ^ width_is_odd); col_start = col_end - thick; break; case L'╮': - row_end = buf->height - row - (thick % 2 ^ buf->height % 2); + row_end = height - row - (thick_is_odd ^ height_is_odd); row_start = row_end - thick; - col_start = col; + col_start = col - ((thick_is_odd ^ width_is_odd) ? supersample / 2 : 0); col_end = col_start + thick; break; case L'╰': - row_start = row; + row_start = row - ((thick_is_odd ^ height_is_odd) ? supersample / 2 : 0); row_end = row_start + thick; - col_end = buf->width - col - (thick % 2 ^ buf->width % 2); + col_end = width - col - (thick_is_odd ^ width_is_odd); col_start = col_end - thick; break; case L'╯': - row_start = row; + row_start = row - ((thick_is_odd ^ height_is_odd) ? supersample / 2 : 0); row_end = row_start + thick; - col_start = col; + col_start = col - ((thick_is_odd ^ width_is_odd) ? supersample / 2 : 0); col_end = col_start + thick; break; } @@ -1341,11 +1344,14 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) xassert(row_end > row_start); xassert(col_end > col_start); - for (int r = max(row_start, 0); r < max(min(row_end, buf->height), 0); r++) { - for (int c = max(col_start, 0); c < max(min(col_end, buf->width), 0); c++) { - size_t idx = c / 8; - size_t bit_no = c % 8; - buf->data[r * buf->stride + idx] |= 1 << bit_no; + for (int r = max(row_start, 0); r < max(min(row_end, height), 0); r++) { + for (int c = max(col_start, 0); c < max(min(col_end, width), 0); c++) { + if (fmt == PIXMAN_a1) { + size_t idx = c / 8; + size_t bit_no = c % 8; + data[r * stride + idx] |= 1 << bit_no; + } else + data[r * stride + c] = 0xff; } } } @@ -1359,27 +1365,54 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) if (wc == L'╭' || wc == L'╰') { for (int y = 0; y < thick; y++) { - int row = (buf->height - thick) / 2 + y; - int col = buf->width - 1; - if (row >= 0 && row < buf->height && col >= 0 && col < buf->width) { - size_t ofs = col / 8; - size_t bit_no = col % 8; - buf->data[row * buf->stride + ofs] |= 1 << bit_no; + int row = (height - thick) / 2 + y - ((thick_is_odd ^ height_is_odd) ? supersample / 2 : 0); + for (int col = width - supersample; col < width; col++) { + if (row >= 0 && row < height && col >= 0) { + if (fmt == PIXMAN_a1) { + size_t ofs = col / 8; + size_t bit_no = col % 8; + data[row * stride + ofs] |= 1 << bit_no; + } else + data[row * stride + col] = 0xff; + } } } } if (wc == L'╭' || wc == L'╮') { for (int x = 0; x < thick; x++) { - int row = buf->height - 1; - int col = (buf->width - thick) / 2 + x; - if (row >= 0 && row < buf->height && col >= 0 && col < buf->width) { - size_t ofs = col / 8; - size_t bit_no = col % 8; - buf->data[row * buf->stride + ofs] |= 1 << bit_no; + int col = (width - thick) / 2 + x - ((thick_is_odd ^ width_is_odd) ? supersample / 2 : 0); + for (int row = height - supersample; row < height; row++) { + if (row >= 0 && col >= 0 && col < width) { + if (fmt == PIXMAN_a1) { + size_t ofs = col / 8; + size_t bit_no = col % 8; + data[row * stride + ofs] |= 1 << bit_no; + } else + data[row * stride + col] = 0xff; + } } } } + + if (fmt == PIXMAN_a8) { + xassert(data != buf->data); + + /* Downsample */ + for (size_t r = 0; r < buf->height; r++) { + for (size_t c = 0; c < buf->width; c++) { + uint32_t total = 0; + for (size_t i = 0; i < supersample; i++) { + for (size_t j = 0; j < supersample; j++) + total += data[(r * supersample + i) * stride + c * supersample + j]; + } + uint8_t average = min(total / (supersample * supersample), 0xff); + buf->data[r * buf->stride + c] = average; + } + } + + free(data); + } } static void -- cgit v1.3 From 9264d6695c1e8b4e4bd3d338026d83836ca3d014 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 22:08:14 +0200 Subject: box-drawing: change_buffer_format: abort on pixman failure --- box-drawing.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/box-drawing.c b/box-drawing.c index 05fad40b..25021e31 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -40,6 +40,12 @@ change_buffer_format(struct buf *buf, pixman_format_code_t new_format) pixman_image_t *new_pix = pixman_image_create_bits_no_clear( new_format, buf->width, buf->height, (uint32_t *)new_data, stride); + if (new_pix == NULL) { + errno = ENOMEM; + perror(__func__); + abort(); + } + pixman_image_unref(buf->pix); free(buf->data); -- cgit v1.3 From c0bd152218ab4ec4e9f8e27427d040a400824a49 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 22:08:35 +0200 Subject: box-drawing: use an a8 buffer when primary font is antialiased This causes relevant box drawing characters (diagonals, arcs etc) to be antialiased as well. --- box-drawing.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/box-drawing.c b/box-drawing.c index 25021e31..39deab50 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -2415,7 +2415,9 @@ box_drawing(const struct terminal *term, wchar_t wc) { int width = term->cell_width; int height = term->cell_height; - pixman_format_code_t fmt = PIXMAN_a1; /* TODO: use a8 when antialiasing=true */ + + pixman_format_code_t fmt = + term->fonts[0]->antialias ? PIXMAN_a8 : PIXMAN_a1; int stride = stride_for_format_and_width(fmt, width); uint8_t *data = xcalloc(height * stride, 1); -- cgit v1.3 From e7109d6b7739503c1d69749bda63460fb65580f0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 May 2021 22:24:25 +0200 Subject: config: add tweak.box-drawing-solid-shades=yes|no When enabled, shades are rendered as solid blocks, using a darker variant of the current foreground color. When disabled, shades are instead rendered in a checker box pattern, using the foreground color unmodified. Default is enabled. --- box-drawing.c | 21 +++++++++++---------- config.c | 9 +++++++++ config.h | 1 + doc/foot.ini.5.scd | 10 ++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 39deab50..e9e7ec33 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -27,9 +27,9 @@ struct buf { int dpi; float cell_size; float base_thickness; + bool solid_shades; }; -static const bool solid_shades = true; /* TODO: configurable? */ static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff}; static void @@ -1756,12 +1756,12 @@ draw_light_shade(struct buf *buf) { pixman_format_code_t fmt = pixman_image_get_format(buf->pix); - if (solid_shades && fmt == PIXMAN_a1) + if (buf->solid_shades && fmt == PIXMAN_a1) change_buffer_format(buf, PIXMAN_a8); - else if (!solid_shades && fmt == PIXMAN_a8) + else if (!buf->solid_shades && fmt == PIXMAN_a8) change_buffer_format(buf, PIXMAN_a1); - if (solid_shades) + if (buf->solid_shades) draw_pixman_shade(buf, 0x2000); else { for (size_t row = 0; row < buf->height; row += 2) { @@ -1779,12 +1779,12 @@ draw_medium_shade(struct buf *buf) { pixman_format_code_t fmt = pixman_image_get_format(buf->pix); - if (solid_shades && fmt == PIXMAN_a1) + if (buf->solid_shades && fmt == PIXMAN_a1) change_buffer_format(buf, PIXMAN_a8); - else if (!solid_shades && fmt == PIXMAN_a8) + else if (!buf->solid_shades && fmt == PIXMAN_a8) change_buffer_format(buf, PIXMAN_a1); - if (solid_shades) + if (buf->solid_shades) draw_pixman_shade(buf, 0x4000); else { for (size_t row = 0; row < buf->height; row++) { @@ -1802,12 +1802,12 @@ draw_dark_shade(struct buf *buf) { pixman_format_code_t fmt = pixman_image_get_format(buf->pix); - if (solid_shades && fmt == PIXMAN_a1) + if (buf->solid_shades && fmt == PIXMAN_a1) change_buffer_format(buf, PIXMAN_a8); - else if (!solid_shades && fmt == PIXMAN_a8) + else if (!buf->solid_shades && fmt == PIXMAN_a8) change_buffer_format(buf, PIXMAN_a1); - if (solid_shades) + if (buf->solid_shades) draw_pixman_shade(buf, 0x8000); else { for (size_t row = 0; row < buf->height; row++) { @@ -2440,6 +2440,7 @@ box_drawing(const struct terminal *term, wchar_t wc) .dpi = term->font_dpi, .cell_size = sqrt(pow(term->cell_width, 2) + pow(term->cell_height, 2)), .base_thickness = term->conf->tweak.box_drawing_base_thickness, + .solid_shades = term->conf->tweak.box_drawing_solid_shades, }; LOG_DBG("LIGHT=%d, HEAVY=%d", diff --git a/config.c b/config.c index 66a4cc81..0f8f5aec 100644 --- a/config.c +++ b/config.c @@ -1929,6 +1929,14 @@ parse_section_tweak( conf->tweak.box_drawing_base_thickness); } + else if (strcmp(key, "box-drawing-solid-shades") == 0) { + conf->tweak.box_drawing_solid_shades = str_to_bool(value); + + if (!conf->tweak.box_drawing_solid_shades) + LOG_WARN("tweak: box-drawing-solid-shades=%s", + conf->tweak.box_drawing_solid_shades ? "yes" : "no"); + } + else { LOG_AND_NOTIFY_ERR("%s:%u: [tweak]: %s: invalid key", path, lineno, key); return false; @@ -2396,6 +2404,7 @@ config_load(struct config *conf, const char *conf_path, .render_timer_log = false, .damage_whole_window = false, .box_drawing_base_thickness = 0.04, + .box_drawing_solid_shades = true, }, .notifications = tll_init(), diff --git a/config.h b/config.h index db0e6775..a5a47ce6 100644 --- a/config.h +++ b/config.h @@ -229,6 +229,7 @@ struct config { uint64_t delayed_render_upper_ns; off_t max_shm_pool_size; float box_drawing_base_thickness; + bool box_drawing_solid_shades; } tweak; user_notifications_t notifications; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index abe90fc7..cb4b4f08 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -809,6 +809,16 @@ any of these options. larger font (and thus larger cells) result in thicker lines. Default: _0.04_. +*box-drawing-solid-shades* + Boolean. When enabled, box drawing "shades" (e.g. LIGHT SHADE, + MEDIUM SHADE and DARK SHADE) are rendered as solid blocks using a + darker variant of the current foreground color. + + When disabled, they are instead rendered as checker box pattern, + using the current foreground color as is. + + Default: _yes_. + *delayed-render-lower*, *delayed-render-upper* These two values control the timeouts (in nanoseconds) that are used to mitigate screen flicker caused by clients writing large, -- cgit v1.3 From b771a28d17397892eebdacdfb07fba6e331a0207 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 May 2021 11:42:23 +0200 Subject: box-drawing: increase brightness of solid shades --- box-drawing.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index e9e7ec33..239fb63f 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1762,7 +1762,7 @@ draw_light_shade(struct buf *buf) change_buffer_format(buf, PIXMAN_a1); if (buf->solid_shades) - draw_pixman_shade(buf, 0x2000); + draw_pixman_shade(buf, 0x4000); else { for (size_t row = 0; row < buf->height; row += 2) { for (size_t col = 0; col < buf->width; col += 2) { @@ -1785,7 +1785,7 @@ draw_medium_shade(struct buf *buf) change_buffer_format(buf, PIXMAN_a1); if (buf->solid_shades) - draw_pixman_shade(buf, 0x4000); + draw_pixman_shade(buf, 0x8000); else { for (size_t row = 0; row < buf->height; row++) { for (size_t col = row % 2; col < buf->width; col += 2) { @@ -1808,7 +1808,7 @@ draw_dark_shade(struct buf *buf) change_buffer_format(buf, PIXMAN_a1); if (buf->solid_shades) - draw_pixman_shade(buf, 0x8000); + draw_pixman_shade(buf, 0xc000); else { for (size_t row = 0; row < buf->height; row++) { for (size_t col = 0; col < buf->width; col += 1 + row % 2) { -- cgit v1.3 From b48414e72c5f690ab5326b42bf11b4f487109613 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 May 2021 14:09:31 +0200 Subject: box-drawing: use fill_boxes() instead of fill_rectangles() --- box-drawing.c | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 239fb63f..87f6fdb5 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -64,18 +64,13 @@ _thickness(struct buf *buf, enum thickness thick) static void NOINLINE _hline(struct buf *buf, int x1, int x2, int y, int thick) { - x1 = min(max(x1, 0), buf->width); - x2 = min(max(x2, 0), buf->width); - - int y1 = max(y, 0); - int y2 = min(max(y + thick, 0), buf->height); - int width = x2 - x1; - int height = y2 - y1; - - pixman_rectangle16_t rect = { - .x = x1, .y = y1, .width = width, .height = height}; - - pixman_image_fill_rectangles(PIXMAN_OP_SRC, buf->pix, &white, 1, &rect); + pixman_box32_t box = { + .x1 = min(max(x1, 0), buf->width), + .x2 = min(max(x2, 0), buf->width), + .y1 = min(max(y, 0), buf->height), + .y2 = min(max(y + thick, 0), buf->height), + }; + pixman_image_fill_boxes(PIXMAN_OP_SRC, buf->pix, &white, 1, &box); } #define hline(x1, x2, y, thick) _hline(buf, x1, x2, y, thick) @@ -83,18 +78,13 @@ _hline(struct buf *buf, int x1, int x2, int y, int thick) static void NOINLINE _vline(struct buf *buf, int y1, int y2, int x, int thick) { - y1 = min(max(y1, 0), buf->height); - y2 = min(max(y2, 0), buf->height); - - int x1 = max(x, 0); - int x2 = min(max(x + thick, 0), buf->width); - int width = x2 - x1; - int height = y2 - y1; - - pixman_rectangle16_t rect = { - .x = x1, .y = y1, .width = width, .height = height}; - - pixman_image_fill_rectangles(PIXMAN_OP_SRC, buf->pix, &white, 1, &rect); + pixman_box32_t box = { + .x1 = min(max(x, 0), buf->width), + .x2 = min(max(x + thick, 0), buf->width), + .y1 = min(max(y1, 0), buf->height), + .y2 = min(max(y2, 0), buf->height), + }; + pixman_image_fill_boxes(PIXMAN_OP_SRC, buf->pix, &white, 1, &box); } #define vline(y1, y2, x, thick) _vline(buf, y1, y2, x, thick) @@ -102,12 +92,12 @@ _vline(struct buf *buf, int y1, int y2, int x, int thick) static void NOINLINE _rect(struct buf *buf, int x1, int y1, int x2, int y2) { - x1 = min(max(x1, 0), buf->width); - y1 = min(max(y1, 0), buf->height); - x2 = min(max(x2, 0), buf->width); - y2 = min(max(y2, 0), buf->height); - - pixman_box32_t box = {.x1 = x1, .y1 = y1, .x2 = x2, .y2 = y2}; + pixman_box32_t box = { + .x1 = min(max(x1, 0), buf->width), + .y1 = min(max(y1, 0), buf->height), + .x2 = min(max(x2, 0), buf->width), + .y2 = min(max(y2, 0), buf->height), + }; pixman_image_fill_boxes(PIXMAN_OP_SRC, buf->pix, &white, 1, &box); } -- cgit v1.3 From 25ce458281facca6a8945a556ba2f9a81a1a6992 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 May 2021 14:34:24 +0200 Subject: box-drawing: don’t inline _thickness() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It results in quite a lot of floating point instructions being emitted in almost every box drawing function we have... --- box-drawing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box-drawing.c b/box-drawing.c index 87f6fdb5..ae152d9b 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -54,7 +54,7 @@ change_buffer_format(struct buf *buf, pixman_format_code_t new_format) buf->stride = stride; } -static int +static int NOINLINE _thickness(struct buf *buf, enum thickness thick) { return max((int)(buf->base_thickness * buf->dpi / 72.0 * buf->cell_size), 1) * thick; -- cgit v1.3 From 3dbb9063258ab904552b9ec3369725f585e99fa2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 May 2021 17:39:36 +0200 Subject: box-drawing: always pass ‘buf’ as the first parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way, the compiler doesn’t have to waste instructions on re-ordering the parameters --- box-drawing.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index ae152d9b..5b9967f3 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1236,7 +1236,7 @@ draw_box_drawings_double_vertical_and_horizontal(struct buf *buf) } static void -draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) +draw_box_drawings_light_arc(struct buf *buf, wchar_t wc) { const pixman_format_code_t fmt = pixman_image_get_format(buf->pix); const int supersample = fmt == PIXMAN_a8 ? 4 : 1; @@ -1997,7 +1997,7 @@ sextant_lower_right(struct buf *buf) } static void -draw_sextant(wchar_t wc, struct buf *buf) +draw_sextant(struct buf *buf, wchar_t wc) { /* * Each byte encodes one sextant: @@ -2189,7 +2189,7 @@ draw_right_seven_eighths_block(struct buf *buf) } static void -draw_glyph(wchar_t wc, struct buf *buf) +draw_glyph(struct buf *buf, wchar_t wc) { IGNORE_WARNING("-Wpedantic") @@ -2309,7 +2309,7 @@ draw_glyph(wchar_t wc, struct buf *buf) case 0x256a: draw_box_drawings_vertical_single_and_horizontal_double(buf); break; case 0x256b: draw_box_drawings_vertical_double_and_horizontal_single(buf); break; case 0x256c: draw_box_drawings_double_vertical_and_horizontal(buf); break; - case 0x256d ... 0x2570: draw_box_drawings_light_arc(wc, buf); break; + case 0x256d ... 0x2570: draw_box_drawings_light_arc(buf, wc); break; case 0x2571: draw_box_drawings_light_diagonal_upper_right_to_lower_left(buf); break; case 0x2572: draw_box_drawings_light_diagonal_upper_left_to_lower_right(buf); break; @@ -2361,7 +2361,7 @@ draw_glyph(wchar_t wc, struct buf *buf) case 0x259e: draw_quadrant_upper_right_and_lower_left(buf); break; case 0x259f: draw_quadrant_upper_right_and_lower_left_and_lower_right(buf); break; - case 0x1fb00 ... 0x1fb3b: draw_sextant(wc, buf); break; + case 0x1fb00 ... 0x1fb3b: draw_sextant(buf, wc); break; case 0x1fb70: draw_vertical_one_eighth_block_2(buf); break; case 0x1fb71: draw_vertical_one_eighth_block_3(buf); break; @@ -2436,7 +2436,7 @@ box_drawing(const struct terminal *term, wchar_t wc) LOG_DBG("LIGHT=%d, HEAVY=%d", _thickness(&buf, LIGHT), _thickness(&buf, HEAVY)); - draw_glyph(wc, &buf); + draw_glyph(&buf, wc); struct fcft_glyph *glyph = xmalloc(sizeof(*glyph)); *glyph = (struct fcft_glyph){ -- cgit v1.3 From 8473deeed35e811152a145e26ed15372009edeeb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 May 2021 18:01:21 +0200 Subject: box-drawing: pre-calculate the LIGHT and HEAVY thicknesses --- box-drawing.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 5b9967f3..2eb92efd 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -14,8 +14,8 @@ #include "xmalloc.h" enum thickness { - LIGHT = 1, - HEAVY = 3, + LIGHT, + HEAVY, }; struct buf { @@ -28,6 +28,7 @@ struct buf { float cell_size; float base_thickness; bool solid_shades; + int thickness[2]; }; static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff}; @@ -57,9 +58,17 @@ change_buffer_format(struct buf *buf, pixman_format_code_t new_format) static int NOINLINE _thickness(struct buf *buf, enum thickness thick) { - return max((int)(buf->base_thickness * buf->dpi / 72.0 * buf->cell_size), 1) * thick; + int multiplier = thick * 2 + 1; + + xassert((thick == LIGHT && multiplier == 1) || + (thick == HEAVY && multiplier == 3)); + + return + max( + (int)(buf->base_thickness * buf->dpi / 72.0 * buf->cell_size), 1) + * multiplier; } -#define thickness(thick) _thickness(buf, thick) +#define thickness(thick) buf->thickness[thick] static void NOINLINE _hline(struct buf *buf, int x1, int x2, int y, int thick) @@ -2433,6 +2442,9 @@ box_drawing(const struct terminal *term, wchar_t wc) .solid_shades = term->conf->tweak.box_drawing_solid_shades, }; + buf.thickness[LIGHT] = _thickness(&buf, LIGHT); + buf.thickness[HEAVY] = _thickness(&buf, HEAVY); + LOG_DBG("LIGHT=%d, HEAVY=%d", _thickness(&buf, LIGHT), _thickness(&buf, HEAVY)); -- cgit v1.3