Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat Unknown Tags with defined VL as OW #232

Merged
merged 4 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down