Beispiel #1
0
            public IFilter CreateFilter(IFilter original, IFilter initial)
            {
                IFilter lab, linear, result = initial;

                var inputSize   = original.OutputSize;
                var currentSize = original.OutputSize;
                var targetSize  = TargetSize();

                var Diff     = CompileShader("Diff.hlsl");
                var SuperRes = CompileShader("SuperRes.hlsl");

                var GammaToLab    = CompileShader("GammaToLab.hlsl");
                var LabToGamma    = CompileShader("LabToGamma.hlsl");
                var LinearToGamma = CompileShader("LinearToGamma.hlsl");
                var GammaToLinear = CompileShader("GammaToLinear.hlsl");
                var LabToLinear   = CompileShader("LabToLinear.hlsl");
                var LinearToLab   = CompileShader("LinearToLab.hlsl");

                var NEDI = new Shiandow.Nedi.Nedi
                {
                    AlwaysDoubleImage = false,
                    Centered          = false,
                    LumaConstants     = new[] { 1.0f, 0.0f, 0.0f }
                };

                var Consts = new[] { Strength, Sharpness, AntiAliasing, AntiRinging };

                // Skip if downscaling
                if (targetSize.Width <= inputSize.Width && targetSize.Height <= inputSize.Height)
                {
                    return(initial);
                }

                // Initial scaling
                lab      = new ShaderFilter(GammaToLab, initial);
                original = new ShaderFilter(GammaToLab, original);

                for (int i = 1; i <= Passes; i++)
                {
                    IFilter res, diff;
                    bool    useBilinear = (upscaler is Scaler.Bilinear) || (FirstPassOnly && !(i == 1));

                    // Calculate size
                    if (i == Passes || NoIntermediates)
                    {
                        currentSize = targetSize;
                    }
                    else
                    {
                        currentSize = CalculateSize(currentSize, targetSize, i);
                    }

                    // Resize
                    if (i == 1 && UseNEDI)
                    {
                        lab = new ResizeFilter(lab + NEDI, currentSize, m_ShiftedScaler, m_ShiftedScaler, m_ShiftedScaler);
                    }
                    else
                    {
                        lab = new ResizeFilter(lab, currentSize, upscaler, downscaler);
                    }

                    // Downscale and Subtract
                    linear = new ShaderFilter(LabToLinear, lab);
                    res    = new ResizeFilter(linear, inputSize, upscaler, downscaler); // Downscale result
                    diff   = new ShaderFilter(Diff, res, original);                     // Compare with original

                    // Scale difference back
                    if (!useBilinear)
                    {
                        diff = new ResizeFilter(diff, currentSize, upscaler, downscaler);
                    }

                    // Update result
                    lab    = new ShaderFilter(SuperRes, useBilinear, Consts, lab, diff, original);
                    result = new ShaderFilter(LabToGamma, lab);
                }

                return(result);
            }
            public IFilter CreateFilter(IFilter original, IFilter initial)
            {
                IFilter lab, linear, result = initial;

                var inputSize   = original.OutputSize;
                var currentSize = original.OutputSize;
                var targetSize  = TargetSize();

                var Diff     = CompileShader("Diff.hlsl");
                var SuperRes = CompileShader("SuperRes.hlsl");

                var GammaToLab    = CompileShader("GammaToLab.hlsl");
                var LabToGamma    = CompileShader("LabToGamma.hlsl");
                var LinearToGamma = CompileShader("LinearToGamma.hlsl");
                var GammaToLinear = CompileShader("GammaToLinear.hlsl");
                var LabToLinear   = CompileShader("LabToLinear.hlsl");
                var LinearToLab   = CompileShader("LinearToLab.hlsl");

                var NEDI = new Shiandow.Nedi.Nedi
                {
                    AlwaysDoubleImage = false,
                    Centered          = false,
                    LumaConstants     = new[] { 1.0f, 0.0f, 0.0f }
                };

                var Consts = new[] { Strength, Sharpness, AntiAliasing, AntiRinging };

                // Initial scaling
                lab      = new ShaderFilter(GammaToLab, initial);
                original = new ShaderFilter(GammaToLab, original);

                for (int i = 1; i <= Passes; i++)
                {
                    IFilter res, diff;
                    bool    useBilinear = (upscaler is Scaler.Bilinear) || (FirstPassOnly && !(i == 1));

                    // Calculate size
                    if (i == Passes)
                    {
                        currentSize = targetSize;
                    }
                    else
                    {
                        currentSize = CalculateSize(currentSize, targetSize, i);
                    }

                    // Resize and Convert
                    if (i == 1 && UseNEDI)
                    {
                        var nedi = lab + NEDI;
                        lab = new ResizeFilter(nedi, currentSize, m_ShiftedScaler, m_ShiftedScaler);

                        if (currentSize == nedi.OutputSize)
                        {
                            // TODO: implement a proper way to shift NEDI without resizing
                            lab = new ResizeFilter(lab, currentSize);
                        }
                    }
                    else
                    {
                        lab = new ResizeFilter(lab, currentSize);
                    }
                    linear = new ShaderFilter(LabToLinear, lab);

                    // Calculate difference
                    res  = new ResizeFilter(linear, inputSize, upscaler, downscaler); // Downscale result
                    diff = new ShaderFilter(Diff, res, original);                     // Compare with original
                    if (!useBilinear)
                    {
                        diff = new ResizeFilter(diff, currentSize, upscaler, downscaler); // Scale to output size
                    }
                    // Update result
                    lab    = new ShaderFilter(SuperRes, useBilinear, Consts, lab, diff, original);
                    result = new ShaderFilter(LabToGamma, lab);
                }

                return(result);
            }