Exemplo n.º 1
0
 public static void SkipItemLittleEndian(DICOMBinaryReader dr, TransferSyntax syntax)
 {
     int length = LengthReader.ReadLittleEndian(VR.Null, dr.Skip(4));
     if (length != -1)
     {
         dr.Skip(length);
     }
     else
     {
         if (syntax == TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN)
         {
             while (!IsEndOfSequenceItemLittleEndian(dr))
             {
                 dr.StreamPosition -= 8;
                 DICOMElementReader.SkipElementExplicitLittleEndian(dr);
             }
         }
         else
         {
             while (!IsEndOfSequenceItemLittleEndian(dr))
             {
                 dr.StreamPosition -= 8;
                 DICOMElementReader.SkipElementImplicitLittleEndian(dr);
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void SkipItemLittleEndian(DICOMBinaryReader dr, TransferSyntax syntax)
        {
            var length = LengthReader.ReadLittleEndian(VR.Null, dr.Skip(4));

            if (length != -1)
            {
                dr.Skip(length);
            }
            else
            {
                if (syntax == TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN)
                {
                    while (!IsEndOfSequenceItemLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
                    {
                        dr.StreamPosition -= 8;
                        DICOMElementReader.SkipElementExplicitLittleEndian(dr);
                    }
                }
                else
                {
                    while (!IsEndOfSequenceItemLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
                    {
                        dr.StreamPosition -= 8;
                        DICOMElementReader.SkipElementImplicitLittleEndian(dr);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static void SkipElementImplicitLittleEndian(DICOMBinaryReader dr)
 {
     Tag tag = TagReader.ReadLittleEndian(dr);
     int length = LengthReader.ReadLittleEndian(VR.Null, dr);
     if (length != -1)
     {
         dr.Skip(length);
     }
     else
     {
         dr.Skip(SequenceReader.ReadIndefiniteLengthLittleEndian(dr, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN));
         dr.Skip(8);
     }
 }
Exemplo n.º 4
0
        public static void SkipElementImplicitLittleEndian(DICOMBinaryReader dr)
        {
            var tag    = TagReader.ReadLittleEndian(dr);
            var length = LengthReader.ReadLittleEndian(VR.Null, dr);

            if (length != -1)
            {
                dr.Skip(length);
            }
            else
            {
                dr.Skip(SequenceReader.ReadIndefiniteLengthLittleEndian(dr, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN));
                dr.Skip(8);
            }
        }
Exemplo n.º 5
0
 public static void SkipItemBigEndian(DICOMBinaryReader dr)
 {
     int length = LengthReader.ReadBigEndian(VR.Null, dr.Skip(4));
     if (length != -1)
     {
         dr.Skip(length);
     }
     else
     {
         while (!IsEndOfSequenceItemBigEndian(dr))
         {
             dr.StreamPosition -= 8;
             DICOMElementReader.SkipElementExplicitBigEndian(dr);
         }
     }
 }
Exemplo n.º 6
0
        public static void SkipElementExplicitBigEndian(DICOMBinaryReader dr)
        {
            var tag    = TagReader.ReadBigEndian(dr);
            var vr     = VRReader.ReadVR(dr);
            var length = LengthReader.ReadBigEndian(vr, dr);

            if (length != -1)
            {
                dr.Skip(length);
            }
            else
            {
                dr.Skip(SequenceReader.ReadIndefiniteLengthBigEndian(dr));
                dr.Skip(8);
            }
        }
Exemplo n.º 7
0
        public static void SkipElementExplicitLittleEndian(DICOMBinaryReader dr)
        {
            Tag tag    = TagReader.ReadLittleEndian(dr);
            VR  vr     = VRReader.ReadVR(dr);
            int length = LengthReader.ReadLittleEndian(vr, dr);

            if (length != -1)
            {
                dr.Skip(length);
            }
            else
            {
                dr.Skip(SequenceReader.ReadIndefiniteLengthLittleEndian(dr, TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN));
                dr.Skip(8);
            }
        }
Exemplo n.º 8
0
 public static int? ReadMaxLength(DICOMBinaryReader dr)
 {
     AssertItemType(dr, "Maximum Length", ItemType.MAXIMUM_LENGTH);
     dr.Skip(2); // PDU ID and Reserved Null Byte
     int length = LengthReader.ReadBigEndian(dr, 2);
     return LengthReader.ReadBigEndian(dr, 4);
 }
Exemplo n.º 9
0
 private static string ReadUIDItem(DICOMBinaryReader dr, string itemName, ItemType iType)
 {
     AssertItemType(dr, itemName, iType);
     dr.Skip(2); // PDU ID and Reserved Null Byte
     int length = LengthReader.ReadBigEndian(dr, 2);
     return dr.ReadString(length).Trim();
 }
Exemplo n.º 10
0
        public static void SkipItemBigEndian(DICOMBinaryReader dr)
        {
            var length = LengthReader.ReadBigEndian(VR.Null, dr.Skip(4));

            if (length != -1)
            {
                dr.Skip(length);
            }
            else
            {
                while (!IsEndOfSequenceItemBigEndian(dr) && dr.StreamLength != dr.StreamPosition)
                {
                    dr.StreamPosition -= 8;
                    DICOMElementReader.SkipElementExplicitBigEndian(dr);
                }
            }
        }
Exemplo n.º 11
0
 public static AsyncOperations ReadAsyncOperations(DICOMBinaryReader dr)
 {
     AssertItemType(dr, "Async Operations", ItemType.ASYNCHRONOUS_OPERATIONS_WINDOW);
     var ao = new AsyncOperations();
     dr.Skip(2); // // PDU ID and Reserved Null Byte
     int length = LengthReader.ReadBigEndian(dr, 2);
     ao.MaxInvokeOperations = LengthReader.ReadBigEndian(dr, 2);
     ao.MaxPerformOperations = LengthReader.ReadBigEndian(dr, 2);
     return ao;
 }
Exemplo n.º 12
0
 /// <summary>
 ///     Reads the data from an element encoded in little endian byte order
 /// </summary>
 /// <param name="lengthToRead">the length of the data</param>
 /// <param name="dr">the binary reader which is reading the DICOM object</param>
 /// <returns>the data from this element</returns>
 public static byte[] ReadLittleEndian(int lengthToRead, DICOMBinaryReader dr, TransferSyntax syntax)
 {
     if (lengthToRead != -1)
     {
         return dr.ReadBytes(lengthToRead);
     }
     int length = SequenceReader.ReadIndefiniteLengthLittleEndian(dr, syntax);
     byte[] seqBytes = dr.ReadBytes(length);
     dr.Skip(8);
     return seqBytes;
 }
Exemplo n.º 13
0
 /// <summary>
 ///     Reads the data from an element encoded in big endian byte order
 /// </summary>
 /// <param name="lengthToRead">the length of the data</param>
 /// <param name="dr">the binary reader which is reading the DICOM object</param>
 /// <returns>the data from this element</returns>
 public static byte[] ReadBigEndian(int lengthToRead, DICOMBinaryReader dr)
 {
     if (lengthToRead != -1)
     {
         return dr.ReadBytes(lengthToRead);
     }
     int length = SequenceReader.ReadIndefiniteLengthBigEndian(dr);
     byte[] seqBytes = dr.ReadBytes(length);
     dr.Skip(8);
     return seqBytes;
 }
Exemplo n.º 14
0
        /// <summary>
        ///     Reads the data from an element encoded in big endian byte order
        /// </summary>
        /// <param name="lengthToRead">the length of the data</param>
        /// <param name="dr">the binary reader which is reading the DICOM object</param>
        /// <returns>the data from this element</returns>
        public static byte[] ReadBigEndian(int lengthToRead, DICOMBinaryReader dr)
        {
            if (lengthToRead != -1)
            {
                return(dr.ReadBytes(lengthToRead));
            }
            var length   = SequenceReader.ReadIndefiniteLengthBigEndian(dr);
            var seqBytes = dr.ReadBytes(length);

            dr.Skip(8);
            return(seqBytes);
        }
Exemplo n.º 15
0
        /// <summary>
        ///     Reads the data from an element encoded in little endian byte order
        /// </summary>
        /// <param name="lengthToRead">the length of the data</param>
        /// <param name="dr">the binary reader which is reading the DICOM object</param>
        /// <returns>the data from this element</returns>
        public static byte[] ReadLittleEndian(int lengthToRead, DICOMBinaryReader dr, TransferSyntax syntax)
        {
            if (lengthToRead != -1)
            {
                return(dr.ReadBytes(lengthToRead));
            }
            var length   = SequenceReader.ReadIndefiniteLengthLittleEndian(dr, syntax);
            var seqBytes = dr.ReadBytes(length);

            dr.Skip(8);
            return(seqBytes);
        }
Exemplo n.º 16
0
        public static DICOMObject ReadBigEndian(DICOMBinaryReader dr, TransferSyntax syntax)
        {
            DICOMObject d;
            int length = LengthReader.ReadLittleEndian(VR.Null, dr.Skip(4));
            if (LengthReader.IsIndefinite(length))
            {
                d = ReadIndefiniteBigEndian(dr, syntax);
            }
            else
            {
                d = DICOMObjectReader.ReadObject(dr.ReadBytes(length), syntax);
            }

            return d;
        }
Exemplo n.º 17
0
        public static DICOMObject ReadBigEndian(DICOMBinaryReader dr, TransferSyntax syntax)
        {
            DICOMObject d;
            int         length = LengthReader.ReadLittleEndian(VR.Null, dr.Skip(4));

            if (LengthReader.IsIndefinite(length))
            {
                d = ReadIndefiniteBigEndian(dr, syntax);
            }
            else
            {
                d = DICOMObjectReader.ReadObject(dr.ReadBytes(length), syntax);
            }

            return(d);
        }
Exemplo n.º 18
0
        public static DICOMObject ReadLittleEndian(DICOMBinaryReader dr, TransferSyntax syntax)
        {
            DICOMObject d;

            //Skip tag
            dr.Skip(4);
            int length = LengthReader.ReadLittleEndian(VR.Null, dr);

            if (LengthReader.IsIndefinite(length))
            {
                d = ReadIndefiniteLittleEndian(dr, syntax);
            }
            else
            {
            }

            return(null);
        }
Exemplo n.º 19
0
        public static DICOMObject ReadBigEndian(DICOMBinaryReader dr, TransferSyntax syntax, StringEncoding enc)
        {
            DICOMObject d;

            //Skip tag
            dr.Skip(4);
            var length = LengthReader.ReadBigEndian(VR.Null, dr);

            if (LengthReader.IsIndefinite(length))
            {
                d = ReadIndefiniteBigEndian(dr, syntax, enc);
            }
            else
            {
                d = DICOMObjectReader.ReadObject(dr.ReadBytes(length), syntax);
            }

            return(d);
        }
Exemplo n.º 20
0
        /// <summary>
        ///     Reads the length in big endian byte format from a series of bytes in a stream. The number of bytes is automatically
        ///     determined from
        ///     VR.
        /// </summary>
        /// <param name="vr">the value representation of the element</param>
        /// <param name="dr">the binary stream with a current position on the length parameter</param>
        /// <returns></returns>
        public static int ReadBigEndian(VR vr, DICOMBinaryReader dr)
        {
            byte[] bytes = null;

            switch (VRDictionary.GetEncodingFromVR(vr))
            {
            case VREncoding.Implicit:
                bytes = dr.ReadBytes(4);
                break;

            case VREncoding.ExplicitLong:
                bytes = dr.Skip(2).ReadBytes(4);
                break;

            case VREncoding.ExplicitShort:
                bytes = dr.ReadBytes(2);
                break;
            }
            return(ReadBigEndian(bytes));
        }
Exemplo n.º 21
0
        /// <summary>
        ///     Reads the length in little endian byte format from a series of bytes in a stream. The number of bytes is
        ///     automatically determined from
        ///     VR.
        /// </summary>
        /// <param name="vr">the value representation of the element</param>
        /// <param name="dr">the binary stream with a current position on the length parameter</param>
        /// <returns></returns>
        public static int ReadLittleEndian(VR vr, DICOMBinaryReader dr)
        {
            int length = 0;

            switch (VRDictionary.GetEncodingFromVR(vr))
            {
                case VREncoding.Implicit:
                    byte[] byteLength = dr.ReadBytes(4);
                    length = BitConverter.ToInt32(byteLength, 0);
                    break;
                case VREncoding.ExplicitLong:
                    byteLength = dr.Skip(2).ReadBytes(4);
                    length = BitConverter.ToInt32(byteLength, 0);
                    break;
                case VREncoding.ExplicitShort:
                    byteLength = dr.ReadBytes(2);
                    length = BitConverter.ToUInt16(byteLength, 0);
                    break;
            }
            return length;
        }
Exemplo n.º 22
0
        /// <summary>
        ///     Reads the length in little endian byte format from a series of bytes in a stream. The number of bytes is
        ///     automatically determined from
        ///     VR.
        /// </summary>
        /// <param name="vr">the value representation of the element</param>
        /// <param name="dr">the binary stream with a current position on the length parameter</param>
        /// <returns></returns>
        public static int ReadLittleEndian(VR vr, DICOMBinaryReader dr)
        {
            int length = 0;

            switch (VRDictionary.GetEncodingFromVR(vr))
            {
            case VREncoding.Implicit:
                byte[] byteLength = dr.ReadBytes(4);
                length = BitConverter.ToInt32(byteLength, 0);
                break;

            case VREncoding.ExplicitLong:
                byteLength = dr.Skip(2).ReadBytes(4);
                length     = BitConverter.ToInt32(byteLength, 0);
                break;

            case VREncoding.ExplicitShort:
                byteLength = dr.ReadBytes(2);
                length     = BitConverter.ToUInt16(byteLength, 0);
                break;
            }
            return(length);
        }
Exemplo n.º 23
0
        /// <summary>
        ///     Reads the length in big endian byte format from a series of bytes in a stream. The number of bytes is automatically
        ///     determined from
        ///     VR.
        /// </summary>
        /// <param name="vr">the value representation of the element</param>
        /// <param name="dr">the binary stream with a current position on the length parameter</param>
        /// <returns></returns>
        public static int ReadBigEndian(VR vr, DICOMBinaryReader dr)
        {
            byte[] bytes = null;

            switch (VRDictionary.GetEncodingFromVR(vr))
            {
                case VREncoding.Implicit:
                    bytes = dr.ReadBytes(4);
                    break;
                case VREncoding.ExplicitLong:
                    bytes = dr.Skip(2).ReadBytes(4);
                    break;
                case VREncoding.ExplicitShort:
                    bytes = dr.ReadBytes(2);
                    break;
            }
            return ReadBigEndian(bytes);
        }
Exemplo n.º 24
0
 public static void SkipElementExplicitBigEndian(DICOMBinaryReader dr)
 {
     Tag tag = TagReader.ReadBigEndian(dr);
     VR vr = VRReader.Read(dr);
     int length = LengthReader.ReadBigEndian(vr, dr);
     if (length != -1)
     {
         dr.Skip(length);
     }
     else
     {
         dr.Skip(SequenceReader.ReadIndefiniteLengthBigEndian(dr));
         dr.Skip(8);
     }
 }
Exemplo n.º 25
0
 public static UserInfo ReadUserInfo(DICOMBinaryReader dr)
 {
     AssertItemType(dr, "User Info", ItemType.USER_INFO);
     var ui = new UserInfo();
     dr.Skip(2); // PDU ID and Reserved Null Byte
     int length = LengthReader.ReadBigEndian(dr, 2);
     if (length > 0)
     {
         ui.MaxPDULength = (int) ReadMaxLength(dr);
         ui.ImplementationUID = ReadImplementationClassUID(dr);
         if (dr.Peek(1)[0] == (byte) ItemType.ASYNCHRONOUS_OPERATIONS_WINDOW)
         {
             ui.AsynchronousOperations = ReadAsyncOperations(dr);
         }
         ui.ImplementationVersion = ReadImplementationVersion(dr);
     }
     return ui;
 }
Exemplo n.º 26
0
 public static PresentationContext ReadPresentationCtxAccept(DICOMBinaryReader dr)
 {
     AssertItemType(dr, "Presentation Context Accept", ItemType.PRESENTATION_CONTEXT_ACCEPT);
     dr.Skip(2); // PDU id Reserved Null Byte
     int length = LengthReader.ReadBigEndian(dr, 2);
     return ReadPresentationCtxContents(dr.Take(length));
 }
Exemplo n.º 27
0
 private static PresentationContext ReadPresentationCtxContents(byte[] contents, bool requestType = false)
 {
     var pc = new PresentationContext();
     pc.TransferSyntaxes = new List<string>();
     using (var dr = new DICOMBinaryReader(contents))
     {
         pc.Id = dr.Take(1)[0];
         dr.Skip(1); //Reserved Null Byte
         pc.Reason = (PresentationContextReason) Enum.ToObject(typeof (PresentationContextReason), dr.Take(1)[0]);
         dr.Skip(1); //Reserved Null Byte
         if (requestType)
         {
             pc.AbstractSyntax = ReadAbstractSyntax(dr).Trim();
         }
         while (dr.StreamPosition < dr.StreamLength)
         {
             long initPos = dr.StreamPosition;
             pc.TransferSyntaxes.Add(ReadTransferSyntax(dr));
             if (dr.StreamPosition == initPos)
             {
                 break;
             }
         }
     }
     return pc;
 }