Clarify the use of RGBA vs ABGR in the game-of-life example

This commit is contained in:
dcodeIO
2018-04-25 22:39:51 +02:00
parent 6d6d1dddcf
commit ab08269276
5 changed files with 492 additions and 685 deletions

View File

@ -62,8 +62,8 @@ fetch("build/optimized.wasm")
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.instantiate(buffer, {
env: {
RGB_ALIVE : rgb2le(RGB_ALIVE) | 1, // little endian, LSB must be set
RGB_DEAD : rgb2le(RGB_DEAD) & ~1, // little endian, LSB must not be set
BGR_ALIVE : rgb2bgr(RGB_ALIVE) | 1, // little endian, LSB must be set
BGR_DEAD : rgb2bgr(RGB_DEAD) & ~1, // little endian, LSB must not be set
BIT_ROT,
memory,
abort: function() {}
@ -125,7 +125,8 @@ fetch("build/optimized.wasm")
console.log(err.stack);
});
function rgb2le(rgb) {
// see comment in assembly/index.ts on why this is useful
function rgb2bgr(rgb) {
return ((rgb >>> 16) & 0xff) | (rgb & 0xff00) | (rgb & 0xff) << 16;
}
</script>