From f15f2a2612ad420be31c50abb7d9341607b2ca23 Mon Sep 17 00:00:00 2001 From: ivmartel Date: Tue, 5 Dec 2023 15:43:49 +0100 Subject: [PATCH] Fix writing data with vr=xs, fixes #1567 --- src/dicom/dicomWriter.js | 7 +++++++ tests/dicom/synthetic-data_explicit.json | 3 ++- tests/dicom/synthetic-data_explicit_big-endian.json | 3 ++- tests/dicom/synthetic-data_implicit.json | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dicom/dicomWriter.js b/src/dicom/dicomWriter.js index 72630d8511..dc032c8f2f 100644 --- a/src/dicom/dicomWriter.js +++ b/src/dicom/dicomWriter.js @@ -643,6 +643,13 @@ export class DicomWriter { const atValue = [dec1, dec2]; byteOffset = writer.writeUint16Array(byteOffset, atValue); } + } else if (element.vr === 'xs') { + // TODO would be better to use pixelRepresentation in if + if (value instanceof Int16Array) { + byteOffset = writer.writeInt16Array(byteOffset, value); + } else { + byteOffset = writer.writeUint16Array(byteOffset, value); + } } else { logger.warn('Unknown VR: ' + element.vr); } diff --git a/tests/dicom/synthetic-data_explicit.json b/tests/dicom/synthetic-data_explicit.json index 1b6fa1a280..e6010019fa 100644 --- a/tests/dicom/synthetic-data_explicit.json +++ b/tests/dicom/synthetic-data_explicit.json @@ -298,7 +298,7 @@ }, { "name": "lee-08", - "description": "Little Endian Explicit test data with mulitple VRs.", + "description": "Little Endian Explicit test data with multiple VRs.", "tags": { "TransferSyntaxUID": "1.2.840.10008.1.2.1", "Modality": "MR", @@ -313,6 +313,7 @@ "BitsAllocated": 16, "BitsStored": 12, "HighBit": 11, + "SmallestImagePixelValue": 0, "PrivateSQ": { "value": [ { diff --git a/tests/dicom/synthetic-data_explicit_big-endian.json b/tests/dicom/synthetic-data_explicit_big-endian.json index 5606cbb5f6..2cd7305c30 100644 --- a/tests/dicom/synthetic-data_explicit_big-endian.json +++ b/tests/dicom/synthetic-data_explicit_big-endian.json @@ -298,7 +298,7 @@ }, { "name": "beb-08", - "description": "Big Endian Explicit test data with mulitple VRs.", + "description": "Big Endian Explicit test data with multiple VRs.", "tags": { "TransferSyntaxUID": "1.2.840.10008.1.2.2", "Modality": "MR", @@ -313,6 +313,7 @@ "BitsAllocated": 16, "BitsStored": 12, "HighBit": 11, + "SmallestImagePixelValue": 0, "PrivateSQ": { "value": [ { diff --git a/tests/dicom/synthetic-data_implicit.json b/tests/dicom/synthetic-data_implicit.json index ff6d2eaf65..113cbf3cff 100644 --- a/tests/dicom/synthetic-data_implicit.json +++ b/tests/dicom/synthetic-data_implicit.json @@ -298,7 +298,7 @@ }, { "name": "lei-08", - "description": "Little Endian Implicit test data with mulitple VRs.", + "description": "Little Endian Implicit test data with multiple VRs.", "tags": { "TransferSyntaxUID": "1.2.840.10008.1.2", "Modality": "MR", @@ -313,6 +313,7 @@ "BitsAllocated": 16, "BitsStored": 12, "HighBit": 11, + "SmallestImagePixelValue": 0, "PrivateSQ": { "value": [ {