Add support for negating only non-alpha channels

Fixes #1035
This commit is contained in:
Espen Hovlandsdal
2021-07-22 23:27:27 +02:00
committed by Lovell Fuller
parent 21d1a7ca62
commit b7ddbe71f7
14 changed files with 122 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -107,4 +107,88 @@ describe('Negate', function () {
done();
});
});
it('negate ({alpha: true})', function (done) {
sharp(fixtures.inputJpg)
.resize(320, 240)
.negate({ alpha: true })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('jpeg', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
});
});
it('negate non-alpha channels (png)', function (done) {
sharp(fixtures.inputPng)
.resize(320, 240)
.negate({ alpha: false })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('negate-preserve-alpha.png'), data, done);
});
});
it('negate non-alpha channels (png, trans)', function (done) {
sharp(fixtures.inputPngWithTransparency)
.resize(320, 240)
.negate({ alpha: false })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('negate-preserve-alpha-trans.png'), data, done);
});
});
it('negate non-alpha channels (png, alpha)', function (done) {
sharp(fixtures.inputPngWithGreyAlpha)
.resize(320, 240)
.negate({ alpha: false })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('negate-preserve-alpha-grey.png'), data, done);
});
});
it('negate non-alpha channels (webp)', function (done) {
sharp(fixtures.inputWebP)
.resize(320, 240)
.negate({ alpha: false })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('webp', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('negate-preserve-alpha.webp'), data, done);
});
});
it('negate non-alpha channels (webp, trans)', function (done) {
sharp(fixtures.inputWebPWithTransparency)
.resize(320, 240)
.negate({ alpha: false })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('webp', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('negate-preserve-alpha-trans.webp'), data, done);
});
});
it('invalid alpha value', function () {
assert.throws(function () {
sharp(fixtures.inputWebPWithTransparency).negate({ alpha: 'non-bool' });
});
});
});