|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import DicomCineImage from '../DicomCineImage'; |
| 4 | +import type { CineHeader } from '../parseCineDicom'; |
| 5 | + |
| 6 | +const TS_EXPLICIT_VR_LE = '1.2.840.10008.1.2.1'; |
| 7 | +const TS_JPEG_BASELINE = '1.2.840.10008.1.2.4.50'; |
| 8 | +const TS_UNSUPPORTED = '1.2.840.10008.1.2.5'; |
| 9 | + |
| 10 | +function cineHeader(overrides: Partial<CineHeader> = {}): CineHeader { |
| 11 | + return { |
| 12 | + transferSyntaxUID: TS_EXPLICIT_VR_LE, |
| 13 | + rows: 2, |
| 14 | + cols: 2, |
| 15 | + numberOfFrames: 2, |
| 16 | + samplesPerPixel: 1, |
| 17 | + bitsAllocated: 8, |
| 18 | + planarConfiguration: 0, |
| 19 | + photometricInterpretation: 'MONOCHROME2', |
| 20 | + frameTimeMs: null, |
| 21 | + patient: { |
| 22 | + PatientID: 'patient-1', |
| 23 | + PatientName: 'Test Patient', |
| 24 | + PatientBirthDate: '', |
| 25 | + PatientSex: '', |
| 26 | + }, |
| 27 | + study: { |
| 28 | + StudyID: 'study-1', |
| 29 | + StudyInstanceUID: 'study-uid', |
| 30 | + StudyDate: '', |
| 31 | + StudyTime: '', |
| 32 | + AccessionNumber: '', |
| 33 | + StudyDescription: '', |
| 34 | + }, |
| 35 | + series: { |
| 36 | + SeriesInstanceUID: 'series-uid', |
| 37 | + SeriesNumber: '1', |
| 38 | + SeriesDescription: 'Cine', |
| 39 | + Modality: 'US', |
| 40 | + SOPInstanceUID: 'sop-uid', |
| 41 | + SOPClassUID: '1.2.840.10008.5.1.4.1.1.3.1', |
| 42 | + }, |
| 43 | + regions: [], |
| 44 | + ...overrides, |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | +describe('DicomCineImage.isSupported', () => { |
| 49 | + it('accepts only MONOCHROME2 for native one-sample 8-bit pixels', () => { |
| 50 | + expect(DicomCineImage.isSupported(cineHeader())).toBe(true); |
| 51 | + |
| 52 | + ['MONOCHROME1', 'PALETTE COLOR', 'RGB', 'YBR_FULL', 'YBR_FULL_422'].forEach( |
| 53 | + (photometricInterpretation) => { |
| 54 | + expect( |
| 55 | + DicomCineImage.isSupported(cineHeader({ photometricInterpretation })) |
| 56 | + ).toBe(false); |
| 57 | + } |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it('accepts only RGB for native three-sample 8-bit pixels', () => { |
| 62 | + expect( |
| 63 | + DicomCineImage.isSupported( |
| 64 | + cineHeader({ |
| 65 | + samplesPerPixel: 3, |
| 66 | + photometricInterpretation: 'RGB', |
| 67 | + }) |
| 68 | + ) |
| 69 | + ).toBe(true); |
| 70 | + |
| 71 | + [ |
| 72 | + 'MONOCHROME2', |
| 73 | + 'MONOCHROME1', |
| 74 | + 'PALETTE COLOR', |
| 75 | + 'YBR_FULL', |
| 76 | + 'YBR_FULL_422', |
| 77 | + ].forEach((photometricInterpretation) => { |
| 78 | + expect( |
| 79 | + DicomCineImage.isSupported( |
| 80 | + cineHeader({ |
| 81 | + samplesPerPixel: 3, |
| 82 | + photometricInterpretation, |
| 83 | + }) |
| 84 | + ) |
| 85 | + ).toBe(false); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it('rejects native pixels unless BitsAllocated is 8', () => { |
| 90 | + expect(DicomCineImage.isSupported(cineHeader({ bitsAllocated: 16 }))).toBe( |
| 91 | + false |
| 92 | + ); |
| 93 | + }); |
| 94 | + |
| 95 | + it('keeps encapsulated support scoped to transfer syntax acceptance', () => { |
| 96 | + expect( |
| 97 | + DicomCineImage.isSupported( |
| 98 | + cineHeader({ |
| 99 | + transferSyntaxUID: TS_JPEG_BASELINE, |
| 100 | + bitsAllocated: 16, |
| 101 | + samplesPerPixel: 3, |
| 102 | + photometricInterpretation: 'YBR_FULL_422', |
| 103 | + }) |
| 104 | + ) |
| 105 | + ).toBe(true); |
| 106 | + |
| 107 | + expect( |
| 108 | + DicomCineImage.isSupported( |
| 109 | + cineHeader({ |
| 110 | + transferSyntaxUID: TS_UNSUPPORTED, |
| 111 | + photometricInterpretation: 'RGB', |
| 112 | + }) |
| 113 | + ) |
| 114 | + ).toBe(false); |
| 115 | + }); |
| 116 | +}); |
0 commit comments