Skip to content
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::drawBitmap overload #68

Open
Pharap opened this issue Apr 10, 2022 · 3 comments
Open

Proposal: Arduboy2Base::drawBitmap overload #68

Pharap opened this issue Apr 10, 2022 · 3 comments

Comments

@Pharap
Copy link
Contributor

Pharap commented Apr 10, 2022

This is an idea I had some time ago and suddenly remembered while doing something else.

The idea is that it would be useful to provide an overload of Arduboy2Base::drawBitmap that doesn't have width and height parameters, and instead extracts those from the image in the same way that the Sprites functions do. I.e. it would be an overload that expects the same image format as the Sprites functions.

Key thoughts:

  • Allows the Sprites-format images to be used with drawBitmap
    • This might make drawBitmap a more viable alternative to Sprites in some situations
  • Much like with Sprites::getWidth and Sprited::getHeight, this hides pgm_read_byte from inexperienced users.
  • Backwards compatible - since the new overload has fewer parameters, there's no conflict with any existing usage

Proposed implementation:

void Arduboy2Base::drawBitmap(int16_t x, int16_t y, const uint8_t * bitmap, uint8_t colour = WHITE)
{
	uint8_t width = pgm_read_byte(&bitmap[0]);
	uint8_t height = pgm_read_byte(&bitmap[1]);
	drawBitmap(x, y, &bitmap[2], width, height, colour);
}

(Note: Intentionally does not rely on Sprites to avoid introducing an unnecessary dependency.)

@MLXXXp
Copy link
Owner

MLXXXp commented Apr 10, 2022

I see no problem with adding this. I'll add it to the ToDo for the next release.

@ace-dent
Copy link
Contributor

When would this be useful?
I presume it may help early development, if switching from Sprites::drawOverwrite <-> drawBitmap, and not wanting to change the first 2 bytes of the image array...
Not sure how often anyone would do that?
As long as it doesn't increase compiled size of existing code- I guess it's harmless 🤷‍♂️

@Pharap
Copy link
Contributor Author

Pharap commented Apr 13, 2022

When would this be useful?

When someone wants to use drawBitmap with a Sprites-format image.

Sprites::drawOverwrite <-> drawBitmap

Arduboy2::drawBitmap does not behave the same as Sprites::drawOverwrite, it behaves like Sprites::drawSelfMasked.

As long as it doesn't increase compiled size of existing code

Why would it? In C++ you don't pay for what you don't use - if you aren't using a function then it's not included in the final executable.

As I expressly stated in my proposal:

  • Backwards compatible - since the new overload has fewer parameters, there's no conflict with any existing usage

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

No branches or pull requests

3 participants