diff --git a/write.go b/write.go index d5f63caa..c18dc1aa 100644 --- a/write.go +++ b/write.go @@ -548,6 +548,7 @@ func writeFloats(w dicomio.Writer, v Value, vr string) error { func writePixelData(w dicomio.Writer, t tag.Tag, value Value, vr string, vl uint32) error { image := MustGetPixelDataInfo(value) + if vl == tag.VLUndefinedLength { if err := writeBasicOffsetTable(w, image.Offsets); err != nil { return err @@ -562,6 +563,9 @@ func writePixelData(w dicomio.Writer, t tag.Tag, value Value, vr string, vl uint return err } } else { + if image.IntentionallySkipped { + return nil + } // For now, IntentionallyUnprocessed will only happen for Native // PixelData. if image.IntentionallyUnprocessed { diff --git a/write_test.go b/write_test.go index 17852423..4e4a2546 100644 --- a/write_test.go +++ b/write_test.go @@ -460,6 +460,38 @@ func TestWrite(t *testing.T) { parseOpts: []ParseOption{SkipProcessingPixelDataValue()}, expectedError: nil, }, + { + name: "Native PixelData with IntentionallySkipped=true", + dataset: Dataset{Elements: []*Element{ + mustNewElement(tag.MediaStorageSOPClassUID, []string{"1.2.840.10008.5.1.4.1.1.1.2"}), + mustNewElement(tag.MediaStorageSOPInstanceUID, []string{"1.2.3.4.5.6.7"}), + mustNewElement(tag.TransferSyntaxUID, []string{uid.ImplicitVRLittleEndian}), + mustNewElement(tag.BitsAllocated, []int{8}), + mustNewElement(tag.FloatingPointValue, []float64{128.10}), + mustNewElement(tag.PixelData, PixelDataInfo{ + IntentionallySkipped: true, + IsEncapsulated: false, + }), + }}, + parseOpts: []ParseOption{SkipPixelData()}, + expectedError: nil, + }, + { + name: "Encapsulated PixelData with IntentionallySkipped=true", + dataset: Dataset{Elements: []*Element{ + mustNewElement(tag.MediaStorageSOPClassUID, []string{"1.2.840.10008.5.1.4.1.1.1.2"}), + mustNewElement(tag.MediaStorageSOPInstanceUID, []string{"1.2.3.4.5.6.7"}), + mustNewElement(tag.TransferSyntaxUID, []string{uid.ImplicitVRLittleEndian}), + mustNewElement(tag.BitsAllocated, []int{8}), + mustNewElement(tag.FloatingPointValue, []float64{128.10}), + setUndefinedLength(mustNewElement(tag.PixelData, PixelDataInfo{ + IntentionallySkipped: true, + IsEncapsulated: true, + })), + }}, + parseOpts: []ParseOption{SkipPixelData()}, + expectedError: nil, + }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) {