コード例 #1
0
        public Bitmap DecodeImage(Stream inps)
        {
            if (inps == null)
            {
                return(null);
            }

            // !!!{{ TODO: add the decoding code here

            IEntropyCodec c = new DeflateCodec();

            c.BinaryStream = inps;
            c.Open(false);

            uint magic = (uint)c.GetBits(32);

            if (magic != MAGIC)
            {
                return(null);
            }

            int width, height;

            width  = (int)c.GetBits(16);
            height = (int)c.GetBits(16);

            if (width < 1 || height < 1)
            {
                return(null);
            }

            Bitmap result = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int gr = c.Get();
                    if (gr < 0)
                    {
                        goto fin;
                    }
                    result.SetPixel(x, y, Color.FromArgb(gr, gr, gr));
                }
            }

fin:
            c.Close();

            return(result);

            // !!!}}
        }
コード例 #2
0
ファイル: VideoCodec.cs プロジェクト: maoap1/grcis-1
        public IEntropyCodec DecodeHeader(Stream inps)
        {
            if (inps == null)
            {
                return(null);
            }

            IEntropyCodec c = new DeflateCodec();

            c.BinaryStream = inps;
            c.Open(false);

            // !!!{{ TODO: add the header decoding here

            // Check the global header:
            uint magic = (uint)c.GetBits(32);

            if (magic != MAGIC)
            {
                return(null);
            }

            frameWidth  = (int)c.GetBits(16);
            frameHeight = (int)c.GetBits(16);

            if (frameWidth < 1 || frameHeight < 1)
            {
                return(null);
            }

            framesPerSecond = (int)c.GetBits(16);

            // !!!}}

            return(c);
        }