mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Update tests and comments after 7faacd9 (#3080)
This commit is contained in:
parent
5a9f89fe06
commit
7eb5efa3a3
@ -184,7 +184,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
if (inputImageType == sharp::ImageType::JPEG) {
|
if (inputImageType == sharp::ImageType::JPEG) {
|
||||||
// Leave at least a factor of two for the final resize step, when fastShrinkOnLoad: false
|
// Leave at least a factor of two for the final resize step, when fastShrinkOnLoad: false
|
||||||
// for more consistent results and avoid occasional small image shifting
|
// for more consistent results and to avoid extra sharpness to the image
|
||||||
int factor = baton->fastShrinkOnLoad ? 1 : 2;
|
int factor = baton->fastShrinkOnLoad ? 1 : 2;
|
||||||
if (shrink >= 8 * factor) {
|
if (shrink >= 8 * factor) {
|
||||||
jpegShrinkOnLoad = 8;
|
jpegShrinkOnLoad = 8;
|
||||||
@ -193,7 +193,7 @@ 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
|
// Lower shrink-on-load for known libjpeg rounding errors
|
||||||
if (jpegShrinkOnLoad > 1 && static_cast<int>(shrink) == jpegShrinkOnLoad) {
|
if (jpegShrinkOnLoad > 1 && static_cast<int>(shrink) == jpegShrinkOnLoad) {
|
||||||
jpegShrinkOnLoad /= 2;
|
jpegShrinkOnLoad /= 2;
|
||||||
}
|
}
|
||||||
|
BIN
test/fixtures/expected/fast-shrink-on-load-false.png
vendored
BIN
test/fixtures/expected/fast-shrink-on-load-false.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 270 B |
Before Width: | Height: | Size: 277 B After Width: | Height: | Size: 277 B |
@ -637,28 +637,21 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fastShrinkOnLoad: false ensures image is not shifted', function (done) {
|
[
|
||||||
return sharp(fixtures.inputJpgCenteredImage)
|
true,
|
||||||
.resize(9, 8, { fastShrinkOnLoad: false })
|
false
|
||||||
.png()
|
].forEach(function (value) {
|
||||||
.toBuffer(function (err, data, info) {
|
it(`fastShrinkOnLoad: ${value} does not causes image shifts`, function (done) {
|
||||||
if (err) throw err;
|
sharp(fixtures.inputJpgCenteredImage)
|
||||||
assert.strictEqual(9, info.width);
|
.resize(9, 8, { fastShrinkOnLoad: value })
|
||||||
assert.strictEqual(8, info.height);
|
.png()
|
||||||
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-false.png'), data, done);
|
.toBuffer(function (err, data, info) {
|
||||||
});
|
if (err) throw err;
|
||||||
});
|
assert.strictEqual(9, info.width);
|
||||||
|
assert.strictEqual(8, info.height);
|
||||||
it('fastShrinkOnLoad: true (default) might result in shifted image', function (done) {
|
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load.png'), data, done);
|
||||||
return sharp(fixtures.inputJpgCenteredImage)
|
});
|
||||||
.resize(9, 8)
|
});
|
||||||
.png()
|
|
||||||
.toBuffer(function (err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(9, info.width);
|
|
||||||
assert.strictEqual(8, info.height);
|
|
||||||
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-true.png'), data, done);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user