Skip to content

Conversation

@corranwebster
Copy link

Summary

This adds a byte-swapped version of the RGB565 format to the the framebuf module, so that pixel color values get stored in the opposite order to the native endianness (ie. if you do buf.pixel(x, y, 0xff00) it gets stored as 0x00ff). This is useful for working with devices which have opposite endianness to the primary device (eg. many 16-bit color displays). This removes the need for a lot of manual byte-swapping when creating color values.

Testing

Added tests for the new format which follow the existing 16-bit tests.

Trade-offs and Alternatives

This has a very small increase in code size. The other alternative would be to have explicit big/little endian formats, but that would potentially break existing code, or would mean having to add 2 new formats (ie. RGB565 is native endianness, RGB565_BE is big-endian, and RGB565_LE is little-endian) one of which is identical to RGB565.

This is required for identifying which bits are in which channels for
alpha blending. It also has some utility when working with display devices
where the display memory is opposite endianness from the microcontroller,
as it permits more straightforward translation from colors to bytes.
Add tests for byteswapped RGB565 format.
Without this, we don't know the bits per pixel.
Re-use the rgb565_fill_rect() function to avoid repeated code.
This keeps the internal C code more-or-less unchanged, but exposes
the byte-order as "RGB565_LE" and "RGB565_BE" for little and big
endian versions. Updates docs and tests and, as a bonus, turns on
RGB565 testing for big-endian native systems.
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

Successfully merging this pull request may close these issues.

2 participants