Skip to content

Instantly share code, notes, and snippets.

View Vanilagy's full-sized avatar
💭
Casually chillin' on le GitHubz.

Vanilagy

💭
Casually chillin' on le GitHubz.
  • clickbar.
  • Germany
  • 10:22 (UTC +02:00)
View GitHub Profile
@Vanilagy
Vanilagy / rgba_to_yuv_420.ts
Last active October 27, 2022 14:57
Canvas RGBA image data to packed planar YUV 4:2:0 using the BT.709 color matrix
const RGBAToYUV420 = ({ width, height, data }: ImageData) => {
// Assume both width and height are even
let yuv = new Uint8Array(width * height * 1.5);
// Use loop tiling as a cache optimization
const tileSize = 64;
for (let y0 = 0; y0 < height; y0 += tileSize) {
for (let x0 = 0; x0 < width; x0 += tileSize) {
let limitX = Math.min(width, x0 + tileSize);
let limitY = Math.min(height, y0 + tileSize);
@Vanilagy
Vanilagy / structured_clone.js
Last active January 24, 2019 22:34
HTML Structured Clone Algorithm directly exposed in JavaScript using BroadcastChannels
// @Vanilagy 2019
//
// Example:
// structuredClone([5, {hello: 'world'}, new Set()]).then((data) => console.log(data));
// > [5, {hello: "world"}, Set(0)]
var structuredClone = (function() {
var sender = new BroadcastChannel('structuredClone'),
receiver = new BroadcastChannel('structuredClone');