It can actually take screenshots of the VM

This commit is contained in:
2026-02-09 14:26:11 +01:00
parent c4223d45e4
commit 9a333bb1c8
7 changed files with 364 additions and 14 deletions

View File

@@ -0,0 +1,9 @@
namespace RemoteFrameBuffer.Common
{
public enum RemoteFramebufferSecurityType
{
Invalid = 0,
None = 1,
VncAuthentication = 2,
}
}

View File

@@ -5,6 +5,8 @@
public Int16 Major = major;
public Int16 Minor = minor;
public override Boolean Equals(Object? obj) => obj is RfbProtoVersion version && this.Major == version.Major && this.Minor == version.Minor;
public override Int32 GetHashCode() => HashCode.Combine(this.Major, this.Minor);
public static Boolean operator ==(RfbProtoVersion a, RfbProtoVersion b)
{
@@ -30,11 +32,11 @@
}
public static Boolean operator <=(RfbProtoVersion a, RfbProtoVersion b)
{
return b < a;
return !(b < a);
}
public static Boolean operator >=(RfbProtoVersion a, RfbProtoVersion b)
{
return a < b;
return !(a < b);
}
}
}

View File

@@ -0,0 +1,78 @@
namespace RemoteFrameBuffer.Common
{
public class RgbFrameBuffer
{
private RgbPixel[][] _frame;
public UInt16 Width
{
get
{
return (UInt16)this._frame[0].Length;
}
}
public UInt16 Height
{
get
{
return (UInt16)this._frame.Length;
}
}
private static RgbPixel[][] MakeFrameBuffer(UInt16 width, UInt16 height)
{
RgbPixel[][] buf = new RgbPixel[height][];
for (Int32 i = 0; i < height; i++)
{
buf[i] = new RgbPixel[width];
}
return buf;
}
public RgbFrameBuffer(UInt16 width, UInt16 height)
{
this._frame = MakeFrameBuffer(width, height);
}
public void SetRegion(RgbPixel[][] source, UInt16 source_x, UInt16 source_y, UInt16 width, UInt16 height, UInt16 target_x, UInt16 target_y)
{
for (Int32 y = 0; y < height; y++)
{
Array.Copy(source[y + source_y], source_x, this._frame[y + target_y], target_x, width);
}
}
public void CopyRegion(UInt16 source_x, UInt16 source_y, UInt16 width, UInt16 height, UInt16 target_x, UInt16 target_y) => this.SetRegion(this._frame, source_x, source_y, width, height, target_x, target_y);
public void SaveBitmap(String filename)
{
#warning Endianness is straight up ignored
Int32 rowBytes = (this.Width * 3) + 3;
rowBytes -= rowBytes % 4;
Int32 bytes = 54 + (this.Height * rowBytes);
Byte[] buf = new Byte[bytes];
buf[0] = 0x42;
buf[1] = 0x4D;
Array.Copy(BitConverter.GetBytes(bytes), 0, buf, 2, 4);
buf[10] = 54;
buf[14] = 40;
Array.Copy(BitConverter.GetBytes((UInt32)this.Width), 0, buf, 18, 4);
Array.Copy(BitConverter.GetBytes((UInt32)this.Height), 0, buf, 22, 4);
buf[26] = 1;
buf[28] = 24;
Array.Copy(BitConverter.GetBytes(this.Height * rowBytes), 0, buf, 34, 4);
for (Int32 j = 0; j < this.Height; j++)
{
Int32 off = 54 + (j * rowBytes);
for (Int32 i = 0; i < this.Width; i++)
{
Int32 pos = off + (i * 3);
buf[pos] = this._frame[this.Height - j - 1][i].Blue;
buf[pos + 1] = this._frame[this.Height - j - 1][i].Green;
buf[pos + 2] = this._frame[this.Height - j - 1][i].Red;
}
}
File.WriteAllBytes(filename, buf);
}
}
}

View File

@@ -0,0 +1,9 @@
namespace RemoteFrameBuffer.Common
{
public struct RgbPixel
{
public Byte Red { get; set; }
public Byte Green { get; set; }
public Byte Blue { get; set; }
}
}