@cornerstonejs/dicom-image-loader 5.10.11 → 5.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/esm/constants/transferSyntaxes.d.ts +5 -0
  2. package/dist/esm/constants/transferSyntaxes.js +5 -0
  3. package/dist/esm/decodeImageFrameWorker.js +19 -0
  4. package/dist/esm/imageLoader/decodeImageFrame.js +8 -0
  5. package/dist/esm/imageLoader/internal/getRetrieveValue.d.ts +1 -0
  6. package/dist/esm/imageLoader/internal/getRetrieveValue.js +9 -0
  7. package/dist/esm/imageLoader/internal/rangeRequest.js +15 -12
  8. package/dist/esm/imageLoader/internal/retrieveDefaults.d.ts +3 -0
  9. package/dist/esm/imageLoader/internal/retrieveDefaults.js +3 -0
  10. package/dist/esm/imageLoader/internal/streamRequest.d.ts +1 -0
  11. package/dist/esm/imageLoader/internal/streamRequest.js +13 -2
  12. package/dist/esm/imageLoader/wadors/getImageQualityStatus.js +3 -1
  13. package/dist/esm/imageLoader/wadors/loadImage.d.ts +9 -0
  14. package/dist/esm/imageLoader/wadors/loadImage.js +30 -4
  15. package/dist/esm/imageLoader/wadouri/getEncapsulatedImageFrame.js +1 -1
  16. package/dist/esm/shared/decoders/decodeDeflatedFrame.d.ts +4 -0
  17. package/dist/esm/shared/decoders/decodeDeflatedFrame.js +14 -0
  18. package/dist/esm/shared/decoders/decodeEncapsulatedUncompressed.d.ts +4 -0
  19. package/dist/esm/shared/decoders/decodeEncapsulatedUncompressed.js +6 -0
  20. package/dist/esm/shared/decoders/decodeJPEGLossless.js +1 -1
  21. package/dist/esm/shared/decoders/decodeJPEGXL.d.ts +5 -0
  22. package/dist/esm/shared/decoders/decodeJPEGXL.js +71 -0
  23. package/dist/esm/shared/decoders/nativeFrameBytes.d.ts +4 -0
  24. package/dist/esm/shared/decoders/nativeFrameBytes.js +20 -0
  25. package/dist/esm/version.d.ts +1 -1
  26. package/dist/esm/version.js +1 -1
  27. package/package.json +11 -10
@@ -2,6 +2,7 @@ export default transferSyntaxes;
2
2
  declare namespace transferSyntaxes {
3
3
  let IMPLICIT_VR_LITTLE_ENDIAN: string;
4
4
  let EXPLICIT_VR_LITTLE_ENDIAN: string;
5
+ let ENCAPSULATED_UNCOMPRESSED_EXPLICIT_VR_LITTLE_ENDIAN: string;
5
6
  let DEFLATED_EXPLICIT_VR_LITTLE_ENDIAN: string;
6
7
  let EXPLICIT_VR_BIG_ENDIAN: string;
7
8
  let JPEG_BASELINE_PROCESS_1: string;
@@ -37,10 +38,14 @@ declare namespace transferSyntaxes {
37
38
  let MPEG4_AVC_H264_HIGH_PROFILE_FOR_3D_VIDEO: string;
38
39
  let JPIP_LOSSLESS: string;
39
40
  let JPIP_PART2_MULTICOMPONENT_IMAGE_COMPRESSION: string;
41
+ let JPEG_XL_LOSSLESS: string;
42
+ let JPEG_XL_JPEG_RECOMPRESSION: string;
43
+ let JPEG_XL: string;
40
44
  let RFC_2557_MIME_ENCAPSULATION: string;
41
45
  let JPEG_XR_IMAGE_COMPRESSION: string;
42
46
  let JPEG_2000_IMAGE_COMPRESSION_LOSSLESS_ONLY_RETIRED: string;
43
47
  let JPEG_2000_IMAGE_COMPRESSION_RETIRED: string;
44
48
  let JPEG_2000_PART_2_MULTICOMPONENT_IMAGE_COMPRESSION_LOSSLESS_ONLY_RETIRED: string;
45
49
  let JPEG_2000_PART_2_MULTICOMPONENT_IMAGE_COMPRESSION_RETIRED: string;
50
+ let DEFLATED_IMAGE_FRAME_COMPRESSION: string;
46
51
  }
@@ -1,6 +1,7 @@
1
1
  const transferSyntaxes = {
2
2
  IMPLICIT_VR_LITTLE_ENDIAN: '1.2.840.10008.1.2',
3
3
  EXPLICIT_VR_LITTLE_ENDIAN: '1.2.840.10008.1.2.1',
4
+ ENCAPSULATED_UNCOMPRESSED_EXPLICIT_VR_LITTLE_ENDIAN: '1.2.840.10008.1.2.1.98',
4
5
  DEFLATED_EXPLICIT_VR_LITTLE_ENDIAN: '1.2.840.10008.1.2.1.99',
5
6
  EXPLICIT_VR_BIG_ENDIAN: '1.2.840.10008.1.2.2',
6
7
  JPEG_BASELINE_PROCESS_1: '1.2.840.10008.1.2.4.50',
@@ -36,11 +37,15 @@ const transferSyntaxes = {
36
37
  MPEG4_AVC_H264_HIGH_PROFILE_FOR_3D_VIDEO: '1.2.840.10008.1.2.4.104',
37
38
  JPIP_LOSSLESS: '1.2.840.10008.1.2.4.96',
38
39
  JPIP_PART2_MULTICOMPONENT_IMAGE_COMPRESSION: '1.2.840.10008.1.2.4.97',
40
+ JPEG_XL_LOSSLESS: '1.2.840.10008.1.2.4.110',
41
+ JPEG_XL_JPEG_RECOMPRESSION: '1.2.840.10008.1.2.4.111',
42
+ JPEG_XL: '1.2.840.10008.1.2.4.112',
39
43
  RFC_2557_MIME_ENCAPSULATION: '1.2.840.10008.1.2.6.1',
40
44
  JPEG_XR_IMAGE_COMPRESSION: '1.2.840.10008.1.2.6.2',
41
45
  JPEG_2000_IMAGE_COMPRESSION_LOSSLESS_ONLY_RETIRED: '1.2.840.10008.1.2.4.90R',
42
46
  JPEG_2000_IMAGE_COMPRESSION_RETIRED: '1.2.840.10008.1.2.4.91R',
43
47
  JPEG_2000_PART_2_MULTICOMPONENT_IMAGE_COMPRESSION_LOSSLESS_ONLY_RETIRED: '1.2.840.10008.1.2.4.92R',
44
48
  JPEG_2000_PART_2_MULTICOMPONENT_IMAGE_COMPRESSION_RETIRED: '1.2.840.10008.1.2.4.93R',
49
+ DEFLATED_IMAGE_FRAME_COMPRESSION: '1.2.840.10008.1.2.8.1',
45
50
  };
46
51
  export default transferSyntaxes;
@@ -10,6 +10,9 @@ import decodeJPEGLossless from './shared/decoders/decodeJPEGLossless.js';
10
10
  import decodeJPEGLS from './shared/decoders/decodeJPEGLS.js';
11
11
  import decodeJPEG2000 from './shared/decoders/decodeJPEG2000.js';
12
12
  import decodeHTJ2K from './shared/decoders/decodeHTJ2K.js';
13
+ import decodeEncapsulatedUncompressed from './shared/decoders/decodeEncapsulatedUncompressed.js';
14
+ import decodeDeflatedFrame from './shared/decoders/decodeDeflatedFrame.js';
15
+ import decodeJPEGXL from './shared/decoders/decodeJPEGXL.js';
13
16
  import applyModalityLUT from './shared/scaling/scaleArray.js';
14
17
  import { setWasmBasePathFromConfig } from './shared/wasmBasePath.js';
15
18
  import getMinMax from './shared/getMinMax.js';
@@ -218,6 +221,12 @@ export async function decodeImageFrame(imageFrame, transferSyntax, pixelData, de
218
221
  case '1.2.840.10008.1.2.1.99':
219
222
  decodePromise = decodeLittleEndian(imageFrame, pixelData);
220
223
  break;
224
+ case '1.2.840.10008.1.2.1.98':
225
+ decodePromise = decodeEncapsulatedUncompressed(imageFrame, pixelData);
226
+ break;
227
+ case '1.2.840.10008.1.2.8.1':
228
+ decodePromise = decodeDeflatedFrame(imageFrame, pixelData);
229
+ break;
221
230
  case '1.2.840.10008.1.2.5':
222
231
  decodePromise = decodeRLE(imageFrame, pixelData);
223
232
  break;
@@ -273,6 +282,16 @@ export async function decodeImageFrame(imageFrame, transferSyntax, pixelData, de
273
282
  };
274
283
  decodePromise = decodeHTJ2K(pixelData, opts);
275
284
  break;
285
+ case '1.2.840.10008.1.2.4.110':
286
+ case '1.2.840.10008.1.2.4.111':
287
+ case '1.2.840.10008.1.2.4.112':
288
+ opts = {
289
+ signed: imageFrame.pixelRepresentation === 1,
290
+ bytesPerPixel: imageFrame.bitsAllocated <= 8 ? 1 : 2,
291
+ ...imageFrame,
292
+ };
293
+ decodePromise = decodeJPEGXL(pixelData, opts);
294
+ break;
276
295
  default:
277
296
  throw new Error(`no decoder for transfer syntax ${transferSyntax}`);
278
297
  }
@@ -30,6 +30,10 @@ function decodeImageFrame(imageFrame, transferSyntax, pixelData, canvas, options
30
30
  return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
31
31
  case '1.2.840.10008.1.2.1.99':
32
32
  return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
33
+ case '1.2.840.10008.1.2.1.98':
34
+ return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
35
+ case '1.2.840.10008.1.2.8.1':
36
+ return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
33
37
  case '1.2.840.10008.1.2.5':
34
38
  return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
35
39
  case '1.2.840.10008.1.2.4.50':
@@ -57,6 +61,10 @@ function decodeImageFrame(imageFrame, transferSyntax, pixelData, canvas, options
57
61
  case '1.2.840.10008.1.2.4.202':
58
62
  case '1.2.840.10008.1.2.4.203':
59
63
  return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
64
+ case '1.2.840.10008.1.2.4.110':
65
+ case '1.2.840.10008.1.2.4.111':
66
+ case '1.2.840.10008.1.2.4.112':
67
+ return processDecodeTask(imageFrame, transferSyntax, pixelData, options, decodeConfig);
60
68
  }
61
69
  return Promise.reject(new Error(`No decoder for transfer syntax ${transferSyntax}`));
62
70
  }
@@ -0,0 +1 @@
1
+ export default function getRetrieveValue<T>(imageId: string, src: unknown, attr: string): T;
@@ -0,0 +1,9 @@
1
+ import metaDataManager from '../wadors/metaDataManager.js';
2
+ export default function getRetrieveValue(imageId, src, attr) {
3
+ const value = src?.[attr];
4
+ if (typeof value !== 'function') {
5
+ return value;
6
+ }
7
+ const metaData = metaDataManager.get(imageId);
8
+ return value(metaData, imageId);
9
+ }
@@ -1,6 +1,7 @@
1
1
  import { logging } from '@cornerstonejs/metadata';
2
2
  import { getOptions } from './options.js';
3
- import metaDataManager from '../wadors/metaDataManager.js';
3
+ import getRetrieveValue from './getRetrieveValue.js';
4
+ import { DEFAULT_CHUNK_SIZE, DEFAULT_INITIAL_CHUNK_SIZE, } from './retrieveDefaults.js';
4
5
  import extractMultipart from '../wadors/extractMultipart.js';
5
6
  import { getImageQualityStatus } from '../wadors/getImageQualityStatus.js';
6
7
  const log = logging.loaderLog.getLogger('rangeRequest');
@@ -8,8 +9,11 @@ export default function rangeRequest(url, imageId, defaultHeaders = {}, options
8
9
  const globalOptions = getOptions();
9
10
  const { retrieveOptions = {}, streamingData } = options;
10
11
  const chunkSize = streamingData.chunkSize ||
11
- getValue(imageId, retrieveOptions, 'chunkSize') ||
12
- 65536;
12
+ getRetrieveValue(imageId, retrieveOptions, 'chunkSize') ||
13
+ DEFAULT_CHUNK_SIZE;
14
+ const initialChunkSize = streamingData.initialChunkSize ||
15
+ getRetrieveValue(imageId, retrieveOptions, 'initialChunkSize') ||
16
+ DEFAULT_INITIAL_CHUNK_SIZE;
13
17
  const errorInterceptor = (err) => {
14
18
  if (typeof globalOptions.errorInterceptor === 'function') {
15
19
  const error = new Error('request failed');
@@ -29,6 +33,7 @@ export default function rangeRequest(url, imageId, defaultHeaders = {}, options
29
33
  try {
30
34
  if (!streamingData.encodedData) {
31
35
  streamingData.chunkSize = chunkSize;
36
+ streamingData.initialChunkSize = initialChunkSize;
32
37
  streamingData.rangesFetched = 0;
33
38
  }
34
39
  const byteRange = getByteRange(streamingData, retrieveOptions);
@@ -102,16 +107,11 @@ async function fetchRangeAndAppend(url, headers, range, streamingData) {
102
107
  }
103
108
  return streamingData;
104
109
  }
105
- function getValue(imageId, src, attr) {
106
- const value = src[attr];
107
- if (typeof value !== 'function') {
108
- return value;
109
- }
110
- const metaData = metaDataManager.get(imageId);
111
- return value(metaData, imageId);
110
+ function rangeEndOffset(rangeIndex, initialChunkSize, chunkSize) {
111
+ return initialChunkSize + rangeIndex * chunkSize;
112
112
  }
113
113
  function getByteRange(streamingData, retrieveOptions) {
114
- const { totalBytes, encodedData, chunkSize = 65536 } = streamingData;
114
+ const { totalBytes, encodedData, chunkSize = DEFAULT_CHUNK_SIZE, initialChunkSize = DEFAULT_INITIAL_CHUNK_SIZE, } = streamingData;
115
115
  const { rangeIndex = 0 } = retrieveOptions;
116
116
  if (rangeIndex === -1 && (!totalBytes || !encodedData)) {
117
117
  return [0, ''];
@@ -119,5 +119,8 @@ function getByteRange(streamingData, retrieveOptions) {
119
119
  if (rangeIndex === -1 || encodedData?.byteLength > totalBytes - chunkSize) {
120
120
  return [encodedData?.byteLength || 0, ''];
121
121
  }
122
- return [encodedData?.byteLength || 0, chunkSize * (rangeIndex + 1) - 1];
122
+ return [
123
+ encodedData?.byteLength || 0,
124
+ rangeEndOffset(rangeIndex, initialChunkSize, chunkSize) - 1,
125
+ ];
123
126
  }
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_INITIAL_CHUNK_SIZE = 131072;
2
+ export declare const DEFAULT_CHUNK_SIZE = 131072;
3
+ export declare const DEFAULT_MS_BETWEEN_DECODE = 500;
@@ -0,0 +1,3 @@
1
+ export const DEFAULT_INITIAL_CHUNK_SIZE = 131072;
2
+ export const DEFAULT_CHUNK_SIZE = 131072;
3
+ export const DEFAULT_MS_BETWEEN_DECODE = 500;
@@ -1,2 +1,3 @@
1
1
  import type { CornerstoneWadoRsLoaderOptions } from '../wadors/loadImage.js';
2
+ export declare function nextDecodeAt(lastSize: number, initialChunkSize: number, chunkSize: number): number;
2
3
  export default function streamRequest(url: string, imageId: string, defaultHeaders?: Record<string, string>, options?: CornerstoneWadoRsLoaderOptions): import("packages/core/dist/esm/utilities/ProgressiveIterator").PromiseIterator<unknown>;
@@ -3,12 +3,21 @@ import { logging } from '@cornerstonejs/metadata';
3
3
  import { getOptions } from './options.js';
4
4
  import extractMultipart from '../wadors/extractMultipart.js';
5
5
  import { getImageQualityStatus } from '../wadors/getImageQualityStatus.js';
6
+ import getRetrieveValue from './getRetrieveValue.js';
7
+ import { DEFAULT_CHUNK_SIZE, DEFAULT_INITIAL_CHUNK_SIZE, } from './retrieveDefaults.js';
6
8
  const log = logging.loaderLog.getLogger('streamRequest');
7
9
  const { ProgressiveIterator } = utilities;
10
+ export function nextDecodeAt(lastSize, initialChunkSize, chunkSize) {
11
+ return lastSize + (lastSize ? chunkSize : initialChunkSize);
12
+ }
8
13
  export default function streamRequest(url, imageId, defaultHeaders = {}, options = {}) {
9
14
  const globalOptions = getOptions();
10
15
  const { retrieveOptions = {}, streamingData = {}, } = options;
11
- const minChunkSize = retrieveOptions.minChunkSize || 128 * 1024;
16
+ const minChunkSize = getRetrieveValue(imageId, retrieveOptions, 'chunkSize') ||
17
+ getRetrieveValue(imageId, retrieveOptions, 'minChunkSize') ||
18
+ DEFAULT_CHUNK_SIZE;
19
+ const initialChunkSize = getRetrieveValue(imageId, retrieveOptions, 'initialChunkSize') ||
20
+ DEFAULT_INITIAL_CHUNK_SIZE;
12
21
  const errorInterceptor = (err) => {
13
22
  if (typeof globalOptions.errorInterceptor === 'function') {
14
23
  const error = new Error('request failed');
@@ -53,7 +62,9 @@ export default function streamRequest(url, imageId, defaultHeaders = {}, options
53
62
  continue;
54
63
  }
55
64
  readDone = done || encodedData.byteLength === totalBytes;
56
- if (!readDone && encodedData.length < lastSize + minChunkSize) {
65
+ if (!readDone &&
66
+ encodedData.length <
67
+ nextDecodeAt(lastSize, initialChunkSize, minChunkSize)) {
57
68
  continue;
58
69
  }
59
70
  lastSize = encodedData.length;
@@ -2,7 +2,9 @@ import { Enums } from '@cornerstonejs/core';
2
2
  const { ImageQualityStatus } = Enums;
3
3
  export function getImageQualityStatus(retrieveOptions, done = true) {
4
4
  if (!done) {
5
- return ImageQualityStatus.SUBRESOLUTION;
5
+ return retrieveOptions.decodeLevel === 0
6
+ ? ImageQualityStatus.LOSSY
7
+ : ImageQualityStatus.SUBRESOLUTION;
6
8
  }
7
9
  return (retrieveOptions.imageQualityStatus ?? ImageQualityStatus.FULL_RESOLUTION);
8
10
  }
@@ -6,6 +6,7 @@ export interface StreamingData {
6
6
  encodedData?: Uint8Array;
7
7
  totalBytes?: number;
8
8
  chunkSize?: number;
9
+ initialChunkSize?: number;
9
10
  totalRanges?: number;
10
11
  rangesFetched?: number;
11
12
  }
@@ -22,4 +23,12 @@ export interface CornerstoneWadoRsLoaderOptions extends DICOMLoaderImageOptions
22
23
  streamingData?: StreamingData;
23
24
  }
24
25
  declare function loadImage(imageId: string, options?: CornerstoneWadoRsLoaderOptions): Types.IImageLoadObject;
26
+ export declare function shouldDecodeAgain({ done, decodeLevel, lastDecodeLevel, lastDecodeTime, now, msBetweenDecode, }: {
27
+ done: boolean;
28
+ decodeLevel: number;
29
+ lastDecodeLevel: number;
30
+ lastDecodeTime: number;
31
+ now: number;
32
+ msBetweenDecode: number;
33
+ }): boolean;
25
34
  export default loadImage;
@@ -4,6 +4,7 @@ import { logging } from '@cornerstonejs/metadata';
4
4
  import createImage from '../createImage.js';
5
5
  import getPixelData from './getPixelData.js';
6
6
  import { loadImageFromCompressedFrameRegistry } from './loadImageFromRegistry.js';
7
+ import { DEFAULT_MS_BETWEEN_DECODE } from '../internal/retrieveDefaults.js';
7
8
  const log = logging.loaderLog.getLogger('wadors');
8
9
  const { ProgressiveIterator } = utilities;
9
10
  const { ImageQualityStatus } = Enums;
@@ -35,8 +36,9 @@ export function getTransferSyntaxForContentType(contentType) {
35
36
  'image/jll': '1.2.840.10008.1.2.4.70',
36
37
  'image/jp2': '1.2.840.10008.1.2.4.90',
37
38
  'image/jpx': '1.2.840.10008.1.2.4.92',
39
+ 'image/jxl': '1.2.840.10008.1.2.4.110',
40
+ 'application/x-deflate': '1.2.840.10008.1.2.8.1',
38
41
  'image/jphc': '3.2.840.10008.1.2.4.96',
39
- 'image/jxl': '1.2.840.10008.1.2.4.140',
40
42
  };
41
43
  if (params['transfer-syntax']) {
42
44
  return params['transfer-syntax'];
@@ -79,17 +81,28 @@ function loadImageFromNetwork(imageId, options = {}) {
79
81
  uncompressedIterator.generate(async (it) => {
80
82
  const compressedIt = ProgressiveIterator.as(getPixelData(imageURI, imageId, mediaType, options));
81
83
  let lastDecodeLevel = 10;
84
+ let lastDecodeTime = 0;
82
85
  for await (const result of compressedIt) {
83
86
  const { pixelData, imageQualityStatus = ImageQualityStatus.FULL_RESOLUTION, percentComplete, done = true, extractDone = true, } = result;
84
87
  const transferSyntax = getTransferSyntaxForContentType(result.contentType);
85
88
  if (!extractDone && !streamableTransferSyntaxes.has(transferSyntax)) {
86
89
  continue;
87
90
  }
91
+ const retrieveDecodeLevel = options.retrieveOptions?.decodeLevel;
88
92
  const decodeLevel = result.decodeLevel ??
89
- (imageQualityStatus === ImageQualityStatus.FULL_RESOLUTION
93
+ (retrieveDecodeLevel === 0 ||
94
+ imageQualityStatus === ImageQualityStatus.FULL_RESOLUTION
90
95
  ? 0
91
- : decodeLevelFromComplete(percentComplete, options.retrieveOptions?.decodeLevel));
92
- if (!done && lastDecodeLevel <= decodeLevel) {
96
+ : decodeLevelFromComplete(percentComplete, retrieveDecodeLevel));
97
+ if (!shouldDecodeAgain({
98
+ done,
99
+ decodeLevel,
100
+ lastDecodeLevel,
101
+ lastDecodeTime,
102
+ now: Date.now(),
103
+ msBetweenDecode: options.retrieveOptions?.msBetweenDecode ??
104
+ DEFAULT_MS_BETWEEN_DECODE,
105
+ })) {
93
106
  continue;
94
107
  }
95
108
  try {
@@ -104,6 +117,7 @@ function loadImageFromNetwork(imageId, options = {}) {
104
117
  image.imageQualityStatus = imageQualityStatus;
105
118
  it.add(image, done);
106
119
  lastDecodeLevel = decodeLevel;
120
+ lastDecodeTime = Date.now();
107
121
  }
108
122
  catch (e) {
109
123
  if (extractDone) {
@@ -124,6 +138,18 @@ function loadImageFromNetwork(imageId, options = {}) {
124
138
  cancelFn: undefined,
125
139
  };
126
140
  }
141
+ export function shouldDecodeAgain({ done, decodeLevel, lastDecodeLevel, lastDecodeTime, now, msBetweenDecode, }) {
142
+ if (done) {
143
+ return true;
144
+ }
145
+ if (decodeLevel > 0) {
146
+ return decodeLevel < lastDecodeLevel;
147
+ }
148
+ if (decodeLevel < lastDecodeLevel) {
149
+ return true;
150
+ }
151
+ return now - lastDecodeTime >= msBetweenDecode;
152
+ }
127
153
  function decodeLevelFromComplete(percent, retrieveDecodeLevel = 4) {
128
154
  const testSize = percent / 100 - 0.02;
129
155
  if (testSize > 1 / 4) {
@@ -1,6 +1,6 @@
1
1
  import * as dicomParser from 'dicom-parser';
2
2
  function framesAreFragmented(dataSet) {
3
- const numberOfFrames = dataSet.intString('x00280008');
3
+ const numberOfFrames = dataSet.intString('x00280008') || 1;
4
4
  const pixelDataElement = dataSet.elements.x7fe00010;
5
5
  return numberOfFrames !== pixelDataElement.fragments.length;
6
6
  }
@@ -0,0 +1,4 @@
1
+ import type { ByteArray } from 'dicom-parser';
2
+ import type { Types } from '@cornerstonejs/core';
3
+ declare function decodeDeflatedFrame(imageFrame: Types.IImageFrame, pixelData: ByteArray): Promise<Types.IImageFrame>;
4
+ export default decodeDeflatedFrame;
@@ -0,0 +1,14 @@
1
+ import pako from 'pako';
2
+ import decodeLittleEndian from './decodeLittleEndian.js';
3
+ import { trimToNativeFrame } from './nativeFrameBytes.js';
4
+ async function decodeDeflatedFrame(imageFrame, pixelData) {
5
+ let inflated;
6
+ try {
7
+ inflated = pako.inflateRaw(new Uint8Array(pixelData.buffer, pixelData.byteOffset, pixelData.length));
8
+ }
9
+ catch (error) {
10
+ throw new Error(`decodeDeflatedFrame: could not inflate the frame (${error})`);
11
+ }
12
+ return decodeLittleEndian(imageFrame, trimToNativeFrame(imageFrame, inflated, 'decodeDeflatedFrame'));
13
+ }
14
+ export default decodeDeflatedFrame;
@@ -0,0 +1,4 @@
1
+ import type { ByteArray } from 'dicom-parser';
2
+ import type { Types } from '@cornerstonejs/core';
3
+ declare function decodeEncapsulatedUncompressed(imageFrame: Types.IImageFrame, pixelData: ByteArray): Promise<Types.IImageFrame>;
4
+ export default decodeEncapsulatedUncompressed;
@@ -0,0 +1,6 @@
1
+ import decodeLittleEndian from './decodeLittleEndian.js';
2
+ import { trimToNativeFrame } from './nativeFrameBytes.js';
3
+ async function decodeEncapsulatedUncompressed(imageFrame, pixelData) {
4
+ return decodeLittleEndian(imageFrame, trimToNativeFrame(imageFrame, pixelData, 'decodeEncapsulatedUncompressed'));
5
+ }
6
+ export default decodeEncapsulatedUncompressed;
@@ -8,7 +8,7 @@ export function initialize(decodeConfig) {
8
8
  return Promise.resolve();
9
9
  }
10
10
  return new Promise((resolve, reject) => {
11
- import('jpeg-lossless-decoder-js').then(({ Decoder }) => {
11
+ import('@cornerstonejs/jpeg-lossless-decoder-js').then(({ Decoder }) => {
12
12
  local.DecoderClass = Decoder;
13
13
  resolve();
14
14
  }, reject);
@@ -0,0 +1,5 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import type { WebWorkerDecodeConfig } from '../../types/index.js';
3
+ export declare function initialize(decodeConfig?: WebWorkerDecodeConfig): Promise<void>;
4
+ declare function decodeAsync(compressedImageFrame: any, imageInfo: any): Promise<Types.IImageFrame>;
5
+ export default decodeAsync;
@@ -0,0 +1,71 @@
1
+ import jpegxlFactory from '@cornerstonejs/codec-libjxl/decodewasmjs';
2
+ const jpegxlWasm = new URL('@cornerstonejs/codec-libjxl/decodewasm', import.meta.url);
3
+ import getPixelData from './getPixelData.js';
4
+ import { resolveWasmUrl, setWasmBasePathFromConfig } from '../wasmBasePath.js';
5
+ const local = {
6
+ codec: undefined,
7
+ decoder: undefined,
8
+ decodeConfig: {},
9
+ };
10
+ function getExceptionMessage(exception) {
11
+ return typeof exception === 'number' && local.codec?.getExceptionMessage
12
+ ? local.codec.getExceptionMessage(exception)
13
+ : exception;
14
+ }
15
+ export function initialize(decodeConfig) {
16
+ local.decodeConfig = decodeConfig;
17
+ setWasmBasePathFromConfig(decodeConfig);
18
+ if (local.codec) {
19
+ return Promise.resolve();
20
+ }
21
+ const jpegxlModule = jpegxlFactory({
22
+ locateFile: (f) => {
23
+ if (f.endsWith('.wasm')) {
24
+ return resolveWasmUrl('jpegxlwasm_decode.wasm', jpegxlWasm);
25
+ }
26
+ return f;
27
+ },
28
+ });
29
+ return new Promise((resolve, reject) => {
30
+ jpegxlModule.then((instance) => {
31
+ local.codec = instance;
32
+ local.decoder = new instance.JpegXLDecoder();
33
+ resolve();
34
+ }, reject);
35
+ });
36
+ }
37
+ async function decodeAsync(compressedImageFrame, imageInfo) {
38
+ try {
39
+ await initialize();
40
+ const decoder = local.decoder;
41
+ const encodedBufferInWASM = decoder.getEncodedBuffer(compressedImageFrame.length);
42
+ encodedBufferInWASM.set(compressedImageFrame);
43
+ decoder.decode();
44
+ const frameInfo = decoder.getFrameInfo();
45
+ const decodedPixelsInWASM = decoder.getDecodedBuffer();
46
+ const encodedImageInfo = {
47
+ columns: frameInfo.width,
48
+ rows: frameInfo.height,
49
+ bitsPerPixel: frameInfo.bitsPerSample,
50
+ signed: imageInfo.signed,
51
+ bytesPerPixel: imageInfo.bytesPerPixel,
52
+ componentsPerPixel: frameInfo.componentCount,
53
+ };
54
+ const pixelData = getPixelData(frameInfo, decodedPixelsInWASM, imageInfo.signed);
55
+ const encodeOptions = {
56
+ frameInfo,
57
+ };
58
+ return {
59
+ ...imageInfo,
60
+ pixelData,
61
+ imageInfo: encodedImageInfo,
62
+ encodeOptions,
63
+ ...encodeOptions,
64
+ ...encodedImageInfo,
65
+ };
66
+ }
67
+ catch (error) {
68
+ throw getExceptionMessage(error);
69
+ }
70
+ }
71
+ export default decodeAsync;
@@ -0,0 +1,4 @@
1
+ import type { ByteArray } from 'dicom-parser';
2
+ import type { Types } from '@cornerstonejs/core';
3
+ export declare function nativeFrameLength(imageFrame: Types.IImageFrame): number;
4
+ export declare function trimToNativeFrame(imageFrame: Types.IImageFrame, pixelData: ByteArray, context: string): ByteArray;
@@ -0,0 +1,20 @@
1
+ export function nativeFrameLength(imageFrame) {
2
+ const { rows, columns, samplesPerPixel, bitsAllocated } = imageFrame;
3
+ const samples = rows * columns * samplesPerPixel;
4
+ if (bitsAllocated === 1) {
5
+ return Math.ceil(samples / 8);
6
+ }
7
+ return samples * (bitsAllocated / 8);
8
+ }
9
+ export function trimToNativeFrame(imageFrame, pixelData, context) {
10
+ const expected = nativeFrameLength(imageFrame);
11
+ if (pixelData.length === expected) {
12
+ return pixelData;
13
+ }
14
+ if (pixelData.length < expected) {
15
+ throw new Error(`${context}: frame is ${pixelData.length} bytes, expected ${expected} for ` +
16
+ `${imageFrame.rows}x${imageFrame.columns} with ${imageFrame.samplesPerPixel} ` +
17
+ `sample(s) at ${imageFrame.bitsAllocated} bits`);
18
+ }
19
+ return pixelData.subarray(0, expected);
20
+ }
@@ -1 +1 @@
1
- export declare const version = "5.10.11";
1
+ export declare const version = "5.11.0";
@@ -1 +1 @@
1
- export const version = '5.10.11';
1
+ export const version = '5.11.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/dicom-image-loader",
3
- "version": "5.10.11",
3
+ "version": "5.11.0",
4
4
  "description": "Cornerstone Image Loader for DICOM WADO-URI and WADO-RS and Local file",
5
5
  "keywords": [
6
6
  "DICOM",
@@ -111,23 +111,24 @@
111
111
  "prepublishOnly": "pnpm run build:loader"
112
112
  },
113
113
  "dependencies": {
114
- "@cornerstonejs/codec-charls": "1.2.5",
115
- "@cornerstonejs/codec-libjpeg-turbo-8bit": "1.2.4",
116
- "@cornerstonejs/codec-openjpeg": "1.3.2",
117
- "@cornerstonejs/codec-openjph": "2.4.9",
114
+ "@cornerstonejs/codec-charls": "1.2.7",
115
+ "@cornerstonejs/codec-libjpeg-turbo-8bit": "1.2.7",
116
+ "@cornerstonejs/codec-libjxl": "1.1.1",
117
+ "@cornerstonejs/codec-openjpeg": "1.3.6",
118
+ "@cornerstonejs/codec-openjph": "2.4.11",
119
+ "@cornerstonejs/jpeg-lossless-decoder-js": "2.2.1",
118
120
  "comlink": "4.4.2",
119
121
  "dicom-parser": "1.8.21",
120
- "jpeg-lossless-decoder-js": "2.1.2",
121
122
  "pako": "2.1.0",
122
123
  "uuid": "9.0.1"
123
124
  },
124
125
  "devDependencies": {
125
- "@cornerstonejs/core": "5.10.11",
126
- "@cornerstonejs/metadata": "5.10.11"
126
+ "@cornerstonejs/core": "5.11.0",
127
+ "@cornerstonejs/metadata": "5.11.0"
127
128
  },
128
129
  "peerDependencies": {
129
- "@cornerstonejs/core": "5.10.11",
130
- "@cornerstonejs/metadata": "5.10.11",
130
+ "@cornerstonejs/core": "5.11.0",
131
+ "@cornerstonejs/metadata": "5.11.0",
131
132
  "dicom-parser": "1.8.21"
132
133
  },
133
134
  "config": {