blob: 5a64871b76d636fd13cd7ddcbd8c17461e6871cd (
plain)
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
|
using System;
using System.Diagnostics.CodeAnalysis;
namespace Colourful.Implementation.RGB
{
/// <summary>
/// Gamma companding
/// </summary>
/// <remarks>
/// For more info see:
/// http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html
/// http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html
/// </remarks>
public sealed class GammaCompanding : ICompanding
{
/// <summary>
/// Constructs with given gamma
/// </summary>
public GammaCompanding(double gamma)
{
Gamma = gamma;
}
/// <summary>
/// Gamma
/// </summary>
public double Gamma { get; }
/// <inheritdoc />
public double InverseCompanding(double channel)
{
var V = channel;
var v = Math.Pow(V, Gamma);
return v;
}
/// <inheritdoc />
public double Companding(double channel)
{
var v = channel;
var V = Math.Pow(v, 1 / Gamma);
return V;
}
/// <inheritdoc cref="object" />
[SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")]
public bool Equals(GammaCompanding other)
{
if (other == null)
return false;
return Gamma == other.Gamma;
}
/// <inheritdoc cref="object" />
public override bool Equals(object obj) => obj is GammaCompanding other && Equals(other);
/// <inheritdoc cref="object" />
public override int GetHashCode() => Gamma.GetHashCode();
/// <inheritdoc cref="object" />
public static bool operator ==(GammaCompanding left, GammaCompanding right) => Equals(left, right);
/// <inheritdoc cref="object" />
public static bool operator !=(GammaCompanding left, GammaCompanding right) => !Equals(left, right);
}
}
|