Пример #1
0
            public override UInt32 ReadBlock(GR.Memory.ByteBuffer BufferTarget, UInt32 BytesToRead)
            {
                if (m_Stream == null)
                {
                    return(0);
                }

                int bytesInCache = (int)m_Cache.Length - m_CacheBytesUsed;

                // full in cache
                if (BytesToRead <= bytesInCache)
                {
                    BufferTarget.Resize(BytesToRead);
                    m_Cache.CopyTo(BufferTarget, m_CacheBytesUsed, (int)BytesToRead);
                    m_CacheBytesUsed += (int)BytesToRead;
                    return(BytesToRead);
                }

                UInt32 bytesRead = 0;

                // partially in cache
                BufferTarget.Resize((uint)bytesInCache);
                m_Cache.CopyTo(BufferTarget, m_CacheBytesUsed, bytesInCache);
                m_CacheBytesUsed += bytesInCache;
                BytesToRead      -= (uint)bytesInCache;

                bytesRead = (UInt32)bytesInCache;


                UInt32 BytesToReadNow = BytesToRead;

                if (m_Stream.Position + BytesToRead > m_Stream.Length)
                {
                    BytesToReadNow = (UInt32)(m_Stream.Length - m_Stream.Position);
                }
                UInt32 OriginalLength = (UInt32)BufferTarget.Length;

                BufferTarget.Resize((UInt32)(BufferTarget.Length + BytesToReadNow));

                m_Stream.Read(BufferTarget.Data(), (int)OriginalLength, (int)BytesToReadNow);

                bytesRead += BytesToReadNow;

                return(bytesRead);
            }
Пример #2
0
            public override UInt32 ReadBlock(GR.Memory.ByteBuffer BufferTarget, UInt32 BytesToRead)
            {
                if (m_Buffer == null)
                {
                    return(0);
                }
                UInt32 BytesToReadNow = BytesToRead;

                if (m_Position + BytesToRead > m_Buffer.Length)
                {
                    BytesToReadNow = (UInt32)(m_Buffer.Length - m_Position);
                }
                UInt32 OriginalLength = (UInt32)BufferTarget.Length;

                BufferTarget.Resize((UInt32)(BufferTarget.Length + BytesToReadNow));

                for (int i = 0; i < BytesToReadNow; ++i)
                {
                    BufferTarget.SetU8At((int)OriginalLength + i, m_Buffer.ByteAt(m_Position + i));
                }
                m_Position += (int)BytesToReadNow;

                return(BytesToReadNow);
            }
Пример #3
0
        public void Create(int Width, int Height, System.Drawing.Imaging.PixelFormat PixelFormat)
        {
            Clear();

            m_Width       = Width;
            m_Height      = Height;
            m_PixelFormat = PixelFormat;

            int bytesPerLine = BitsPerPixel * Width / 8;

            m_ImageData.Resize((uint)(bytesPerLine * Height));

            switch (m_PixelFormat)
            {
            case System.Drawing.Imaging.PixelFormat.Format1bppIndexed:
                m_PaletteData = new GR.Memory.ByteBuffer(2 * 3);
                break;

            case System.Drawing.Imaging.PixelFormat.Format4bppIndexed:
                m_PaletteData = new GR.Memory.ByteBuffer(16 * 3);
                break;

            case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
                m_PaletteData = new GR.Memory.ByteBuffer(256 * 3);
                break;

            case System.Drawing.Imaging.PixelFormat.Format16bppRgb555:
            case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
            case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
            case System.Drawing.Imaging.PixelFormat.Format32bppRgb:
                break;

            default:
                throw new NotSupportedException("Pixelformat " + PixelFormat + " not supported");
            }
        }