Prevent bandbool creating a single channel sRGB image (#519)

This commit is contained in:
Matt Hirsch 2016-08-13 09:55:15 -04:00 committed by Lovell Fuller
parent ef6e90fb3c
commit 82ec2715f1
2 changed files with 14 additions and 2 deletions

View File

@ -396,7 +396,8 @@ namespace sharp {
Perform boolean/bitwise operation on image color channels - results in one channel image
*/
VImage Bandbool(VImage image, VipsOperationBoolean const boolean) {
return image.bandbool(boolean);
image = image.bandbool(boolean);
return image.copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_B_W));
}
/*

View File

@ -16,15 +16,26 @@ describe('Bandbool per-channel boolean operations', function() {
sharp(fixtures.inputPngBooleanNoAlpha)
.bandbool(op)
.toBuffer(function(err, data, info) {
// should use .toColourspace('b-w') here to get 1 channel output, when it is merged
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(200, info.height);
assert.strictEqual(1, info.channels);
//assert.strictEqual(1, info.channels);
assert.strictEqual(3, info.channels);
fixtures.assertSimilar(fixtures.expected('bandbool_' + op + '_result.png'), data, done);
});
});
});
it('sRGB image retains 3 channels', function(done) {
sharp(fixtures.inputJpg)
.bandbool('and')
.toBuffer(function(err, data, info) {
assert.strictEqual(3, info.channels);
done();
});
});
it('Invalid operation', function() {
assert.throws(function() {
sharp().bandbool('fail');