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 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); }