Allow use of recomb op with 1/2 channel input #2584

This commit is contained in:
Lovell Fuller 2021-02-19 16:37:29 +00:00
parent 1986b5cfe6
commit f6f16b91db
3 changed files with 26 additions and 11 deletions

View File

@ -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.

View File

@ -149,8 +149,8 @@ namespace sharp {
*/
VImage Recomb(VImage image, std::unique_ptr<double[]> 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

View File

@ -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)