diff --git a/docs/changelog.md b/docs/changelog.md index e5da75dd..c805fecf 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -38,6 +38,10 @@ Requires libvips v8.3.1 [#486](https://github.com/lovell/sharp/issues/486) [@kapouer](https://github.com/kapouer) +* Allow images with an alpha channel to work with LAB-colourspace based sharpen. + [#490](https://github.com/lovell/sharp/issues/490) + [@jwagner](https://github.com/jwagner) + #### v0.15.0 - 21st May 2016 * Use libvips' new Lanczos 3 kernel as default for image reduction. diff --git a/src/operations.cc b/src/operations.cc index cdbc12cf..6adfe165 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -244,9 +244,13 @@ namespace sharp { return image.conv(sharpen); } else { // Slow, accurate sharpen in LAB colour space, with control over flat vs jagged areas + VipsInterpretation colourspaceBeforeSharpen = image.interpretation(); + if (colourspaceBeforeSharpen == VIPS_INTERPRETATION_RGB) { + colourspaceBeforeSharpen = VIPS_INTERPRETATION_sRGB; + } return image.sharpen( VImage::option()->set("sigma", sigma)->set("m1", flat)->set("m2", jagged) - ); + ).colourspace(colourspaceBeforeSharpen); } } diff --git a/test/fixtures/expected/sharpen-rgba.png b/test/fixtures/expected/sharpen-rgba.png new file mode 100644 index 00000000..841511ca Binary files /dev/null and b/test/fixtures/expected/sharpen-rgba.png differ diff --git a/test/unit/sharpen.js b/test/unit/sharpen.js index 244059de..2b70a666 100644 --- a/test/unit/sharpen.js +++ b/test/unit/sharpen.js @@ -12,6 +12,7 @@ describe('Sharpen', function() { .resize(320, 240) .sharpen(6) .toBuffer(function(err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -24,6 +25,7 @@ describe('Sharpen', function() { .resize(320, 240) .sharpen(1.5, 0.5, 2.5) .toBuffer(function(err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -36,6 +38,7 @@ describe('Sharpen', function() { .resize(320, 240) .sharpen(3.5, 2, 4) .toBuffer(function(err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -43,11 +46,26 @@ describe('Sharpen', function() { }); }); + it('specific radius/levels with alpha channel', function(done) { + sharp(fixtures.inputPngWithTransparency) + .resize(320, 240) + .sharpen(5, 4, 8) + .toBuffer(function(err, data, info) { + if (err) throw err; + assert.strictEqual('png', info.format); + assert.strictEqual(4, info.channels); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('sharpen-rgba.png'), data, done); + }); + }); + it('mild sharpen', function(done) { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen() .toBuffer(function(err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -78,6 +96,7 @@ describe('Sharpen', function() { .resize(320, 240) .sharpen(false) .toBuffer(function(err, notSharpened, info) { + if (err) throw err; assert.strictEqual(true, notSharpened.length > 0); assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -86,6 +105,7 @@ describe('Sharpen', function() { .resize(320, 240) .sharpen(true) .toBuffer(function(err, sharpened, info) { + if (err) throw err; assert.strictEqual(true, sharpened.length > 0); assert.strictEqual(true, sharpened.length > notSharpened.length); assert.strictEqual('jpeg', info.format);