-
Notifications
You must be signed in to change notification settings - Fork 21
Added JPG support #81
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
Conversation
Add support for JPG files using a wrapper that implements the jpegio library.
Added a JPG module that calls jpegio and updated the base __init__.py to recognize JPG files.
Removed the palette option from the load function since it isnt used, as we use colorconverter instead.
Completed the simpletest example script, along with a provided jpg.
Disabled the too-many-branches pylint check in __init__.py The new 'if' statement goes over the limit of 12 branches. Shortened comment in jpg.py
Pictures of cats are always welcome. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! This is helpful. I bet you need to setup pre-commit locally: https://learn.adafruit.com/improve-your-code-with-pylint/check-your-code-with-pre-commit
Formatting errors in jpg.py should be corrected now. PyCharm was using CRLF instead of LF line separators.
Sorry for that, pre-commit was choking on me. I have Python 3.12 installed and pre-commit was choking because I am on Python 3.12. I wound up setting up PyCharm to run pylint and black for me. |
Helps if I include them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good. Sorry about the 3.12 issues. We're in the process of moving over ourselves.
Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.21.0 from 1.20.2: > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#81 from ch4nsuk3/jpg-support Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Fixes #79
Adds JPG support via calls to the jpegio library, allowing use of consistent code without having to switch back and forth between the two libraries directly. This is the easiest way to do it, as trying to create a JPG decoder in python is never going to be as efficient as jpegio as it and the library it relies upon, tjpgd, are coded in C and are well optimized. Progressive JPG images are not supported.
I originally was going to implement a check for the flags which indicate what encoding method is used by scanning the header data, as other classes in this library do, in order to allow for raising an error without having to call jpegio at all. However these flags come after exif data, which can run quite long. This means it could potentially require quite a bit of chewing through a file to get to the needed flags, something jpegio will do much quicker.
I intentionally kept the arguments provided to
jpegio.decode
minimal. The extra arguments are primarily for blit operations and anyone needing those options is likely better served by using jpegio directly.The load function returns a Bitmap and ColorConverter
Changes to the init file are to check for the flags indicating a JPG image, then calling for the load function if so.
I have also included a simpletest showcasing usage. I have provided a sample image as well, a 48x48px image of my cat, done in a posterized style, along with a license document using the MIT license. I understand if you would prefer to use a different image as the test image.