Closed tannewt closed 5 years ago
There are 7 formats in the family, and the pycon group worked on p1-p6. http://netpbm.sourceforge.net/doc/pnm.html Getting help from Scott on the palette object.
@matt-land What help do you need?
Can you point to any doc on using the palette object? We got it working with mono and I think grayscale, but we were kinda guessing.
With grey, we kept a set of all observed pixel values as we seek over the file, so it works kind of like below
"""
color_list = set()
for decoded_pixel in (reading of file):
# push into the bitmap
bitmap[x, y] = decoded_pixel
# add to the color list
color_list.add(decoded_pixel)
...
# color_list is now set([33, 255, 127, 56])
palette = palette(len(color_list))
for count, color in enumerate(color_list):
# Like this ?
palette[count] = 0x{color_as_hex}{color_as_hex}{color_as_hex}
# or like this for greyscale values?
palette[count] = color
return bitmap, palette
I think the PR getting landed will look like:
Hrm, docs aren't very useful. :-) https://circuitpython.readthedocs.io/en/latest/shared-bindings/displayio/Palette.html
The easiest thing is to return None for the palette because the values are encoding the color. An optimization would be to do a pass to count the number of unique colors and use a smaller bitmap value if possible. I'd do that second though.
https://github.com/adafruit/circuitpython/pull/1874/files I made the docs better, but it seems like the blind leading the blind.
OK I have a branch that works with formats P1-P6. I'm not ready to open a PR, but should I get hit by a bus, here is where I stopped: This branch: https://github.com/crookedstorm/Adafruit_CircuitPython_ImageLoad/tree/feature-tests
This doc covers testing on the hardware with a Feature M4 Express and a Feature 320x240 touch screen: https://github.com/crookedstorm/Adafruit_CircuitPython_ImageLoad/blob/feature-tests/docs/pbm_test_code.py
Can we close this now?
Yup! Go ahead if you can.
Fixed by #12. Will release shortly.
According to atmakers: One tip: add pnm format next. It’s easy to support and imagemagick converts everything to it