示例#1
0
            public override IFilter CreateFilter(IFilter input)
            {
                var yInput = new YSourceFilter();
                var uInput = new USourceFilter();
                var vInput = new VSourceFilter();

                Vector2 offset = Renderer.ChromaOffset + new Vector2(0.5f, 0.5f);

                var chromaShader = CompileShader("Chroma.hlsl").Configure(arguments: new[] { B, C, offset[0], offset[1] });

                var chroma = new ShaderFilter(chromaShader, yInput, uInput, vInput);
                var rgb    = chroma.ConvertToRgb();

                return(rgb);
            }
            public override IFilter CreateFilter(IResizeableFilter sourceFilter)
            {
                var chromaShader = CompileShader("Chroma.hlsl");

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

                float[] offset = { 0.0f, 0.5f };

                var chroma = new ShaderFilter(chromaShader, new[] { B, C, offset[0], offset[1] }, yInput, uInput, vInput);
                var rgb    = chroma.ConvertToRgb();

                return(rgb);
            }
示例#3
0
            public override IFilter CreateFilter(IFilter input)
            {
                if (Renderer.InputFormat.IsRgb())
                {
                    return(input);
                }

                IFilter hiRes;

                var chromaSize = (TextureSize)Renderer.ChromaSize;
                var targetSize = input.OutputSize;

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

                float[] yuvConsts = Renderer.Colorimetric.GetYuvConsts();
                int     bitdepth  = Renderer.InputFormat.GetBitDepth();
                bool    limited   = Renderer.Colorimetric.IsLimitedRange();

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

                Vector2 offset        = Renderer.ChromaOffset;
                Vector2 adjointOffset = -offset * targetSize / chromaSize;

                string superResMacros = "";

                if (IsIntegral(Strength))
                {
                    superResMacros += String.Format("strength = {0};", Strength);
                }
                if (IsIntegral(Softness))
                {
                    superResMacros += String.Format("softness = {0};", Softness);
                }

                string diffMacros = string.Format("LimitedRange = {0}; range = {1}", limited ? 1 : 0, (1 << bitdepth) - 1);

                var CopyLuma    = CompileShader("CopyLuma.hlsl");
                var CopyChroma  = CompileShader("CopyChroma.hlsl");
                var MergeChroma = CompileShader("MergeChroma.hlsl").Configure(format: TextureFormat.Float16);

                var Diff = CompileShader("Diff.hlsl", macroDefinitions: diffMacros)
                           .Configure(arguments: yuvConsts, format: TextureFormat.Float16);

                var SuperRes = CompileShader("SuperResEx.hlsl", macroDefinitions: superResMacros)
                               .Configure(
                    arguments: new[] { Strength, Softness, yuvConsts[0], yuvConsts[1], offset.X, offset.Y }
                    );

                var CrossBilateral = CompileShader("CrossBilateral.hlsl")
                                     .Configure(
                    arguments: new[] { offset.X, offset.Y, yuvConsts[0], yuvConsts[1] },
                    perTextureLinearSampling: new[] { true, false }
                    );

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

                hiRes = Prescaler ? new ShaderFilter(CrossBilateral, yInput, uInput, vInput) : input.ConvertToYuv();

                for (int i = 1; i <= Passes; i++)
                {
                    IFilter diff, linear;

                    // Compare to chroma
                    var rgb = new RgbFilter(hiRes, limitChroma: false);
                    linear = new ShaderFilter(GammaToLinear, rgb);
                    linear = new ResizeFilter(linear, chromaSize, adjointOffset, upscaler, downscaler);
                    diff   = new ShaderFilter(Diff, linear, uInput, vInput);

                    // Update result
                    hiRes = new ShaderFilter(SuperRes, hiRes, diff);
                }

                return(hiRes.ConvertToRgb());
            }
示例#4
0
            public override IFilter CreateFilter(IFilter input)
            {
                IFilter hiRes;

                var chromaSize = (TextureSize)Renderer.ChromaSize;
                var targetSize = input.OutputSize;

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

                float[] yuvConsts = new float[0];
                int     bitdepth  = (uInput.OutputFormat == TextureFormat.Unorm8) ? 8 : 10;

                float range = (1 << bitdepth) - 1;

                switch (Renderer.Colorimetric)
                {
                case YuvColorimetric.Auto: return(input);

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

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

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

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

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

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

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

                Vector2 offset        = Renderer.ChromaOffset;
                Vector2 adjointOffset = -offset * targetSize / chromaSize;

                string macroDefinitions = "";

                if (IsIntegral(Strength))
                {
                    macroDefinitions += String.Format("strength = {0};", Strength);
                }
                if (IsIntegral(Softness))
                {
                    macroDefinitions += String.Format("softness = {0};", Softness);
                }

                var CopyLuma    = CompileShader("CopyLuma.hlsl");
                var CopyChroma  = CompileShader("CopyChroma.hlsl");
                var MergeChroma = CompileShader("MergeChroma.hlsl").Configure(format: TextureFormat.Float16);

                var Diff = CompileShader("Diff.hlsl")
                           .Configure(arguments: yuvConsts, format: TextureFormat.Float16);

                var SuperRes = CompileShader("SuperResEx.hlsl", macroDefinitions: macroDefinitions)
                               .Configure(
                    arguments: new[] { Strength, Softness, yuvConsts[0], yuvConsts[1], offset.X, offset.Y }
                    );

                var CrossBilateral = CompileShader("CrossBilateral.hlsl")
                                     .Configure(
                    arguments: new[] { offset.X, offset.Y, yuvConsts[0], yuvConsts[1] },
                    perTextureLinearSampling: new[] { true, false }
                    );

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

                hiRes = Prescaler ? new ShaderFilter(CrossBilateral, yInput, uInput, vInput) : input.ConvertToYuv();

                for (int i = 1; i <= Passes; i++)
                {
                    IFilter diff, linear;

                    // Compare to chroma
                    linear = new ShaderFilter(GammaToLinear, hiRes.ConvertToRgb());
                    linear = new ResizeFilter(linear, chromaSize, adjointOffset, upscaler, downscaler);
                    diff   = new ShaderFilter(Diff, linear, uInput, vInput);

                    // Update result
                    hiRes = new ShaderFilter(SuperRes, hiRes, diff);
                }

                return(hiRes.ConvertToRgb());
            }
示例#5
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());
            }