Ejemplo n.º 1
0
 public I <float> Filter(
     IImageBuffer image,
     [InputPin(PropertyMode = PropertyMode.Default)] int width,
     [InputPin(PropertyMode = PropertyMode.Default)] int height,
     [InputPin(PropertyMode = PropertyMode.Default)] ResizeFilterType resizeFilterType = ResizeFilterType.Lanczos8
     )
 {
     return(image.ToF32().Resize(new Int2(width, height), resizeFilterType));
 }
Ejemplo n.º 2
0
 public AviSynthSettings(string template, ResizeFilterType resizeMethod, bool resize,
                         DenoiseFilterType denoiseMethod, bool denoise, bool mpeg2deblock, bool colourCorrect, mod16Method method)
 {
     this.Template      = template;
     this.ResizeMethod  = resizeMethod;
     this.DenoiseMethod = denoiseMethod;
     this.Deinterlace   = deinterlace;
     this.Denoise       = denoise;
     this.IVTC          = ivtc;
     this.MPEG2Deblock  = mpeg2deblock;
     this.ColourCorrect = colourCorrect;
     this.Mod16Method   = method;
 }
Ejemplo n.º 3
0
        public AviSynthSettings(string template, ResizeFilterType resizeMethod, bool resize,
			DenoiseFilterType denoiseMethod, bool denoise, bool mpeg2deblock, bool colourCorrect, mod16Method method, bool dss2)
        {
            this.Template = template;
            this.Resize = resize;
            this.ResizeMethod = resizeMethod;
            this.DenoiseMethod = denoiseMethod;
            this.Deinterlace = deinterlace;
            this.Denoise = denoise;
            this.IVTC = ivtc;
            this.MPEG2Deblock = mpeg2deblock;
            this.ColourCorrect = colourCorrect;
            this.Mod16Method = method;
            this.DSS2 = dss2;
        }
Ejemplo n.º 4
0
        public static string GetResizeLine(bool resize, int hres, int vres, ResizeFilterType type)
        {
            if (!resize)
            {
                return("#resize");
            }
            EnumProxy p = EnumProxy.Create(type);

            if (p.Tag != null)
            {
                return(string.Format(p.Tag + " # {2}", hres, vres, p));
            }
            else
            {
                return("#resize - " + p);
            }
        }
Ejemplo n.º 5
0
        internal static float GetFilterRadius(ResizeFilterType filterType)
        {
            switch (filterType)
            {
            case ResizeFilterType.Hermite:
                return(1.0f);

            case ResizeFilterType.NearestNeighbor:
                return(0.5f);

            case ResizeFilterType.Triangle:
                return(1.0f);

            case ResizeFilterType.Bell:
                return(1.5f);

            case ResizeFilterType.CubicBSpline:
                return(2.0f);

            case ResizeFilterType.Lanczos3:
                return(3.0f);

            case ResizeFilterType.Mitchell:
                return(2.0f);

            case ResizeFilterType.Cosine:
                return(1.0f);

            case ResizeFilterType.CatmullRom:
                return(2.0f);

            case ResizeFilterType.Quadratic:
                return(1.5f);

            case ResizeFilterType.QuadraticBSpline:
                return(1.5f);

            case ResizeFilterType.CubicConvolution:
                return(3.0f);

            case ResizeFilterType.Lanczos8:
                return(8.0f);
            }

            throw new NotSupportedException("Invalid resize filter type");
        }
Ejemplo n.º 6
0
 public AviSynthSettings()
 {
     this.Template               = "<input>\r\n<deinterlace>\r\n<crop>\r\n<resize>\r\n<denoise>\r\n"; // Default -- will act as it did before avs profiles
     this.resize                 = true;
     this.resizeMethod           = ResizeFilterType.Lanczos;                                          // Lanczos
     this.preferAnimeDeinterlace = false;
     this.denoise                = false;
     this.denoiseMethod          = 0; // UnDot
     this.mpeg2deblock           = false;
     this.colourCorrect          = true;
     this.mod16Method            = mod16Method.none;
     this.modValueUsed           = modValue.mod8;
     this.dss2   = false;
     this.upsize = false;
     this.acceptableAspectError = 1;
     this.nvResize = false;
 }
