/** @type {Uint8ClampedArray} */
const rgb = …;
const rgba = new Uint8ClampedArray((rgb.length / 3) * 4);
for (let index = 0; index < rgba.length; index++) {
// Set alpha channel to full
if (index % 4 === 3) {
rgba[index] = 255;
}
// Copy RGB channel components from the RGB array
else {
rgba[index] = rgb[~~(index / 4) * 3 + (index % 4)];
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
TomasHubelbauer/rgb-to-rgba
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
JavaScript code for converting RGBA to RGB in Uint8ClampedArray