mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Allow use of recomb op with 1/2 channel input #2584
This commit is contained in:
parent
1986b5cfe6
commit
f6f16b91db
@ -10,6 +10,9 @@ Requires libvips v8.10.5
|
|||||||
[#2581](https://github.com/lovell/sharp/pull/2581)
|
[#2581](https://github.com/lovell/sharp/pull/2581)
|
||||||
[@florian-busch](https://github.com/florian-busch)
|
[@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
|
### v0.27.1 - 27th January 2021
|
||||||
|
|
||||||
* Ensure TIFF is cast when using float predictor.
|
* Ensure TIFF is cast when using float predictor.
|
||||||
|
@ -149,8 +149,8 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
||||||
double *m = matrix.get();
|
double *m = matrix.get();
|
||||||
|
image = image.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
return image
|
return image
|
||||||
.colourspace(VIPS_INTERPRETATION_sRGB)
|
|
||||||
.recomb(image.bands() == 3
|
.recomb(image.bands() == 3
|
||||||
? VImage::new_from_memory(
|
? VImage::new_from_memory(
|
||||||
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
||||||
|
@ -5,15 +5,17 @@ const assert = require('assert');
|
|||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
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 () {
|
describe('Recomb', function () {
|
||||||
it('applies a sepia filter using recomb', function (done) {
|
it('applies a sepia filter using recomb', function (done) {
|
||||||
const output = fixtures.path('output.recomb-sepia.jpg');
|
const output = fixtures.path('output.recomb-sepia.jpg');
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.recomb([
|
.recomb(sepia)
|
||||||
[0.3588, 0.7044, 0.1368],
|
|
||||||
[0.299, 0.587, 0.114],
|
|
||||||
[0.2392, 0.4696, 0.0912]
|
|
||||||
])
|
|
||||||
.toFile(output, function (err, info) {
|
.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
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) {
|
it('applies a sepia filter using recomb to an PNG with Alpha', function (done) {
|
||||||
const output = fixtures.path('output.recomb-sepia.png');
|
const output = fixtures.path('output.recomb-sepia.png');
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.recomb([
|
.recomb(sepia)
|
||||||
[0.3588, 0.7044, 0.1368],
|
|
||||||
[0.299, 0.587, 0.114],
|
|
||||||
[0.2392, 0.4696, 0.0912]
|
|
||||||
])
|
|
||||||
.toFile(output, function (err, info) {
|
.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
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) {
|
it('applies a different sepia filter using recomb', function (done) {
|
||||||
const output = fixtures.path('output.recomb-sepia2.jpg');
|
const output = fixtures.path('output.recomb-sepia2.jpg');
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user