Skip to content

Commit be0b29c

Browse files
authored
Merge branch 'main' into jpeg-supports
2 parents ed294cd + b00166e commit be0b29c

31 files changed

+8901
-9509
lines changed

.github/workflows/bench_pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
env:
88
GOBIN: /home/runner/go
99
steps:
10-
- name: Set up Go 1.18
10+
- name: Set up Go 1.22
1111
uses: actions/setup-go@v3
1212
with:
13-
go-version: 1.18
13+
go-version: 1.22
1414
id: go
1515

1616
- name: Check out code

.github/workflows/bench_push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
env:
88
GOBIN: /home/runner/go
99
steps:
10-
- name: Set up Go 1.18
10+
- name: Set up Go 1.22
1111
uses: actions/setup-go@v3
1212
with:
13-
go-version: 1.18
13+
go-version: 1.22
1414
id: go
1515

1616
- name: Check out code

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99

10-
- name: Set up Go 1.18
10+
- name: Set up Go 1.22
1111
uses: actions/setup-go@v3
1212
with:
13-
go-version: 1.18
13+
go-version: 1.22
1414
id: go
1515

1616
- name: Check out code

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
BINARY = dicomutil
22
VERSION = `git describe --tags --always`
33

4+
.PHONY: codegen
5+
codegen:
6+
- go generate -x ./...
7+
- gofmt -s -w ./pkg/tag
8+
49
.PHONY: build
510
build:
611
go mod download

dataset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (d *Dataset) FindElementByTag(tag tag.Tag) (*Element, error) {
3333
return e, nil
3434
}
3535
}
36-
return nil, ErrorElementNotFound
36+
return nil, fmt.Errorf("unable to find %v element: %w", tag, ErrorElementNotFound)
3737
}
3838

3939
func (d *Dataset) transferSyntax() (binary.ByteOrder, bool, error) {
@@ -57,7 +57,7 @@ func (d *Dataset) FindElementByTagNested(tag tag.Tag) (*Element, error) {
5757
return e, nil
5858
}
5959
}
60-
return nil, ErrorElementNotFound
60+
return nil, fmt.Errorf("unable to find %v element: %w", tag, ErrorElementNotFound)
6161
}
6262

6363
// FlatIterator will be deprecated soon in favor of
@@ -175,7 +175,7 @@ func (d *Dataset) String() string {
175175
tabs := buildTabs(elem.l)
176176
var tagName string
177177
if tagInfo, err := tag.Find(elem.e.Tag); err == nil {
178-
tagName = tagInfo.Name
178+
tagName = tagInfo.Keyword
179179
}
180180

181181
b.WriteString(fmt.Sprintf("%s[\n", tabs))

dataset_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ func makeSequenceElement(tg tag.Tag, items [][]*Element) *Element {
2424
}
2525
}
2626

