-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPGEng.ColorInt.cs
41 lines (36 loc) · 1.02 KB
/
CPGEng.ColorInt.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
/*
* Crispycat PixelGraphic Engine
* CPGEng.ColorInt; ColorInt objects and functions
* (C) 2020 crispycat; https://github.com/crispycat0/CPGEng/LICENSE
* 2020/04/01
*/
using System;
namespace CPGEng {
public class ColorInt {
public readonly int Value, Red, Green, Blue;
/// <summary>Creates a ColorInt from an integer.</summary>
/// <param name="v">Value</param>
public ColorInt(int v) {
Value = v & 16777215;
Red = v & 255;
Green = v >> 8 & 255;
Blue = v >> 16 & 255;
}
/// <summary>Creates a ColorInt from BGR or RGB values.</summary>
/// <param name="b">BGR Blue/RGB Red</param>
/// <param name="g">Green</param>
/// <param name="r">BGR Red/RGB Blue</param>
/// <param name="c">Color format, defaults to BGR</param>
public ColorInt(int b, int g, int r, ColorFormat c = 0) {
if (c == ColorFormat.RGB) {
int _ = b;
b = r;
r = _;
}
Red = r & 255;
Green = g & 255;
Blue = b & 255;
Value = (Blue << 16) | (Green << 8) | Red;
}
}
}