mirror of
https://github.com/lovell/sharp.git
synced 2025-07-13 20:30:14 +02:00
Allow use of extend with greyscale input (#623)
This commit is contained in:
parent
dd9d66ef20
commit
6ccccf8c39
@ -521,11 +521,21 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Scale up 8-bit values to match 16-bit input image
|
// Scale up 8-bit values to match 16-bit input image
|
||||||
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
||||||
// Create background colour
|
// Create background colour
|
||||||
std::vector<double> background {
|
std::vector<double> background;
|
||||||
baton->background[0] * multiplier,
|
if (image.bands() > 2) {
|
||||||
baton->background[1] * multiplier,
|
background = {
|
||||||
baton->background[2] * multiplier
|
multiplier * baton->background[0],
|
||||||
|
multiplier * baton->background[1],
|
||||||
|
multiplier * baton->background[2]
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
// Convert sRGB to greyscale
|
||||||
|
background = { multiplier * (
|
||||||
|
0.2126 * baton->background[0] +
|
||||||
|
0.7152 * baton->background[1] +
|
||||||
|
0.0722 * baton->background[2]
|
||||||
|
)};
|
||||||
|
}
|
||||||
// Add alpha channel to background colour
|
// Add alpha channel to background colour
|
||||||
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
||||||
background.push_back(baton->background[3] * multiplier);
|
background.push_back(baton->background[3] * multiplier);
|
||||||
|
BIN
test/fixtures/expected/extend-2channel.png
vendored
Normal file
BIN
test/fixtures/expected/extend-2channel.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
@ -60,4 +60,19 @@ describe('Extend', function () {
|
|||||||
fixtures.assertSimilar(fixtures.expected('addAlphaChanelBeforeExtend.png'), data, done);
|
fixtures.assertSimilar(fixtures.expected('addAlphaChanelBeforeExtend.png'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('PNG with 2 channels', function (done) {
|
||||||
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
|
.background('transparent')
|
||||||
|
.extend({top: 0, bottom: 20, left: 0, right: 20})
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('png', info.format);
|
||||||
|
assert.strictEqual(420, info.width);
|
||||||
|
assert.strictEqual(320, info.height);
|
||||||
|
assert.strictEqual(4, info.channels);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('extend-2channel.png'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user