forked from Nominom/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorVariationGenerator.cs
More file actions
52 lines (43 loc) · 2.17 KB
/
Copy pathColorVariationGenerator.cs
File metadata and controls
52 lines (43 loc) · 2.17 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
using System.Collections.Generic;
using BCnEncoder.Shared;
namespace BCnEncoder.Encoder
{
internal static class ColorVariationGenerator
{
private static readonly int[] variatePatternEp0R = 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 readonly int[] variatePatternEp0G = 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 readonly int[] variatePatternEp0B = 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 readonly int[] variatePatternEp1R = 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 readonly int[] variatePatternEp1G = 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 readonly int[] variatePatternEp1B = 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 => variatePatternEp0R.Length;
public static (ColorRgb565, ColorRgb565) Variate565(ColorRgb565 c0, ColorRgb565 c1, int i)
{
var idx = i % variatePatternEp0R.Length;
var newEp0 = new ColorRgb565();
var newEp1 = new ColorRgb565();
newEp0.RawR = ByteHelper.ClampToByte(c0.RawR + variatePatternEp0R[idx]);
newEp0.RawG = ByteHelper.ClampToByte(c0.RawG + variatePatternEp0G[idx]);
newEp0.RawB = ByteHelper.ClampToByte(c0.RawB + variatePatternEp0B[idx]);
newEp1.RawR = ByteHelper.ClampToByte(c1.RawR + variatePatternEp1R[idx]);
newEp1.RawG = ByteHelper.ClampToByte(c1.RawG + variatePatternEp1G[idx]);
newEp1.RawB = ByteHelper.ClampToByte(c1.RawB + variatePatternEp1B[idx]);
return (newEp0, newEp1);
}
public static ((int, int, int), (int, int, int)) VariateInt((int, int, int) ep0,
(int, int, int) ep1, int i)
{
var idx = i % variatePatternEp0R.Length;
return ((
ep0.Item1 + variatePatternEp0R[idx],
ep0.Item2 + variatePatternEp0G[idx],
ep0.Item3 + variatePatternEp0B[idx]
),
(
ep1.Item1 + variatePatternEp1R[idx],
ep1.Item2 + variatePatternEp1G[idx],
ep1.Item3 + variatePatternEp1B[idx]
));
}
}
}