Ejemplo n.º 1
0
        public WicScaler(WicTransform prev, bool hybrid = false) : base(prev)
        {
            if (Context.Settings.Width == Context.Width && Context.Settings.Height == Context.Height)
            {
                return;
            }

            double rat = Context.Settings.HybridScaleRatio;

            if (hybrid && rat == 1d)
            {
                return;
            }

            if (Source is IWICBitmapSourceTransform)
            {
                // null crop to disable IWICBitmapSourceTransform scaling
                var clip = AddRef(Wic.CreateBitmapClipper());
                clip.Initialize(Source, new WICRect {
                    X = 0, Y = 0, Width = (int)Context.Width, Height = (int)Context.Height
                });

                Source = clip;
            }

            uint ow   = hybrid ? (uint)Math.Ceiling(Context.Width / rat) : (uint)Context.Settings.Width;
            uint oh   = hybrid ? (uint)Math.Ceiling(Context.Height / rat) : (uint)Context.Settings.Height;
            var  mode = hybrid ? WICBitmapInterpolationMode.WICBitmapInterpolationModeFant :
                        Context.Settings.Interpolation.WeightingFunction.Support <0.1 ? WICBitmapInterpolationMode.WICBitmapInterpolationModeNearestNeighbor :
                                                                                  Context.Settings.Interpolation.WeightingFunction.Support> 1.0 ? Context.Settings.ScaleRatio < 1.0 ? WICBitmapInterpolationMode.WICBitmapInterpolationModeCubic : WICBitmapInterpolationMode.WICBitmapInterpolationModeHighQualityCubic :
                        WICBitmapInterpolationMode.WICBitmapInterpolationModeFant;

            var scaler = AddRef(Wic.CreateBitmapScaler());

            scaler.Initialize(Source, ow, oh, mode);

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

            if (hybrid)
            {
                Context.Settings.Crop = new Rectangle(0, 0, (int)Context.Width, (int)Context.Height);
            }
        }
Ejemplo n.º 2
0
        public WicNativeScaler(WicTransform prev) : base(prev)
        {
            double rat = Context.Settings.HybridScaleRatio;

            if (rat == 1d)
            {
                return;
            }

            var trans = Source as IWICBitmapSourceTransform;

            if (trans == null)
            {
                return;
            }

            uint ow = Context.Width, oh = Context.Height;
            uint cw = (uint)Math.Ceiling(ow / rat), ch = (uint)Math.Ceiling(oh / rat);

            trans.GetClosestSize(ref cw, ref ch);

            if (cw == ow && ch == oh)
            {
                return;
            }

            double wrat = (double)ow / cw, hrat = (double)oh / ch;

            var crop = Context.Settings.Crop;

            Context.Settings.Crop = new Rectangle((int)Math.Floor(crop.X / wrat), (int)Math.Floor(crop.Y / hrat), (int)Math.Ceiling(crop.Width / wrat), (int)Math.Ceiling(crop.Height / hrat));

            var scaler = AddRef(Wic.CreateBitmapScaler());

            scaler.Initialize(Source, cw, ch, WICBitmapInterpolationMode.WICBitmapInterpolationModeFant);

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