Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

relic-se
Copy link
Contributor

@relic-se relic-se commented Sep 8, 2025

When working with framebufferio.FramebufferDisplay sources, the byte order of 16-bit pixel data was flipped, causing major color errors. This update simply changes the byteorder.

This fix has been tested on the Adafruit Fruit Jam using the following code:

import displayio
import supervisor
from terminalio import FONT
import vectorio

from adafruit_bitmapsaver import save_pixels
from adafruit_display_text.label import Label
from adafruit_fruitjam.peripherals import request_display_config

BAR_COLORS = (
    0x000000,
    0x444444,
    0x888888,
    0xcccccc,
    0xffffff
)
CIRCLE_COLOR = 0xff0000
TEXT_COLOR = 0xffffff

# initialize display
request_display_config(320, 240)
display = supervisor.runtime.display
display.auto_refresh = False

# create root group
group = displayio.Group()
display.root_group = group

# draw bars
for i, color in enumerate(BAR_COLORS):
    palette = displayio.Palette(1)
    palette[0] = color
    group.append(vectorio.Rectangle(
        pixel_shader=palette,
        width=display.width//len(BAR_COLORS),
        height=display.height,
        x=display.width//len(BAR_COLORS)*i,
    ))

# draw circle
palette = displayio.Palette(1)
palette[0] = CIRCLE_COLOR
group.append(vectorio.Circle(
    pixel_shader=palette, radius=min(display.width, display.height)//4,
    x=display.width//2, y=display.height//2,
))

# draw text
group.append(Label(
    font=FONT, text="Hello, World!",
    anchor_point=(.5, .5),
    anchored_position=(display.width//2, display.height//2),
))

# update display
display.refresh()

print("Taking Screenshot... ")
save_pixels("/sd/screenshot.bmp", display)
print("Screenshot Saved")

Before:
screenshot-before.bmp

After:
screenshot-after.bmp

Note: This update has not been tested on other display sources. It is possible that the source needs to be tested in some manner to decide the byte order.

Fixes #36

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Sep 9, 2025

I suspect that changing the hard-coded order like this is going to make it have a similar issue with BusDisplay or other types of displays. I'll test on a pyportal to try to confirm. If that is the case we may need to add a parameter or something that allows it to be set to the order required for a given display. Or maybe if display types are always consistent accross the same types it could just check the type of the display object and then behave accordingly.

@relic-se
Copy link
Contributor Author

relic-se commented Sep 9, 2025

I suspect that changing the hard-coded order like this is going to make it have a similar issue with BusDisplay or other types of displays.

You are likely correct here. I don't have enough knowledge of how CircuitPython handles different types of displays to comment further.

If that is the case we may need to add a parameter or something that allows it to be set to the order required for a given display. Or maybe if display types are always consistent across the same types it could just check the type of the display object and then behave accordingly.

Adding an argument to handle this should be sufficient for now unless someone who has more knowledge in this area can comment further.

The only display types I am aware of which incur this issue are the following:

  • picodvi.Framebuffer
  • dotclockframebuffer.DotClockFramebuffer (mentioned in the associated issue, though untested with the fix)

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tannewt tannewt merged commit 2b972cd into adafruit:main Sep 9, 2025
1 check passed
@relic-se
Copy link
Contributor Author

relic-se commented Sep 9, 2025

Awesome. Thank you for the technical input, @tannewt! 🎉

@relic-se relic-se deleted the display-byteorder branch September 9, 2025 18:11
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 12, 2025
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.

Issue with Sunton dotclockframebuffer display and bitmapsaver
3 participants