forked from crskycode/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorVariationGenerator.cs
More file actions
166 lines (141 loc) · 3.91 KB
/
Copy pathColorVariationGenerator.cs
File metadata and controls
166 lines (141 loc) · 3.91 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System.Collections.Generic;
using BCnEncoder.Shared;
namespace BCnEncoder.Encoder
{
internal static class ColorVariationGenerator
{
private static int[] varPatternEp0R = new int[] { 1, 1, 0, 0, -1, 0, 0, -1, 1, -1, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
private static int[] varPatternEp0G = new int[] { 1, 0, 1, 0, 0, -1, 0, -1, 1, -1, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
private static int[] varPatternEp0B = new int[] { 1, 0, 0, 1, 0, 0, -1, -1, 1, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0 };
private static int[] varPatternEp1R = new int[] { -1, -1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 1, 0, 0, -1, 0, 0 };
private static int[] varPatternEp1G = new int[] { -1, 0, -1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 1, 0, 0, -1, 0 };
private static int[] varPatternEp1B = new int[] { -1, 0, 0, -1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 1, 0, 0, -1 };
public static int VarPatternCount => varPatternEp0R.Length;
public static void Variate565(ColorRgb565 c0, ColorRgb565 c1, int i, out ColorRgb565 outC0, out ColorRgb565 outC1) {
int idx = i % varPatternEp0R.Length;
var newEp0 = new ColorRgb565();
var newEp1 = new ColorRgb565();
newEp0.RawR = ByteHelper.ClampToByte(c0.RawR + varPatternEp0R[idx]);
newEp0.RawG = ByteHelper.ClampToByte(c0.RawG + varPatternEp0G[idx]);
newEp0.RawB = ByteHelper.ClampToByte(c0.RawB + varPatternEp0B[idx]);
newEp1.RawR = ByteHelper.ClampToByte(c1.RawR + varPatternEp1R[idx]);
newEp1.RawG = ByteHelper.ClampToByte(c1.RawG + varPatternEp1G[idx]);
newEp1.RawB = ByteHelper.ClampToByte(c1.RawB + varPatternEp1B[idx]);
outC0 = newEp0;
outC1 = newEp1;
}
public static List<ColorRgb565> GenerateVariationsSidewaysMax(int variations, ColorYCbCr min, ColorYCbCr max)
{
List<ColorRgb565> colors = new List<ColorRgb565>();
colors.Add(min.ToColorRgb565());
colors.Add(max.ToColorRgb565());
for (int i = 0; i < variations; i++)
{
max.y -= 0.05f;
min.y += 0.05f;
var ma = max.ToColorRgb565();
var mi = min.ToColorRgb565();
if (!colors.Contains(ma))
{
colors.Add(ma);
}
if (!colors.Contains(mi))
{
colors.Add(mi);
}
//variate reds in max
ma.RawR += 1;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
ma.RawR -= 2;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
//variate blues in max
ma.RawR += 1;
ma.RawB += 1;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
ma.RawB -= 2;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
}
return colors;
}
public static List<ColorRgb565> GenerateVariationsSidewaysMinMax(int variations, ColorYCbCr min, ColorYCbCr max)
{
List<ColorRgb565> colors = new List<ColorRgb565>();
colors.Add(min.ToColorRgb565());
colors.Add(max.ToColorRgb565());
for (int i = 0; i < variations; i++)
{
max.y -= 0.05f;
min.y += 0.05f;
var ma = max.ToColorRgb565();
var mi = min.ToColorRgb565();
if (!colors.Contains(ma))
{
colors.Add(ma);
}
if (!colors.Contains(mi))
{
colors.Add(mi);
}
//variate reds in max
ma.RawR += 1;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
ma.RawR -= 2;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
//variate blues in max
ma.RawR += 1;
ma.RawB += 1;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
ma.RawB -= 2;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
//variate reds in min
mi.RawR += 1;
if (!colors.Contains(mi))
{
colors.Add(mi);
}
ma.RawR -= 2;
if (!colors.Contains(ma))
{
colors.Add(ma);
}
//variate blues in min
mi.RawR += 1;
mi.RawB += 1;
if (!colors.Contains(mi))
{
colors.Add(mi);
}
mi.RawB -= 2;
if (!colors.Contains(mi))
{
colors.Add(mi);
}
}
return colors;
}
}
}