Skip to content

Instantly share code, notes, and snippets.

/lz4.js Secret

Created September 14, 2016 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/33e0e7aaa18a49f375d355511882bd87 to your computer and use it in GitHub Desktop.
Save anonymous/33e0e7aaa18a49f375d355511882bd87 to your computer and use it in GitHub Desktop.
//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