mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added GDI-based rendering test
This commit is contained in:
1 parent
610b45e017
commit
60544e7814
21 files changed
+382
-111
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Artemis.Core.RGB.NET
|
||||
{
|
||||
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; }
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public void SetPixel(int x, int y, Color colour)
|
||||
{
|
||||
int index = x + (y * Width);
|
||||
int col = colour.ToArgb();
|
||||
|
||||
Bits[index] = col;
|
||||
}
|
||||
|
||||
public Color GetPixel(int x, int y)
|
||||
{
|
||||
int index = x + (y * Width);
|
||||
int col = Bits[index];
|
||||
Color result = Color.FromArgb(col);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Disposed) return;
|
||||
Disposed = true;
|
||||
Bitmap.Dispose();
|
||||
BitsHandle.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Groups;
|
||||
using Color = RGB.NET.Core.Color;
|
||||
using Rectangle = RGB.NET.Core.Rectangle;
|
||||
|
||||
namespace Artemis.Core.RGB.NET
|
||||
{
|
||||
public class GraphicsDecorator : AbstractDecorator, IBrushDecorator
|
||||
{
|
||||
private readonly DirectBitmap _bitmap;
|
||||
|
||||
public GraphicsDecorator(ListLedGroup ledGroup)
|
||||
{
|
||||
// var width = ledGroup.GetLeds().Max(l => l.LedRectangle.X + l.LedRectangle.Width);
|
||||
// var height = ledGroup.GetLeds().Max(l => l.LedRectangle.Y + l.LedRectangle.Height);
|
||||
var width = 500;
|
||||
var height = 500;
|
||||
_bitmap = new DirectBitmap((int) width, (int) height);
|
||||
}
|
||||
|
||||
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
||||
{
|
||||
var pixel = _bitmap.GetPixel((int) (renderTarget.Rectangle.X + renderTarget.Rectangle.Width / 2), (int) (renderTarget.Rectangle.Y + renderTarget.Rectangle.Height / 2));
|
||||
return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
|
||||
}
|
||||
|
||||
public Graphics GetGraphics()
|
||||
{
|
||||
return Graphics.FromImage(_bitmap.Bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user