Created
November 5, 2023 06:56
-
-
Save ledunguit/25941684bf4ed949d2d760f439af6eb8 to your computer and use it in GitHub Desktop.
Add alpha channel to Unit8ClampedArray
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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment