public WicPlanarCache(WicTransform prev) : base(prev) { if (!(prev.Source is IWICPlanarBitmapSourceTransform)) { throw new NotSupportedException("Transform chain doesn't support planar mode. Only JPEG Decoder, Rotator, Scaler, and ColorSpaceConverter are allowed"); } var trans = (IWICPlanarBitmapSourceTransform)prev.Source; double rat = Context.Settings.HybridScaleRatio.Clamp(1d, 8d); Context.Width = (uint)Math.Ceiling(Context.Width / rat); Context.Height = (uint)Math.Ceiling(Context.Height / rat); // Although generally the last scan has the least significant bit(s) of the luma plane and skipping it could be very beneficial performance-wise, there is no guarantee of scan order. Might be able to do something with more decoder support. //var prog = Frame as IWICProgressiveLevelControl; //if (prog != null) //{ // uint levels = prog.GetLevelCount(); // uint level = (uint)Math.Ceiling(levels / rat) + (Context.Settings.HybridMode == HybridScaleMode.FavorQuality || Context.Settings.HybridMode == HybridScaleMode.Off ? (uint)Math.Ceiling(levels / 8d) : 0u); // prog.SetCurrentLevel(Math.Min(level, levels - (Context.Settings.ScaleRatio >= 2d && levels > 7u ? 2u : 1u))); //} var fmts = new Guid[] { Consts.GUID_WICPixelFormat8bppY, Consts.GUID_WICPixelFormat16bppCbCr }; var desc = new WICBitmapPlaneDescription[2]; if (!trans.DoesSupportTransform(ref Context.Width, ref Context.Height, Context.TransformOptions, WICPlanarOptions.WICPlanarOptionsDefault, fmts, desc, 2)) { throw new NotSupportedException("Requested planar transform not supported"); } var crop = new WICRect { X = Context.Settings.Crop.X, Y = Context.Settings.Crop.Y, Width = Context.Settings.Crop.Width, Height = Context.Settings.Crop.Height }; cacheSource = new WicPlanarCacheSource(trans, desc[0], desc[1], crop, Context.TransformOptions, Context.Width, Context.Height, rat, Context.NeedsCache); SourceY = cacheSource.GetPlane(WicPlane.Luma); SourceCbCr = cacheSource.GetPlane(WicPlane.Chroma); }
public WicPlanarCache(WicTransform prev) : base(prev) { Contract.Requires <NotSupportedException>(prev.Source is IWICPlanarBitmapSourceTransform, "Transform chain doesn't support planar mode. Only JPEG Decoder, Rotator, Scaler, and ColorSpaceConverter are allowed"); var trans = (IWICPlanarBitmapSourceTransform)prev.Source; double rat = Context.Settings.HybridScaleRatio.Clamp(1d, 8d); Context.Width = (uint)Math.Ceiling(Context.Width / rat); Context.Height = (uint)Math.Ceiling(Context.Height / rat); var prog = Frame as IWICProgressiveLevelControl; if (prog != null) // TODO needs work { uint levels = prog.GetLevelCount(); uint level = (uint)Math.Ceiling(levels / rat) + (Context.Settings.HybridMode == HybridScaleMode.FavorQuality || Context.Settings.HybridMode == HybridScaleMode.Off ? (uint)Math.Ceiling(levels / 8d) : 0u); prog.SetCurrentLevel(Math.Min(level, levels - (Context.Settings.ScaleRatio >= 2d && levels > 7u ? 2u : 1u))); } var fmts = new Guid[] { Consts.GUID_WICPixelFormat8bppY, Consts.GUID_WICPixelFormat16bppCbCr }; var desc = new WICBitmapPlaneDescription[2]; if (!trans.DoesSupportTransform(ref Context.Width, ref Context.Height, Context.TransformOptions, WICPlanarOptions.WICPlanarOptionsPreserveSubsampling, fmts, desc, 2)) { throw new NotSupportedException("Planar Transform not supported"); } var crop = new WICRect() { X = Context.Settings.Crop.X, Y = Context.Settings.Crop.Y, Width = Context.Settings.Crop.Width, Height = Context.Settings.Crop.Height }; var source = new WicPlanarCacheSource(trans, desc[0], desc[1], crop, Context.TransformOptions, Context.Width, Context.Height, rat); SourceY = source.GetPlane(WicPlane.Luma); SourceCbCr = source.GetPlane(WicPlane.Chroma); }