protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                var sourceSize = input.Output.Size;

                if (!IsUpscalingFrom(sourceSize))
                {
                    return(input);
                }

                var targetSize = Renderer.TargetSize;

                CreateWeights((Size)sourceSize, targetSize);

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

                return(GetEwaFilter(shader, new[] { input }));
            }
            public ITextureFilter ScaleChroma(ICompositionFilter composition)
            {
                var chromaSize = composition.Chroma.Size();
                var targetSize = composition.TargetSize;

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

                CreateWeights(chromaSize, targetSize);

                var offset = composition.ChromaOffset + new Vector2(0.5f, 0.5f);
                int lobes  = TapCount.ToInt() / 2;
                var shader = new Shader(FromFile("EwaScaler.hlsl",
                                                 compilerOptions:
                                                 string.Format("LOBES = {0}; AR = {1}; CHROMA = 1;", lobes, AntiRingingEnabled ? 1 : 0)))
                {
                    Transform      = size => targetSize,
                    Arguments      = new[] { AntiRingingStrength, offset.X, offset.Y },
                    LinearSampling = true
                };

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

                return(GetEwaFilter(shader, new[] { resizedLuma, composition.Chroma }).ConvertToRgb());
            }
Beispiel #3
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());
            }
Beispiel #4
0
            protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                var sourceSize = input.Size();

                if ((Renderer.TargetSize <= sourceSize).Any)
                {
                    return(input);
                }

                var targetSize = Renderer.TargetSize;

                CreateWeights((Size)sourceSize, targetSize);

                int lobes  = TapCount.ToInt() / 2;
                var shader = new Shader(FromFile("EwaScaler.hlsl",
                                                 compilerOptions:
                                                 string.Format("LOBES = {0}; AR = {1}",
                                                               lobes, AntiRingingEnabled ? 1 : 0)))
                {
                    Transform      = size => targetSize,
                    Arguments      = new[] { AntiRingingStrength },
                    LinearSampling = true
                };

                return(GetEwaFilter(shader, new[] { input }));
            }
            protected void CreateWeights(TextureSize sourceSize, TextureSize targetSize)
            {
                DisposeHelper.DisposeElements(ref m_Weights);

                double scaleFactorX = GetScaleFactor(targetSize.Width, sourceSize.Width);
                double scaleFactorY = GetScaleFactor(targetSize.Height, sourceSize.Height);

                var tapCount = TapCount.ToInt();
                int lobes    = tapCount / 2;

                m_Weights = new IManagedTexture <ISourceTexture> [lobes];
                var dataPointsX = GetDataPointCount(scaleFactorX);
                var dataPointsY = GetDataPointCount(scaleFactorY);
                var channels    = lobes == 2 ? 2 : 4;
                var data        = new Half[dataPointsY, dataPointsX *channels];

                for (int z = 0; z < lobes; z++)
                {
                    for (int y = 0; y < dataPointsY; y++)
                    {
                        for (int x = 0; x < dataPointsX; x++)
                        {
                            var offsetX = x / (double)dataPointsX;
                            var offsetY = y / (double)dataPointsX;

                            for (int i = 0; i < lobes; i++)
                            {
                                var distance = GetDistance(i + offsetX, z + offsetY);
                                data[y, x *channels + i] = GetWeight(distance, tapCount);
                            }
                        }
                    }
                    var weight = Renderer.CreateTexture(dataPointsX, dataPointsY,
                                                        channels == 2 ? TextureFormat.Float16_RG : TextureFormat.Float16);
                    Renderer.UpdateTexture(weight, data);
                    m_Weights[z] = weight.GetManaged();
                }
            }
Beispiel #6
0
            protected void CreateWeights(Size sourceSize, Size targetSize)
            {
                if (m_Weights != null)
                {
                    return;
                }

                double scaleFactorX = GetScaleFactor(targetSize.Width, sourceSize.Width);
                double scaleFactorY = GetScaleFactor(targetSize.Height, sourceSize.Height);

                var tapCount = TapCount.ToInt();
                int lobes    = tapCount / 2;

                m_Weights = new ISourceTexture[lobes];
                var dataPointsX = GetDataPointCount(scaleFactorX);
                var dataPointsY = GetDataPointCount(scaleFactorY);
                var data        = new Half[dataPointsY, dataPointsX * 4];

                for (int z = 0; z < lobes; z++)
                {
                    for (int y = 0; y < dataPointsY; y++)
                    {
                        for (int x = 0; x < dataPointsX; x++)
                        {
                            var offsetX = x / (double)dataPointsX;
                            var offsetY = y / (double)dataPointsX;

                            for (int i = 0; i < 4; i++)
                            {
                                var distance = GetDistance(i + offsetX, z + offsetY);
                                data[y, x *4 + i] = GetWeight(distance, tapCount);
                            }
                        }
                    }
                    m_Weights[z] = Renderer.CreateTexture(dataPointsX, dataPointsY);
                    Renderer.UpdateTexture(m_Weights[z], data);
                }
            }
Beispiel #7
0
            public override IFilter CreateFilter(IFilter input)
            {
                DiscardTextures();

                if (Renderer.InputFormat.IsRgb())
                {
                    return(input);
                }

                var sourceSize = input.OutputSize;

                if (!IsUpscalingFrom(sourceSize))
                {
                    return(input);
                }

                var targetSize = Renderer.LumaSize;

                CreateWeights((Size)sourceSize, targetSize);

                var offset = Renderer.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
                    );

                var yuvFilters = new IFilter[] { new YSourceFilter(), new USourceFilter(), new VSourceFilter() };

                return(GetEwaFilter(shader, yuvFilters).ConvertToRgb());
            }