Beispiel #1
0
        /// <summary>
        /// Initializes new PDU reader from buffer
        /// </summary>
        /// <param name="buffer">Buffer</param>
        public RawPDU(byte[] buffer)
        {
            _is = new MemoryStream(buffer);
            BinaryReader br = EndianBinaryReader.Create(_is, _encoding, Endian.Big);

            _type = br.ReadByte();
        }
Beispiel #2
0
 /// <summary>
 /// Initializes new PDU reader from buffer
 /// </summary>
 /// <param name="buffer">Buffer</param>
 public RawPDU(byte[] buffer)
 {
     _ms   = new MemoryStream(buffer);
     _br   = EndianBinaryReader.Create(_ms, _encoding, Endian.Big);
     _type = _br.ReadByte();
     _ms.Seek(6, SeekOrigin.Begin);
 }
Beispiel #3
0
            public RLEDecoder(IList <ByteBuffer> data)
            {
                uint size = 0;

                foreach (ByteBuffer frag in data)
                {
                    size += (uint)frag.Length;
                }
                MemoryStream stream = new MemoryStream(data[0].ToBytes());

                for (int i = 1; i < data.Count; i++)
                {
                    stream.Seek(0, SeekOrigin.End);
                    byte[] ba = data[i].ToBytes();
                    stream.Write(ba, 0, ba.Length);
                }
                BinaryReader reader = EndianBinaryReader.Create(stream, Endian.Little);

                _count   = (int)reader.ReadUInt32();
                _offsets = new int[15];
                for (int i = 0; i < 15; i++)
                {
                    _offsets[i] = reader.ReadInt32();
                }
                _data = new byte[stream.Length - 64];                 // take off 64 bytes for the offsets
                stream.Read(_data, 0, _data.Length);
            }
Beispiel #4
0
        /// <summary>
        /// Initializes new PDU reader from stream
        /// </summary>
        /// <param name="s">Input stream</param>
        public RawPDU(Stream s)
        {
            _is = s;
            BinaryReader br = EndianBinaryReader.Create(_is, _encoding, Endian.Big);

            _type = br.ReadByte();
        }
Beispiel #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// It is assumed that this constructor must be used when reading a PDU.  This constructor
        /// will not work when writing a PDU.
        /// </remarks>
        /// <param name="s">The Stream to read from.</param>
        public RawPDU(Stream s)
        {
            BinaryReader br = EndianBinaryReader.Create(s, Endian.Big);

            _type = br.ReadByte();      // PDU-Type
            _is   = s;
        }
Beispiel #6
0
        /// <summary>
        /// Reads PDU into memory
        /// </summary>
        public void ReadPDU()
        {
            _ms = new MemoryStream();
            BinaryReader br = EndianBinaryReader.Create(_is, _encoding, Endian.Big);

            br.ReadByte();
            uint len = br.ReadUInt32();                 // PDU-Length

            byte[] data = br.ReadBytes((int)len);
            _ms = new MemoryStream(data, false);
            _br = EndianBinaryReader.Create(_ms, _encoding, Endian.Big);
        }
Beispiel #7
0
        public void ReadPDU()
        {
            BinaryReader br = EndianBinaryReader.Create(_is, Endian.Big);

            _type = br.ReadByte();
            br.ReadByte();
            uint len = br.ReadUInt32(); // PDU-Length

            byte[] data = br.ReadBytes((int)len);
            _ms = new MemoryStream(data, 0, data.Length, false, true);
            _br = EndianBinaryReader.Create(_ms, Endian.Big);
        }
Beispiel #8
0
            public RLEDecoder(IList <DicomFragment> data)
            {
                uint size = 0;

                foreach (DicomFragment frag in data)
                {
                    size += frag.Length;
                }
                MemoryStream stream = new MemoryStream(data[0].GetByteArray());

                for (int i = 1; i < data.Count; i++)
                {
                    stream.Seek(0, SeekOrigin.End);
                    byte[] ba = data[i].GetByteArray();
                    stream.Write(ba, 0, ba.Length);
                }
                BinaryReader reader = EndianBinaryReader.Create(stream, Endian.Little);

                _count   = (int)reader.ReadUInt32();
                _offsets = new int[15];
                for (int i = 0; i < 15; i++)
                {
                    _offsets[i] = reader.ReadInt32();
                }
                _data = new byte[stream.Length - 64]; // take off 64 bytes for the offsets

                var tempBuffer = new byte[_data.Length];

                using (var ms = new MemoryStream())
                {
                    int read;
                    while ((read = stream.Read(tempBuffer, 0, tempBuffer.Length)) > 0)
                    {
                        ms.Write(tempBuffer, 0, read);
                    }

                    _data = ms.ToArray();
                }
            }
