1
1
import type { ByteArray } from 'dicom-parser' ;
2
2
import getMinMax from '../shared/getMinMax' ;
3
- import getPixelDataTypeFromMinMax from '../shared/getPixelDataTypeFromMinMax' ;
4
3
import type { DICOMLoaderImageOptions , DICOMLoaderIImage } from '../types' ;
5
4
import type { Types } from '@cornerstonejs/core' ;
6
5
import {
@@ -16,68 +15,12 @@ import getImageFrame from './getImageFrame';
16
15
import getScalingParameters from './getScalingParameters' ;
17
16
import { getOptions } from './internal/options' ;
18
17
import isColorImageFn from '../shared/isColorImage' ;
18
+ import removeAFromRGBA from './removeAFromRGBA' ;
19
+ import isModalityLUTForDisplay from './isModalityLutForDisplay' ;
20
+ import setPixelDataType from './setPixelDataType' ;
19
21
20
22
let lastImageIdDrawn = '' ;
21
23
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
-
81
24
function createImage (
82
25
imageId : string ,
83
26
pixelData : ByteArray ,
0 commit comments