diff --git a/test/fixtures/expected/modulate-all.jpg b/test/fixtures/expected/modulate-all.jpg deleted file mode 100644 index bdd2332a..00000000 Binary files a/test/fixtures/expected/modulate-all.jpg and /dev/null differ diff --git a/test/fixtures/expected/modulate-brightness-0-5.jpg b/test/fixtures/expected/modulate-brightness-0-5.jpg deleted file mode 100644 index 047d9980..00000000 Binary files a/test/fixtures/expected/modulate-brightness-0-5.jpg and /dev/null differ diff --git a/test/fixtures/expected/modulate-brightness-2.jpg b/test/fixtures/expected/modulate-brightness-2.jpg deleted file mode 100644 index 4ffbd5f9..00000000 Binary files a/test/fixtures/expected/modulate-brightness-2.jpg and /dev/null differ diff --git a/test/fixtures/expected/modulate-hue-120.jpg b/test/fixtures/expected/modulate-hue-120.jpg deleted file mode 100644 index 3d6c7868..00000000 Binary files a/test/fixtures/expected/modulate-hue-120.jpg and /dev/null differ diff --git a/test/fixtures/expected/modulate-hue-angle-120.png b/test/fixtures/expected/modulate-hue-angle-120.png index 8fbad61d..59ef7f68 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-120.png and b/test/fixtures/expected/modulate-hue-angle-120.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-150.png b/test/fixtures/expected/modulate-hue-angle-150.png index c0863293..5ad29b03 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-150.png and b/test/fixtures/expected/modulate-hue-angle-150.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-180.png b/test/fixtures/expected/modulate-hue-angle-180.png index 3e6c45de..95944f6e 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-180.png and b/test/fixtures/expected/modulate-hue-angle-180.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-210.png b/test/fixtures/expected/modulate-hue-angle-210.png index 0bdfd5e4..d85ab59c 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-210.png and b/test/fixtures/expected/modulate-hue-angle-210.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-240.png b/test/fixtures/expected/modulate-hue-angle-240.png index a0d220e3..591af1a7 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-240.png and b/test/fixtures/expected/modulate-hue-angle-240.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-270.png b/test/fixtures/expected/modulate-hue-angle-270.png index d6673b62..c01996a5 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-270.png and b/test/fixtures/expected/modulate-hue-angle-270.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-30.png b/test/fixtures/expected/modulate-hue-angle-30.png index bcbd36dd..4cafb5a6 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-30.png and b/test/fixtures/expected/modulate-hue-angle-30.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-300.png b/test/fixtures/expected/modulate-hue-angle-300.png index db93b499..05ec97c8 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-300.png and b/test/fixtures/expected/modulate-hue-angle-300.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-330.png b/test/fixtures/expected/modulate-hue-angle-330.png index a5aadc5a..377c173f 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-330.png and b/test/fixtures/expected/modulate-hue-angle-330.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-360.png b/test/fixtures/expected/modulate-hue-angle-360.png index 380bcbeb..bb937aa4 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-360.png and b/test/fixtures/expected/modulate-hue-angle-360.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-60.png b/test/fixtures/expected/modulate-hue-angle-60.png index ce398b1a..fa2eded8 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-60.png and b/test/fixtures/expected/modulate-hue-angle-60.png differ diff --git a/test/fixtures/expected/modulate-hue-angle-90.png b/test/fixtures/expected/modulate-hue-angle-90.png index 19e35243..39603417 100644 Binary files a/test/fixtures/expected/modulate-hue-angle-90.png and b/test/fixtures/expected/modulate-hue-angle-90.png differ diff --git a/test/fixtures/expected/modulate-linear.jpg b/test/fixtures/expected/modulate-linear.jpg deleted file mode 100644 index bd7899fa..00000000 Binary files a/test/fixtures/expected/modulate-linear.jpg and /dev/null differ diff --git a/test/fixtures/expected/modulate-saturation-0.5.jpg b/test/fixtures/expected/modulate-saturation-0.5.jpg deleted file mode 100644 index f922992c..00000000 Binary files a/test/fixtures/expected/modulate-saturation-0.5.jpg and /dev/null differ diff --git a/test/fixtures/expected/modulate-saturation-2.jpg b/test/fixtures/expected/modulate-saturation-2.jpg deleted file mode 100644 index deaef8d1..00000000 Binary files a/test/fixtures/expected/modulate-saturation-2.jpg and /dev/null differ diff --git a/test/unit/modulate.js b/test/unit/modulate.js index c187b48a..8cd6b5ab 100644 --- a/test/unit/modulate.js +++ b/test/unit/modulate.js @@ -28,115 +28,138 @@ describe('Modulate', function () { }); }); - it('should be able to hue-rotate', function () { - const base = 'modulate-hue-120.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - return sharp(fixtures.inputJpg) + it('should be able to hue-rotate', async () => { + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) .modulate({ hue: 120 }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 25); - }); + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 41, g: 107, b: 57 }, { r, g, b }); }); - it('should be able to brighten', function () { - const base = 'modulate-brightness-2.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - return sharp(fixtures.inputJpg) + it('should be able to brighten', async () => { + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) .modulate({ brightness: 2 }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 25); - }); + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 255, g: 173, b: 168 }, { r, g, b }); }); - it('should be able to unbrighten', function () { - const base = 'modulate-brightness-0-5.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - return sharp(fixtures.inputJpg) + it('should be able to darken', async () => { + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) .modulate({ brightness: 0.5 }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 25); - }); + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 97, g: 17, b: 25 }, { r, g, b }); }); - it('should be able to saturate', function () { - const base = 'modulate-saturation-2.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - return sharp(fixtures.inputJpg) + it('should be able to saturate', async () => { + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) .modulate({ saturation: 2 }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 30); - }); + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 198, g: 0, b: 43 }, { r, g, b }); }); - it('should be able to desaturate', function () { - const base = 'modulate-saturation-0.5.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - return sharp(fixtures.inputJpg) + it('should be able to desaturate', async () => { + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) .modulate({ saturation: 0.5 }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 25); - }); + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 127, g: 83, b: 81 }, { r, g, b }); }); - it('should be able to modulate all channels', function () { - const base = 'modulate-all.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - return sharp(fixtures.inputJpg) + it('should be able to modulate all channels', async () => { + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) .modulate({ brightness: 2, saturation: 0.5, hue: 180 }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 25); - }); + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 149, g: 209, b: 214 }, { r, g, b }); }); - describe('hue-rotate', function (done) { - [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360].forEach(function (angle) { - it('should properly hue rotate by ' + angle + 'deg', function () { - const base = 'modulate-hue-angle-' + angle + '.png'; - const actual = fixtures.path('output.' + base); + it('should be able to use linear and modulate together', async () => { + const contrast = 1.5; + const brightness = 0.5; + + const [r, g, b] = await sharp({ + create: { + width: 1, + height: 1, + channels: 3, + background: { r: 153, g: 68, b: 68 } + } + }) + .linear(contrast, -(128 * contrast) + 128) + .modulate({ brightness }) + .raw() + .toBuffer(); + + assert.deepStrictEqual({ r: 81, g: 0, b: 0 }, { r, g, b }); + }); + + describe('hue-rotate', () => { + [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360].forEach(angle => { + it(`should hue rotate by ${angle} deg`, async () => { + const base = `modulate-hue-angle-${angle}.png`; + const actual = fixtures.path(`output.${base}`); const expected = fixtures.expected(base); - return sharp(fixtures.testPattern) + await sharp(fixtures.testPattern) + .resize(320) .modulate({ hue: angle }) + .png({ compressionLevel: 0 }) .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected, 25); + .then(() => { + fixtures.assertMaxColourDistance(actual, expected); }); }); }); }); - - it('should be able to use linear and modulate together', function () { - const base = 'modulate-linear.jpg'; - const actual = fixtures.path('output.' + base); - const expected = fixtures.expected(base); - - const contrast = 1.5; - const brightness = 0.5; - - return sharp(fixtures.testPattern) - .linear(contrast, -(128 * contrast) + 128) - .modulate({ brightness }) - .toFile(actual) - .then(function () { - fixtures.assertMaxColourDistance(actual, expected); - }); - }); });