Improve performance and accuracy of multi-image composite #2286
BIN
test/fixtures/expected/composite-multiple.png
vendored
|
Before Width: | Height: | Size: 222 B After Width: | Height: | Size: 320 B |
BIN
test/fixtures/expected/composite.blend.dest-over.png
vendored
|
Before Width: | Height: | Size: 197 B After Width: | Height: | Size: 291 B |
BIN
test/fixtures/expected/composite.blend.over.png
vendored
|
Before Width: | Height: | Size: 197 B After Width: | Height: | Size: 292 B |
BIN
test/fixtures/expected/composite.blend.saturate.png
vendored
|
Before Width: | Height: | Size: 194 B After Width: | Height: | Size: 288 B |
BIN
test/fixtures/expected/composite.blend.xor.png
vendored
|
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 286 B |
@@ -45,22 +45,20 @@ const blends = [
|
||||
|
||||
// Test
|
||||
describe('composite', () => {
|
||||
it('blend', () => Promise.all(
|
||||
blends.map(blend => {
|
||||
blends.forEach(blend => {
|
||||
it(`blend ${blend}`, async () => {
|
||||
const filename = `composite.blend.${blend}.png`;
|
||||
const actual = fixtures.path(`output.${filename}`);
|
||||
const expected = fixtures.expected(filename);
|
||||
return sharp(redRect)
|
||||
await sharp(redRect)
|
||||
.composite([{
|
||||
input: blueRect,
|
||||
blend
|
||||
}])
|
||||
.toFile(actual)
|
||||
.then(() => {
|
||||
fixtures.assertMaxColourDistance(actual, expected);
|
||||
});
|
||||
})
|
||||
));
|
||||
.toFile(actual);
|
||||
fixtures.assertMaxColourDistance(actual, expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('premultiplied true', () => {
|
||||
const filename = 'composite.premultiplied.png';
|
||||
@@ -121,11 +119,11 @@ describe('composite', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('multiple', () => {
|
||||
it('multiple', async () => {
|
||||
const filename = 'composite-multiple.png';
|
||||
const actual = fixtures.path(`output.${filename}`);
|
||||
const expected = fixtures.expected(filename);
|
||||
return sharp(redRect)
|
||||
await sharp(redRect)
|
||||
.composite([{
|
||||
input: blueRect,
|
||||
gravity: 'northeast'
|
||||
@@ -133,10 +131,8 @@ describe('composite', () => {
|
||||
input: greenRect,
|
||||
gravity: 'southwest'
|
||||
}])
|
||||
.toFile(actual)
|
||||
.then(() => {
|
||||
fixtures.assertMaxColourDistance(actual, expected);
|
||||
});
|
||||
.toFile(actual);
|
||||
fixtures.assertMaxColourDistance(actual, expected);
|
||||
});
|
||||
|
||||
it('zero offset', done => {
|
||||
|
||||
@@ -140,7 +140,7 @@ describe('Extend', function () {
|
||||
});
|
||||
|
||||
it('Premultiply background when compositing', async () => {
|
||||
const background = '#bf1942cc';
|
||||
const background = { r: 191, g: 25, b: 66, alpha: 0.8 };
|
||||
const data = await sharp({
|
||||
create: {
|
||||
width: 1, height: 1, channels: 4, background: '#fff0'
|
||||
@@ -158,10 +158,6 @@ describe('Extend', function () {
|
||||
})
|
||||
.raw()
|
||||
.toBuffer();
|
||||
const [r1, g1, b1, a1, r2, g2, b2, a2] = data;
|
||||
assert.strictEqual(true, Math.abs(r2 - r1) < 2);
|
||||
assert.strictEqual(true, Math.abs(g2 - g1) < 2);
|
||||
assert.strictEqual(true, Math.abs(b2 - b1) < 2);
|
||||
assert.strictEqual(true, Math.abs(a2 - a1) < 2);
|
||||
assert.deepStrictEqual(Array.from(data), [191, 25, 65, 204, 238, 31, 82, 204]);
|
||||
});
|
||||
});
|
||||
|
||||