BizHawk/BizHawk.Client.EmuHawk/AVOut/BmpVideoProvder.cs

64 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Drawing;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
2017-04-18 17:27:44 +00:00
/// an IVideoProvider wrapping a Bitmap
/// </summary>
public class BmpVideoProvider : IVideoProvider, IDisposable
{
2017-04-18 17:27:44 +00:00
private Bitmap _bmp;
public BmpVideoProvider(Bitmap bmp)
{
2017-04-18 17:27:44 +00:00
_bmp = bmp;
}
public void Dispose()
{
2017-04-18 17:27:44 +00:00
if (_bmp != null)
{
2017-04-18 17:27:44 +00:00
_bmp.Dispose();
_bmp = null;
}
}
public int[] GetVideoBuffer()
{
// is there a faster way to do this?
2017-04-18 17:27:44 +00:00
var data = _bmp.LockBits(new Rectangle(0, 0, _bmp.Width, _bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
2017-04-18 17:27:44 +00:00
int[] ret = new int[_bmp.Width * _bmp.Height];
// won't work if stride is messed up
2017-04-18 17:27:44 +00:00
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, ret, 0, _bmp.Width * _bmp.Height);
_bmp.UnlockBits(data);
return ret;
}
2017-04-18 17:27:44 +00:00
public int VirtualWidth => _bmp.Width;
2017-04-18 17:27:44 +00:00
// todo: Bitmap actually has size metric data; use it
public int VirtualHeight => _bmp.Height;
2017-04-18 17:27:44 +00:00
public int BufferWidth => _bmp.Width;
2017-04-18 17:27:44 +00:00
public int BufferHeight => _bmp.Height;
2017-04-18 17:27:44 +00:00
public int BackgroundColor => 0;
2017-05-05 16:25:38 +00:00
public int VsyncNumerator
{
get { throw new InvalidOperationException(); }
}
2017-05-05 16:25:38 +00:00
public int VsyncDenominator
{
get { throw new InvalidOperationException(); }
}
}
}