Beispiel #9
0
            //DCMTK djcodecd.cxx
            public static int ScanJpegForBitDepth(DicomPixelData pixelData)
            {
                DicomItem    item   = pixelData.Dataset.GetDicomItem <DicomItem>(DicomTag.PixelData);
                IByteBuffer  buffer = item is DicomFragmentSequence fragmentSequence ? fragmentSequence.Fragments[0] : (item as DicomElement).Buffer;
                var          ms     = new MemoryStream(buffer.Data);
                BinaryReader br     = EndianBinaryReader.Create(ms, Endian.Big);

                long length = ms.Length;

                while (ms.Position < length)
                {
                    ushort marker = br.ReadUInt16();
                    switch (marker)
                    {
                    case 0xffc0:     // SOF_0: JPEG baseline
                    case 0xffc1:     // SOF_1: JPEG extended sequential DCT
                    case 0xffc2:     // SOF_2: JPEG progressive DCT
                    case 0xffc3:     // SOF_3: JPEG lossless sequential
                    case 0xffc5:     // SOF_5: differential (hierarchical) extended sequential, Huffman
                    case 0xffc6:     // SOF_6: differential (hierarchical) progressive, Huffman
                    case 0xffc7:     // SOF_7: differential (hierarchical) lossless, Huffman
                        ms.Seek(2, SeekOrigin.Current);
                        return((int)br.ReadByte());

                    case 0xffc8:     // Reserved for JPEG extentions
                        ms.Seek(br.ReadUInt16() - 2, SeekOrigin.Current);
                        break;

                    case 0xffc9:     // SOF_9: extended sequential, arithmetic
                    case 0xffca:     // SOF_10: progressive, arithmetic
                    case 0xffcb:     // SOF_11: lossless, arithmetic
                    case 0xffcd:     // SOF_13: differential (hierarchical) extended sequential, arithmetic
                    case 0xffce:     // SOF_14: differential (hierarchical) progressive, arithmetic
                    case 0xffcf:     // SOF_15: differential (hierarchical) lossless, arithmetic
                        ms.Seek(2, SeekOrigin.Current);
                        return((int)br.ReadByte());

                    case 0xffc4:     // DHT
                    case 0xffcc:     // DAC
                        ms.Seek(br.ReadUInt16() - 2, SeekOrigin.Current);
                        break;

                    case 0xffd0:     // RST m
                    case 0xffd1:
                    case 0xffd2:
                    case 0xffd3:
                    case 0xffd4:
                    case 0xffd5:
                    case 0xffd6:
                    case 0xffd7:
                    case 0xffd8:     // SOI
                    case 0xffd9:     // EOI
                        break;

                    case 0xffda:     // SOS
                    case 0xffdb:     // DQT
                    case 0xffdc:     // DNL
                    case 0xffdd:     // DRI
                    case 0xffde:     // DHP
                    case 0xffdf:     // EXP
                    case 0xffe0:     // APPn
                    case 0xffe1:
                    case 0xffe2:
                    case 0xffe3:
                    case 0xffe4:
                    case 0xffe5:
                    case 0xffe6:
                    case 0xffe7:
                    case 0xffe8:
                    case 0xffe9:
                    case 0xffea:
                    case 0xffeb:
                    case 0xffec:
                    case 0xffed:
                    case 0xffee:
                    case 0xffef:
                    case 0xfff0:     // JPGn
                    case 0xfff1:
                    case 0xfff2:
                    case 0xfff3:
                    case 0xfff4:
                    case 0xfff5:
                    case 0xfff6:
                    case 0xfff7:
                    case 0xfff8:
                    case 0xfff9:
                    case 0xfffa:
                    case 0xfffb:
                    case 0xfffc:
                    case 0xfffd:
                    case 0xfffe:     // COM
                        ms.Seek(br.ReadUInt16() - 2, SeekOrigin.Current);
                        break;

                    case 0xff01:     // TEM
                        break;

                    default:
                        int b1 = br.ReadByte();
                        int b2 = br.ReadByte();
                        if (b1 == 0xff && b2 > 2 && b2 <= 0xbf)     // RES reserved markers
                        {
                            break;
                        }
                        else
                        {
                            throw new DicomCodecException("Unable to determine bit depth: JPEG syntax error!");
                        }
                    }
                }
                throw new DicomCodecException("Unable to determine bit depth: no JPEG SOF marker found!");
            }