all files / src/imageLoader/ convertColorSpace.js

0% Statements 0/20
0% Branches 0/16
0% Functions 0/3
0% Lines 0/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                                 
import { convertRGBColorByPixel, convertRGBColorByPlane,
  convertYBRFullByPixel, convertYBRFullByPlane,
  convertPALETTECOLOR } from './colorSpaceConverters/index.js';
 
function convertRGB (imageFrame, rgbaBuffer) {
  if (imageFrame.planarConfiguration === 0) {
    convertRGBColorByPixel(imageFrame.pixelData, rgbaBuffer);
  } else {
    convertRGBColorByPlane(imageFrame.pixelData, rgbaBuffer);
  }
}
 
function convertYBRFull (imageFrame, rgbaBuffer) {
  if (imageFrame.planarConfiguration === 0) {
    convertYBRFullByPixel(imageFrame.pixelData, rgbaBuffer);
  } else {
    convertYBRFullByPlane(imageFrame.pixelData, rgbaBuffer);
  }
}
 
export default function convertColorSpace (imageFrame, imageData) {
  const rgbaBuffer = imageData.data;
  // convert based on the photometric interpretation
 
  if (imageFrame.photometricInterpretation === 'RGB') {
    convertRGB(imageFrame, rgbaBuffer);
  } else if (imageFrame.photometricInterpretation === 'YBR_RCT') {
    convertRGB(imageFrame, rgbaBuffer);
  } else if (imageFrame.photometricInterpretation === 'YBR_ICT') {
    convertRGB(imageFrame, rgbaBuffer);
  } else if (imageFrame.photometricInterpretation === 'PALETTE COLOR') {
    convertPALETTECOLOR(imageFrame, rgbaBuffer);
  } else if (imageFrame.photometricInterpretation === 'YBR_FULL_422') {
    convertRGB(imageFrame, rgbaBuffer);
  } else if (imageFrame.photometricInterpretation === 'YBR_FULL') {
    convertYBRFull(imageFrame, rgbaBuffer);
  } else {
    throw new Error(`No color space conversion for photometric interpretation ${imageFrame.photometricInterpretation}`);
  }
}