Skip to content

JavaScript code for converting RGBA to RGB in Uint8ClampedArray

Notifications You must be signed in to change notification settings

TomasHubelbauer/rgb-to-rgba

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

RGB to RGBA

/** @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)];
  }
}

About

JavaScript code for converting RGBA to RGB in Uint8ClampedArray

Topics

Resources

Stars

Watchers

Forks