diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-02 23:30:34 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-02 23:30:34 +0200 |
| commit | 0dcd742a3c35527386a93e1b1ef761c2aeff8308 (patch) | |
| tree | d5adb3fee35e73af95fa5d68b5316d25522471de /Software/Visual_Studio/Tango.RemoteDesktop/Utils/DirectBitmap.cs | |
| parent | 1a7fb274158f8a0e279aef26206a65fefac8c4c3 (diff) | |
| download | Tango-0dcd742a3c35527386a93e1b1ef761c2aeff8308.tar.gz Tango-0dcd742a3c35527386a93e1b1ef761c2aeff8308.zip | |
Implemented Tango.RemoteDesktop.
Implemented png 8 bit quantization.
Implemented RasterFrame bounds clipping.
Refactored VectorFrame to use indexed colors.
Diffstat (limited to 'Software/Visual_Studio/Tango.RemoteDesktop/Utils/DirectBitmap.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.RemoteDesktop/Utils/DirectBitmap.cs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Utils/DirectBitmap.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Utils/DirectBitmap.cs new file mode 100644 index 000000000..83b36fcfa --- /dev/null +++ b/Software/Visual_Studio/Tango.RemoteDesktop/Utils/DirectBitmap.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.RemoteDesktop.Utils +{ + /// <summary> + /// Represents a bitmap object with fast Get/Set Pixel methods. + /// </summary> + /// <seealso cref="System.IDisposable" /> + public class DirectBitmap : IDisposable + { + public Bitmap Bitmap { get; private set; } + public Int32[] Bits { get; private set; } + public bool Disposed { get; private set; } + public int Height { get; private set; } + public int Width { get; private set; } + + protected GCHandle BitsHandle { get; private set; } + + /// <summary> + /// Initializes a new instance of the <see cref="DirectBitmap"/> class. + /// </summary> + /// <param name="width">The width.</param> + /// <param name="height">The height.</param> + public DirectBitmap(int width, int height) + { + Width = width; + Height = height; + Bits = new Int32[width * height]; + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject()); + } + + /// <summary> + /// Sets the pixel color. + /// </summary> + /// <param name="x">The x position.</param> + /// <param name="y">The y position.</param> + /// <param name="color">The color.</param> + public void SetPixel(int x, int y, Color color) + { + int index = x + (y * Width); + int col = color.ToArgb(); + + Bits[index] = col; + } + + /// <summary> + /// Gets the pixel color. + /// </summary> + /// <param name="x">The x position.</param> + /// <param name="y">The y position.</param> + /// <returns></returns> + public Color GetPixel(int x, int y) + { + int index = x + (y * Width); + int col = Bits[index]; + Color result = Color.FromArgb(col); + + return result; + } + + /// <summary> + /// Releases unmanaged and - optionally - managed resources. + /// </summary> + public void Dispose() + { + if (Disposed) return; + Disposed = true; + BitsHandle.Free(); + } + } +} |
