All files / tools/src/utilities/viewport isViewportPreScaled.ts

50% Statements 4/8
37.5% Branches 3/8
100% Functions 1/1
50% Lines 4/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                        8x 8x 8x 8x                    
import type { Types } from '@cornerstonejs/core';
import {
  cache,
  StackViewport,
  BaseVolumeViewport,
  utilities,
} from '@cornerstonejs/core';
 
function isViewportPreScaled(
  viewport: Types.IStackViewport | Types.IVolumeViewport,
  targetId: string
): boolean {
  if (viewport instanceof BaseVolumeViewport) {
    const volumeId = utilities.getVolumeId(targetId);
    const volume = cache.getVolume(volumeId);
    return !!volume?.scaling && Object.keys(volume.scaling).length > 0;
  } else Eif (viewport instanceof StackViewport) {
    const { preScale } = viewport.getImageData() || {};
    return !!preScale?.scaled;
  } else {
    return false;
  }
}
 
export { isViewportPreScaled };