screenshot: add optimized hotpath for original size screenshots
This commit is contained in:
parent
ad08c0abfb
commit
30fea2e6a7
|
@ -94,6 +94,55 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe struct BMP
|
||||||
|
{
|
||||||
|
public int* Data;
|
||||||
|
public int Width;
|
||||||
|
public int Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Blit(BMP src, BMP dst)
|
||||||
|
{
|
||||||
|
if (src.Width == dst.Width && src.Height == dst.Height)
|
||||||
|
Blit_Same(src, dst);
|
||||||
|
else
|
||||||
|
Blit_Any(src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe static void Blit_Same(BMP src, BMP dst)
|
||||||
|
{
|
||||||
|
int* sp = src.Data + src.Width * (src.Height - 1);
|
||||||
|
int* dp = dst.Data;
|
||||||
|
for (int j = 0; j < src.Height; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < src.Width; i++)
|
||||||
|
dp[i] = sp[i];
|
||||||
|
sp -= src.Width;
|
||||||
|
dp += src.Width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe static void Blit_Any(BMP src, BMP dst)
|
||||||
|
{
|
||||||
|
int w = dst.Width;
|
||||||
|
int h = dst.Height;
|
||||||
|
int in_w = src.Width;
|
||||||
|
int in_h = src.Height;
|
||||||
|
int* sp = src.Data;
|
||||||
|
int* dp = dst.Data;
|
||||||
|
|
||||||
|
// vflip along the way
|
||||||
|
for (int j = h - 1; j >= 0; j--)
|
||||||
|
{
|
||||||
|
sp = src.Data + in_w * (j * in_h / h);
|
||||||
|
for (int i = 0; i < w; i++)
|
||||||
|
{
|
||||||
|
dp[i] = sp[i * in_w / w];
|
||||||
|
}
|
||||||
|
dp += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public unsafe static bool Load(IVideoProvider v, Stream s)
|
public unsafe static bool Load(IVideoProvider v, Stream s)
|
||||||
{
|
{
|
||||||
var bf = BITMAPFILEHEADER.FromStream(s);
|
var bf = BITMAPFILEHEADER.FromStream(s);
|
||||||
|
@ -114,22 +163,19 @@ namespace BizHawk.Client.Common
|
||||||
fixed (byte *srcp = src)
|
fixed (byte *srcp = src)
|
||||||
fixed (int* dstp = dst)
|
fixed (int* dstp = dst)
|
||||||
{
|
{
|
||||||
int w = v.BufferWidth;
|
using (new BizHawk.Common.SimpleTime("Blit"))
|
||||||
int h = v.BufferHeight;
|
Blit(new BMP
|
||||||
|
|
||||||
int* sp = (int*)srcp;
|
|
||||||
int* dp = dstp;
|
|
||||||
|
|
||||||
// vflip along the way
|
|
||||||
for (int j = h - 1; j >= 0; j--)
|
|
||||||
{
|
{
|
||||||
sp = (int*)srcp + in_w * (j * in_h / h);
|
Data = (int*)srcp,
|
||||||
for (int i = 0; i < w; i++)
|
Width = in_w,
|
||||||
{
|
Height = in_h
|
||||||
dp[i] = sp[i * in_w / w];
|
},
|
||||||
}
|
new BMP
|
||||||
dp += w;
|
{
|
||||||
}
|
Data = dstp,
|
||||||
|
Width = v.BufferWidth,
|
||||||
|
Height = v.BufferHeight,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -161,22 +207,19 @@ namespace BizHawk.Client.Common
|
||||||
fixed (int* srcp = src)
|
fixed (int* srcp = src)
|
||||||
fixed (byte* dstp = dst)
|
fixed (byte* dstp = dst)
|
||||||
{
|
{
|
||||||
int in_w = v.BufferWidth;
|
using (new BizHawk.Common.SimpleTime("Blit"))
|
||||||
int in_h = v.BufferHeight;
|
Blit(new BMP
|
||||||
|
|
||||||
int* sp = srcp;
|
|
||||||
int* dp = (int*)dstp;
|
|
||||||
|
|
||||||
// vflip along the way
|
|
||||||
for (int j = h - 1; j >= 0; j--)
|
|
||||||
{
|
{
|
||||||
sp = srcp + in_w * (j * in_h / h);
|
Data = srcp,
|
||||||
for (int i = 0; i < w; i++)
|
Width = v.BufferWidth,
|
||||||
{
|
Height = v.BufferHeight
|
||||||
dp[i] = sp[i * in_w / w];
|
},
|
||||||
}
|
new BMP
|
||||||
dp += w;
|
{
|
||||||
}
|
Data = (int*)dstp,
|
||||||
|
Width = w,
|
||||||
|
Height = h,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Write(dst, 0, dst.Length);
|
s.Write(dst, 0, dst.Length);
|
||||||
|
|
|
@ -67,7 +67,8 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QuickBmpFile.Load(Global.Emulator.VideoProvider(), br.BaseStream);
|
using (new SimpleTime("Load Framebuffer"))
|
||||||
|
QuickBmpFile.Load(Global.Emulator.VideoProvider(), br.BaseStream);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue