Skip to content

Commit 7eb5efa

Browse files
authored
Update tests and comments after 7faacd9 (#3080)
1 parent 5a9f89f commit 7eb5efa

4 files changed

Lines changed: 17 additions & 24 deletions

File tree

src/pipeline.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class PipelineWorker : public Napi::AsyncWorker {
184184

185185
if (inputImageType == sharp::ImageType::JPEG) {
186186
// Leave at least a factor of two for the final resize step, when fastShrinkOnLoad: false
187-
// for more consistent results and avoid occasional small image shifting
187+
// for more consistent results and to avoid extra sharpness to the image
188188
int factor = baton->fastShrinkOnLoad ? 1 : 2;
189189
if (shrink >= 8 * factor) {
190190
jpegShrinkOnLoad = 8;
@@ -193,7 +193,7 @@ class PipelineWorker : public Napi::AsyncWorker {
193193
} else if (shrink >= 2 * factor) {
194194
jpegShrinkOnLoad = 2;
195195
}
196-
// Skip shrink-on-load for known libjpeg rounding errors
196+
// Lower shrink-on-load for known libjpeg rounding errors
197197
if (jpegShrinkOnLoad > 1 && static_cast<int>(shrink) == jpegShrinkOnLoad) {
198198
jpegShrinkOnLoad /= 2;
199199
}
-270 Bytes
Binary file not shown.
File renamed without changes.

test/unit/resize.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -637,28 +637,21 @@ describe('Resize dimensions', function () {
637637
});
638638
});
639639

640-
it('fastShrinkOnLoad: false ensures image is not shifted', function (done) {
641-
return sharp(fixtures.inputJpgCenteredImage)
642-
.resize(9, 8, { fastShrinkOnLoad: false })
643-
.png()
644-
.toBuffer(function (err, data, info) {
645-
if (err) throw err;
646-
assert.strictEqual(9, info.width);
647-
assert.strictEqual(8, info.height);
648-
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-false.png'), data, done);
649-
});
650-
});
651-
652-
it('fastShrinkOnLoad: true (default) might result in shifted image', function (done) {
653-
return sharp(fixtures.inputJpgCenteredImage)
654-
.resize(9, 8)
655-
.png()
656-
.toBuffer(function (err, data, info) {
657-
if (err) throw err;
658-
assert.strictEqual(9, info.width);
659-
assert.strictEqual(8, info.height);
660-
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-true.png'), data, done);
661-
});
640+
[
641+
true,
642+
false
643+
].forEach(function (value) {
644+
it(`fastShrinkOnLoad: ${value} does not causes image shifts`, function (done) {
645+
sharp(fixtures.inputJpgCenteredImage)
646+
.resize(9, 8, { fastShrinkOnLoad: value })
647+
.png()
648+
.toBuffer(function (err, data, info) {
649+
if (err) throw err;
650+
assert.strictEqual(9, info.width);
651+
assert.strictEqual(8, info.height);
652+
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load.png'), data, done);
653+
});
654+
});
662655
});
663656

664657
[

0 commit comments

Comments
 (0)