Esempio n. 1
0
        public static float LutFromLinear(Babl trc, float x)
        {
            var Trc   = (BablTrc)trc;
            var entry = (int)(x * (Trc.LutSize - 1));
            var diff  = ((x * (Trc.LutSize - 1)) - entry);

            if (entry >= Trc.LutSize - 1)
            {
                entry = Trc.LutSize - 1;
                diff  = 0.0f;
            }
            else if (entry < 0)
            {
                entry = 0;
            }

            if (diff > 0)
            {
                return(Trc.InvLut[entry] * (1.0f - diff) + Trc.InvLut[entry + 1] * diff);
            }
            else
            {
                return(Trc.InvLut[entry]);
            }
        }
Esempio n. 2
0
        private static float FormulaSrgbToLinear(Babl trc, float value)
        {
            var Trc = (BablTrc)trc;

            (var x, var a, var b, var c, var d, var e, var f) = (value, Trc.Lut[1], Trc.Lut[2], Trc.Lut[3], Trc.Lut[4], Trc.Lut[5], Trc.Lut[6]);

            if (x >= d)
            {
                return(GammaToLinear(trc, a * x + b) + e);
            }
            return(c * x + f);
        }
Esempio n. 3
0
        private static float FormulaCieToLinear(Babl trc, float value)
        {
            var Trc = (BablTrc)trc;

            (var x, var a, var b, var c) = (value, Trc.Lut[1], Trc.Lut[2], Trc.Lut[3]);

            if (x >= -b / a)
            {
                return(GammaToLinear(trc, a * x + b) + c);
            }
            return(c);
        }
Esempio n. 4
0
        private static void LinearBuffered(Babl _, ReadOnlyMemory <float> @in, Memory <float> @out, int inGap, int outGap, int components, int count)
        {
            var inSpan  = @in.Span;
            var outSpan = @out.Span;

            for (var i = 0; i < count; i++)
            {
                for (var c = 0; c < components; c++)
                {
                    @outSpan[outGap * i + c] = @inSpan[inGap * i + c];
                }
            }
        }
Esempio n. 5
0
        private static void FromLinearBufferedGeneric(Babl trc, ReadOnlyMemory <float> @in, Memory <float> @out, int inGap, int outGap, int components, int count)
        {
            var inSpan  = @in.Span;
            var outSpan = @out.Span;

            for (var i = 0; i < count; i++)
            {
                for (var c = 0; c < components; c++)
                {
                    @outSpan[outGap * i + c] = ((BablTrc)trc).FuncFromLinear(trc, @inSpan[inGap * i + c]);
                }
            }
        }
Esempio n. 6
0
        private static float GammaFromLinear(Babl trc, float value)
        {
            var Trc = (BablTrc)trc;

            if (value >= Trc.GammaFromLinearX0 &&
                value <= Trc.GammaFromLinearX1)
            {
                return((float)Trc.GammaFromLinearPoly.Eval(value));
            }
            else if (value > 0f)
            {
                return(MathF.Pow(value, (float)Trc.Rgamma));
            }
            return(0f);
        }
Esempio n. 7
0
        private static float FormulaCieFromLinear(Babl trc, float value)
        {
            var Trc = (BablTrc)trc;

            (var x, var a, var b, var c) = (value, Trc.Lut[1], Trc.Lut[2], Trc.Lut[3]);

            if (x > c)
            {
                var v = GammaFromLinear(trc, x - c);
                v = (v - b) / a;
                if (v is < 0 or >= 0)
                {
                    return(v);
                }
            }
            return(0);
        }
Esempio n. 8
0
        private static float FormulaSrgbFromLinear(Babl trc, float value)
        {
            var Trc = (BablTrc)trc;

            (var x, var a, var b, var c, var d, var e, var f) = (value, Trc.Lut[1], Trc.Lut[2], Trc.Lut[3], Trc.Lut[4], Trc.Lut[5], Trc.Lut[6]);

            if (x - f > c * d)
            {
                var v = GammaFromLinear(trc, x - f);
                v = (v - b) / a;
                if (v is < 0 or >= 0)
                {
                    return(v);
                }
                return(0);
            }
            if (c > 0)
            {
                return((x - e) / c);
            }
            return(0);
        }
Esempio n. 9
0
        public static Polynomial ProjectCopy(this Polynomial[] basis, Polynomial rpoly, int n, double x0, double x1)
        {
            Babl.Assert(n > 0);
            var poly = Empty with {
                Scale = basis[0].Scale
            };

            for (var i = 0; i < n; i++)
            {
                var temp = basis[i] with
                {
                    Degree = basis[i].Degree,
                    Scale  = basis[i].Scale,
                    Coeff  = basis[i].Coeff
                };
                temp.Mul(temp.InnerProduct(rpoly, x0, x1));

                poly.Add(temp);
            }

            return(poly);
        }
Esempio n. 10
0
 private static float Linear(Babl _, float value) =>
 value;
Esempio n. 11
0
 public static void ToLinearBuffered(Babl trc, ReadOnlyMemory <float> @in, Memory <float> @out, int inGap, int outGap, int components, int count) =>
 ((BablTrc)trc).FuncToLinearBuffered(trc, @in, @out, inGap, outGap, components, count);
Esempio n. 12
0
 private static float SrgbFromLinear(Babl _, float value) =>
 Utils.LinearToGamma22(value);
Esempio n. 13
0
 private static float SrgbToLinear(Babl _, float value) =>
 Utils.Gamma22ToLinear(value);
Esempio n. 14
0
 public static void LookingUp(string name,
                              [CallerMemberName] string memberName = "",
                              [CallerFilePath] string filePath     = "",
                              [CallerLineNumber] int lineNumber    = 0) =>
 Babl.Log($"\"{name}\": looking up", memberName, filePath, lineNumber);