generated from napi-rs/package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88d29d4
commit 6079927
Showing
36 changed files
with
1,036 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { promises as fs, readFileSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
import ava, { TestInterface } from 'ava' | ||
|
||
import { createCanvas, Canvas, SKRSContext2D, Image } from '../index' | ||
|
||
import { snapshotImage } from './image-snapshot' | ||
|
||
const test = ava as TestInterface<{ | ||
ctx: SKRSContext2D | ||
canvas: Canvas | ||
}> | ||
|
||
const FIREFOX = readFileSync(join(__dirname, 'fixtures', 'firefox-logo.svg')) | ||
const FIREFOX_IMAGE = new Image() | ||
FIREFOX_IMAGE.width = 200 | ||
FIREFOX_IMAGE.height = 206.433 | ||
FIREFOX_IMAGE.src = FIREFOX | ||
|
||
test.beforeEach((t) => { | ||
const canvas = createCanvas(300, 300) | ||
t.context.canvas = canvas | ||
t.context.ctx = canvas.getContext('2d') | ||
}) | ||
|
||
test('filter-blur', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'blur(5px)' | ||
ctx.drawImage(FIREFOX_IMAGE, 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-brightness', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'brightness(2)' | ||
const image = new Image() | ||
image.src = await fs.readFile(join(__dirname, 'fixtures', 'filter-brightness.jpg')) | ||
ctx.drawImage(image, 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-contrast', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'contrast(200%)' | ||
const image = new Image() | ||
image.src = await fs.readFile(join(__dirname, 'fixtures', 'filter-contrast.jpeg')) | ||
ctx.drawImage(image, 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-contrast-ff', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'contrast(200%)' | ||
ctx.drawImage(FIREFOX_IMAGE, 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-grayscale', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'grayscale(80%)' | ||
ctx.drawImage(FIREFOX_IMAGE, 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-hue-rotate', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'hue-rotate(90deg)' | ||
ctx.drawImage(FIREFOX_IMAGE, 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-drop-shadow', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'drop-shadow(16px 16px 10px black)' | ||
ctx.drawImage(await createImage('filter-drop-shadow.jpeg'), 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-invert', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'invert(100%)' | ||
ctx.drawImage(await createImage('filter-invert.jpeg'), 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-opacity', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'opacity(20%)' | ||
ctx.drawImage(await createImage('filter-opacity.jpeg'), 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-saturate', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'saturate(200%)' | ||
ctx.drawImage(await createImage('filter-saturate.jpeg'), 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-sepia', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'sepia(100%)' | ||
ctx.drawImage(await createImage('filter-sepia.jpeg'), 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
test('filter-combine-contrast-brightness', async (t) => { | ||
const { ctx } = t.context | ||
ctx.filter = 'contrast(175%) brightness(103%)' | ||
ctx.drawImage(await createImage('filter-combine-contrast-brightness.jpeg'), 0, 0) | ||
await snapshotImage(t) | ||
}) | ||
|
||
async function createImage(name: string) { | ||
const i = new Image() | ||
i.src = await fs.readFile(join(__dirname, 'fixtures', name)) | ||
return i | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
6079927
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
Draw house#skia-canvas
19.8
ops/sec (±1%
)22
ops/sec (±1.13%
)1.11
Draw house#node-canvas
20.2
ops/sec (±1.09%
)19
ops/sec (±0.68%
)0.94
Draw house#@napi-rs/skia
20.8
ops/sec (±1.78%
)21
ops/sec (±1.11%
)1.01
Draw gradient#skia-canvas
18.7
ops/sec (±1.83%
)21
ops/sec (±0.31%
)1.12
Draw gradient#node-canvas
18.5
ops/sec (±1.87%
)18
ops/sec (±0.97%
)0.97
Draw gradient#@napi-rs/skia
20.1
ops/sec (±1.07%
)20
ops/sec (±0.06%
)1.00
This comment was automatically generated by workflow using github-action-benchmark.