adafruit / Adafruit_CircuitPython_ImageLoad

Super-slim image decoder that loads code as needed to minimize memory use
MIT License
15 stars 21 forks source link

Add PNM support #1

Closed tannewt closed 5 years ago

tannewt commented 6 years ago

According to atmakers: One tip: add pnm format next. It’s easy to support and imagemagick converts everything to it

matt-land commented 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.

tannewt commented 5 years ago

@matt-land What help do you need?

matt-land commented 5 years ago

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
matt-land commented 5 years ago

I think the PR getting landed will look like:

tannewt commented 5 years ago

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.

matt-land commented 5 years ago

https://github.com/adafruit/circuitpython/pull/1874/files I made the docs better, but it seems like the blind leading the blind.

matt-land commented 5 years ago

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

matt-land commented 5 years ago

Can we close this now?

tannewt commented 5 years ago

Yup! Go ahead if you can.

tannewt commented 5 years ago

Fixed by #12. Will release shortly.