forked from GoogleChromeLabs/squoosh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement alpha premultiplication (GoogleChromeLabs#507)
* Implement alpha premultiplication * Add benchmark to resize * Only display "Premultiply alpha" if it's one of the rust resize types. * Add comment about division by zero
- Loading branch information
1 parent
d29cf2f
commit 45221c0
Showing
12 changed files
with
127 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// THIS IS NOT A NODE SCRIPT | ||
// This is a d8 script. Please install jsvu[1] and install v8. | ||
// Then run `npm run --silent benchmark`. | ||
// [1]: https://github.com/GoogleChromeLabs/jsvu | ||
|
||
self = global = this; | ||
load('./pkg/resize.js'); | ||
|
||
async function init() { | ||
// Adjustable constants. | ||
const inputDimensions = 2000; | ||
const outputDimensions = 1500; | ||
const algorithm = 3; // Lanczos | ||
const iterations = new Array(100); | ||
|
||
// Constants. Don’t change. | ||
const imageByteSize = inputDimensions * inputDimensions * 4; | ||
const imageBuffer = new Uint8ClampedArray(imageByteSize); | ||
|
||
const module = await WebAssembly.compile(readbuffer("./pkg/resize_bg.wasm")); | ||
await wasm_bindgen(module); | ||
[false, true].forEach(premulti => { | ||
print(`\npremultiplication: ${premulti}`); | ||
print(`==============================`); | ||
for (let i = 0; i < 100; i++) { | ||
const start = Date.now(); | ||
wasm_bindgen.resize(imageBuffer, inputDimensions, inputDimensions, outputDimensions, outputDimensions, algorithm, premulti); | ||
iterations[i] = Date.now() - start; | ||
} | ||
const average = iterations.reduce((sum, c) => sum + c) / iterations.length; | ||
const stddev = Math.sqrt( | ||
iterations | ||
.map(i => Math.pow(i - average, 2)) | ||
.reduce((sum, c) => sum + c) / iterations.length | ||
); | ||
print(`n = ${iterations.length}`); | ||
print(`Average: ${average}`); | ||
print(`StdDev: ${stddev}`); | ||
}); | ||
} | ||
init().catch(e => console.error(e, e.stack)); |
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
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
Binary file not shown.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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