All files / extensions/cornerstone/src/utils initGpuSettingsPreset.ts

50% Statements 10/20
75% Branches 3/4
100% Functions 2/2
50% Lines 10/20

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    249x                                   249x 249x   249x 1746x   1746x 1746x                                     249x   249x 249x    
import { setGpuSettingsPreset, resetGpuSettingsPreset, setLossyDownsampling } from '@cornerstonejs/core';
 
const CUSTOMIZATION_ID = 'cornerstone.gpuSettingsPreset';
 
/**
 * Applies the `cornerstone.gpuSettingsPreset` customization, and applies it
 * again when the global or the mode customization changes.
 *
 * - A preset id selects that preset and turns final downsampling on, also in a
 *   config that keeps `lossyDownsampling.final` off, such as `config/default.js`.
 * - `null` returns to the Cornerstone3D default preset and to
 *   `appConfig.lossyDownsampling.final`.
 *
 * A volume viewport reads the preset when it adds its actor, so call this
 * before a mode opens a viewport. The `bootstrap` and `global` phases of a
 * `?customization=` module both apply early enough.
 *
 * See the "Select the GPU settings preset" section of specificCustomizations.md.
 */
export default function initGpuSettingsPreset({ customizationService, appConfig }): void {
  const configuredFinal = Boolean(appConfig?.lossyDownsampling?.final);
  let appliedId = null;
 
  const apply = () => {
    const presetId = customizationService.getValue(CUSTOMIZATION_ID) ?? null;
 
    if (presetId === appliedId) {
      return;
    }
 
    Iif (!presetId) {
      resetGpuSettingsPreset();
      setLossyDownsampling({ final: configuredFinal });
      appliedId = null;
      return;
    }
 
    try {
      setGpuSettingsPreset(presetId);
      setLossyDownsampling({ final: true });
      appliedId = presetId;
    } catch (error) {
      console.warn(`${CUSTOMIZATION_ID} states "${presetId}", which is not a preset.`, error);
    }
  };
 
  apply();
 
  customizationService.subscribe(customizationService.EVENTS.GLOBAL_CUSTOMIZATION_MODIFIED, apply);
  customizationService.subscribe(customizationService.EVENTS.MODE_CUSTOMIZATION_MODIFIED, apply);
}