aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/Colourful/Implementation/RGB/Rec709Companding.cs
blob: 48c5b511e0feb9f87a7046b1eea9a6e9a3c1d276 (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
using System;

namespace Colourful.Implementation.RGB
{
    /// <summary>
    /// Rec. 709 companding function
    /// </summary>
    /// <remarks>
    /// http://en.wikipedia.org/wiki/Rec._709
    /// </remarks>
    public sealed class Rec709Companding : ICompanding
    {
        /// <inheritdoc />
        public double InverseCompanding(double channel)
        {
            var V = channel;
            var L = V < 0.081 ? V / 4.5 : Math.Pow((V + 0.099) / 1.099, 1 / 0.45);
            return L;
        }

        /// <inheritdoc />
        public double Companding(double channel)
        {
            var L = channel;
            var V = L < 0.018 ? 4.5 * L : 1.099 * Math.Pow(L, 0.45) - 0.099;
            return V;
        }
    }
}