27+
func makeUNSequenceElement(tg tag.Tag, items [][]*Element) *Element {
28+
sequenceItems := make([]*SequenceItemValue, 0, len(items))
29+
for _, item := range items {
30+
sequenceItems = append(sequenceItems, &SequenceItemValue{elements: item})
31+
}
32+
33+
return &Element{
34+
Tag: tg,
35+
ValueRepresentation: tag.VRUnknown,
36+
RawValueRepresentation: "UN",
37+
Value: &sequencesValue{
38+
value: sequenceItems,
39+
},
40+
ValueLength: tag.VLUndefinedLength,
41+
}
42+
}
43+
2744
func TestDataset_FindElementByTag(t *testing.T) {
2845
data := Dataset{
2946
Elements: []*Element{

element.go

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (e *Element) Equals(target *Element) bool {
4646
func (e *Element) String() string {
4747
var tagName string
4848
if tagInfo, err := tag.Find(e.Tag); err == nil {
49-
tagName = tagInfo.Name
49+
tagName = tagInfo.Keyword
5050
}
5151
return fmt.Sprintf("[\n Tag: %s\n Tag Name: %s\n VR: %s\n VR Raw: %s\n VL: %d\n Value: %s\n]\n\n",
5252
e.Tag.String(),
@@ -91,7 +91,7 @@ type Value interface {
9191
ValueType() ValueType
9292
// GetValue returns the underlying value that this Value holds. What type is returned here can be determined exactly
9393
// from the ValueType() of this Value (see the ValueType godoc).
94-
GetValue() interface{} // TODO: rename to Get to read cleaner
94+
GetValue() any // TODO: rename to Get to read cleaner
9595
String() string
9696
MarshalJSON() ([]byte, error)
9797
// Equals returns true if this value equals the input Value.
@@ -107,7 +107,7 @@ type Value interface {
107107
// Acceptable types: []int, []string, []byte, []float64, PixelDataInfo,
108108
// [][]*Element (represents a sequence, which contains several
109109
// items which each contain several elements).
110-
func NewValue(data interface{}) (Value, error) {
110+
func NewValue(data any) (Value, error) {
111111
switch data.(type) {
112112
case []int:
113113
return &intsValue{value: data.([]int)}, nil
@@ -127,11 +127,11 @@ func NewValue(data interface{}) (Value, error) {
127127
}
128128
return &sequencesValue{value: sequenceItems}, nil
129129
default:
130-
return nil, ErrorUnexpectedDataType
130+
return nil, fmt.Errorf("NewValue: unexpected data type %T: %w", data, ErrorUnexpectedDataType)
131131
}
132132
}
133133

134-
func mustNewValue(data interface{}) Value {
134+
func mustNewValue(data any) Value {
135135
v, err := NewValue(data)
136136
if err != nil {
137137
panic(err)
@@ -142,13 +142,15 @@ func mustNewValue(data interface{}) Value {
142142
// NewElement creates a new DICOM Element with the supplied tag and with a value
143143
// built from the provided data. The data can be one of the types that is
144144
// acceptable to NewValue.
145-
func NewElement(t tag.Tag, data interface{}) (*Element, error) {
145+
func NewElement(t tag.Tag, data any) (*Element, error) {
146146
tagInfo, err := tag.Find(t)
147147
if err != nil {
148148
return nil, err
149149
}
150-
rawVR := tagInfo.VR
151-
150+
rawVR := tagInfo.VRs[0]
151+
if t == tag.PixelData {
152+
rawVR = "OW"
153+
}
152154
value, err := NewValue(data)
153155
if err != nil {
154156
return nil, err
@@ -162,15 +164,15 @@ func NewElement(t tag.Tag, data interface{}) (*Element, error) {
162164
}, nil
163165
}
164166

165-
func mustNewElement(t tag.Tag, data interface{}) *Element {
167+
func mustNewElement(t tag.Tag, data any) *Element {
166168
elem, err := NewElement(t, data)
167169
if err != nil {
168170
log.Panic(err)
169171
}
170172
return elem
171173
}
172174

173-
func mustNewPrivateElement(t tag.Tag, rawVR string, data interface{}) *Element {
175+
func mustNewPrivateElement(t tag.Tag, rawVR string, data any) *Element {
174176
value, err := NewValue(data)
175177
if err != nil {
176178
log.Panic(fmt.Errorf("error creating value: %w", err))
@@ -215,9 +217,9 @@ type bytesValue struct {
215217
value []byte
216218
}
217219

218-
func (b *bytesValue) isElementValue() {}
219-
func (b *bytesValue) ValueType() ValueType { return Bytes }
220-
func (b *bytesValue) GetValue() interface{} { return b.value }
220+
func (b *bytesValue) isElementValue() {}
221+
func (b *bytesValue) ValueType() ValueType { return Bytes }
222+
func (b *bytesValue) GetValue() any { return b.value }
221223
func (b *bytesValue) String() string {
222224
return fmt.Sprintf("%v", b.value)
223225
}
@@ -240,9 +242,9 @@ type stringsValue struct {
240242
value []string
241243
}
242244

243-
func (s *stringsValue) isElementValue() {}
244-
func (s *stringsValue) ValueType() ValueType { return Strings }
245-
func (s *stringsValue) GetValue() interface{} { return s.value }
245+
func (s *stringsValue) isElementValue() {}
246+
func (s *stringsValue) ValueType() ValueType { return Strings }
247+
func (s *stringsValue) GetValue() any { return s.value }
246248
func (s *stringsValue) String() string {
247249
return fmt.Sprintf("%v", s.value)
248250
}
@@ -271,9 +273,9 @@ type intsValue struct {
271273
value []int
272274
}
273275

274-
func (i *intsValue) isElementValue() {}
275-
func (i *intsValue) ValueType() ValueType { return Ints }
276-
func (i *intsValue) GetValue() interface{} { return i.value }
276+
func (i *intsValue) isElementValue() {}
277+
func (i *intsValue) ValueType() ValueType { return Ints }
278+
func (i *intsValue) GetValue() any { return i.value }
277279
func (i *intsValue) String() string {
278280
return fmt.Sprintf("%v", i.value)
279281
}
@@ -302,9 +304,9 @@ type floatsValue struct {
302304
value []float64
303305
}
304306

305-
func (f *floatsValue) isElementValue() {}
306-
func (f *floatsValue) ValueType() ValueType { return Floats }
307-
func (f *floatsValue) GetValue() interface{} { return f.value }
307+
func (f *floatsValue) isElementValue() {}
308+
func (f *floatsValue) ValueType() ValueType { return Floats }
309+
func (f *floatsValue) GetValue() any { return f.value }
308310
func (f *floatsValue) String() string {
309311
return fmt.Sprintf("%v", f.value)
310312
}
@@ -343,7 +345,7 @@ func (s *SequenceItemValue) ValueType() ValueType { return SequenceItem }
343345
// GetValue returns the underlying value that this Value holds. What type is
344346
// returned here can be determined exactly from the ValueType() of this Value
345347
// (see the ValueType godoc).
346-
func (s *SequenceItemValue) GetValue() interface{} { return s.elements }
348+
func (s *SequenceItemValue) GetValue() any { return s.elements }
347349

348350
// String is used to get a string representation of this struct.
349351
func (s *SequenceItemValue) String() string {
@@ -377,9 +379,9 @@ type sequencesValue struct {
377379
value []*SequenceItemValue
378380
}
379381

380-
func (s *sequencesValue) isElementValue() {}
381-
func (s *sequencesValue) ValueType() ValueType { return Sequences }
382-
func (s *sequencesValue) GetValue() interface{} { return s.value }
382+
func (s *sequencesValue) isElementValue() {}
383+
func (s *sequencesValue) ValueType() ValueType { return Sequences }
384+
func (s *sequencesValue) GetValue() any { return s.value }
383385
func (s *sequencesValue) String() string {
384386
// TODO: consider adding more sophisticated formatting
385387
return fmt.Sprintf("%+v", s.value)
@@ -438,9 +440,9 @@ type pixelDataValue struct {
438440
PixelDataInfo
439441
}
440442

441-
func (p *pixelDataValue) isElementValue() {}
442-
func (p *pixelDataValue) ValueType() ValueType { return PixelData }
443-
func (p *pixelDataValue) GetValue() interface{} { return p.PixelDataInfo }
443+
func (p *pixelDataValue) isElementValue() {}
444+
func (p *pixelDataValue) ValueType() ValueType { return PixelData }
445+
func (p *pixelDataValue) GetValue() any { return p.PixelDataInfo }
444446
func (p *pixelDataValue) String() string {
445447
if len(p.Frames) == 0 {
446448
return "empty pixel data"
@@ -528,7 +530,7 @@ func MustGetPixelDataInfo(v Value) PixelDataInfo {
528530

529531
// allValues is used for tests that need to pass in instances of the unexported
530532
// value structs to cmp.AllowUnexported.
531-
var allValues = []interface{}{
533+
var allValues = []any{
532534
floatsValue{},
533535
intsValue{},
534536
stringsValue{},

element_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dicom
22

33
import (
44
"encoding/json"
5+
"errors"
56
"testing"
67

78
"github.com/google/go-cmp/cmp"
@@ -62,7 +63,7 @@ func TestElement_String(t *testing.T) {
6263
func TestNewValue(t *testing.T) {
6364
cases := []struct {
6465
name string
65-
data interface{}
66+
data any
6667
wantValue Value
6768
wantError error
6869
}{
@@ -141,7 +142,7 @@ func TestNewValue(t *testing.T) {
141142
func TestNewValue_UnexpectedType(t *testing.T) {
142143
data := 10
143144
_, err := NewValue(data)
144-
if err != ErrorUnexpectedDataType {
145+
if !errors.Is(err, ErrorUnexpectedDataType) {
145146
t.Errorf("NewValue(%v) expected an error. got: %v, want: %v", data, err, ErrorUnexpectedDataType)
146147
}
147148
}

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module github.com/suyashkumar/dicom
22

3-
go 1.18
3+
go 1.22
44

55
require (
6-
github.com/golang/mock v1.4.4
76
github.com/google/go-cmp v0.5.2
87
golang.org/x/text v0.3.8
98
)

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
2-
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
31
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
42
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
6-
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
7-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
9-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
103
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
114
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
12-
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
135
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
146
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 commit comments

Comments
 (0)