Skip to content

Imageload palette has no len() #80

Closed
@7ensation

Description

@7ensation

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)

Activity

ch4nsuk3

ch4nsuk3 commented on Jul 18, 2024

@ch4nsuk3
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

FoamyGuy commented on Jul 19, 2024

@FoamyGuy
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

ch4nsuk3 commented on Jul 23, 2024

@ch4nsuk3
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

7ensation commented on Jul 23, 2024

@7ensation
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @FoamyGuy@7ensation@ch4nsuk3

      Issue actions

        Imageload palette has no len() · Issue #80 · adafruit/Adafruit_CircuitPython_ImageLoad