public WicPlanarCacheSource(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, WICRect crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio)
        {
            // TODO fractional ratio support?
            subsampleRatioX = Math.Ceiling((double)descY.Width / descC.Width);
            subsampleRatioY = Math.Ceiling((double)descY.Height / descC.Height);

            var scrop = new WICRect();

            scrop.X      = (int)Math.Floor(crop.X / ratio);
            scrop.Y      = (int)Math.Floor(crop.Y / ratio);
            scrop.Width  = Math.Min((int)Math.Ceiling(crop.Width / ratio), (int)descY.Width);
            scrop.Height = Math.Min((int)Math.Ceiling(crop.Height / ratio), (int)descY.Height);

            if (subsampleRatioX > 1d)
            {
                descC.Width = Math.Min((uint)Math.Ceiling(scrop.Width / subsampleRatioX), descC.Width);
                descY.Width = (uint)Math.Min(descC.Width * subsampleRatioX, scrop.Width);

                if (scrop.X % subsampleRatioX > 0)
                {
                    scrop.X = (int)(scrop.X / subsampleRatioX) * (int)subsampleRatioX;
                }
            }
            else
            {
                descC.Width = descY.Width = (uint)scrop.Width;
            }

            if (subsampleRatioY > 1d)
            {
                descC.Height = Math.Min((uint)Math.Ceiling(scrop.Height / subsampleRatioY), descC.Height);
                descY.Height = (uint)Math.Min(descC.Height * subsampleRatioY, scrop.Height);

                if (scrop.Y % subsampleRatioY > 0)
                {
                    scrop.Y = (int)(scrop.Y / subsampleRatioY) * (int)subsampleRatioY;
                }
            }
            else
            {
                descC.Height = descY.Height = (uint)scrop.Height;
            }

            sourceTransform        = source;
            sourceTransformOptions = transformOptions;
            planeDescriptionY      = descY;
            planeDescriptionC      = descC;
            scaledCrop             = scrop;
            scaledWidth            = width;
            scaledHeight           = height;

            strideY     = (uint)scrop.Width + 3u & ~3u;
            buffHeightY = 16u;

            strideC     = (uint)(Math.Ceiling(scrop.Width / subsampleRatioX)) * 2u + 3u & ~3u;
            buffHeightC = (uint)(buffHeightY / subsampleRatioY);

            sourceY = new WicPlanarSource(this, WicPlane.Luma, descY);
            sourceC = new WicPlanarSource(this, WicPlane.Chroma, descC);
        }
 public WicPlanarCache(IWICPlanarBitmapSourceTransform source, ReadOnlySpan <WICBitmapPlaneDescription> desc, WICBitmapTransformOptions transformOptions, uint width, uint height, in PixelArea crop)
Exemple #3
0
        public WicPlanarCache(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, WICRect crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio)
        {
            subsampleRatioX = Math.Ceiling((double)descY.Width / descC.Width);
            subsampleRatioY = Math.Ceiling((double)descY.Height / descC.Height);

            var scrop = new WICRect {
                X      = (int)Math.Floor(crop.X / ratio),
                Y      = (int)Math.Floor(crop.Y / ratio),
                Width  = Math.Min((int)Math.Ceiling(crop.Width / ratio), (int)descY.Width),
                Height = Math.Min((int)Math.Ceiling(crop.Height / ratio), (int)descY.Height)
            };

            if (subsampleRatioX > 1d)
            {
                if (scrop.X % subsampleRatioX > double.Epsilon)
                {
                    scrop.X = (int)(scrop.X / subsampleRatioX) * (int)subsampleRatioX;
                }
                if (scrop.Width % subsampleRatioX > double.Epsilon)
                {
                    scrop.Width = (int)Math.Min(Math.Ceiling(scrop.Width / subsampleRatioX) * (int)subsampleRatioX, descY.Width - scrop.X);
                }

                descC.Width = Math.Min((uint)Math.Ceiling(scrop.Width / subsampleRatioX), descC.Width);
                descY.Width = (uint)Math.Min(descC.Width * subsampleRatioX, scrop.Width);
            }
            else
            {
                descC.Width = descY.Width = (uint)scrop.Width;
            }

            if (subsampleRatioY > 1d)
            {
                if (scrop.Y % subsampleRatioY > double.Epsilon)
                {
                    scrop.Y = (int)(scrop.Y / subsampleRatioY) * (int)subsampleRatioY;
                }
                if (scrop.Height % subsampleRatioY > double.Epsilon)
                {
                    scrop.Height = (int)Math.Min(Math.Ceiling(scrop.Height / subsampleRatioY) * (int)subsampleRatioY, descY.Height - scrop.Y);
                }

                descC.Height = Math.Min((uint)Math.Ceiling(scrop.Height / subsampleRatioY), descC.Height);
                descY.Height = (uint)Math.Min(descC.Height * subsampleRatioY, scrop.Height);
            }
            else
            {
                descC.Height = descY.Height = (uint)scrop.Height;
            }

            sourceTransform        = source;
            sourceTransformOptions = transformOptions;
            scaledCrop             = scrop;
            scaledWidth            = width;
            scaledHeight           = height;

            strideY     = scrop.Width + 3 & ~3;
            strideC     = (int)Math.Ceiling(scrop.Width / subsampleRatioX) * 2 + 3 & ~3;
            buffHeightY = Math.Min(scrop.Height, transformOptions.RequiresCache() ? scrop.Height : 16);
            buffHeightC = (int)Math.Ceiling(buffHeightY / subsampleRatioY);

            sourceY = new PlanarPixelSource(this, WicPlane.Luma, descY);
            sourceC = new PlanarPixelSource(this, WicPlane.Chroma, descC);
        }
 public WicPlanarCache(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, in Rectangle crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio)
