Ejemplo n.º 1
0
        public static void AddHighQualityScaler(WicProcessingContext ctx)
        {
            uint width = (uint)ctx.Settings.Width, height = (uint)ctx.Settings.Height;
            var  fmt           = ctx.Source.Format;
            var  interpolator  = ctx.Settings.Interpolation.WeightingFunction.Support > 1d && fmt.ColorRepresentation == PixelColorRepresentation.Unspecified ? InterpolationSettings.Hermite : ctx.Settings.Interpolation;
            var  interpolatorx = width == ctx.Source.Width ? InterpolationSettings.NearestNeighbor : interpolator;
            var  interpolatory = height == ctx.Source.Height ? InterpolationSettings.NearestNeighbor : interpolator;

            if (fmt.NumericRepresentation == PixelNumericRepresentation.Float)
            {
                var mx = ctx.AddDispose(KernelMap <float> .MakeScaleMap(ctx.Source.Width, width, fmt.ColorChannelCount, fmt.AlphaRepresentation != PixelAlphaRepresentation.None, true, interpolatorx));
                var my = ctx.AddDispose(KernelMap <float> .MakeScaleMap(ctx.Source.Height, height, fmt.ChannelCount == 3 ? 4 : fmt.ColorChannelCount, fmt.AlphaRepresentation != PixelAlphaRepresentation.None, true, interpolatory));

                ctx.Source = ctx.AddDispose(new ConvolutionTransform <float, float>(ctx.Source, mx, my));
            }
            else
            {
                var mx = ctx.AddDispose(KernelMap <int> .MakeScaleMap(ctx.Source.Width, width, 1, false, false, interpolatorx));
                var my = ctx.AddDispose(KernelMap <int> .MakeScaleMap(ctx.Source.Height, height, 1, false, false, interpolatory));

                if (fmt.NumericRepresentation == PixelNumericRepresentation.Fixed)
                {
                    ctx.Source = ctx.AddDispose(new ConvolutionTransform <ushort, int>(ctx.Source, mx, my));
                }
                else
                {
                    ctx.Source = ctx.AddDispose(new ConvolutionTransform <byte, int>(ctx.Source, mx, my));
                }
            }
        }
Ejemplo n.º 2
0
        public static void AddHighQualityScaler(WicProcessingContext ctx, bool hybrid = false)
        {
            uint   width = (uint)ctx.Settings.Width, height = (uint)ctx.Settings.Height;
            double rat = ctx.Settings.HybridScaleRatio;

            if ((ctx.Source.Width == width && ctx.Source.Height == height) || (hybrid && rat == 1d))
            {
                return;
            }

            if (hybrid)
            {
                if (ctx.Source.Format.FormatGuid != Consts.GUID_WICPixelFormat32bppCMYK)
                {
                    return;
                }

                width  = (uint)Math.Ceiling(ctx.Source.Width / rat);
                height = (uint)Math.Ceiling(ctx.Source.Height / rat);
                ctx.Settings.HybridMode = HybridScaleMode.Off;
            }

            AddInternalFormatConverter(ctx, allow96bppFloat: true);

            var fmt           = ctx.Source.Format;
            var interpolator  = ctx.Settings.Interpolation.WeightingFunction.Support > 1d && fmt.ColorRepresentation == PixelColorRepresentation.Unspecified ? InterpolationSettings.Hermite : ctx.Settings.Interpolation;
            var interpolatorx = width == ctx.Source.Width ? InterpolationSettings.NearestNeighbor : hybrid ? InterpolationSettings.Average : interpolator;
            var interpolatory = height == ctx.Source.Height ? InterpolationSettings.NearestNeighbor : hybrid ? InterpolationSettings.Average : interpolator;

            if (fmt.NumericRepresentation == PixelNumericRepresentation.Float)
            {
                var mx = ctx.AddDispose(KernelMap <float> .MakeScaleMap(ctx.Source.Width, width, fmt.ColorChannelCount, fmt.AlphaRepresentation != PixelAlphaRepresentation.None, true, interpolatorx));
                var my = ctx.AddDispose(KernelMap <float> .MakeScaleMap(ctx.Source.Height, height, fmt.ChannelCount == 3 ? 4 : fmt.ColorChannelCount, fmt.AlphaRepresentation != PixelAlphaRepresentation.None, true, interpolatory));

                ctx.Source = ctx.AddDispose(new ConvolutionTransform <float, float>(ctx.Source, mx, my));
            }
            else
            {
                var mx = ctx.AddDispose(KernelMap <int> .MakeScaleMap(ctx.Source.Width, width, 1, false, false, interpolatorx));
                var my = ctx.AddDispose(KernelMap <int> .MakeScaleMap(ctx.Source.Height, height, 1, false, false, interpolatory));

                if (fmt.NumericRepresentation == PixelNumericRepresentation.Fixed)
                {
                    ctx.Source = ctx.AddDispose(new ConvolutionTransform <ushort, int>(ctx.Source, mx, my));
                }
                else
                {
                    ctx.Source = ctx.AddDispose(new ConvolutionTransform <byte, int>(ctx.Source, mx, my));
                }
            }
        }