Ejemplo n.º 7
0
        internal static OutputPixel[] CreateContributors(ResizeFilterType filterType, int inputWidth, int leftIn, int rightIn, int widthOut)
        {
            switch (filterType)
            {
            case ResizeFilterType.Hermite:
                return(Hermite(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Triangle:
                return(Triangle(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.CubicBSpline:
                return(CubicBSpline(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Lanczos3:
                return(Lanczos3(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Mitchell:
                return(Mitchell(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Cosine:
                return(Cosine(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.CatmullRom:
                return(CatmullRom(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.QuadraticBSpline:
                return(QuadraticBSpline(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Bell:
                return(Bell(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Quadratic:
                return(Quadratic(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.CubicConvolution:
                return(CubicConvolution(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.Lanczos8:
                return(Lanczos8(inputWidth, leftIn, rightIn, widthOut));

            case ResizeFilterType.NearestNeighbor:
            default:
                return(NearestNeighbor(inputWidth, leftIn, rightIn, widthOut));
            }
        }
Ejemplo n.º 8
0
 public AviSynthSettings(string template, ResizeFilterType resizeMethod, bool resize, bool upsize, DenoiseFilterType denoiseMethod,
                         bool denoise, bool mpeg2deblock, bool colourCorrect, mod16Method method, bool dss2, modValue modValueUsed, decimal acceptableAspectError)
 {
     this.Template              = template;
     this.Resize                = resize;
     this.ResizeMethod          = resizeMethod;
     this.DenoiseMethod         = denoiseMethod;
     this.Deinterlace           = deinterlace;
     this.Denoise               = denoise;
     this.IVTC                  = ivtc;
     this.MPEG2Deblock          = mpeg2deblock;
     this.ColourCorrect         = colourCorrect;
     this.Mod16Method           = method;
     this.DSS2                  = dss2;
     this.Upsize                = upsize;
     this.ModValue              = modValueUsed;
     this.acceptableAspectError = acceptableAspectError;
 }
Ejemplo n.º 9
0
        public static void Resize(I <float> source, IntRect sourceRect, I <float> destination, ResizeFilterType filterType, CancellationToken cancel = default(CancellationToken))
        {
            if (source == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            sourceRect = sourceRect.Clip(new IntRect(0, 0, source.Width, source.Height));
            if (sourceRect.Width <= 0 || sourceRect.Height <= 0 || source.Channels <= 0)
            {
                throw new ArgumentNullException("Source image must not be empty");
            }

            if (destination.Width <= 0 || destination.Height <= 0 || destination.Channels <= 0)
            {
                return;
            }

            var s = source.Data.Buffer;
            var d = destination.Data.Buffer;

            int sourceChannelCount      = source.Format.ChannelCount;
            int destinationChannelCount = destination.Format.ChannelCount;
            int sourceStride            = source.Width * source.Format.ChannelCount;
            int destinationStride       = destination.Width * destination.Format.ChannelCount;

            OutputPixel[] contribX = CreateContributors(filterType, source.Width, sourceRect.Left, sourceRect.Right, destination.Width);
            OutputPixel[] contribY = CreateContributors(filterType, source.Height, sourceRect.Top, sourceRect.Bottom, destination.Height);

            float filterRadius    = GetFilterRadius(filterType);
            int   ringBufferLines = contribY.Max(x => x.N);
            var   ringBuffer      = new float[destinationStride * ringBufferLines];

            var ranges = destination.Format.ChannelRanges.Select(r => Range.Create((float)r.Low, (float)r.High)).ToArray();

            int   sY = sourceRect.Top;
            int   dX, j;
            int   offset = 0;
            float value;
            int   positionInRing = sY % ringBufferLines;

            for (int dY = 0; dY < destination.Height; ++dY)
            {
                if ((dY % 128) == 0 && cancel.IsCancellationRequested)
                {
                    break;
                }

                int rowIn, rowOut;
                while (sY < sourceRect.Bottom && sY <= contribY[dY].MaxPixel)
                {
                    rowIn  = sY * sourceStride;
                    rowOut = positionInRing * destinationStride;

                    for (dX = 0; dX < destination.Width; ++dX)
                    {
                        var contrib = contribX[dX];
                        for (int c = 0; c < destinationChannelCount; ++c)
                        {
                            value = 0;

                            for (j = 0; j < contrib.N; ++j)
                            {
                                float weight = contrib.P[j].Weight;
                                if (weight != 0)
                                {
                                    offset = contrib.P[j].Pixel * sourceChannelCount;
                                    value  = value + s[rowIn + offset + c] * weight;
                                }
                            }

                            ringBuffer[rowOut] = value * contrib.Normalize;
                            ++rowOut;
                        }
                    }

                    ++sY;
                    positionInRing = (positionInRing + 1) % ringBufferLines;
                }

                // resize lines vertically
                for (int k = 0; k < destinationStride;)
                {
                    var contrib = contribY[dY];
                    for (int c = 0; c < destinationChannelCount; ++c, ++k)
                    {
                        value = 0;

                        for (j = 0; j < contrib.N; ++j)
                        {
                            float weight = contrib.P[j].Weight;
                            if (weight != 0)
                            {
                                offset = (contrib.P[j].Pixel % ringBufferLines) * destinationStride + k;
                                value  = value + ringBuffer[offset] * weight;
                            }
                        }

                        d[dY * destinationStride + k] = ranges[c].Clamp((float)(value * contrib.Normalize));
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public static void Resize(I <float> source, I <float> destination, ResizeFilterType filterType, CancellationToken cancel = default(CancellationToken))
 {
     Resize(source, new IntRect(0, 0, source.Width, source.Height), destination, filterType, cancel);
 }
Ejemplo n.º 11
0
        public static I <float> Resize(this I <float> source, int targetHeight, int targetWidth, IntRect sourceRect, ResizeFilterType filterType, CancellationToken cancel = default(CancellationToken))
        {
            var destination = new I <float>(source.Format, targetHeight, targetWidth);

            Resize(source, sourceRect, destination, filterType, cancel);
            return(destination);
        }
Ejemplo n.º 12
0
        public static void Resize(I <Vector3> source, IntRect sourceRect, I <Vector3> destination, ResizeFilterType filterType, CancellationToken cancel = default(CancellationToken))
        {
            if (source == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            sourceRect = sourceRect.Clip(new IntRect(0, 0, source.Width, source.Height));
            if (sourceRect.Width <= 0 || sourceRect.Height <= 0 || source.Channels <= 0)
            {
                throw new ArgumentNullException("Source image must not be empty");
            }

            if (destination.Width <= 0 || destination.Height <= 0 || destination.Channels <= 0)
            {
                return;
            }

            var s = source.Data.Buffer;
            var d = destination.Data.Buffer;

            var contribX = ImageBufferResize.CreateContributors(filterType, source.Width, sourceRect.Left, sourceRect.Right, destination.Width);
            var contribY = ImageBufferResize.CreateContributors(filterType, source.Height, sourceRect.Top, sourceRect.Bottom, destination.Height);

            float filterRadius    = ImageBufferResize.GetFilterRadius(filterType);
            int   ringBufferLines = contribY.Max(x => x.N);
            var   ringBuffer      = new Vector3[destination.Width * ringBufferLines];


            var ranges = destination.Format.ChannelRanges;
            var low    = new Vector3((float)ranges[0].Low, (float)ranges[1].Low, (float)ranges[2].Low);
            var high   = new Vector3((float)ranges[0].High, (float)ranges[1].High, (float)ranges[2].High);

            int sY = sourceRect.Top;
            int dX, j;
            int offset         = 0;
            int positionInRing = sY % ringBufferLines;

            for (int dY = 0; dY < destination.Height; ++dY)
            {
                if ((dY % 128) == 0 && cancel.IsCancellationRequested)
                {
                    break;
                }

                int rowIn, rowOut;
                while (sY < sourceRect.Bottom && sY <= contribY[dY].MaxPixel)
                {
                    rowIn  = sY * source.Width;
                    rowOut = positionInRing * destination.Width;

                    for (dX = 0; dX < destination.Width; ++dX)
                    {
                        var contrib = contribX[dX];
                        var value   = Vector3.Zero;

                        for (j = 0; j < contribX[dX].N; ++j)
                        {
                            float weight = contrib.P[j].Weight;
                            if (weight != 0)
                            {
                                offset = contrib.P[j].Pixel;
                                value  = value + s[rowIn + offset] * weight;
                            }
                        }

                        ringBuffer[rowOut] = value * contrib.Normalize;
                        ++rowOut;
                    }

                    ++sY;
                    positionInRing = (positionInRing + 1) % ringBufferLines;
                }

                // resize lines vertically
                for (int k = 0; k < destination.Width; ++k)
                {
                    var contrib = contribY[dY];
                    var value   = Vector3.Zero;

                    for (j = 0; j < contrib.N; ++j)
                    {
                        float weight = contrib.P[j].Weight;
                        if (weight != 0)
                        {
                            offset = contrib.P[j].Pixel % ringBufferLines;
                            offset = offset * destination.Width + k;
                            value  = value + ringBuffer[offset] * weight;
                        }
                    }

                    value = Vector3.Max(Vector3.Min(value * contrib.Normalize, high), low);
                    d[dY * destination.Width + k] = value;
                }
            }
        }
Ejemplo n.º 13
0
 public static I <double> Resize(this I <double> source, Int2 targetSize, ResizeFilterType filterType, CancellationToken cancel = default(CancellationToken))
 {
     return(Resize(source, targetSize.Y, targetSize.X, filterType, cancel));
 }
Ejemplo n.º 14
0
 public static string GetResizeLine(bool resize, int hres, int vres, ResizeFilterType type)
 {
     if (!resize)
         return "#resize";
     EnumProxy p = EnumProxy.Create(type);
     if (p.Tag != null)
         return string.Format(p.Tag + " # {2}", hres, vres, p);
     else
         return "#resize - " + p;
 }
Ejemplo n.º 15
0
        public static string GetResizeLine(bool resize, int hres, int vres, int hresWithBorder, int vresWithBorder, ResizeFilterType type, bool crop, CropValues cropValues, int originalHRes, int originalVRes)
        {
            int iInputHresAfterCrop = originalHRes;
            int iInputVresAfterCrop = originalVRes;

            if (crop)
            {
                iInputHresAfterCrop = iInputHresAfterCrop - cropValues.left - cropValues.right;
                iInputVresAfterCrop = iInputVresAfterCrop - cropValues.top - cropValues.bottom;
            }

            // only resize if necessary
            if (!resize || (hres == iInputHresAfterCrop && vres == iInputVresAfterCrop))
            {
                if (hresWithBorder > iInputHresAfterCrop || vresWithBorder > iInputVresAfterCrop)
                {
                    return(getAddBorders(hres, vres, hresWithBorder, vresWithBorder));
                }
                else
                {
                    return("#resize");
                }
            }

            EnumProxy p = EnumProxy.Create(type);

            if (p.Tag != null)
            {
                if (hresWithBorder > hres || vresWithBorder > vres)
                {
                    return(string.Format(p.Tag + "." + getAddBorders(hres, vres, hresWithBorder, vresWithBorder) + " # {2}", hres, vres, p));
                }
                else
                {
                    return(string.Format(p.Tag + " # {2}", hres, vres, p));
                }
            }
            else
            {
                return("#resize - " + p);
            }
        }
Ejemplo n.º 16
0
        public static string GetResizeLine(bool resize, int hres, int vres, int hresWithBorder, int vresWithBorder, ResizeFilterType type, bool crop, CropValues cropValues, int originalHRes, int originalVRes)
        {
            int iInputHresAfterCrop = originalHRes;
            int iInputVresAfterCrop = originalVRes;

            if (crop)
            {
                iInputHresAfterCrop = iInputHresAfterCrop - cropValues.left - cropValues.right;
                iInputVresAfterCrop = iInputVresAfterCrop - cropValues.top - cropValues.bottom;
            }

            // only resize if necessary
            if (!resize || (hres == iInputHresAfterCrop && vres == iInputVresAfterCrop))
            {
                if (hresWithBorder > iInputHresAfterCrop || vresWithBorder > iInputVresAfterCrop)
                {
                    return(string.Format("AddBorders({0},{1},{2},{3})",
                                         Math.Floor((hresWithBorder - iInputHresAfterCrop) / 2.0), Math.Floor((vresWithBorder - iInputVresAfterCrop) / 2.0),
                                         Math.Ceiling((hresWithBorder - iInputHresAfterCrop) / 2.0), Math.Ceiling((vresWithBorder - iInputVresAfterCrop) / 2.0)));
                }
                else
                {
                    return("#resize");
                }
            }

            EnumProxy p = EnumProxy.Create(type);

            if (p.Tag != null)
            {
                if (hresWithBorder > hres || vresWithBorder > vres)
                {
                    return(string.Format(p.Tag + ".AddBorders({3},{4},{5},{6}) # {2}", hres, vres, p,
                                         Math.Floor((hresWithBorder - hres) / 2.0), Math.Floor((vresWithBorder - vres) / 2.0),
                                         Math.Ceiling((hresWithBorder - hres) / 2.0), Math.Ceiling((vresWithBorder - vres) / 2.0)));
                }
                else
                {
                    return(string.Format(p.Tag + " # {2}", hres, vres, p));
                }
            }
            else
            {
                return("#resize - " + p);
            }
        }
Ejemplo n.º 17
0
 public static I <float> Resize(this I <float> source, Int2 targetSize, IntRect sourceRec, ResizeFilterType filterType, CancellationToken cancel = default(CancellationToken))
 {
     return(Resize(source, targetSize.Y, targetSize.X, sourceRec, filterType, cancel));
 }