diff --git a/pkg/tag/tag.go b/pkg/tag/tag.go index 36f1db57..5c250e54 100644 --- a/pkg/tag/tag.go +++ b/pkg/tag/tag.go @@ -128,7 +128,7 @@ func GetVRKind(tag Tag, vr string) VRKind { return VRDate case "AT": return VRTagList - case "OW", "OB": + case "OW", "OB", "UN": return VRBytes case "LT", "UT": return VRString diff --git a/read.go b/read.go index 78567994..fe4b829b 100644 --- a/read.go +++ b/read.go @@ -422,7 +422,7 @@ func readSequenceItem(r dicomio.Reader, t tag.Tag, vr string, vl uint32) (Value, func readBytes(r dicomio.Reader, t tag.Tag, vr string, vl uint32) (Value, error) { // TODO: add special handling of PixelData - if vr == vrraw.OtherByte { + if vr == vrraw.OtherByte || vr == vrraw.Unknown { data := make([]byte, vl) _, err := io.ReadFull(r, data) return &bytesValue{value: data}, err @@ -466,7 +466,6 @@ func readString(r dicomio.Reader, t tag.Tag, vr string, vl uint32) (Value, error // Split multiple strings strs := strings.Split(str, "\\") - return &stringsValue{value: strs}, err } diff --git a/read_test.go b/read_test.go index 715ccf17..0d9820d4 100644 --- a/read_test.go +++ b/read_test.go @@ -168,12 +168,19 @@ func TestReadOWBytes(t *testing.T) { expectedErr error }{ { - name: "even-number bytes", + name: "OW VR with even-number bytes", bytes: []byte{0x1, 0x2, 0x3, 0x4}, VR: vrraw.OtherWord, want: &bytesValue{value: []byte{0x1, 0x2, 0x3, 0x4}}, expectedErr: nil, }, + { + name: "UN VR even-number bytes", + bytes: []byte{0x1, 0x2, 0x3, 0x4}, + VR: vrraw.Unknown, + want: &bytesValue{value: []byte{0x1, 0x2, 0x3, 0x4}}, + expectedErr: nil, + }, { name: "error on odd-number bytes", bytes: []byte{0x1, 0x2, 0x3}, diff --git a/write.go b/write.go index 4b148ff5..7d1f6409 100644 --- a/write.go +++ b/write.go @@ -313,7 +313,7 @@ func verifyValueType(t tag.Tag, value Value, vr string) error { ok = valueType == Sequences case "NA": ok = valueType == SequenceItem - case vrraw.OtherWord, vrraw.OtherByte: + case vrraw.OtherWord, vrraw.OtherByte, vrraw.Unknown: if t == tag.PixelData { ok = valueType == PixelData } else { @@ -488,7 +488,7 @@ func writeStrings(w dicomio.Writer, values []string, vr string) error { func writeBytes(w dicomio.Writer, values []byte, vr string) error { var err error switch vr { - case vrraw.OtherWord: + case vrraw.OtherWord, vrraw.Unknown: err = writeOtherWordString(w, values) case vrraw.OtherByte: err = writeOtherByteString(w, values) diff --git a/write_test.go b/write_test.go index ae87fade..3b682002 100644 --- a/write_test.go +++ b/write_test.go @@ -47,6 +47,17 @@ func TestWrite(t *testing.T) { mustNewElement(tag.FloatingPointValue, []float64{128.10}), mustNewElement(tag.DimensionIndexPointer, []int{32, 36950}), mustNewElement(tag.RedPaletteColorLookupTableData, []byte{0x1, 0x2, 0x3, 0x4}), + mustNewElement(tag.SelectorSLValue, []int{-20}), + // Some tag with an unknown VR. + { + Tag: tag.Tag{0x0019, 0x1027}, + ValueRepresentation: tag.VRBytes, + RawValueRepresentation: "UN", + ValueLength: 4, + Value: &bytesValue{ + value: []byte{0x1, 0x2, 0x3, 0x4}, + }, + }, }}, expectedError: nil, },