aboutsummaryrefslogtreecommitdiff
path: root/box-drawing.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-30 12:30:39 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-01 20:09:37 +0000
commitbd42986a8bd67e5ea647d5ed91fc4a89307e308c (patch)
treecefe8a42765bcb486fcd5bf220709d64fedd7ba4 /box-drawing.c
parentbox-drawing: thickness(): ensure thickness is *at least* 1px (diff)
box-drawing: {h,v}line(): handle both start/end point being too small *and* too large
Diffstat (limited to 'box-drawing.c')
-rw-r--r--box-drawing.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/box-drawing.c b/box-drawing.c
index 8584f8ad..07deb387 100644
--- a/box-drawing.c
+++ b/box-drawing.c
@@ -24,8 +24,11 @@ thickness(float pts, int dpi)
static void
_hline(uint8_t *buf, int x1, int x2, int y, int thick, int width, int height, int stride)
{
+ x1 = min(max(x1, 0), width);
+ x2 = min(max(x2, 0), width);
+
for (size_t row = max(y, 0); row < min(y + thick, height); row++) {
- for (size_t col = max(x1, 0); col < min(x2, width); col++) {
+ for (size_t col = x1; col < x2; col++) {
size_t idx = col / 8;
size_t bit_no = col % 8;
buf[row * stride + idx] |= 1 << bit_no;
@@ -38,7 +41,10 @@ _hline(uint8_t *buf, int x1, int x2, int y, int thick, int width, int height, in
static void
_vline(uint8_t *buf, int y1, int y2, int x, int thick, int width, int height, int stride)
{
- for (size_t row = max(y1, 0); row < min(y2, height); row++) {
+ y1 = min(max(y1, 0), height);
+ y2 = min(max(y2, 0), height);
+
+ for (size_t row = y1; row < y2; row++) {
for (size_t col = max(x, 0); col < min(x + thick, width); col++) {
size_t idx = col / 8;
size_t bit_no = col % 8;