All files / packages/core/src/RenderingEngine/helpers/cpuFallback/rendering getImageSize.ts

87.5% Statements 7/8
70% Branches 7/10
100% Functions 2/2
87.5% Lines 7/8

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 51 52 53 54 55 56                    34x                                     34x 34x       34x       34x         34x             34x          
import { validateParameterUndefinedOrNull } from './validator';
import { IImage } from '../../../../types';
 
/**
 * Check if the angle is rotated
 * @param {Number} rotation the rotation angle
 * @returns {Boolean} true if the angle is rotated; Otherwise, false.
 * @memberof Internal
 */
function isRotated(rotation?: number | null): boolean {
  return !(
    rotation === null ||
    rotation === undefined ||
    rotation === 0 ||
    rotation === 180
  );
}
 
/**
 * Retrieves the current image dimensions given an enabled element
 *
 * @param {any} image The Cornerstone image.
 * @param {Number} rotation Optional. The rotation angle of the image.
 * @return {{width:Number, height:Number}} The Image dimensions
 * @memberof Internal
 */
export default function (
  image: IImage,
  rotation = null
): { height: number; width: number } {
  validateParameterUndefinedOrNull(
    image,
    'getImageSize: parameter image must not be undefined'
  );
  validateParameterUndefinedOrNull(
    image.width,
    'getImageSize: parameter image must have width'
  );
  validateParameterUndefinedOrNull(
    image.height,
    'getImageSize: parameter image must have height'
  );
 
  Iif (isRotated(rotation)) {
    return {
      height: image.width,
      width: image.height,
    };
  }
 
  return {
    width: image.width,
    height: image.height,
  };
}