Skip to content

displayio: remove per-pixel divides from TileGrid.fill_area - #11459

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
MakerClassCZ:displayio-tilegrid-fast
Sep 24, 2026
Merged

dhalbert merged 1 commit into
adafruit:mainfrom
MakerClassCZ:displayio-tilegrid-fast

Conversation

@lynt-smitka

Copy link
Copy Markdown

TileGrid.fill_area did nine integer divides per pixel. The divisors do not change during the call, and five of the divides depend only on the row. On cores without a hw divide each one is a library call.

Now the row terms are computed once per row, the x terms are stepped along the row, and the tile's position in the bitmap is recomputed only when the tile changes. Bitmap.get_pixel no longer divides for 8 and 16 bpp bitmaps.

Full-screen 320x240 repaint on an RP2040: 297 ms -> 203 ms. Flash +104 bytes.

Output is unchanged, checked with checksums of 12 test scenes via BusDisplay.fill_row (tile sizes, flips, transpose, scale, transparency, 1-16 bpp, ColorConverter, dither).

This is the same approach the picogame blitters use.

TileGrid.fill_area computed the tile index, the position inside the tile
and the tile's place in the bitmap with nine integer divides per pixel.
All divisors are constant for the call, and five of the divides depend
only on the row. On cores without a divide instruction each one is a
library call.

- The row terms are computed once per row.
- The x terms are stepped along the row.
- The tile's position in the bitmap is recomputed only when the tile
  changes.
- Bitmap.get_pixel computes values_per_byte only for bitmaps below
  8 bits per pixel, so 8 and 16 bpp reads no longer divide.

RP2040 (pajenicko_picopad), full-screen 320x240 repaint of an 8 bpp
bitmap: 297 -> 203 ms. Flash +104 bytes.
Output is unchanged: 12 cases (tiles of 16x16 and 12x10, partly
off-screen, flip_x, flip_y, transpose, scale 2 and 3, transparency with
overlap, 1/2/4/8/16 bpp, ColorConverter, dither) checksum identically
through BusDisplay.fill_row.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@dhalbert
dhalbert merged commit 746577d into adafruit:main Sep 24, 2026
610 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants