diff --git a/docs/changelog.md b/docs/changelog.md index 8bd2ca19..4fb2cde9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,9 @@ Requires libvips v8.10.5 [#2581](https://github.com/lovell/sharp/pull/2581) [@florian-busch](https://github.com/florian-busch) +* Allow use of `recomb` operation with single channel input. + [#2584](https://github.com/lovell/sharp/issues/2584) + ### v0.27.1 - 27th January 2021 * Ensure TIFF is cast when using float predictor. diff --git a/src/operations.cc b/src/operations.cc index bd3dfca4..4cf56d4a 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -149,8 +149,8 @@ namespace sharp { */ VImage Recomb(VImage image, std::unique_ptr const &matrix) { double *m = matrix.get(); + image = image.colourspace(VIPS_INTERPRETATION_sRGB); return image - .colourspace(VIPS_INTERPRETATION_sRGB) .recomb(image.bands() == 3 ? VImage::new_from_memory( m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE diff --git a/test/unit/recomb.js b/test/unit/recomb.js index 1f59d844..df880fe5 100644 --- a/test/unit/recomb.js +++ b/test/unit/recomb.js @@ -5,15 +5,17 @@ const assert = require('assert'); const sharp = require('../../'); const fixtures = require('../fixtures'); +const sepia = [ + [0.3588, 0.7044, 0.1368], + [0.299, 0.587, 0.114], + [0.2392, 0.4696, 0.0912] +]; + describe('Recomb', function () { it('applies a sepia filter using recomb', function (done) { const output = fixtures.path('output.recomb-sepia.jpg'); sharp(fixtures.inputJpgWithLandscapeExif1) - .recomb([ - [0.3588, 0.7044, 0.1368], - [0.299, 0.587, 0.114], - [0.2392, 0.4696, 0.0912] - ]) + .recomb(sepia) .toFile(output, function (err, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); @@ -31,11 +33,7 @@ describe('Recomb', function () { it('applies a sepia filter using recomb to an PNG with Alpha', function (done) { const output = fixtures.path('output.recomb-sepia.png'); sharp(fixtures.inputPngAlphaPremultiplicationSmall) - .recomb([ - [0.3588, 0.7044, 0.1368], - [0.299, 0.587, 0.114], - [0.2392, 0.4696, 0.0912] - ]) + .recomb(sepia) .toFile(output, function (err, info) { if (err) throw err; assert.strictEqual('png', info.format); @@ -50,6 +48,20 @@ describe('Recomb', function () { }); }); + it('recomb with a single channel input', async () => { + const { info } = await sharp(Buffer.alloc(64), { + raw: { + width: 8, + height: 8, + channels: 1 + } + }) + .recomb(sepia) + .toBuffer({ resolveWithObject: true }); + + assert.strictEqual(3, info.channels); + }); + it('applies a different sepia filter using recomb', function (done) { const output = fixtures.path('output.recomb-sepia2.jpg'); sharp(fixtures.inputJpgWithLandscapeExif1)