Skip to content

pbio/image/media: Add mechanism for images.#460

Draft
laurensvalk wants to merge 1 commit intomasterfrom
ev3-ui
Draft

pbio/image/media: Add mechanism for images.#460
laurensvalk wants to merge 1 commit intomasterfrom
ev3-ui

Conversation

@laurensvalk
Copy link
Member

@laurensvalk laurensvalk commented Feb 8, 2026

This draft adds pybricks.parameters.ImageFile and support for images in the system UI.

Image files in lib/pbio/src/image/media are converted to a suitable C struct that we can use in the firmware. They are compressed to take up far less space than their bitmap or PNG counterpart.

This is a draft, since there are a few aspects that I haven't decided on or didn't like.

Building

  • Do we want to commit the generated source files?
  • Or do we want it as a build step (as in this PR?). This currently adds a dependency (cairosvg), though I suppose we could add a Python dependency instead.

ImageFile

  • The attribute handler for ImageFile does a lookup to find the image file. But since this lives in pbio, we can't use QSTRs and so we use strncmp instead. Instead, since we're generating code anyway, we could just generate the QSTRs in a separate file for use by ImageFile, and get rid of the const char *name field in the pbio structs.

  • We would have to make some assumptions for some formats. For example, we might want to let all monochrome images be black+transparant, and perhaps use pbdrv_display_get_value_from_hsv to find the value. This needs some work.

Media
I propose to include all images from ev3dev-media. Not done yet. Just included two images for testing.

API

Since we've already moved Image to parameters, we'll move ImageFile there too.

We could also just let the instances be class attribute of Image, so you can do Image.ACCEPT.

This is similar to what we do with Color(), which also has Color.RED.

Compression
The current draft has compression types that allow for more efficient packing depending on the image.

It does make a big difference, but it makes the code a bit messier. So for now I'll cut this out and keep only the 1 byte = 8 pixels format to keep things simple. We can optimize later.

/**
 * Compression types.
 */
typedef enum {
    /**
     * One byte per pixel, same as uncompressed image.
     */
    PBIO_IMAGE_COMPRESSION_TYPE_NONE,
    /**
     * One byte for 8 pixels. High is black, most significant bit is first pixel.
     */
    PBIO_IMAGE_COMPRESSION_MONOCHROME_8BIT_MAP,
    /**
     * Monochrome image limited to 256x256 pixels.
     *
     * Image starts at black. Data is an array of 2x8-bit values
     * representing the coordinates where the color inverts.
     */
    PBIO_IMAGE_COMPRESSION_MONOCHROME_256x256_FLIP,
} pbio_image_compression_type_t;

Example:

from pybricks.hubs import VirtualHub
from pybricks.tools import wait
from pybricks.parameters import ImageFile

hub = VirtualHub()

hub.screen.draw_image(source=ImageFile.ACCEPT, x=0, y=0)

hub.screen.draw_image(source=ImageFile.WRENCH17, x=90, y=100)

wait(10000)
image

@laurensvalk laurensvalk marked this pull request as draft February 8, 2026 12:46
Include images in the firmware, which is needed for the UI. Also provides access to images via `ImageFile` class.
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.

1 participant