public static void AddCropper(PipelineContext ctx, PixelArea area = default) { var crop = area.IsEmpty ? PixelArea.FromGdiRect(ctx.Settings.Crop).DeOrient(ctx.Orientation, ctx.Source.Width, ctx.Source.Height) : area; if (crop == ctx.Source.Area) { return; } ctx.Source = new CropTransform(ctx.Source, crop); }
public static void AddPlanarCropper(PipelineContext ctx) { Debug.Assert(ctx.PlanarContext is not null); var crop = PixelArea.FromGdiRect(ctx.Settings.Crop).DeOrient(ctx.Orientation, ctx.Source.Width, ctx.Source.Height); if (crop == ctx.Source.Area) { return; } int yw = ctx.Source.Width; int yh = ctx.Source.Height; int cw = ctx.PlanarContext.SourceCb.Width; int ch = ctx.PlanarContext.SourceCb.Height; int ratioX = (yw + 1) / cw; int ratioY = (yh + 1) / ch; int scropX = MathUtil.PowerOfTwoFloor(crop.X, ratioX); int scropY = MathUtil.PowerOfTwoFloor(crop.Y, ratioY); int scropW = Math.Min(MathUtil.PowerOfTwoCeiling(crop.Width, ratioX), yw - scropX); int scropH = Math.Min(MathUtil.PowerOfTwoCeiling(crop.Height, ratioY), yh - scropY); var scrop = new PixelArea(scropX, scropY, scropW, scropH); AddCropper(ctx, scrop); ctx.PlanarContext.SourceY = ctx.Source; ctx.Source = ctx.PlanarContext.SourceCb; cw = Math.Min(MathUtil.DivCeiling(scrop.Width, ratioX), cw); ch = Math.Min(MathUtil.DivCeiling(scrop.Height, ratioY), ch); scrop = new PixelArea(scrop.X / ratioX, scrop.Y / ratioY, cw, ch); AddCropper(ctx, scrop); ctx.PlanarContext.SourceCb = ctx.Source; ctx.Source = ctx.PlanarContext.SourceCr; AddCropper(ctx, scrop); ctx.PlanarContext.SourceCr = ctx.Source; ctx.Source = ctx.PlanarContext.SourceY; }
public static void AddPad(PipelineContext ctx) { if (ctx.Settings.InnerSize == ctx.Settings.OuterSize) { return; } AddExternalFormatConverter(ctx); ctx.Source = new PadTransformInternal(ctx.Source, ctx.Settings.MatteColor, PixelArea.FromGdiRect(ctx.Settings.InnerRect), PixelArea.FromGdiSize(ctx.Settings.OuterSize)); }
public static void AddPad(PipelineContext ctx) { if (ctx.Settings.InnerSize == ctx.Settings.OuterSize) { return; } AddExternalFormatConverter(ctx); var fmt = ctx.Source.Format; if (fmt.AlphaRepresentation == PixelAlphaRepresentation.None && ctx.Settings.MatteColor.IsTransparent()) { ctx.Source = ctx.AddDispose(new ConversionTransform(ctx.Source, null, null, PixelFormat.Bgra32Bpp)); } else if (fmt.ColorRepresentation == PixelColorRepresentation.Grey && !ctx.Settings.MatteColor.IsGrey()) { ctx.Source = ctx.AddDispose(new ConversionTransform(ctx.Source, null, null, PixelFormat.Bgr24Bpp)); } ctx.Source = new PadTransformInternal(ctx.Source, ctx.Settings.MatteColor, PixelArea.FromGdiRect(ctx.Settings.InnerRect), PixelArea.FromGdiSize(ctx.Settings.OuterSize)); }
/// <inheritdoc /> public unsafe void CopyPixels(Rectangle sourceArea, int cbStride, Span <byte> buffer) { fixed(byte *pbBuffer = buffer) Source.CopyPixels(PixelArea.FromGdiRect(sourceArea), cbStride, buffer.Length, (IntPtr)pbBuffer); }