forked from Nominom/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComponentHelper.cs
More file actions
87 lines (68 loc) · 1.93 KB
/
Copy pathComponentHelper.cs
File metadata and controls
87 lines (68 loc) · 1.93 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
using System;
using BCnEncoder.Encoder;
namespace BCnEncoder.Shared
{
internal static class ComponentHelper
{
public static ColorRgba32 ComponentToColor(ColorComponent component, byte componentValue)
{
switch (component)
{
case ColorComponent.R:
return new ColorRgba32(componentValue, 0, 0, 255);
case ColorComponent.G:
return new ColorRgba32(0, componentValue, 0, 255);
case ColorComponent.B:
return new ColorRgba32(0, 0, componentValue, 255);
case ColorComponent.A:
return new ColorRgba32(0, 0, 0, componentValue);
case ColorComponent.Luminance:
return new ColorRgba32(componentValue, componentValue, componentValue, 255);
default:
throw new InvalidOperationException("Unsupported component.");
}
}
public static ColorRgba32 ComponentToColor(ColorRgba32 existingColor, ColorComponent component, byte componentValue)
{
switch (component)
{
case ColorComponent.R:
existingColor.r = componentValue;
break;
case ColorComponent.G:
existingColor.g = componentValue;
break;
case ColorComponent.B:
existingColor.b = componentValue;
break;
case ColorComponent.A:
existingColor.a = componentValue;
break;
case ColorComponent.Luminance:
existingColor.r = existingColor.g = existingColor.b = componentValue;
break;
default:
throw new InvalidOperationException("Unsupported component.");
}
return existingColor;
}
public static byte ColorToComponent(ColorRgba32 color, ColorComponent component)
{
switch (component)
{
case ColorComponent.R:
return color.r;
case ColorComponent.G:
return color.g;
case ColorComponent.B:
return color.b;
case ColorComponent.A:
return color.a;
case ColorComponent.Luminance:
return (byte)(new ColorYCbCr(color).y * 255);
default:
throw new InvalidOperationException("Unsupported component.");
}
}
}
}