-
Notifications
You must be signed in to change notification settings - Fork 21
Add PNG support #61
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
Add PNG support #61
Conversation
3c6f522
to
34f548e
Compare
This is a first stab at adding PNG support. For now there are no filters, so only indexed images will work.
Thank you for the PR. Would you feel comfortable adding the type annotations? Here are some examples of the annotations: https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad/blob/main/adafruit_imageload/pnm/pbm_ascii.py#L30-L36 |
@matt-land I intentionally didn't add type annotations, because I think they make the code much harder to read and are very wasteful on memory-constrained systems such as CircuitPython. Plus, I really don't see the point of adding them to a function that pretty much takes and returns arbitrary types. |
@matt-land Speaking of which, I think the example annotations you linked to are wrong. First, the function takes classes as the arguments, and returns the instances of those classes, and your annotations say it both takes and returns instances, second, and more importantly, the classes from displayio are not the only classes you can pass to them – in fact, the whole point of passing the classes is that you can use any type you want, as long as it has the same protocol. So not only are those annotations wasteful, but they are also wrong, and will raise errors on perfectly good code. I think they should be removed. |
Note that the MicroPython core simply discards type annotations. They are not in the compiled bytecode. It is true that the boilerplate conditional |
Even if it adds only a little, I'm working on systems where a dozen bytes of flash space makes a difference, and as evidenced by the example linked, those type annotations don't actually prevent the exact kind of error they were supposed to prevent. They are harmful, at least in this particular case, where you would need to write quite a bit of code using |
Let's not argue over the value of type annotations here. @matt-land's request was reasonable given that this library and many of our others have type annotations. @deshipu you are welcome to maintain your own version without type annotations for your constrained case. In CircuitPython libraries, they bring value in editor convenience and validation. If they are incorrect, then we should fix them, not throw them out completely. |
If you want to hand that out to me @deshipu, let me know! |
Just revisiting this, let me know if you want to hand that over to me, either to add to this PR or add to a follow up one. |
Thanks @deshipu for working on this! It is great to have support for PNG images on the horizon! The only feedback I have really is that it may be nice to include an example in the examples dir that shows how to use the new functionality, I'm happy to work on that as well. I am willing to help however I can to keep this moving along. I am excited about the new functionality. I tested this successfully on a Hack Tablet ( I tested using these images: and this code file:
|
I re-tested this with a more basic example on the Feather S2 TFT here is the test code:
I'm going to merge this one now and then work on a follow up PR with the type annotations and this example included. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x to 1.12.7 from 1.12.6: > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#37 from tekktrik/dev/fix-value-error Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306 to 1.5.10 from 1.5.9: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306#29 from tekktrik/dev/fix-type-annotation Updating https://github.com/adafruit/Adafruit_CircuitPython_GPS to 3.10.6 from 3.10.5: > Merge pull request adafruit/Adafruit_CircuitPython_GPS#90 from tekktrik/dev/fix-example-import Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 2.1.13 from 2.1.12: > Merge pull request adafruit/Adafruit_CircuitPython_PM25#25 from tekktrik/main Updating https://github.com/adafruit/Adafruit_CircuitPython_SD to 3.3.15 from 3.3.14: > Merge pull request adafruit/Adafruit_CircuitPython_SD#51 from calcut/main Updating https://github.com/adafruit/Adafruit_CircuitPython_SHTC3 to 1.1.10 from 1.1.9: > Merge pull request adafruit/Adafruit_CircuitPython_SHTC3#17 from tcfranks/main Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.17 from 0.5.16: > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#30 from jepler/make-tests-pass Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 0.5.2 from 0.5.1: > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#15 from FoamyGuy/smaller_file_read_buffer Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.16.7 from 1.16.6: > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#61 from deshipu/png Updating https://github.com/adafruit/Adafruit_CircuitPython_Ticks to 1.0.8 from 1.0.7: > Merge pull request adafruit/Adafruit_CircuitPython_Ticks#8 from adafruit/try-time-ticksms
This is a first stab at adding PNG support. For now there are no
filters, so only indexed images will work.