Skip to content

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

Merged
merged 7 commits into from
Jul 26, 2024
Merged

Added JPG support #81

merged 7 commits into from
Jul 26, 2024

Conversation

ch4nsuk3
Copy link
Contributor

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.

ch4nsuk3 and others added 5 commits July 19, 2024 15:13
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
@tannewt
Copy link
Member

tannewt commented Jul 24, 2024

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.

Pictures of cats are always welcome. Thanks!

Copy link
Member

@tannewt tannewt left a 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.
@ch4nsuk3 ch4nsuk3 marked this pull request as ready for review July 25, 2024 19:24
@ch4nsuk3
Copy link
Contributor Author

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.
Copy link
Member

@tannewt tannewt left a 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.

@tannewt tannewt merged commit 6b7deeb into adafruit:main Jul 26, 2024
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add JPG to Imageload
2 participants