예제 #1
0
        public static unsafe bool Load(IVideoProvider v, Stream s)
        {
            var bf = BITMAPFILEHEADER.FromStream(s);
            var bi = BITMAPINFOHEADER.FromStream(s);

            if (bf.bfType != 0x4d42 ||
                bf.bfOffBits != bf.bfSize + bi.biSize ||
                bi.biPlanes != 1 ||
                bi.biBitCount != 32 ||
                bi.biCompression != BitmapCompressionMode.BI_RGB)
            {
                return(false);
            }

            int inW = bi.biWidth;
            int inH = bi.biHeight;

            byte[] src = new byte[inW * inH * 4];
            s.Read(src, 0, src.Length);
            if (v is LoadedBMP)
            {
                var l = v as LoadedBMP;
                l.BufferWidth  = inW;
                l.BufferHeight = inH;
                l.VideoBuffer  = new int[inW * inH];
            }

            int[] dst = v.GetVideoBuffer();

            fixed(byte *srcp = src)
            fixed(int *dstp = dst)
            {
                using (new SimpleTime("Blit"))
                {
                    Blit(new BMP
                    {
                        Data   = (int *)srcp,
                        Width  = inW,
                        Height = inH
                    },
                         new BMP
                    {
                        Data   = dstp,
                        Width  = v.BufferWidth,
                        Height = v.BufferHeight,
                    });
                }
            }

            return(true);
        }