From 7bd40f86db0f0a4ee71e62224271c1be3085eb1b Mon Sep 17 00:00:00 2001 From: Bastien Lecoeur Date: Mon, 11 Nov 2024 14:51:53 +0000 Subject: [PATCH] Fix even padding for IS and DS values --- src/DICOM.jl | 2 +- test/runtests.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DICOM.jl b/src/DICOM.jl index cc52d3d..a7e59ee 100644 --- a/src/DICOM.jl +++ b/src/DICOM.jl @@ -676,7 +676,7 @@ function dcm_store(st::IO, gelt::Tuple{UInt16,UInt16}, writef::Function, vr::Str vr == "SQ" || gelt == (0xFFFE, 0xE000) ? write(st, convert(lentype, 0xffffffff)) : write(st, convert(lentype, max(0, sz))) seek(st, endp) if szWasOdd - vr in ("AE", "CS", "SH", "LO", "PN", "DA", "DT", "TM") ? write(st, UInt8(0x20)) : write(st, UInt8(0)) + vr in ("AE", "CS", "SH", "LO", "PN", "DA", "DT", "TM", "IS", "DS") ? write(st, UInt8(0x20)) : write(st, UInt8(0)) end end diff --git a/test/runtests.jl b/test/runtests.jl index a88b64c..7ab9288 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -285,10 +285,16 @@ end SOPClassUID = write_to_string(io -> DICOM.write_element(io, (0x0008, 0x0016), "1.2.840.10008.5.1.4.1.1.4", true, empty_vr_dict)) @test length(SOPClassUID) % 2 == 0 @test SOPClassUID[end] == '\0' + # Test that SH strings are padded with ' ' to even length StudyDescription = write_to_string(io -> DICOM.write_element(io, (0x0008, 0x1030), "BestImageEver", true, empty_vr_dict)) @test length(StudyDescription) % 2 == 0 @test StudyDescription[end] == ' ' + + # Test that DS strings are padded with ' ' to even length + PixelSpacing = write_to_string(io -> DICOM.write_element(io, (0x0028, 0x0030), [0.5, 0.5], true, empty_vr_dict)) + @test length(PixelSpacing) % 2 == 0 + @test PixelSpacing[end] == ' ' end @testset "Writing Sequence" begin