-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
95 lines (87 loc) · 3.38 KB
/
Copy pathProgram.cs
File metadata and controls
95 lines (87 loc) · 3.38 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
using System;
using System.Collections.Generic;
using App.win32;
using App.math;
namespace App {
class Program {
// constant data
private const string APP = "egamma";
// static method
/// <summary>
/// I can touch the sky,
/// I know that i am alive.
/// : Celine Dion
/// </summary>
/// <param name="args">Input arguments.</param>
static void Main(string[] args) {
EParams p = new EParams(args);
if (args.Length == 0) { GetGdiRamp(); return; }
if (p.Red.Count == 0) { Console.Error.WriteLine("{0}: no red values.", APP); return; }
if (p.Green.Count == 0) { Console.Error.WriteLine("{0}: no green values.", APP); return; }
if (p.Blue.Count == 0) { Console.Error.WriteLine("{0}: no blue values.", APP); return; }
if (p.Ramp) {
RampMin2(p.Red, p.Green, p.Blue);
p.Red = EVector.GetLin(new double[EGdi.RAMP_SZ], p.Red);
p.Green = EVector.GetLin(new double[EGdi.RAMP_SZ], p.Green);
p.Blue = EVector.GetLin(new double[EGdi.RAMP_SZ], p.Blue);
}
else {
p.Red = GetRamp(p.Red[0], EGdi.RAMP_SZ);
p.Green = GetRamp(p.Green[0], EGdi.RAMP_SZ);
p.Blue = GetRamp(p.Blue[0], EGdi.RAMP_SZ);
}
SetGdiRamp(p.Red, p.Green, p.Blue);
}
/// <summary>
/// Make sure the red, green and blue ramps have minimum 2 values.
/// </summary>
/// <param name="red">Red floating-point ramp.</param>
/// <param name="green">Green floating-point ramp.</param>
/// <param name="blue">Blue floating-point ramp.</param>
private static void RampMin2(IList<double> red, IList<double> green, IList<double> blue) {
if (red.Count < 2) { red.Add(red[0]); red[0] = 0; }
if (green.Count < 2) { green.Add(green[0]); green[0] = 0; }
if (blue.Count < 2) { blue.Add(blue[0]); blue[0] = 0; }
}
/// <summary>
/// Set Gdi Ramp from floating-point input ramps.
/// </summary>
/// <param name="r">Gdi Ramp.</param>
/// <param name="red">Red floating-point ramp.</param>
/// <param name="green">Green floating-point ramp.</param>
/// <param name="blue">Blue floating-point ramp.</param>
private static void SetGdiRamp(IList<double> red, IList<double> green, IList<double> blue) {
EGdi.RAMP r = new EGdi.RAMP(null);
EVector.Map(r.Red, UInt16.MinValue, UInt16.MaxValue, red, 0, 1);
EVector.Map(r.Green, UInt16.MinValue, UInt16.MaxValue, green, 0, 1);
EVector.Map(r.Blue, UInt16.MinValue, UInt16.MaxValue, blue, 0, 1);
EGdi.SetDeviceGammaRamp(EUser.GetDC(IntPtr.Zero), ref r);
}
/// <summary>
/// Get the current gamma ramp.
/// </summary>
private static void GetGdiRamp() {
EGdi.RAMP r = new EGdi.RAMP(null);
EGdi.GetDeviceGammaRamp(EUser.GetDC(IntPtr.Zero), ref r);
IList<double> red = EVector.Map(null, 0, 1, r.Red, UInt16.MinValue, UInt16.MaxValue);
IList<double> green = EVector.Map(null, 0, 1, r.Green, UInt16.MinValue, UInt16.MaxValue);
IList<double> blue = EVector.Map(null, 0, 1, r.Blue, UInt16.MinValue, UInt16.MaxValue);
Console.WriteLine("Red");
EVector.Print(red);
Console.WriteLine("Green");
EVector.Print(green);
Console.WriteLine("Blue");
EVector.Print(blue);
}
/// <summary>
/// Get double ramp from gamma value.
/// </summary>
/// <param name="g">Gamma value.</param>
/// <param name="len">Output ramp length.</param>
/// <returns>Ramp.</returns>
private static IList<double> GetRamp(double g, int sz) {
IList<double> d = EVector.LinSpace(null, 0, 1, sz);
return EVector.Pow(d, d, g);
}
}
}