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

Thumbnail tuning #1029

Merged
merged 2 commits into from
Dec 29, 2014
Merged

Thumbnail tuning #1029

merged 2 commits into from
Dec 29, 2014

Conversation

homm
Copy link
Member

@homm homm commented Nov 28, 2014

There are two changes related to how Image.thumbnail works.

JPEG draft decoding

Image.thumbnail (or more precise Image.draft) instructs libJPEG to open image in draft mode. I don't know original motivation of libJPEG authors to add this mode. Looks like it gives very small performance win:

In [1]: from PIL import Image

In [2]: %timeit -n 20 i = Image.open('5k.jpg'); i.decoderconfig = (1, 0); i.load()
20 loops, best of 3: 245 ms per loop

In [3]: %timeit -n 20 i = Image.open('5k.jpg'); i.decoderconfig = (1, 1); i.load()
20 loops, best of 3: 234 ms per loop

Also it does't affect too much most of images, but for some images it introduces noticeable artifacts. For example this is cropped part of normal decoded image and draft. Source.

jeans ref jeans draft

Docstring of Image.draft() method says:

Configures the image file loader so it returns a version of the image that as closely as possible matches the given mode and size.

I believe what this is exactly what this method should do. But not decrease quality of image decoding even if decoder options named the same as this method.

Bicubic as default filter

In Pillow 2.5 default filter was changed from NEAREST to ANTIALIAS. Antialias was chosen because all other filters gave poor quality for reduction. Starting from Pillow 2.7 we can replace ANTIALIAS with BICUBIC, because bicubic is a bit faster and ANTIALIAS doesn't give any advantages if we first scales down image with libJPEG (which uses supersampling, not convolutions).

@homm
Copy link
Member Author

homm commented Dec 4, 2014

I'll resolve conflicts.

@homm
Copy link
Member Author

homm commented Dec 4, 2014

Done.

@homm
Copy link
Member Author

homm commented Dec 27, 2014

I'm worry about this PR. Will it be merged in 2.7? If you don't want to change thumbnail default filter, just let me know, I'll remove this part. But draft JPEG decoder mode should be definitely eliminated.

@aclark4life
Copy link
Member

@homm Do you want it merged in 2.7? Have @wiredfool and/or @hugovk reviewed?

@homm
Copy link
Member Author

homm commented Dec 28, 2014

I definitely want :)

@hugovk
Copy link
Member

hugovk commented Dec 28, 2014

Looks fine for me but I'll let @wiredfool check too.

@wiredfool
Copy link
Member

Ok, works for me.

wiredfool added a commit that referenced this pull request Dec 29, 2014
@wiredfool wiredfool merged commit a31e340 into python-pillow:master Dec 29, 2014
This was referenced Apr 2, 2015
@homm homm deleted the thumbnail-tune branch April 27, 2016 21:42
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.

None yet

4 participants