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

Support using the bitmap device in the Arduino library #2486

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

matthijskooijman
Copy link
Contributor

The header files in csrc and cppsrc contained various declarations related to the bitmap device backend (e..g the u8g2_SetupBitmap function and the U8G2_BITMAP class), but the definitions of those were in sys/bitmap/u8x8_d_bitmap.c and thus not included in default builds and in particular not the Arduino library.

This moves this code into csrc, leaving behind the TGA export code that relies on stdio.h, to make this bitmap backend usable in the Arduino library. It also adds an example for how to use this code in the Arduino library.

I tested:

  • The new example From within u8g2 with Makefile.184.uno, an unpacked Arduino 1.8.4 tarball and an offical Uno R3.
  • The same with arduino-cli, the arduino:avr core version 1.8.5 after generating an Arduino library with tools/release/arduino/create_release.sh
  • The examples in sys/bitmap

The Arduino example sketch outputs the following:

image

This moves the TGA export code into a new file called
u8x8_d_bitmap_tga.c, which removes the stdio.h dependency from
u8x8_d_bitmap.c (making that file compilable on microcontroller targets
as well).

This slightly reworks the TGA export code so it uses the external bitmap
device API instead of reading directly from the global u8x8_bitmap
struct.

This also moves u8x8_d_bitmap.c into csrc, so it is included in all
builds (including the Arduino build).
This prevents warnings when directories already exist and creates parent
directories as needed.
@olikraus
Copy link
Owner

nice idea, so you just output the bitmap as a x/blank ASCII art, correct?

@olikraus
Copy link
Owner

hmmm isn't this very similar to https://github.com/olikraus/u8g2/wiki/u8g2reference#writebufferxbm

@olikraus olikraus added this to the 2.35 milestone Aug 18, 2024
@matthijskooijman
Copy link
Contributor Author

matthijskooijman commented Aug 20, 2024

nice idea, so you just output the bitmap as a x/blank ASCII art, correct?

Yeah, that's just a way to actually do something with the pixel data, but the point of the example is to show how to access the raw pixels.

hmmm isn't this very similar to https://github.com/olikraus/u8g2/wiki/u8g2reference#writebufferxbm

In a way, but that outputs XBM format, without accessing the pixels programmatically.

However, reading onwards, I see: https://github.com/olikraus/u8g2/wiki/u8g2reference#direct-access-buffer-api

Which is an API to directly access the rendering buffer tiles/pixels, which would actually also work perfectly for my usecase.

Thinking on this a bit more, I actually wonder what the point of the "bitmap" device is - u8g2 already keeps a buffer containing all pixels, which is then copied to another buffer inside the "bitmap" device, but there does not really seem to be any point (and it needs twice the memory).

I would say this could just as well use a "dummy" device (that just throws away pixels) and then use the above buffer API to access the upper buffer directly - for this example, but also for the non-arduino examples that use the bitmap device currently for TGA output (there could also be a simple TGA output function that reads from the buffer like writeBufferXBM does).

I wonder if/why we did not think about this when we worked on the bitmap device a few years ago...

@olikraus
Copy link
Owner

hmmm... you have removed the TGA write procedures, but those are needed for the automatic image generation.
Even if we keep the old file, the PR will break the tga image generation. I think more effort is required to fix this.

@matthijskooijman
Copy link
Contributor Author

you have removed the TGA write procedures

They are not removed, but split off from the bitmap backend. They are still here: https://github.com/matthijskooijman/u8g2/blob/509954977b2d40c34dfc6f7a9a696910b93d88cd/sys/bitmap/common/u8x8_d_bitmap_tga.c

This does mean that TGA generation is not available in the Arduino version, but TGA is probably not relevant there anyway (and this particular implementation relies on stdio.h, which is not available in all architectures IIRC.

Even if we keep the old file, the PR will break the tga image generation. I think more effort is required to fix this.

The hello_world and cimg_annotate_screenshot examples still work for me. Is there something else that you think will break?

@olikraus
Copy link
Owner

olikraus commented Sep 9, 2024

I will move this topic...

@olikraus olikraus modified the milestones: 2.35, 2.36 Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants