Skip to content

Commit 483f14b

Browse files
committed
Allow lines with ends out of bitmap in bitmaptools_obj_draw_line
1 parent 936ecdd commit 483f14b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

shared-bindings/bitmaptools/__init__.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,6 @@ STATIC mp_obj_t bitmaptools_obj_draw_line(size_t n_args, const mp_obj_t *pos_arg
514514
int16_t x2 = args[ARG_x2].u_int;
515515
int16_t y2 = args[ARG_y2].u_int;
516516

517-
// verify points are within the bitmap boundary (inclusive)
518-
if ((x1 < 0) || (x2 < 0) || (y1 < 0) || (y2 < 0) ||
519-
(x1 >= destination->width) || (x2 >= destination->width) ||
520-
(y1 >= destination->height) || (y2 >= destination->height)) {
521-
mp_raise_ValueError(translate("out of range of target"));
522-
}
523-
524517
common_hal_bitmaptools_draw_line(destination, x1, y1, x2, y2, value);
525518

526519
return mp_const_none;

shared-module/bitmaptools/__init__.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
423423
y0 = y1;
424424
y1 = temp;
425425
}
426+
y0 = max(0, y0); // only draw inside bitmap
427+
y1 = min(y1, destination->height - 1);
426428
for (y = y0; y < (y1 + 1); y++) { // write a horizontal line
427429
displayio_bitmap_write_pixel(destination, x0, y, value);
428430
}
@@ -432,6 +434,8 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
432434
x0 = x1;
433435
x1 = temp;
434436
}
437+
x0 = max(0, x0); // only draw inside bitmap
438+
x1 = min(x1, destination->width - 1);
435439
for (x = x0; x < (x1 + 1); x++) { // write a horizontal line
436440
displayio_bitmap_write_pixel(destination, x, y0, value);
437441
}

shared-module/displayio/Bitmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y
131131
// Writes the color index value into a pixel position
132132
// Must update the dirty area separately
133133

134+
// Don't write if out of area
135+
if (0 > x || x >= self->width || 0 > y || y >= self->height) {
136+
return;
137+
}
138+
134139
// Update one pixel of data
135140
int32_t row_start = y * self->stride;
136141
uint32_t bytes_per_value = self->bits_per_value / 8;

0 commit comments

Comments
 (0)