Add support for the "nearest" kernel for image reductions (#732)

This commit is contained in:
Alice Monday 2017-03-14 03:29:23 -07:00 committed by Lovell Fuller
parent 8b5d8a0577
commit 72f69dda30
3 changed files with 7 additions and 1 deletions

View File

@ -36,6 +36,7 @@ const strategy = {
* @private * @private
*/ */
const kernel = { const kernel = {
nearest: 'nearest',
cubic: 'cubic', cubic: 'cubic',
lanczos2: 'lanczos2', lanczos2: 'lanczos2',
lanczos3: 'lanczos3' lanczos3: 'lanczos3'
@ -62,6 +63,7 @@ const interpolator = {
* By default, the resized image is centre cropped to the exact size specified. * By default, the resized image is centre cropped to the exact size specified.
* *
* Possible reduction kernels are: * Possible reduction kernels are:
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline). * - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`. * - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default). * - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).

View File

@ -392,7 +392,10 @@ class PipelineWorker : public Nan::AsyncWorker {
if (yresidual < 1.0 || xresidual < 1.0) { if (yresidual < 1.0 || xresidual < 1.0) {
VipsKernel kernel = static_cast<VipsKernel>( VipsKernel kernel = static_cast<VipsKernel>(
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data())); vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data()));
if (kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 && kernel != VIPS_KERNEL_LANCZOS3) { if (
kernel != VIPS_KERNEL_NEAREST && kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 &&
kernel != VIPS_KERNEL_LANCZOS3
) {
throw vips::VError("Unknown kernel"); throw vips::VError("Unknown kernel");
} }
if (yresidual < 1.0) { if (yresidual < 1.0) {

View File

@ -8,6 +8,7 @@ const fixtures = require('../fixtures');
describe('Interpolators and kernels', function () { describe('Interpolators and kernels', function () {
describe('Reducers', function () { describe('Reducers', function () {
[ [
sharp.kernel.nearest,
sharp.kernel.cubic, sharp.kernel.cubic,
sharp.kernel.lanczos2, sharp.kernel.lanczos2,
sharp.kernel.lanczos3 sharp.kernel.lanczos3