Repository navigation
encode_png: RGB565 framebuffer to PNG - #36
Merged
Merged
Conversation
Adds encode_png() for encoding RGB565 framebuffers to PNG byte strings, used by roku_companion's frame server to stream display output to Roku TVs. C implementation (src/gfx_png.c): - Minimal PNG encoder: IHDR, IDAT (deflate via uzlib), IEND - RGB565 to RGB888 conversion during encoding - Exposed as pygraphics.encode_png() via MicroPython bindings Pure-Python fallback (lib/pygraphics/_png.py): - zlib-based PNG encoder for CPython and environments without the C module - Same API: encode_png(buffer, width, height, format) Build system: - micropython.mk, micropython.cmake, circuitpython.mk updated - qstr definitions for encode_png added Tests: - test_files.py updated with encode_png coverage
…e parity tool's staged files; import order
bdbarnett
marked this pull request as ready for review
October 6, 2026 07:07
…_png and FrameBuffer.to_png, MicroPython gets FrameBuffer.to_png, and every saver writes PNG for a .png name or RGB888 through one shared rule (gfx_png_wanted)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A PNG encoder for RGB565 framebuffers (also RGB888 and GS8),
pygraphics.encode_png(fb, width=None, height=None, format=None): C insrc/gfx_png.c(deflate via uzlib) with a pure-Python fallback inlib/pygraphics/_png.py. It's half of the Roku companion feature written on 2026-09-30, and Brad wants it for the casting work (2026-10-06). The examples half is PyDevices/pydevices-examples#158.CI fixes (2026-10-06):
_png.pyis now inpygraphics.toml, regenerated with the publisher's generator; its--checkpasses._png.pyis now intools/compare_graphics.py's staged files. Without it the MicroPython job failed:no module named 'pygraphics_py._png'.Tested locally, 2026-10-06:
ruff check lib testspasses, and CPythonunittestis OK.implementation() == native_cmod):test_area,test_subclass,test_parity(45 public names),compare_graphics_run(385 checks) andcompare_framebuf_mpall pass.Known limit: MicroPython's built-in
framebuf.FrameBufferisn't recognised as a framebuffer, onlypygraphics.FrameBufferis, so passwidthandheightwith it (that works, and is tested above).