Ejemplo n.º 3
0
        public WicHighQualityScaler(WicTransform prev) : base(prev)
        {
            uint width = (uint)Context.Settings.Width, height = (uint)Context.Settings.Height;
            var  interpolatorx = width == Context.Width ? InterpolationSettings.NearestNeighbor : Context.Settings.Interpolation;
            var  interpolatory = height == Context.Height ? InterpolationSettings.NearestNeighbor : Context.Settings.Interpolation;

            var mapx = KernelMap.MakeScaleMap(Context.Width, width, interpolatorx);
            var mapy = KernelMap.MakeScaleMap(Context.Height, height, interpolatory);

            if (Context.Settings.BlendingMode == GammaMode.Linear)
            {
                Source = new WicConvolution16bpc(Source, mapx, mapy);
            }
            else
            {
                Source = new WicConvolution8bpc(Source, mapx, mapy);
            }

            Source.GetSize(out Context.Width, out Context.Height);
        }
        public WicHighQualityScaler(WicTransform prev) : base(prev)
        {
            uint width = (uint)Context.Settings.Width, height = (uint)Context.Settings.Height;
            var  interpolatorx = width == Context.Width ? InterpolationSettings.NearestNeighbor : Context.Settings.Interpolation;
            var  interpolatory = height == Context.Height ? InterpolationSettings.NearestNeighbor : Context.Settings.Interpolation;

            var fmt = PixelFormat.Cache[Source.GetPixelFormat()];

            if (fmt.NumericRepresentation == PixelNumericRepresentation.Float)
            {
                var mx = KernelMap <float> .MakeScaleMap(Context.Width, width, fmt.ColorChannelCount, fmt.AlphaRepresentation != PixelAlphaRepresentation.None, true, interpolatorx);

                var my = KernelMap <float> .MakeScaleMap(Context.Height, height, fmt.ColorChannelCount, fmt.AlphaRepresentation != PixelAlphaRepresentation.None, true, interpolatory);

                source = new WicConvolution <float, float>(Source, mx, my);

                mapx = mx;
                mapy = my;
            }
            else
            {
                var mx = KernelMap <int> .MakeScaleMap(Context.Width, width, 1, fmt.AlphaRepresentation == PixelAlphaRepresentation.Unassociated, false, interpolatorx);

                var my = KernelMap <int> .MakeScaleMap(Context.Height, height, 1, fmt.AlphaRepresentation == PixelAlphaRepresentation.Unassociated, false, interpolatory);

                if (fmt.NumericRepresentation == PixelNumericRepresentation.Fixed)
                {
                    source = new WicConvolution <ushort, int>(Source, mx, my);
                }
                else
                {
                    source = new WicConvolution <byte, int>(Source, mx, my);
                }

                mapx = mx;
                mapy = my;
            }

            Source = source;
            Source.GetSize(out Context.Width, out Context.Height);
        }