All files / dicomImageLoader/src/imageLoader isColorConversionRequired.ts

75% Statements 9/12
75% Branches 9/12
100% Functions 1/1
75% Lines 9/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 42 43 44 45 46 47 48 49 50                      60x                 60x     60x   20x     40x 8x     32x         32x               32x        
/**
 * This function checks color space conversion data requirements before
 * applying them. This function was created to solve problems like the one
 * discussed in here https://discourse.orthanc-server.org/t/orthanc-convert-ybr-to-rgb-but-does-not-change-metadata/3533/17
 * In this case, Orthanc server converts the pixel data from YBR to RGB, but maintain
 * the photometricInterpretation dicom tag in YBR
 * @param imageFrame
 * @param RGBA
 * @returns
 */
export default function isColorConversionRequired(imageFrame) {
  Iif (imageFrame === undefined) {
    return false;
  }
  const {
    rows,
    columns,
    photometricInterpretation,
    pixelDataLength,
    planarConfiguration,
  } = imageFrame;
 
  // if it is rgba don't convert (typically jpeg, jpeg-xl, jpeg2000 etc)
  if (pixelDataLength === 4 * columns * rows) {
    // RGBA - JPEG
    return false;
  }
 
  if (photometricInterpretation === 'PALETTE COLOR') {
    return true;
  }
 
  Iif (photometricInterpretation.endsWith('420')) {
    return (
      pixelDataLength ===
      (3 * Math.ceil(columns / 2) + Math.floor(columns / 2)) * rows
    );
  } else Iif (photometricInterpretation.endsWith('422')) {
    return (
      pixelDataLength ===
      (3 * Math.ceil(columns / 2) + Math.floor(columns / 2)) *
        Math.ceil(rows / 2) +
        Math.floor(rows / 2) * columns
    );
  } else {
    return photometricInterpretation !== 'RGB' || planarConfiguration === 1;
    // and it is one of the rle and lei cases then we need to convert
  }
}