For the project I am working on (a compositing window manager which uses Adafruit GFX/Arduino GFX Library as its underlying graphics driver layer), I have the need to draw only certain parts of a memory buffer/canvas containing the pixels to render to the display hardware (using the optimized hardware class' drawing routines).
As far as I can tell, there is currently no way to do that cleanly: I can only do an un-optimized loop and draw individual pixels, or call Adafruit_SPITFT's setAddrWindow and writePixels, but those are not part of the Adafruit_GFX interface (I may just change my underlying requirement to the SPITFT class instead of the GFX interface if this PR is unwanted).
In order to resolve this situation, I:
Added an additional drawRGBBitmap function to Adafruit_GFX as well as Adafruit_SPITFT(to utilize its optimized drawing routine) that takes the following additional parameters:
src_x the x offset into the bitmap/canvas to begin reading from
src_y the y offset ""
src_w the actual width of the bitmap/canvas (used to move the read pointer forward by a scan line)
Retrofitted the existing version of drawRGBBitmap to simply call the new one with default arguments, resulting in the same behavior as before the change
Limitations
I have only implemented this for the RAM-resident RGB 565 routines. If you guys are keen on taking the change, I would be glad to do the others as well, but this is the only one I need for now.
I tested to make sure that the existing interface works as expected when calling with 0,0 for x,y and the bitmap's width and height, but I did not test edge cases like negative x,y or invalid width/height values. I did the best I could to mimic the logic that was already in place.
If more formal testing and proof that I didn't break anything is required, let me know and I will write something up.
For the project I am working on (a compositing window manager which uses Adafruit GFX/Arduino GFX Library as its underlying graphics driver layer), I have the need to draw only certain parts of a memory buffer/canvas containing the pixels to render to the display hardware (using the optimized hardware class' drawing routines).
As far as I can tell, there is currently no way to do that cleanly: I can only do an un-optimized loop and draw individual pixels, or call
Adafruit_SPITFT
'ssetAddrWindow
andwritePixels
, but those are not part of theAdafruit_GFX
interface (I may just change my underlying requirement to the SPITFT class instead of the GFX interface if this PR is unwanted).In order to resolve this situation, I:
Added an additional
drawRGBBitmap
function toAdafruit_GFX
as well asAdafruit_SPITFT
(to utilize its optimized drawing routine) that takes the following additional parameters:src_x
the x offset into the bitmap/canvas to begin reading fromsrc_y
the y offset ""src_w
the actual width of the bitmap/canvas (used to move the read pointer forward by a scan line)Retrofitted the existing version of
drawRGBBitmap
to simply call the new one with default arguments, resulting in the same behavior as before the changeLimitations
I tested to make sure that the existing interface works as expected when calling with 0,0 for x,y and the bitmap's width and height, but I did not test edge cases like negative x,y or invalid width/height values. I did the best I could to mimic the logic that was already in place.
If more formal testing and proof that I didn't break anything is required, let me know and I will write something up.