-
-
Save anonymous/33e0e7aaa18a49f375d355511882bd87 to your computer and use it in GitHub Desktop.
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
//e.data == ArrayBuffer from websocket msg | |
var dataView = new DataView(e.data); | |
var t0 = performance.now(); | |
var PPMWidth = dataView.getInt16(1); | |
var PPMHeight = dataView.getInt16(3); | |
var LZ4OriginalSize = dataView.getInt32(5); | |
//Decode the LZ4 | |
var PPMBytes = new Uint8Array(e.data, 9, dataView.byteLength - 9); | |
var input = new Buffer(PPMBytes); | |
var uncompressed = new Buffer(LZ4OriginalSize); | |
var uncompressedSize = LZ4.decodeBlock(input, uncompressed); | |
PPMBytes = new Uint8ClampedArray(uncompressed); | |
var imageData = new ImageData(PPMBytes, PPMWidth, PPMHeight); | |
var canvas = document.getElementById("image"); | |
var ctx = canvas.getContext("2d"); | |
if (canvas.width != PPMWidth) { | |
canvas.width = PPMWidth; | |
} | |
if (canvas.height != PPMHeight) { | |
canvas.height = PPMHeight; | |
} | |
ctx.putImageData(imageData, 0, 0); | |
var t1 = performance.now(); | |
console.log("Render done: "+t0 + " " +t1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment