Skip to content

Commit c082dc2

Browse files
authored
add more exports to dicomImageLoader (#1855)
1 parent 7ddb7a1 commit c082dc2

File tree

5 files changed

+79
-60
lines changed

5 files changed

+79
-60
lines changed

packages/dicomImageLoader/src/imageLoader/createImage.ts

+3-60
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ByteArray } from 'dicom-parser';
22
import getMinMax from '../shared/getMinMax';
3-
import getPixelDataTypeFromMinMax from '../shared/getPixelDataTypeFromMinMax';
43
import type { DICOMLoaderImageOptions, DICOMLoaderIImage } from '../types';
54
import type { Types } from '@cornerstonejs/core';
65
import {
@@ -16,68 +15,12 @@ import getImageFrame from './getImageFrame';
1615
import getScalingParameters from './getScalingParameters';
1716
import { getOptions } from './internal/options';
1817
import isColorImageFn from '../shared/isColorImage';
18+
import removeAFromRGBA from './removeAFromRGBA';
19+
import isModalityLUTForDisplay from './isModalityLutForDisplay';
20+
import setPixelDataType from './setPixelDataType';
1921

2022
let lastImageIdDrawn = '';
2123

22-
function isModalityLUTForDisplay(sopClassUid: string): boolean {
23-
// special case for XA and XRF
24-
// https://groups.google.com/forum/#!searchin/comp.protocols.dicom/Modality$20LUT$20XA/comp.protocols.dicom/UBxhOZ2anJ0/D0R_QP8V2wIJ
25-
return (
26-
sopClassUid !== '1.2.840.10008.5.1.4.1.1.12.1' && // XA
27-
sopClassUid !== '1.2.840.10008.5.1.4.1.1.12.2.1'
28-
); // XRF
29-
}
30-
31-
/**
32-
* Helper function to set the right typed array.
33-
* This is needed because web workers can transfer array buffers but not typed arrays
34-
*
35-
* Here we are setting the pixel data to the right typed array based on the final
36-
* min and max values
37-
*/
38-
function setPixelDataType(imageFrame) {
39-
const minValue = imageFrame.smallestPixelValue;
40-
const maxValue = imageFrame.largestPixelValue;
41-
42-
const TypedArray = getPixelDataTypeFromMinMax(minValue, maxValue);
43-
44-
if (TypedArray) {
45-
// @ts-ignore
46-
const typedArray = new TypedArray(imageFrame.pixelData);
47-
imageFrame.pixelData = typedArray;
48-
} else {
49-
throw new Error('Could not apply a typed array to the pixel data');
50-
}
51-
}
52-
53-
/**
54-
* Removes the A from RGBA to return RGB buffer, this is used when the
55-
* decoding happens with browser API which results in RGBA, but if useRGBA flag
56-
* is set to false, we want to return RGB
57-
*
58-
* @param pixelData - decoded image in RGBA
59-
* @param targetBuffer - target buffer to write to
60-
*/
61-
function removeAFromRGBA(
62-
pixelData: Types.PixelDataTypedArray,
63-
targetBuffer: Uint8ClampedArray | Uint8Array
64-
) {
65-
const numPixels = pixelData.length / 4;
66-
67-
let rgbIndex = 0;
68-
69-
let bufferIndex = 0;
70-
71-
for (let i = 0; i < numPixels; i++) {
72-
targetBuffer[bufferIndex++] = pixelData[rgbIndex++]; // red
73-
targetBuffer[bufferIndex++] = pixelData[rgbIndex++]; // green
74-
targetBuffer[bufferIndex++] = pixelData[rgbIndex++]; // blue
75-
rgbIndex++; // skip alpha
76-
}
77-
78-
return targetBuffer;
79-
}
80-
8124
function createImage(
8225
imageId: string,
8326
pixelData: ByteArray,

packages/dicomImageLoader/src/imageLoader/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import { default as getMinMax } from '../shared/getMinMax';
1717
import { default as isColorImage } from '../shared/isColorImage';
1818
import { default as isJPEGBaseline8BitColor } from './isJPEGBaseline8BitColor';
1919
import { default as getPixelData } from './wadors/getPixelData';
20+
import { default as getScalingParameters } from './getScalingParameters';
21+
import { default as isColorConversionRequired } from './isColorConversionRequired';
22+
import { default as removeAFromRGBA } from './removeAFromRGBA';
23+
import { default as isModalityLUTForDisplay } from './isModalityLutForDisplay';
24+
import { default as setPixelDataType } from './setPixelDataType';
2025
import { internal } from './internal/index';
2126

2227
const cornerstoneDICOMImageLoader = {
@@ -36,6 +41,11 @@ const cornerstoneDICOMImageLoader = {
3641
getMinMax,
3742
isColorImage,
3843
isJPEGBaseline8BitColor,
44+
getScalingParameters,
45+
isColorConversionRequired,
46+
removeAFromRGBA,
47+
isModalityLUTForDisplay,
48+
setPixelDataType,
3949
internal,
4050
};
4151

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function isModalityLUTForDisplay(sopClassUid: string): boolean {
2+
// special case for XA and XRF
3+
// https://groups.google.com/forum/#!searchin/comp.protocols.dicom/Modality$20LUT$20XA/comp.protocols.dicom/UBxhOZ2anJ0/D0R_QP8V2wIJ
4+
return (
5+
sopClassUid !== '1.2.840.10008.5.1.4.1.1.12.1' && // XA
6+
sopClassUid !== '1.2.840.10008.5.1.4.1.1.12.2.1'
7+
); // XRF
8+
}
9+
10+
export default isModalityLUTForDisplay;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Types } from '@cornerstonejs/core';
2+
3+
/**
4+
* Removes the A from RGBA to return RGB buffer, this is used when the
5+
* decoding happens with browser API which results in RGBA, but if useRGBA flag
6+
* is set to false, we want to return RGB
7+
*
8+
* @param pixelData - decoded image in RGBA
9+
* @param targetBuffer - target buffer to write to
10+
*/
11+
function removeAFromRGBA(
12+
pixelData: Types.PixelDataTypedArray,
13+
targetBuffer: Uint8ClampedArray | Uint8Array
14+
) {
15+
const numPixels = pixelData.length / 4;
16+
17+
let rgbIndex = 0;
18+
19+
let bufferIndex = 0;
20+
21+
for (let i = 0; i < numPixels; i++) {
22+
targetBuffer[bufferIndex++] = pixelData[rgbIndex++]; // red
23+
targetBuffer[bufferIndex++] = pixelData[rgbIndex++]; // green
24+
targetBuffer[bufferIndex++] = pixelData[rgbIndex++]; // blue
25+
rgbIndex++; // skip alpha
26+
}
27+
28+
return targetBuffer;
29+
}
30+
31+
export default removeAFromRGBA;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import getPixelDataTypeFromMinMax from '../shared/getPixelDataTypeFromMinMax';
2+
3+
/**
4+
* Helper function to set the right typed array.
5+
* This is needed because web workers can transfer array buffers but not typed arrays
6+
*
7+
* Here we are setting the pixel data to the right typed array based on the final
8+
* min and max values
9+
*/
10+
function setPixelDataType(imageFrame) {
11+
const minValue = imageFrame.smallestPixelValue;
12+
const maxValue = imageFrame.largestPixelValue;
13+
14+
const TypedArray = getPixelDataTypeFromMinMax(minValue, maxValue);
15+
16+
if (TypedArray) {
17+
// @ts-ignore
18+
const typedArray = new TypedArray(imageFrame.pixelData);
19+
imageFrame.pixelData = typedArray;
20+
} else {
21+
throw new Error('Could not apply a typed array to the pixel data');
22+
}
23+
}
24+
25+
export default setPixelDataType;

0 commit comments

Comments
 (0)