png resize artefacts related to premultiplication rounding?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 32.7k
- Forks
- 1.4k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
### What are you trying to achieve?
We develop a product that relies heavily on image processing, and in particular on image resizing. We were previously using ImageMagick for this but wanted to transition to Sharp. Using Sharp 0.31.3 (or earlier), resizing (downscaling) png images with transparency works as expected (i.e the results using Sharp are almost indistinguishable from the results using ImageMagick), but using Sharp >= 0.32.0 downscaled pngs get weird color artefacts at the cross over from opaque to transparent. Our first thought was that libvips had changed something between 8.13 and 8.14, but using libvips directly proved that theory wrong. Hence, our best guess is that the change to "Prefer integer (un)premultiply for faster resizing of RGBA images", introduced in Sharp 0.32.0, is to blame for what we are seeing. If so, would it be possible to add a flag to opt out of using the integer premultiply when resizing?
### When you searched for similar issues, what did you find that might be related?
https://github.com/lovell/sharp/issues/3658
### Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
`sharp("path to image").resize(20, 20)
`
### Please provide sample image(s) that help explain this question
These images are very small in size and zooming will be required to notice the artefacts I'm referring to. Larger images can be provided if needed.
Original (100x100)

Resized using Sharp 0.31.3 (20x20)

Resized using Sharp 0.33.3 (20x20). Notice the discoloring of the top opaque pixel row.

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with issue #4051 and the related issue #3658, then reproduce the transparent PNG resize using the provided sample and resize(20, 20) with Sharp 0.31.3 and 0.33.3. Compare the crossover artefacts and investigate the Sharp 0.32.0 change to integer premultiplication; done means resolving the artefacts or providing and verifying an opt-out flag.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- computer-graphics, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100