Add bandbool feature for channel-wise boolean operations (#496)

This commit is contained in:
Matt Hirsch
2016-07-07 16:03:49 -04:00
committed by Lovell Fuller
parent a982cfdb20
commit 65b7f7d7d5
12 changed files with 124 additions and 0 deletions

BIN
test/fixtures/bandbool.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -79,6 +79,7 @@ module.exports = {
inputPngOverlayLayer2LowAlpha: getPath('alpha-layer-2-ink-low-alpha.png'),
inputPngAlphaPremultiplicationSmall: getPath('alpha-premultiply-1024x768-paper.png'),
inputPngAlphaPremultiplicationLarge: getPath('alpha-premultiply-2048x1536-paper.png'),
inputPngBooleanNoAlpha: getPath('bandbool.png'),
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp

51
test/unit/bandbool.js Normal file
View File

@@ -0,0 +1,51 @@
'use strict';
var assert = require('assert');
var fixtures = require('../fixtures');
var sharp = require('../../index');
describe('Bandbool per-channel boolean operations', function() {
it('\'and\' Operation', function(done) {
sharp(fixtures.inputPngBooleanNoAlpha)
.bandbool('and')
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(200, info.height);
assert.strictEqual(1, info.channels);
fixtures.assertSimilar(fixtures.expected('bandbool_and_result.png'), data, done);
});
});
it('\'or\' Operation', function(done) {
sharp(fixtures.inputPngBooleanNoAlpha)
.bandbool(sharp.bool.or)
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(200, info.height);
assert.strictEqual(1, info.channels);
fixtures.assertSimilar(fixtures.expected('bandbool_or_result.png'), data, done);
});
});
it('\'eor\' Operation', function(done) {
sharp(fixtures.inputPngBooleanNoAlpha)
.bandbool('eor')
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(200, info.height);
assert.strictEqual(1, info.channels);
fixtures.assertSimilar(fixtures.expected('bandbool_eor_result.png'), data, done);
});
});
it('Invalid operation', function() {
assert.throws(function() {
sharp(fixtures.inputPngBooleanNoAlpha)
.bandbool('fail');
});
});
});