-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalImage.cs
More file actions
38 lines (32 loc) · 1.08 KB
/
TerminalImage.cs
File metadata and controls
38 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Color = System.Drawing.Color;
using Point = System.Drawing.Point;
namespace TerminalRenderer;
public class TerminalImage : ITerminalRenderable
{
public Point TopLeft = Point.Empty;
public Image<Argb32> ImageData;
public TerminalImage(Point topLeft, Image<Argb32> image)
{
TopLeft = topLeft;
ImageData = image;
}
public static TerminalImage Centered(Point center, int width, int height, Image<Argb32> image)
{
var tl = new Point(center.X - width / 2, center.Y - height / 2);
return new TerminalImage(tl, image);
}
public IEnumerable<TerminalPixel> Render()
{
for (int y = 0; y < ImageData.Height; y++)
{
for (int x = 0; x < ImageData.Width; x++)
{
var pixel = ImageData[x, y];
Color col = Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B);
yield return new TerminalPixel(new Point(TopLeft.X + x, TopLeft.Y + y), col);
}
}
}
}