Skip normalise operation for images with one colour

It didn't play nicely with premultiplication
This commit is contained in:
Lovell Fuller
2015-05-20 20:07:32 +01:00
parent d2a2654ace
commit f19b6c48ca
3 changed files with 25 additions and 63 deletions

View File

@@ -98,31 +98,15 @@ describe('Normalization', function () {
});
});
it('returns a black image for images with only one color', function (done) {
it('does not alter images with only one color', function (done) {
var output = fixtures.path('output.unmodified-png-with-one-color.png');
sharp(fixtures.inputPngWithOneColor)
.normalize()
.toBuffer()
.bind({})
.then(function (imageData) {
this.imageData = imageData;
return sharp(imageData)
.metadata();
})
.then(function (metadata) {
assert.strictEqual(false, metadata.hasAlpha);
assert.strictEqual(3, metadata.channels);
assert.strictEqual('srgb', metadata.space);
})
.then(function () {
return sharp(this.imageData)
.raw()
.toBuffer();
})
.then(function (rawData) {
var blackBuffer = new Buffer([0,0,0, 0,0,0, 0,0,0, 0,0,0]);
assert.strictEqual(blackBuffer.toString(), rawData.toString());
})
.finally(done);
.toFile(output, function(err, info) {
if (err) done(err);
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
done();
});
});
}