/// <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; }
/// <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; }
/// <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); }
/// <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); }
public static Tag ReadLittleEndian(DICOMBinaryReader dr) { var tag = dr.ReadBytes(4); tag = new[] { tag[1], tag[0], tag[3], tag[2] }; return(CreateTag(tag)); }
public static PDVItemFragment ReadPDVFragment(DICOMBinaryReader dr, int length) { var pif = new PDVItemFragment(); byte messageHeader = dr.Take(1)[0]; pif.IsCommandObject = messageHeader.GetBit(0); pif.IsLastItem = messageHeader.GetBit(1); pif.Data = dr.ReadBytes(length - 1); return pif; }
/// <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)); }
/// <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; }
/// <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); }
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; }
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); }
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); }
/// <summary> /// Reads the first 132 bits of a file to check if it contains the DICOM preamble. /// </summary> /// <param name="dr">a stream containing the bits of the file</param> /// <returns>a boolean indicating whether or not the DICOM preamble was in the file</returns> public static bool Read(DICOMBinaryReader dr) { byte[] preamble = new byte[132]; try { dr.ReadBytes(preamble, 0, 132); } catch (Exception) { throw new Exception("Could not read 128 null bit preamble. Perhaps file is too short"); } if (preamble[128] != 'D' || preamble[129] != 'I' || preamble[130] != 'C' || preamble[131] != 'M') { Console.WriteLine("Missing characters D I C M in bits 128-131. Technically not a valid DICOM file. Will try to read anyway."); dr.Reset(); return false; } else { return true; } }
/// <summary> /// Reads the first 132 bits of a file to check if it contains the DICOM preamble. /// </summary> /// <param name="dr">a stream containing the bits of the file</param> /// <returns>a boolean indicating whether or not the DICOM preamble was in the file</returns> public static bool Read(DICOMBinaryReader dr) { byte[] preamble = new byte[132]; try { dr.ReadBytes(preamble, 0, 132); } catch (Exception) { throw new Exception("Could not read 128 null bit preamble. Perhaps file is too short"); } if (preamble[128] != 'D' || preamble[129] != 'I' || preamble[130] != 'C' || preamble[131] != 'M') { Console.WriteLine("Missing characters D I C M in bits 128-131. Technically not a valid DICOM file. Will try to read anyway."); dr.Reset(); return(false); } else { return(true); } }
/// <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); }
public static Tag ReadLittleEndian(DICOMBinaryReader dr) { byte[] tag = dr.ReadBytes(4); tag = new[] {tag[1], tag[0], tag[3], tag[2]}; return CreateTag(tag); }
public static Tag ReadBigEndian(DICOMBinaryReader dr) { byte[] tag = dr.ReadBytes(4); return CreateTag(tag); }
private static bool IsEndOfSequenceItemLittleEndian(DICOMBinaryReader dr) { byte[] bytes = dr.ReadBytes(8); return(ByteHelper.AreEqual(bytes, _endOfSequenceItem_LE)); }
public static Tag ReadBigEndian(DICOMBinaryReader dr) { byte[] tag = dr.ReadBytes(4); return(CreateTag(tag)); }
private static bool IsEndOfSequenceItemBigEndian(DICOMBinaryReader dr) { byte[] bytes = dr.ReadBytes(8); return ByteHelper.AreEqual(bytes, _endOfSequenceItem_BE); }
private static bool IsEndOfSequenceItemBigEndian(DICOMBinaryReader dr) { var bytes = dr.ReadBytes(8); return(ByteHelper.AreEqual(bytes, _endOfSequenceItem_BE)); }