Exemplo n.º 1
0
            public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset)
            {
                float[] yuvConsts  = Renderer.Colorimetric.GetYuvConsts();
                var     chromaSize = chromaInput.Output.Size;
                var     lumaSize   = lumaInput.Output.Size;

                Vector2 adjointOffset = -chromaOffset * lumaSize / chromaSize;

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

                // Fall back to default when downscaling is needed
                if (targetSize.Width < chromaSize.Width || targetSize.Height < chromaSize.Height)
                {
                    return(null);
                }

                var resizedLuma = lumaInput.SetSize(targetSize, tagged: true);
                var lowresYUV   = DownscaleLuma(lumaInput, chromaInput, chromaSize, adjointOffset);

                return(crossBilateral.ApplyTo(resizedLuma, lowresYUV).ConvertToRgb());
            }
Exemplo n.º 2
0
            public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset)
            {
                var chromaSize = chromaInput.Output.Size;

                CreateWeights(chromaSize, targetSize);

                var offset = chromaOffset + new Vector2(0.5f, 0.5f);
                int lobes  = TapCount.ToInt() / 2;
                var shader = CompileShader("EwaScaler.hlsl",
                                           macroDefinitions:
                                           string.Format("LOBES = {0}; AR = {1}; CHROMA = 1;",
                                                         lobes, AntiRingingEnabled ? 1 : 0))
                             .Configure(
                    transform: size => targetSize,
                    arguments: new[] { AntiRingingStrength, offset.X, offset.Y },
                    linearSampling: true
                    );

                // Fall back to default when downscaling is needed
                if (targetSize.Width < chromaSize.Width || targetSize.Height < chromaSize.Height)
                {
                    return(null);
                }

                var resizedLuma = lumaInput.SetSize(targetSize, tagged: true);

                return(GetEwaFilter(shader, new[] { resizedLuma, chromaInput }).ConvertToRgb());
            }
Exemplo n.º 3
0
        public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset)
        {
            if (lumaInput is YSourceFilter && chromaInput is ChromaSourceFilter && chromaOffset == Renderer.ChromaOffset)
            {
                return(m_SourceFilter.SetSize(targetSize, tagged: true));
            }

            return(null);
        }
Exemplo n.º 4
0
        public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset)
        {
            var fullSizeChroma = new ResizeFilter(chromaInput, targetSize, TextureChannels.ChromaOnly,
                                                  chromaOffset, Renderer.ChromaUpscaler, Renderer.ChromaDownscaler);

            return(new MergeFilter(lumaInput.SetSize(targetSize, tagged: true), fullSizeChroma)
                   .ConvertToRgb()
                   .Tagged(new ChromaScalerTag(chromaInput, fullSizeChroma.Status().PrependToStatus("Chroma: "))));
        }
            public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset)
            {
                var chromaSize = chromaInput.Output.Size;

                // Fall back to default when downscaling is needed
                if (targetSize.Width < chromaSize.Width || targetSize.Height < chromaSize.Height)
                {
                    return(null);
                }

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

                var resizedLuma = lumaInput.SetSize(targetSize, tagged: true);

                return(chromaShader.ApplyTo(resizedLuma, chromaInput).ConvertToRgb());
            }
Exemplo n.º 6
0
        public static ITextureFilter ScaleChroma(ITextureFilter luma, ITextureFilter chroma, TextureSize targetSize, Vector2 chromaOffset)
        {
            luma = luma.SetSize(targetSize);
            var resizedLuma = luma as ResizeFilter;

            if (resizedLuma != null)
            {
                resizedLuma.AddLabel(resizedLuma.ScaleDescription.AddPrefixToDescription("Luma: "));
            }

            if (chroma.Size() != luma.Size())
            {
                var resizedChroma = new ResizeFilter(chroma, luma.Size(), TextureChannels.ChromaOnly, chromaOffset, Renderer.ChromaUpscaler, Renderer.ChromaDownscaler);
                resizedChroma.AddLabel(resizedChroma.ScaleDescription.AddPrefixToDescription("Chroma: "));
                chroma = resizedChroma;
            }

            return(luma
                   .MergeWith(chroma)
                   .ConvertToRgb());
        }
