adafruit / Adafruit-GFX-Library

Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
https://learn.adafruit.com/adafruit-gfx-graphics-library
Other
2.41k stars 1.55k forks source link

GFX lib with font, canvas, and drawBitmap() runs slow #415

Open norbinz opened 1 year ago

norbinz commented 1 year ago

I breadboarded an Adafruit 3677 (ItsyBitsy 32u4 5V) with an Adafruit 4383 (240x135 LCD ST7789). I'm seeing very slow run-time of the GFX library's drawBitmap(). In the Adafruit forum I asked what's the reason for the slowness, and does the library offer a faster alternative? I shared a demonstration sketch that includes the slow drawBitmap(), and a faster code that I whipped up. A support (?) fellow suggested that I ask on github. Here's the forum discussion: https://forums.adafruit.com/viewtopic.php?p=960409

I understand that the GFX lib has a Prime Directive, but I'm not sure if that applies here.

norbinz commented 1 year ago

Oops, broken URL. Trying again: https://forums.adafruit.com/viewtopic.php?p=960155

jsseab commented 3 months ago

I noticed this problem too. I have an application that draws a canvas that is 141 x 19 pixels, and this takes around 183 ms with an ATMega644 running at 10 MHz (it's a custom Arduino-compatible board).

I looked at the implementation and realized one big factor is how each pixel write is done with an address window that is 1x1 pixels. This is obviously not a very good idea. A much better implementation is to setup the whole window first, then just write all pixels in sequence.

I changed the code and got about 23 ms execution time (8 times faster!). I will try and submit a pull request for this, but I am a little unsure of exactly how to implement the change due to the class hierarchy.