Skip to content

Instantly share code, notes, and snippets.

@ledunguit
Created November 5, 2023 06:56
Show Gist options
  • Select an option

  • Save ledunguit/25941684bf4ed949d2d760f439af6eb8 to your computer and use it in GitHub Desktop.

Select an option

Save ledunguit/25941684bf4ed949d2d760f439af6eb8 to your computer and use it in GitHub Desktop.

Revisions

  1. ledunguit created this gist Nov 5, 2023.
    12 changes: 12 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function addAlphaChannelToUnit8ClampedArray(unit8Array: Uint8ClampedArray, imageWidth: number, imageHeight: number) {
    const newImageData = new Uint8ClampedArray(imageWidth * imageHeight * 4);

    for (let j = 0, k = 0, jj = imageWidth * imageHeight * 4; j < jj; ) {
    newImageData[j++] = unit8Array[k++];
    newImageData[j++] = unit8Array[k++];
    newImageData[j++] = unit8Array[k++];
    newImageData[j++] = 255;
    }

    return newImageData;
    }