Exemplo n.º 7
0
        private VideoSourceFilter(TrueSourceFilter trueSource, TextureSize outputSize, bool wantYuv)
            : base(Compile(new TextureDescription(outputSize), () =>
        {
            ITextureFilter source = trueSource;

            if (trueSource.IsYuv() && !wantYuv)
                source = source.ConvertToYuv();

            if (!trueSource.IsYuv() && wantYuv)
                source = source.ConvertToRgb();

            return(source.SetSize(outputSize));
        }))
        {
            m_TrueSource = trueSource;
            m_WantYuv    = wantYuv;

            if (m_WantYuv)
            {
                m_TrueSource.WantYuv = true;         // Prefer enabling (generates less overhead)
            }
            m_TrueSource.PrescaleSize = Output.Size; // Try change source size, always use latest value
        }
Exemplo n.º 8
0
            public override ITextureFilter ScaleChroma(ICompositionFilter composition)
            {
                ITextureFilter input = composition;

                if (Prescaler)
                {
                    input = composition + (new Bilateral.Bilateral());
                }

                var chromaSize   = composition.Chroma.Size();
                var lumaSize     = composition.Luma.Size();
                var chromaOffset = composition.ChromaOffset;

                var downscaler = new Bicubic(0.75f, false);

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

                Vector2 adjointOffset = -chromaOffset * lumaSize / chromaSize;

                string superResMacros = "";

                if (Softness == 0.0f)
                {
                    superResMacros += "SkipSoftening = 1;";
                }
                string diffMacros = string.Format("LimitedRange = {0}; Range = {1}", limited ? 1 : 0, (1 << bitdepth) - 1);

                var configArgs = yuvConsts.Concat(new[] { chromaOffset.X, chromaOffset.Y }).ToArray();

                var Diff = new Shader(FromFile("Diff.hlsl", compilerOptions: diffMacros))
                {
                    Arguments = configArgs, Format = TextureFormat.Float16
                };
                var SuperRes = new Shader(FromFile("SuperRes.hlsl", compilerOptions: superResMacros))
                {
                    Arguments = (new[] { Strength, Softness }).Concat(configArgs).ToArray()
                };

                if (Passes == 0 || Strength == 0.0f)
                {
                    return(input);
                }

                var hiRes = input.SetSize(lumaSize).ConvertToYuv();

                for (int i = 1; i <= Passes; i++)
                {
                    // Downscale and Subtract
                    ITextureFilter diff;
                    if (LegacyDownscaling)
                    {
                        var lores = hiRes.Resize(chromaSize, TextureChannels.ChromaOnly, adjointOffset, null, downscaler);
                        diff = Diff.ApplyTo(lores, composition.Chroma);
                    }
                    else
                    {
                        diff = DownscaleAndDiff(hiRes, composition.Chroma, chromaSize, adjointOffset);
                    }

                    // Update result
                    hiRes = SuperRes.ApplyTo(hiRes, diff);
                }

                return(hiRes.ConvertToRgb());
            }
Exemplo n.º 9
0
 public static ITextureFilter AddTaggedResizer(this ITextureFilter <ITexture2D> filter)
 {
     return(filter.SetSize(filter.Output.Size, true));
 }
Exemplo n.º 10
0
            public ITextureFilter CreateFilter(ITextureFilter original, ITextureFilter initial)
            {
                ITextureFilter result;
                var            HQDownscaler = (IScaler) new Bicubic(0.75f, false);

                // Calculate Sizes
                var inputSize  = original.Size();
                var targetSize = TargetSize();

                string macroDefinitions = "";

                if (Softness == 0.0f)
                {
                    macroDefinitions += "SkipSoftening = 1;";
                }
                if (Strength == 0.0f)
                {
                    return(initial);
                }

                // Compile Shaders
                var Diff = new Shader(FromFile("Diff.hlsl"))
                {
                    Format = TextureFormat.Float16
                };

                var SuperRes = new Shader(FromFile("SuperRes.hlsl", compilerOptions: macroDefinitions))
                {
                    Arguments = new[] { Strength, Softness }
                };
                var FinalSuperRes = new Shader(FromFile("SuperRes.hlsl", compilerOptions: macroDefinitions + "FinalPass = 1;"))
                {
                    Arguments = new[] { Strength }
                };

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

                // Skip if downscaling
                if ((targetSize <= inputSize).Any)
                {
                    return(original);
                }

                // Initial scaling
                if (initial != original)
                {
                    // Always correct offset (if any)
                    var filter = initial as IOffsetFilter;
                    if (filter != null)
                    {
                        filter.ForceOffsetCorrection();
                    }

                    result = initial.SetSize(targetSize).Apply(GammaToLinear);
                }
                else
                {
                    result = original.Apply(GammaToLinear).Resize(targetSize, tagged: true);
                }

                for (int i = 1; i <= Passes; i++)
                {
                    // Downscale and Subtract
                    ITextureFilter diff;
                    if (LegacyDownscaling)
                    {
                        var loRes = result.Resize(inputSize, downscaler: HQDownscaler);
                        diff = Diff.ApplyTo(loRes, original);
                    }
                    else
                    {
                        diff = DownscaleAndDiff(result, original, inputSize);
                    }

                    // Update result
                    result = (i != Passes ? SuperRes : FinalSuperRes).ApplyTo(result, diff);
                }

                return(result);
            }
