-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixel.cs
37 lines (34 loc) · 960 Bytes
/
Pixel.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
using System;
using System.Runtime.InteropServices;
namespace BitMapper
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Pixel
{
public static Pixel Create(byte R, byte G, byte B) =>
new Pixel
{
B = B,
G = G,
R = R
};
public byte B;
public byte G;
public byte R;
public Pixel Blend(Pixel pixel, int opacityp)
{
var opacity = opacityp;
byte OpacityBlend(byte value, byte secondValue)
{
var result = (((value / 100f) * opacity) + ((secondValue / 100f) * (100f - opacity)));
return Convert.ToByte(result);
}
return new Pixel
{
B = OpacityBlend(pixel.B, B),
G = OpacityBlend(pixel.G, G),
R = OpacityBlend(pixel.R, R),
};
}
}
}