add arbitrary rect drawing from bitmaps/canvases (RGB 565, RAM only) #442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.