DataVRDictionary; Should EVR_DS extended length = 1?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
budric
Posts: 29
Joined: Thu, 2007-06-28, 20:48

DataVRDictionary; Should EVR_DS extended length = 1?

#1 Post by budric »

Hi,

I'm using post 3.6.0 trunk version bf1a1e13d24678c05d599cc16b942f83b02342c8. I was trying to save a StrutureSet to a file with write(dcmStrm, EXS_LittleEndianExplicit, EET_ExplicitLength, NULL); It fails with
E: DcmObject: Length of element ContourData (3006,0050) exceeds maximum of 16-bit length field
After much debugging I tracked it down to dcobject.cc writeTagAndLength() routine, which throws an error because VR (DS in this case) is not set to use extended length, and the length is more than 16 bits. That check seems to come from the data dictionary. Does that seem correct? I had a quick look at part 5 and part 6 but couldn't find if DS should not return usesExtendedLengthEncoding().

The code is posted below for your quick reference:

Code: Select all

dcobject.cc:
OFCondition DcmObject::writeTagAndLength(DcmOutputStream &outStream,
                                         const E_TransferSyntax oxfer,
                                         Uint32 &writtenBytes) const

            ...

            /* in case we are dealing with a transfer syntax with explicit VR (see if above) */
            /* and the actual VR uses extended length encoding (see DICOM standard part 5, */
            /* section 7.1.2) we have to add 2 reserved bytes (set to a value of 00H) to the */
            /* data type field and the actual length field is 4 bytes wide. Write the */
            /* corresponding information to the stream. */
            if (outvr.usesExtendedLengthEncoding())                        <-----------!!! Returns FALSE
            {
                Uint16 reserved = 0;
                outStream.write(&reserved, 2);                                      // write 2 reserved bytes to stream
                Uint32 valueLength = Length;                                        // determine length
                swapIfNecessary(oByteOrder, gLocalByteOrder, &valueLength, 4, 4);   // mind transfer syntax
                outStream.write(&valueLength, 4);                                   // write length, 4 bytes wide
                writtenBytes += 6;                                                  // remember that 6 bytes were written in total
            }
            /* in case that we are dealing with a transfer syntax with explicit VR (see if above) and */
            /* the actual VR does not use extended length encoding (see DICOM standard part 5, section */
            /* 7.1.2) we do not have to add reserved bytes to the data type field and the actual length */
            /* is 2 bytes wide. Write the corresponding information to the stream. But, make sure that */
            /* the length really fits into the 2-byte field ... */
            else if (Length <= 0xffff)
            {
                Uint16 valueLength = OFstatic_cast(Uint16, Length);                 // determine length (cast to 16 bit)
                swapIfNecessary(oByteOrder, gLocalByteOrder, &valueLength, 2, 2);   // mind transfer syntax
                outStream.write(&valueLength, 2);                                   // write length, 2 bytes wide
                writtenBytes += 2;                                                  // remember that 2 bytes were written in total
            }
            /* ... if not, report an error message and return an error code. */
            else {
                DcmTag tag(Tag);
                DCMDATA_ERROR("DcmObject: Length of element " << tag.getTagName() << " " << tag
                    << " exceeds maximum of 16-bit length field");
                l_error = EC_ElemLengthExceeds16BitField;
            }

And dcvr.cc
OFBool
DcmVR::usesExtendedLengthEncoding() const
{
    return (DcmVRDict[vr].propertyFlags & DCMVR_PROP_EXTENDEDLENGTHENCODING) ? OFTrue : OFFalse;
}
My current fix is to write with Implicit transfer syntax which doesn't do those checks.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: DataVRDictionary; Should EVR_DS extended length = 1?

#2 Post by J. Riesmeier »

This is a known issue (with the DICOM standard, not with the DCMTK). CP-1066 (Encoding of Attributes with value length > 64kB with Explicit VR) is intended to fix/clarify this.

Bottom line: Currently, you have to use implicit VR encoding (as you did) if you need to store more than 64 kB in a DS element.

budric
Posts: 29
Joined: Thu, 2007-06-28, 20:48

Re: DataVRDictionary; Should EVR_DS extended length = 1?

#3 Post by budric »

Thanks for the clarification.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest