mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Recalculate residual after adjusting shrink #831
This commit is contained in:
parent
9e39a7fa95
commit
f42a1ceab7
@ -291,8 +291,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
if (xshrink > 1 && yshrink > 1 && (xresidual == 1.0 || yresidual == 1.0)) {
|
if (xshrink > 1 && yshrink > 1 && (xresidual == 1.0 || yresidual == 1.0)) {
|
||||||
xshrink = xshrink / 2;
|
xshrink = xshrink / 2;
|
||||||
yshrink = yshrink / 2;
|
yshrink = yshrink / 2;
|
||||||
xresidual = xresidual / 2.0;
|
xresidual = static_cast<double>(xshrink) / xfactor;
|
||||||
yresidual = yresidual / 2.0;
|
yresidual = static_cast<double>(yshrink) / yfactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we're using a device-independent colour space
|
// Ensure we're using a device-independent colour space
|
||||||
|
BIN
test/fixtures/expected/resize-diff-shrink-even.jpg
vendored
Normal file
BIN
test/fixtures/expected/resize-diff-shrink-even.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
BIN
test/fixtures/expected/resize-diff-shrink-odd.jpg
vendored
Normal file
BIN
test/fixtures/expected/resize-diff-shrink-odd.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
@ -413,14 +413,39 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Dimensions that result in differing shrinks on each axis', function () {
|
it('Dimensions that result in differing even shrinks on each axis', function (done) {
|
||||||
return sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(645, 399)
|
.resize(645, 399)
|
||||||
.toBuffer()
|
.toBuffer(function (err, data, info) {
|
||||||
.then(function (data) {
|
if (err) throw err;
|
||||||
return sharp(data)
|
assert.strictEqual(645, info.width);
|
||||||
|
assert.strictEqual(399, info.height);
|
||||||
|
sharp(data)
|
||||||
.resize(150, 100)
|
.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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user