-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Arduboy2Base::drawBitmapFrame #69
Comments
One goal of the Arduboy2 library has been to optimize for size and/or speed (no matter how small the savings), sometimes at the expense of things not working if the developer doesn't follow the documentation. Unless there would be a common use case for providing a sprite that didn't have a height that's a multiple of eight, I'd be in favour of leaving out the rounding. I think "inconveniences" that may result with vs without the rounding step could be equally as bad. For the likely rare case that a developer actually wanted to use a non-modulo 8 height sprite, they could provide their own function (standalone or inherit & overload) that did the rounding before calling drawBitmapFrame(). Otherwise, I don't see a problem with adding these functions to the next release, so will do. |
I can see several arguments in favour of accepting heights that are not a multiple of eight... Firstly, This means that there will be plenty of images already in use that don't have multiple-of-eight heights, and it's likely that image converters don't bother to check either.
You might be surprised to learn that it's not actually that rare. For example:
Even TeamARG managed to break the rule at least once, and they appear to be the ones who allowed non-multiples-of-eight in the first place. One other point, in case a 'rule of majority' argument isn't enough: With the addition of This would be a problem for the work-in-progress game that lead me to suggest Proposed compromise Hence, I think the best option overall would be to make the multiple-of-eight-correcting version the main version and provide an alternative 'unsafe' function for the minority of users who wanted to opt-out of the multiple-of-eight-correction because they can guarantee that their images are multiples of eight and thus are safe to skip the extra step. |
My humble suggestion: don't do this! Duplicate code adds to maintenance and also user confusion. Sorry if I've missed something, but genuinely want to know if this has any real world utility? |
People who use For those who are considering using one or the other, the ability to change the function without having to change the sprite data would be very convenient.
Thinking about it, existing code that uses |
(Note: I'm proposing this separately because although it's effectively working towards a similar goal to #68, the implementation is potentially more demanding and requires a bit more commitment, whereas #68 is much more straight forward.)
Following on from the suggestion to allow
drawBitmap
to handleSprites
-format images (see #68), in addition to allowingdrawBitmap
to handle the width and height elements, it would potentially be useful to allowArduboy2Base
to handle multiple frames, thus implementing fullSprites
-format support.Unfortunately this can't be done with a
drawBitmap
overload, because introducing theframe
parameter would conflict with the default argument, hence a new function name would be needed, and I am proposingdrawBitmapFrame
as it seems the most logical answer - it draws a frame of a bitmap.Key thoughts:
Sprites
-format images with frames to be used withdrawBitmap
drawBitmap
a more viable alternative toSprites
in some situationsSprites::getWidth
andSprited::getHeight
, this hidespgm_read_byte
from inexperienced users.Proposed implementation:
Note that the height is explicitly rounded to the next nearest multiple of eight to account for the possibility that the user has provided a height that is a multiple of eight, which would upset the frame calculations. This rounding uses addition, masking and a single branch, which should be relatively cheap overall.
The alternative would be to require the height to be a multiple of eight and allow the function to simply fall apart if this were not the case, but I'm doubtful that the amount of speed and memory saved by avoiding the rounding calculation would be worth the inconvenience to the user.
In hindsight, it's a shame that the height used in the
Sprites
format is the actual height rather than the number of columns. Multiplying by eight would have been cheaper than trying to account for a height that is not a multiple of eight.The text was updated successfully, but these errors were encountered: