mirror of
https://github.com/lovell/sharp.git
synced 2025-07-10 19:10:14 +02:00
Improve perf/accuracy of nearest neighbour integral upsample
This commit is contained in:
parent
52bea15ad7
commit
4d1a1694cd
@ -14,6 +14,10 @@ Requires libvips v8.5.2.
|
|||||||
[#607](https://github.com/lovell/sharp/issues/607)
|
[#607](https://github.com/lovell/sharp/issues/607)
|
||||||
[@puzrin](https://github.com/puzrin)
|
[@puzrin](https://github.com/puzrin)
|
||||||
|
|
||||||
|
* Improve performance and accuracy of nearest neighbour integral upsampling.
|
||||||
|
[#752](https://github.com/lovell/sharp/issues/752)
|
||||||
|
[@MrIbby](https://github.com/MrIbby)
|
||||||
|
|
||||||
* Ensure ARM64 pre-built binaries use correct C++11 ABI version.
|
* Ensure ARM64 pre-built binaries use correct C++11 ABI version.
|
||||||
[#772](https://github.com/lovell/sharp/issues/772)
|
[#772](https://github.com/lovell/sharp/issues/772)
|
||||||
[@ajiratech2](https://github.com/ajiratech2)
|
[@ajiratech2](https://github.com/ajiratech2)
|
||||||
|
@ -417,19 +417,27 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("centre", baton->centreSampling));
|
->set("centre", baton->centreSampling));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Perform affine enlargement
|
// Perform enlargement
|
||||||
if (yresidual > 1.0 || xresidual > 1.0) {
|
if (yresidual > 1.0 || xresidual > 1.0) {
|
||||||
|
if (trunc(xresidual) == xresidual && trunc(yresidual) == yresidual && baton->interpolator == "nearest") {
|
||||||
|
// Fast, integral nearest neighbour enlargement
|
||||||
|
image = image.zoom(xresidual, yresidual);
|
||||||
|
} else {
|
||||||
|
// Floating point affine transformation
|
||||||
vips::VInterpolate interpolator = vips::VInterpolate::new_from_name(baton->interpolator.data());
|
vips::VInterpolate interpolator = vips::VInterpolate::new_from_name(baton->interpolator.data());
|
||||||
if (yresidual > 1.0) {
|
if (yresidual > 1.0 && xresidual > 1.0) {
|
||||||
|
image = image.affine({xresidual, 0.0, 0.0, yresidual}, VImage::option()
|
||||||
|
->set("interpolate", interpolator));
|
||||||
|
} else if (yresidual > 1.0) {
|
||||||
image = image.affine({1.0, 0.0, 0.0, yresidual}, VImage::option()
|
image = image.affine({1.0, 0.0, 0.0, yresidual}, VImage::option()
|
||||||
->set("interpolate", interpolator));
|
->set("interpolate", interpolator));
|
||||||
}
|
} else if (xresidual > 1.0) {
|
||||||
if (xresidual > 1.0) {
|
|
||||||
image = image.affine({xresidual, 0.0, 0.0, 1.0}, VImage::option()
|
image = image.affine({xresidual, 0.0, 0.0, 1.0}, VImage::option()
|
||||||
->set("interpolate", interpolator));
|
->set("interpolate", interpolator));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate
|
// Rotate
|
||||||
if (!baton->rotateBeforePreExtract && rotation != VIPS_ANGLE_D0) {
|
if (!baton->rotateBeforePreExtract && rotation != VIPS_ANGLE_D0) {
|
||||||
|
@ -35,16 +35,53 @@ describe('Interpolators and kernels', function () {
|
|||||||
sharp.interpolator.locallyBoundedBicubic,
|
sharp.interpolator.locallyBoundedBicubic,
|
||||||
sharp.interpolator.vertexSplitQuadraticBasisSpline
|
sharp.interpolator.vertexSplitQuadraticBasisSpline
|
||||||
].forEach(function (interpolator) {
|
].forEach(function (interpolator) {
|
||||||
it(interpolator, function (done) {
|
describe(interpolator, function () {
|
||||||
sharp(fixtures.inputJpg)
|
it('x and y', function (done) {
|
||||||
.resize(320, null, { interpolator: interpolator })
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
|
.resize(200, 200, { interpolator: interpolator })
|
||||||
|
.png()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual(200, info.width);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(200, info.height);
|
||||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('x only', function (done) {
|
||||||
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
|
.resize(200, 21, { interpolator: interpolator })
|
||||||
|
.png()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(200, info.width);
|
||||||
|
assert.strictEqual(21, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('y only', function (done) {
|
||||||
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
|
.resize(21, 200, { interpolator: interpolator })
|
||||||
|
.png()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(21, info.width);
|
||||||
|
assert.strictEqual(200, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('nearest with integral factor', function (done) {
|
||||||
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
|
.resize(210, 210, { interpolator: 'nearest' })
|
||||||
|
.png()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(210, info.width);
|
||||||
|
assert.strictEqual(210, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user