Skip to content
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

Compare combined data to saved JPEG #1

Closed

Conversation

radarhere
Copy link

Suggestions for python-pillow#7491

  1. As per https://pillow.readthedocs.io/en/stable/releasenotes/7.0.0.html#image-del, images should not be implicitly closed, so I've added a context manager to the opened image.
  2. Rather than asserting that the combined image is similar to the original image, I've saved the original image as a separate JPEG, and asserted that it is equal to the combined version. That seems like a more interesting check to me.

I've also restructured the test code, which you may have different thoughts about, so feel free to only use part of this.

bgilbert and others added 3 commits October 24, 2023 12:08
We already support streamtype=2 to skip producing JPEG tables, but
streamtype=1, which skips everything but the tables, was never implemented.
The streamtype=1 stub code dates to Git pre-history, so it's not
immediately clear why.  Implement the missing support.

jpeg_write_tables() can't resume after a full output buffer (it fails with
JERR_CANT_SUSPEND), so it might seem that Pillow needs to pre-compute the
necessary buffer size.  However, in the normal case of producing an
interchange stream, the tables are written via the same libjpeg codepath
during the first jpeg_write_scanlines() call, and table writes aren't
resumable there either.  Thus, any buffer large enough for the normal case
will also be large enough for a tables-only file.

The streamtype option isn't documented and this commit doesn't change that.
It does add a test though.
@bgilbert
Copy link
Owner

Thanks, the suggestions and refactor LGTM! I've done some additional refactoring on top (including eliminating the temporary file) and pushed back to the original PR.

@bgilbert bgilbert closed this Oct 25, 2023
@radarhere radarhere deleted the jpeg-tables-only branch October 25, 2023 02:13
bgilbert pushed a commit that referenced this pull request Nov 25, 2023
Do not assign new fp attribute to image when closing
bgilbert pushed a commit that referenced this pull request Dec 8, 2023
bgilbert pushed a commit that referenced this pull request Dec 24, 2023
radarhere pushed a commit that referenced this pull request Feb 11, 2024
radarhere pushed a commit that referenced this pull request Jul 26, 2024
radarhere pushed a commit that referenced this pull request Jul 26, 2024
radarhere pushed a commit that referenced this pull request Jul 26, 2024
radarhere pushed a commit that referenced this pull request Jul 26, 2024
Do not import numpy.typing unless TYPE_CHECKING
radarhere added a commit that referenced this pull request Jul 26, 2024
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants