2012-09-21 18:01:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2012-09-21 18:01:24 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-04-18 17:27:44 +00:00
|
|
|
|
/// an IVideoProvider wrapping a Bitmap
|
2012-09-21 18:01:24 +00:00
|
|
|
|
/// </summary>
|
2014-06-02 20:16:59 +00:00
|
|
|
|
public class BmpVideoProvider : IVideoProvider, IDisposable
|
2012-09-21 18:01:24 +00:00
|
|
|
|
{
|
2017-04-18 17:27:44 +00:00
|
|
|
|
private Bitmap _bmp;
|
|
|
|
|
|
2017-06-16 00:40:38 +00:00
|
|
|
|
public BmpVideoProvider(Bitmap bmp, int vsyncnum, int vsyncden)
|
2012-09-21 18:01:24 +00:00
|
|
|
|
{
|
2017-04-18 17:27:44 +00:00
|
|
|
|
_bmp = bmp;
|
2017-06-16 00:40:38 +00:00
|
|
|
|
VsyncNumerator = vsyncnum;
|
|
|
|
|
VsyncDenominator = vsyncden;
|
2012-09-21 18:01:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-26 02:25:23 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2017-04-18 17:27:44 +00:00
|
|
|
|
if (_bmp != null)
|
2012-11-26 02:25:23 +00:00
|
|
|
|
{
|
2017-04-18 17:27:44 +00:00
|
|
|
|
_bmp.Dispose();
|
|
|
|
|
_bmp = null;
|
2012-11-26 02:25:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-21 18:01:24 +00:00
|
|
|
|
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);
|
2012-09-21 18:01:24 +00:00
|
|
|
|
|
2017-04-18 17:27:44 +00:00
|
|
|
|
int[] ret = new int[_bmp.Width * _bmp.Height];
|
2012-09-21 18:01:24 +00:00
|
|
|
|
|
|
|
|
|
// 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);
|
2012-09-21 18:01:24 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 17:27:44 +00:00
|
|
|
|
public int VirtualWidth => _bmp.Width;
|
2012-09-21 18:01:24 +00:00
|
|
|
|
|
2017-04-18 17:27:44 +00:00
|
|
|
|
// todo: Bitmap actually has size metric data; use it
|
|
|
|
|
public int VirtualHeight => _bmp.Height;
|
2014-04-30 23:48:37 +00:00
|
|
|
|
|
2017-04-18 17:27:44 +00:00
|
|
|
|
public int BufferWidth => _bmp.Width;
|
2012-09-21 18:01:24 +00:00
|
|
|
|
|
2017-04-18 17:27:44 +00:00
|
|
|
|
public int BufferHeight => _bmp.Height;
|
2012-09-21 18:01:24 +00:00
|
|
|
|
|
2017-04-18 17:27:44 +00:00
|
|
|
|
public int BackgroundColor => 0;
|
2017-05-05 16:21:37 +00:00
|
|
|
|
|
2017-06-16 00:40:38 +00:00
|
|
|
|
public int VsyncNumerator { get; private set; }
|
2017-05-05 16:21:37 +00:00
|
|
|
|
|
2017-06-16 00:40:38 +00:00
|
|
|
|
public int VsyncDenominator { get; private set; }
|
2012-09-21 18:01:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|