Skip to content

Instantly share code, notes, and snippets.

/lz4.js Secret

Created Sep 14, 2016
Embed
What would you like to do?
//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