Skip to content
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

Imageload palette has no len() #80

Closed
7ensation opened this issue Apr 26, 2024 · 4 comments · Fixed by #90
Closed

Imageload palette has no len() #80

7ensation opened this issue Apr 26, 2024 · 4 comments · Fixed by #90

Comments

@7ensation
Copy link

Im trying to dynamically index a palette that is being loaded via imageload in circuitpython, however, when i try to get the length of the palette an error occurs saying "object of type 'ColorConverter' has no len()" code sample below:

source_bitmap, source_palette = adafruit_imageload.load("bitmap.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
test = len(source_palette)

@ch4nsuk3
Copy link
Contributor

I was unable to reproduce this on CircuitPython 9.0.4, instead getting the expected behavior. If you are still experiencing can you please provide the version of CircuitPython you are using? It can be found by reading the boot_out.txt file in your CIRCUITPY drive.

@FoamyGuy
Copy link
Contributor

I think this might boil down to a difference between Palette which does have a length, and ColorConverter which does not have length.

imageload will return a Palette if the loaded image is indexed, and that palette will have a length representing the number of different colors in the Palette.

However if the image loaded is RGB (not indexed) then imageload would return a ColorConverter instance not a palette. ColorConverter does not use a specific subset of colors like Palette so it doesn't have a length. It's function is to convert RGB888 color values (which is what it assumes to find in RGB non-indexed images) into RGB565 colorspace because that is what displayio uses internally.

@ch4nsuk3
Copy link
Contributor

That makes sense. In that case I noticed RTD is missing information on adafruit_imageload.bmp.truecolor, so there is no mention of getting a ColorConverter object back instead of a Palette. The information given for adafruit_imageload.bmp simply states it returns a tuple of a Bitmap and a Palette so getting a ColorConverter back could be a bit of a surprise, especially for someone who isnt aware there are differences between indexed and non-indexed bitmaps.

A method allowing the user to check which type of image they have (and whether or not its a supported type) may be handy, though I dont think that this is a big enough issue to merit adding code.

@7ensation
Copy link
Author

Its been a while since i was messing with this but from what i remember, theres multiple types of bitmaps and you have to convert the image to the correct type of bitmap for this to work.

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 a pull request may close this issue.

3 participants