Exemplo n.º 11
0
 protected override ITextureFilter CreateFilter(ITextureFilter input)
 {
     return(input.SetSize(GetOutputSize(), tagged: true));
 }
Exemplo n.º 12
0
 protected override ITextureFilter CreateFilter(ITextureFilter input)
 {
     return(input.SetSize(GetOutputSize(), tagged: true)
            .Tagged(new TemporaryTag("Resizer")));
 }
Exemplo n.º 13
0
            public ITextureFilter CreateFilter(ITextureFilter original, ITextureFilter initial)
            {
                ITextureFilter result;

                // Calculate Sizes
                var inputSize  = original.Size();
                var targetSize = TargetSize();

                // Compile Shaders
                var SharpDiff = CompileShader("Diff.hlsl", macroDefinitions: "MODE = 0;")
                                .Configure(format: TextureFormat.Float16);
                var Diff = CompileShader("Diff.hlsl", macroDefinitions: String.Format("MODE = {0};", Mode == SSSRMode.Sharp ? 0 : 1))
                           .Configure(format: TextureFormat.Float16);
                var SuperRes      = CompileShader("SuperRes.hlsl");
                var FinalSuperRes = CompileShader("SuperRes.hlsl", macroDefinitions: "FinalPass = 1;" + (LinearLight ? "LinearLight = 1;" : ""));
                var GammaToLinear = CompileShader("GammaToLinear.hlsl");

                SharpDiff["spread"]    = 1 / Locality;
                SharpDiff["oversharp"] = OverSharp;

                Diff["spread"]    = 1 / Locality;
                Diff["oversharp"] = OverSharp;

                // Skip if downscaling
                if ((targetSize <= inputSize).Any)
                {
                    return(original);
                }

                // Initial scaling
                if (initial != original)
                {
                    // Always correct offset (if any)
                    var filter = initial as IOffsetFilter;
                    if (filter != null)
                    {
                        filter.ForceOffsetCorrection();
                    }

                    result = initial.SetSize(targetSize, tagged: true);
                    if (LinearLight)
                    {
                        original = original.Apply(GammaToLinear);
                        result   = result.Apply(GammaToLinear);
                    }
                }
                else
                {
                    if (LinearLight)
                    {
                        original = original.Apply(GammaToLinear);
                    }
                    result = original.Resize(targetSize, tagged: true);
                }

                for (int i = 1; i <= Passes; i++)
                {
                    ITextureFilter diff;

                    // Downscale and Subtract
                    var loRes = Downscale(result, original, inputSize);

                    // Calculate difference
                    if (Mode == SSSRMode.Hybrid && i == 1)
                    {
                        diff = SharpDiff.ApplyTo(loRes, original);
                    }
                    else
                    {
                        diff = Diff.ApplyTo(loRes, original);
                    }

                    // Update result
                    result = (i != Passes ? SuperRes : FinalSuperRes).ApplyTo(result, diff, loRes);
                }

                return(result);
            }
Exemplo n.º 14
0
 protected override IFilter <ITextureOutput <ITexture2D> > Optimize()
 {
     return(Fallback
            .SetSize(TargetSize)
            .Compile());
 }
Exemplo n.º 15
0
 protected override ITextureFilter FinalizeOutput(ITextureFilter output)
 {
     return(output.SetSize(Renderer.TargetSize, tagged: true));
 }