From 82ec2715f1bc33844806c77c1f3e8881f098569c Mon Sep 17 00:00:00 2001 From: Matt Hirsch Date: Sat, 13 Aug 2016 09:55:15 -0400 Subject: [PATCH] Prevent bandbool creating a single channel sRGB image (#519) --- src/operations.cc | 3 ++- test/unit/bandbool.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/operations.cc b/src/operations.cc index b1a3f1d9..1c05d2db 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -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)); } /* diff --git a/test/unit/bandbool.js b/test/unit/bandbool.js index d1d9de0b..2194dcc4 100644 --- a/test/unit/bandbool.js +++ b/test/unit/bandbool.js @@ -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');