forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitmapImageWs2808GRB.cs
57 lines (50 loc) · 1.67 KB
/
BitmapImageWs2808GRB.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Drawing;
namespace Iot.Device.Ws28xx.Esp32
{
/// <summary>
/// BitmapImage Ws2808 GRB.
/// </summary>
public class BitmapImageWs2808Grb : BitmapImage
{
private const int BytesPerPixel = 3;
/// <summary>
/// Initializes a new instance of the <see cref="BitmapImageWs2808Grb"/> class.
/// </summary>
/// <param name="width">Width of the image.</param>
/// <param name="height">Height of the image.</param>
public BitmapImageWs2808Grb(int width, int height)
: base(new byte[width * height * BytesPerPixel], width, height, width * BytesPerPixel)
{
}
/// <inheritdoc />
public override void SetPixel(int x, int y, Color c)
{
var offset = (y * Stride) + (x * BytesPerPixel);
Data[offset++] = c.G;
Data[offset++] = c.R;
Data[offset++] = c.B;
}
/// <inheritdoc />
public override void SetPixel(int x, int y, byte r, byte g, byte b)
{
var offset = (y * Stride) + (x * BytesPerPixel);
Data[offset++] = g;
Data[offset++] = r;
Data[offset++] = b;
}
/// <inheritdoc />
public override void Clear()
{
Array.Clear(Data, 0, Data.Length);
}
/// <inheritdoc />
public override void Clear(int x, int y)
{
var offset = (y * Stride) + (x * BytesPerPixel);
Array.Clear(Data, offset, 3);
}
}
}