diff --git a/README.md b/README.md index 15bdb086..270874d4 100755 --- a/README.md +++ b/README.md @@ -272,9 +272,10 @@ Use the given interpolator for image resizing, where `interpolator` is an attrib Possible interpolators, in order of performance, are: -* `bilinear`: Use [bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation), the default (and fastest) interpolation. +* `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation), suitable for image enlargement only. +* `bilinear`: Use [bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation), the default and fastest image reduction interpolation. * `bicubic`: Use [bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation), which typically reduces performance by 5%. -* `vertexSplitQuadraticBasisSpline`: Use [VSQBS interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48), which prevents "staircasing" when enlarging and typically reduces performance by 5%. +* `vertexSplitQuadraticBasisSpline`: Use [VSQBS interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48), which prevents "staircasing" and typically reduces performance by 5%. * `locallyBoundedBicubic`: Use [LBB interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/lbb.cpp#L100), which prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" and typically reduces performance by a factor of 2. * `nohalo`: Use [Nohalo interpolation](http://eprints.soton.ac.uk/268086/), which prevents acutance and typically reduces performance by a factor of 3. diff --git a/index.js b/index.js index b6948027..0422a60e 100755 --- a/index.js +++ b/index.js @@ -139,6 +139,7 @@ Sharp.prototype.sharpen = function(sharpen) { Set the interpolator to use for the affine transformation */ module.exports.interpolator = { + nearest: 'nearest', bilinear: 'bilinear', bicubic: 'bicubic', nohalo: 'nohalo', diff --git a/package.json b/package.json index f2d21c5e..832904d7 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sharp", - "version": "0.6.1", + "version": "0.6.2", "author": "Lovell Fuller ", "contributors": [ "Pierre Inglebert ", @@ -36,7 +36,7 @@ ], "dependencies": { "nan": "^1.3.0", - "bluebird": "^2.3.1" + "bluebird": "^2.3.2" }, "devDependencies": { "imagemagick": "^0.1.3", diff --git a/tests/perf.js b/tests/perf.js index 1abd5fe1..c2b60d96 100755 --- a/tests/perf.js +++ b/tests/perf.js @@ -185,6 +185,18 @@ async.series({ } }); } + }).add("sharp-file-buffer-nearest-neighbour", { + defer: true, + fn: function(deferred) { + sharp(inputJpg).resize(width, height).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, buffer) { + if (err) { + throw err; + } else { + assert.notStrictEqual(null, buffer); + deferred.resolve(); + } + }); + } }).add("sharp-file-buffer-bicubic", { defer: true, fn: function(deferred) { diff --git a/tests/unit.js b/tests/unit.js index 31d14cc9..57090aef 100755 --- a/tests/unit.js +++ b/tests/unit.js @@ -247,6 +247,16 @@ async.series([ done(); }); }, + // Interpolation: nearest neighbour + function(done) { + sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + done(); + }); + }, // Interpolation: bilinear function(done) { sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.bilinear).toBuffer(function(err, data, info) {