mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 20:10:13 +02:00
Skip JPEG shrink-on-load for known rounding errors #3066
Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
This commit is contained in:
parent
83bb6a4554
commit
2b01951306
@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
Requires libvips v8.12.2
|
Requires libvips v8.12.2
|
||||||
|
|
||||||
|
### v0.30.1 - TBD
|
||||||
|
|
||||||
|
* Skip shrink-on-load for known libjpeg rounding errors.
|
||||||
|
[#3066](https://github.com/lovell/sharp/issues/3066)
|
||||||
|
|
||||||
### v0.30.0 - 1st February 2022
|
### v0.30.0 - 1st February 2022
|
||||||
|
|
||||||
* Add support for GIF output to prebuilt binaries.
|
* Add support for GIF output to prebuilt binaries.
|
||||||
|
@ -193,6 +193,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
} else if (shrink >= 2 * factor) {
|
} else if (shrink >= 2 * factor) {
|
||||||
jpegShrinkOnLoad = 2;
|
jpegShrinkOnLoad = 2;
|
||||||
}
|
}
|
||||||
|
// Skip shrink-on-load for known libjpeg rounding errors
|
||||||
|
if (jpegShrinkOnLoad > 1 && shrink == jpegShrinkOnLoad) {
|
||||||
|
jpegShrinkOnLoad /= 2;
|
||||||
|
}
|
||||||
} else if (inputImageType == sharp::ImageType::WEBP ||
|
} else if (inputImageType == sharp::ImageType::WEBP ||
|
||||||
inputImageType == sharp::ImageType::SVG ||
|
inputImageType == sharp::ImageType::SVG ||
|
||||||
inputImageType == sharp::ImageType::PDF) {
|
inputImageType == sharp::ImageType::PDF) {
|
||||||
|
@ -780,6 +780,27 @@ describe('Resize dimensions', function () {
|
|||||||
assert.strictEqual(info.height, 1);
|
assert.strictEqual(info.height, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Skip JPEG shrink-on-load for known libjpeg rounding errors', async () => {
|
||||||
|
const input = await sharp({
|
||||||
|
create: {
|
||||||
|
width: 1000,
|
||||||
|
height: 667,
|
||||||
|
channels: 3,
|
||||||
|
background: 'red'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
const output = await sharp(input)
|
||||||
|
.resize({ width: 500 })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
const { width, height } = await sharp(output).metadata();
|
||||||
|
assert.strictEqual(width, 500);
|
||||||
|
assert.strictEqual(height, 334);
|
||||||
|
});
|
||||||
|
|
||||||
it('unknown kernel throws', function () {
|
it('unknown kernel throws', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().resize(null, null, { kernel: 'unknown' });
|
sharp().resize(null, null, { kernel: 'unknown' });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user