box-drawing: {h,v}line(): handle both start/end point being too small *and* too large

This commit is contained in:
Daniel Eklöf 2020-12-30 13:30:39 +01:00
parent a8496eef03
commit bd42986a8b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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;