Exemple #5
0
        public WicPlanarCacheSource(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, WICRect crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio, bool cacheFull)
        {
            this.cacheFull = cacheFull;

            // TODO fractional ratio support?
            subsampleRatioX = Math.Ceiling((double)descY.Width / descC.Width);
            subsampleRatioY = Math.Ceiling((double)descY.Height / descC.Height);

            var scrop = new WICRect {
                X      = (int)Math.Floor(crop.X / ratio),
                Y      = (int)Math.Floor(crop.Y / ratio),
                Width  = Math.Min((int)Math.Ceiling(crop.Width / ratio), (int)descY.Width),
                Height = Math.Min((int)Math.Ceiling(crop.Height / ratio), (int)descY.Height)
            };

            if (subsampleRatioX > 1d)
            {
                if (scrop.X % subsampleRatioX > 0d)
                {
                    scrop.X = (int)(scrop.X / subsampleRatioX) * (int)subsampleRatioX;
                }
                if (scrop.Width % subsampleRatioX > 0d)
                {
                    scrop.Width = (int)Math.Min(Math.Ceiling(scrop.Width / subsampleRatioX) * (int)subsampleRatioX, descY.Width);
                }

                descC.Width = Math.Min((uint)Math.Ceiling(scrop.Width / subsampleRatioX), descC.Width);
                descY.Width = (uint)Math.Min(descC.Width * subsampleRatioX, scrop.Width);
            }
            else
            {
                descC.Width = descY.Width = (uint)scrop.Width;
            }

            if (subsampleRatioY > 1d)
            {
                if (scrop.Y % subsampleRatioY > 0d)
                {
                    scrop.Y = (int)(scrop.Y / subsampleRatioY) * (int)subsampleRatioY;
                }
                if (scrop.Height % subsampleRatioY > 0d)
                {
                    scrop.Height = (int)Math.Min(Math.Ceiling(scrop.Height / subsampleRatioY) * (int)subsampleRatioY, descY.Height);
                }

                descC.Height = Math.Min((uint)Math.Ceiling(scrop.Height / subsampleRatioY), descC.Height);
                descY.Height = (uint)Math.Min(descC.Height * subsampleRatioY, scrop.Height);
            }
            else
            {
                descC.Height = descY.Height = (uint)scrop.Height;
            }

            sourceTransform        = source;
            sourceTransformOptions = transformOptions;
            scaledCrop             = scrop;
            scaledWidth            = width;
            scaledHeight           = height;

            strideY     = scrop.Width + 3 & ~3;
            buffHeightY = Math.Min(scrop.Height, cacheFull ? scrop.Height : 16);

            strideC     = (int)Math.Ceiling(scrop.Width / subsampleRatioX) * 2 + 3 & ~3;
            buffHeightC = (int)Math.Ceiling(buffHeightY / subsampleRatioY);

            sourceY = new WicPlanarSource(this, WicPlane.Luma, descY);
            sourceC = new WicPlanarSource(this, WicPlane.Chroma, descC);
        }