コード例 #1
0
ファイル: QuickBmpFile.cs プロジェクト: Techokami/BizHawk
        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);
        }
コード例 #2
0
ファイル: QuickBmpFile.cs プロジェクト: Techokami/BizHawk
        public static unsafe void Save(IVideoProvider v, Stream s, int w, int h)
        {
            var bf = new Bitmapfileheader();
            var bi = new Bitmapinfoheader();

            bf.bfType    = 0x4d42;
            bf.bfOffBits = bf.bfSize + bi.biSize;

            bi.biPlanes      = 1;
            bi.biBitCount    = 32;          // xrgb
            bi.biCompression = BitmapCompressionMode.BI_RGB;
            bi.biSizeImage   = (uint)(w * h * 4);
            bi.biWidth       = w;
            bi.biHeight      = h;

            byte[] bfb = GetBytes(bf);
            byte[] bib = GetBytes(bi);

            s.Write(bfb, 0, bfb.Length);
            s.Write(bib, 0, bib.Length);

            int[]  src = v.GetVideoBuffer();
            byte[] dst = new byte[4 * w * h];

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

            s.Write(dst, 0, dst.Length);
        }