Recalculate residual after adjusting shrink #831

This commit is contained in:
Lovell Fuller 2017-05-30 20:22:15 +01:00
parent 9e39a7fa95
commit f42a1ceab7
4 changed files with 33 additions and 8 deletions

View File

@ -291,8 +291,8 @@ class PipelineWorker : public Nan::AsyncWorker {
if (xshrink > 1 && yshrink > 1 && (xresidual == 1.0 || yresidual == 1.0)) {
xshrink = xshrink / 2;
yshrink = yshrink / 2;
xresidual = xresidual / 2.0;
yresidual = yresidual / 2.0;
xresidual = static_cast<double>(xshrink) / xfactor;
yresidual = static_cast<double>(yshrink) / yfactor;
}
// Ensure we're using a device-independent colour space

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -413,14 +413,39 @@ describe('Resize dimensions', function () {
});
});
it('Dimensions that result in differing shrinks on each axis', function () {
return sharp(fixtures.inputJpg)
it('Dimensions that result in differing even shrinks on each axis', function (done) {
sharp(fixtures.inputJpg)
.resize(645, 399)
.toBuffer()
.then(function (data) {
return sharp(data)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(645, info.width);
assert.strictEqual(399, info.height);
sharp(data)
.resize(150, 100)
.toBuffer();
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(150, info.width);
assert.strictEqual(100, info.height);
fixtures.assertSimilar(fixtures.expected('resize-diff-shrink-even.jpg'), data, done);
});
});
});
it('Dimensions that result in differing odd shrinks on each axis', function (done) {
return sharp(fixtures.inputJpg)
.resize(600, 399)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(600, info.width);
assert.strictEqual(399, info.height);
sharp(data)
.resize(200)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(133, info.height);
fixtures.assertSimilar(fixtures.expected('resize-diff-shrink-odd.jpg'), data, done);
});
});
});
});