コード例 #1
0
            public override IFilter CreateFilter(IResizeableFilter sourceFilter)
            {
                var upscaler   = new Scaler.Custom(new GaussianBlur(0.75), ScalerTaps.Four, false);
                var downscaler = new Scaler.HwBilinear(); // Good enough (?)

                int bits = 8;

                switch (Renderer.InputFormat)
                {
                case FrameBufferInputFormat.P010: bits = 10; break;

                case FrameBufferInputFormat.Y410: bits = 10; break;

                case FrameBufferInputFormat.P016: bits = 16; break;

                case FrameBufferInputFormat.Y416: bits = 16; break;

                case FrameBufferInputFormat.Rgb24: return(sourceFilter);

                case FrameBufferInputFormat.Rgb32: return(sourceFilter);
                }
                if (bits > maxbitdepth)
                {
                    return(sourceFilter);
                }

                var inputsize = sourceFilter.OutputSize;
                var size      = inputsize;
                var current   = sourceFilter.ConvertToYuv();

                var factor     = 2.0;
                var downscaled = new Stack <IFilter>();

                downscaled.Push(current);

                // Generate downscaled images
                for (int i = 0; i < 8; i++)
                {
                    size = new Size((int)Math.Floor(size.Width / factor), (int)Math.Floor(size.Height / factor));
                    if (size.Width == 0 || size.Height == 0)
                    {
                        break;
                    }

                    current = new ResizeFilter(current, size, upscaler, downscaler);
                    downscaled.Push(current);
                }

                var deband = downscaled.Pop();

                while (downscaled.Count > 0)
                {
                    deband = new ShaderFilter(CompileShader("Deband.hlsl"), true,
                                              new[]
                    {
                        (1 << bits) - 1,
                        advancedMode ? threshold : DEFAULT_THRESHOLD,
                        advancedMode ? margin : DEFAULT_MARGIN
                    },
                                              downscaled.Pop(), deband);
                }

                return(deband.ConvertToRgb());
            }
コード例 #2
0
            public override IFilter CreateFilter(IResizeableFilter sourceFilter)
            {
                IFilter yuv;

                var chromaSize = Renderer.ChromaSize;
                var targetSize = sourceFilter.OutputSize;

                var Diff       = CompileShader("SuperChromaRes/Diff.hlsl");
                var CopyLuma   = CompileShader("SuperChromaRes/CopyLuma.hlsl");
                var CopyChroma = CompileShader("SuperChromaRes/CopyChroma.hlsl");
                var SuperRes   = CompileShader("SuperChromaRes/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");

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

                // Original values
                var yInput = new YSourceFilter();
                var uInput = new USourceFilter();
                var vInput = new VSourceFilter();

                float[] YuvConsts = new float[2];
                switch (Renderer.Colorimetric)
                {
                case YuvColorimetric.Auto: return(sourceFilter);

                case YuvColorimetric.FullRangePc601: YuvConsts = new[] { 0.114f, 0.299f, 0.0f }; break;

                case YuvColorimetric.FullRangePc709: YuvConsts = new[] { 0.0722f, 0.2126f, 0.0f }; break;

                case YuvColorimetric.FullRangePc2020: YuvConsts = new[] { 0.0593f, 0.2627f, 0.0f }; break;

                case YuvColorimetric.ItuBt601: YuvConsts = new[] { 0.114f, 0.299f, 1.0f }; break;

                case YuvColorimetric.ItuBt709: YuvConsts = new[] { 0.0722f, 0.2126f, 1.0f }; break;

                case YuvColorimetric.ItuBt2020: YuvConsts = new[] { 0.0593f, 0.2627f, 1.0f }; break;
                }

                var Consts = new[] { Strength, Sharpness, AntiAliasing, AntiRinging,
                                     Softness, YuvConsts[0], YuvConsts[1] };

                yuv = sourceFilter.ConvertToYuv();

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

                    // Compare to chroma
                    linear = new ShaderFilter(GammaToLinear, yuv.ConvertToRgb());
                    res    = new ResizeFilter(linear, chromaSize, upscaler, downscaler);
                    res    = new ShaderFilter(LinearToGamma, res).ConvertToYuv();
                    diff   = new ShaderFilter(Diff, YuvConsts, res, uInput, vInput);
                    if (!useBilinear)
                    {
                        diff = new ResizeFilter(diff, targetSize, upscaler, downscaler); // Scale to output size
                    }
                    // Update result
                    yuv = new ShaderFilter(SuperRes, useBilinear, Consts, yuv, diff, uInput, vInput);
                }

                return(yuv.ConvertToRgb());
            }