using System;
using System.Diagnostics.CodeAnalysis;
namespace Colourful.Implementation.RGB
{
///
/// Gamma companding
///
///
/// 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
///
public sealed class GammaCompanding : ICompanding
{
///
/// Constructs with given gamma
///
public GammaCompanding(double gamma)
{
Gamma = gamma;
}
///
/// Gamma
///
public double Gamma { get; }
///
public double InverseCompanding(double channel)
{
var V = channel;
var v = Math.Pow(V, Gamma);
return v;
}
///
public double Companding(double channel)
{
var v = channel;
var V = Math.Pow(v, 1 / Gamma);
return V;
}
///
[SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")]
public bool Equals(GammaCompanding other)
{
if (other == null)
return false;
return Gamma == other.Gamma;
}
///
public override bool Equals(object obj) => obj is GammaCompanding other && Equals(other);
///
public override int GetHashCode() => Gamma.GetHashCode();
///
public static bool operator ==(GammaCompanding left, GammaCompanding right) => Equals(left, right);
///
public static bool operator !=(GammaCompanding left, GammaCompanding right) => !Equals(left, right);
}
}