all files / src/imageLoader/colorSpaceConverters/ convertYBRFullByPixel.js

0% Statements 0/15
0% Branches 0/4
0% Functions 0/1
0% Lines 0/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                                               
export default function (imageFrame, rgbaBuffer) {
  if (imageFrame === undefined) {
    throw new Error('decodeRGB: ybrBuffer must not be undefined');
  }
  if (imageFrame.length % 3 !== 0) {
    throw new Error('decodeRGB: ybrBuffer length must be divisble by 3');
  }
 
  const numPixels = imageFrame.length / 3;
  let ybrIndex = 0;
  let rgbaIndex = 0;
 
  for (let i = 0; i < numPixels; i++) {
    const y = imageFrame[ybrIndex++];
    const cb = imageFrame[ybrIndex++];
    const cr = imageFrame[ybrIndex++];
 
    rgbaBuffer[rgbaIndex++] = y + 1.40200 * (cr - 128);// red
    rgbaBuffer[rgbaIndex++] = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green
    rgbaBuffer[rgbaIndex++] = y + 1.77200 * (cb - 128); // blue
    rgbaBuffer[rgbaIndex++] = 255; // alpha
  }
}