pbio/image/media: Add mechanism for images.#460
Draft
laurensvalk wants to merge 1 commit intomasterfrom
Draft
Conversation
54dce17 to
78be7fe
Compare
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.
This draft adds
pybricks.parameters.ImageFileand support for images in the system UI.Image files in
lib/pbio/src/image/mediaare 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
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
strncmpinstead. Instead, since we're generating code anyway, we could just generate the QSTRs in a separate file for use byImageFile, and get rid of theconst char *namefield in thepbiostructs.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
Imageto parameters, we'll moveImageFilethere too.We could also just let the instances be class attribute of
Image, so you can doImage.ACCEPT.This is similar to what we do with
Color(), which also hasColor.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.
Example: