-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Endianness handling for RGB565 framebuf mode. #3536
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
Conversation
Thanks @jimmo for the patch. At the very least the byte order of this RGB565 format should be documented, so that it's not a surprise when it comes out "reverse". But do you think it's worth an entire new format id and extra code to handle it? As an alternative, wouldn't it be possible to just provide (in Python, maybe in C...) an rgb-creation function OTOH, if/when we blit supports conversion of colour then it would need to know the precise RGB layout including byte order. Also note that it might be possible to optimise your patch here (for code size and/or speed) by swapping the byte order of the incoming colour value, instead of using |
Thanks Damien -- I can't quite see a nice way to support a conversion function (it's not clear whether it should live on the display or the framebuf, but like you say there are good reasons for putting it on the framebuf for blit/conversion etc - I was keen to work on this next). It's confusing for the programmer to ever see a "backwards" value, and it's a bit burdensome to have to remember when to flip the bytes (i.e. it's fine if I always use the To be honest I can't think of a reason why you'd ever not want BE, so for code size/speed I think I'd prefer to just retain the one mode and making it always BE... the current behaviour is surprising enough that maybe this would count as a bug fix rather than a breaking backwards-compatibility? The two cases I can see for the current behaviour:
@deshipu did you have any thoughts on this? When you added this mode which display were you using? Did you use an |
I originally added that mode to handle ST7735, SSD1331, SSD1351 and ILI9341 displays — they all use the same endianness, some even allow you to change it. I have done much thinking about the general problem of handling displays — you can for example look at my pull request that adds a color mapping option to |
The current behavior uses the CPU endianness, which I found surprising: ``` b = bytearray(2) f = framebuf.FrameBuffer(b, 1, 1, framebuf.RGB565) f.fill(0xabcd) print(b) # bytearray(b'\xcd\xab') ``` I would expect that to result in `bytearray(b'\xab\xcd')`. The RGB565 OLED that I'm using needs the bytes arranged big-endian, so currently this means pushing the endianness-handling to the user of FrameBuffer. This commits retains the existing behavior for backwards-compatibility but adds two new modes `RGB565_BE` and `RGB565_LE` to allow the user to explicitly set the behavior. The existing `RGB565` will use whatever the CPU endianness is.
@peterhinch's comment on #2973 (comment) reminded me that I was still sitting on this... I still feel the current behavior of
@dpgeorge I tried this and it made the code size larger (+8 bytes). But it would definitely be a speed improvement for all three methods (always for fill, and when the endianess matches for the other two). I've now included this change, happy to go back to the original |
I just want to bump this PR because I think that the framebuffer without big-little endiannes option is incomplete. I think that having an out-of-the-box solution for the cheapest display on the market, from my point of view, is much more important than every other mode implemented in |
Fix micropython#3504: Don't use time module in pew.tick()
Discussion moving to #7253 |
The current behavior uses the CPU endianness, which I found surprising:
I would expect that to result in
bytearray(b'\xab\xcd')
. The RGB565OLED that I'm using needs the bytes arranged big-endian, so currently
this means pushing the endianness-handling to the user of FrameBuffer.
This commits retains the existing behavior for backwards-compatibility
but adds two new modes
RGB565_BE
andRGB565_LE
to allow the userto explicitly set the behavior. The existing
RGB565
will usewhatever the CPU endianness is.