Add raw pixel data support to boolean and withOverlay ops

The previously-scattered image opening logic has been refactored to a
single ImageDescriptor struct/Object available to both JS and C++ code

This removed about 150 LOC but more importantly reduces the complexity
of adding/exposing new operations that require an input image.
This commit is contained in:
Lovell Fuller
2016-07-26 22:26:55 +01:00
parent 36bfbdee0d
commit e6bfa52b0b
11 changed files with 589 additions and 696 deletions

View File

@@ -40,6 +40,23 @@ describe('Boolean operation between two images', function() {
});
});
it(op + ' operation, raw', function(done) {
sharp(fixtures.inputJpgBooleanTest)
.raw()
.toBuffer(function(err, data, info) {
if (err) throw err;
sharp(fixtures.inputJpg)
.resize(320, 240)
.boolean(data, op, { raw: info })
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertSimilar(fixtures.expected('boolean_' + op + '_result.jpg'), data, done);
});
});
});
});
it('Invalid operation', function() {

View File

@@ -528,4 +528,28 @@ describe('Overlays', function() {
});
});
it('Composite RGBA raw buffer onto JPEG', function(done) {
sharp(fixtures.inputPngOverlayLayer1)
.raw()
.toBuffer(function(err, data, info) {
if (err) throw err;
sharp(fixtures.inputJpg)
.resize(2048, 1536)
.overlayWith(data, { raw: info })
.toBuffer(function(err, data) {
if (err) throw err;
fixtures.assertSimilar(fixtures.expected('overlay-jpeg-with-rgb.jpg'), data, done);
});
});
});
it('Throws an error when called with an invalid file', function(done) {
sharp(fixtures.inputJpg)
.overlayWith('notfound.png')
.toBuffer(function(err) {
assert(err instanceof Error);
done();
});
});
});