public OverlayInfo Resize(SizeD oldOverSize, SizeD newOverSize, SizeD oldSrcSize, SizeD newSrcSize) { var rect = GetRectangle(oldOverSize); var coefWidth = newSrcSize.Width / oldSrcSize.Width; var coefHeight = newSrcSize.Height / oldSrcSize.Height; rect = new RectangleD( rect.X * coefWidth, rect.Y * coefHeight, rect.Width * coefWidth, rect.Height * coefHeight ); var info = Clone(); info.Warp = Warp.Scale(coefWidth, coefHeight); coefWidth = newOverSize.Width / rect.Width; coefHeight = newOverSize.Height / rect.Height; info.SourceWidth = (int)Math.Floor(newSrcSize.Width); info.SourceHeight = (int)Math.Floor(newSrcSize.Height); info.X = (int)Math.Ceiling(rect.X); info.Y = (int)Math.Ceiling(rect.Y); info.Width = (int)Math.Floor(rect.Right) - info.X; info.Height = (int)Math.Floor(rect.Bottom) - info.Y; info.SetCrop(RectangleD.FromLTRB( (info.X - rect.X) * coefWidth, (info.Y - rect.Y) * coefHeight, (rect.Right - info.Width - info.X) * coefWidth, (rect.Bottom - info.Height - info.Y) * coefHeight )); return(info); }
public RectangleD GetCrop() { return(RectangleD.FromLTRB( CropLeft / CROP_VALUE_COUNT_R, CropTop / CROP_VALUE_COUNT_R, CropRight / CROP_VALUE_COUNT_R, CropBottom / CROP_VALUE_COUNT_R)); }
public static RectangleD RealCrop(this Rectangle crop) { return(RectangleD.FromLTRB( crop.Left / OverlayInfo.CROP_VALUE_COUNT_R, crop.Top / OverlayInfo.CROP_VALUE_COUNT_R, crop.Right / OverlayInfo.CROP_VALUE_COUNT_R, crop.Bottom / OverlayInfo.CROP_VALUE_COUNT_R )); }
public dynamic ResizeRotate( Clip clip, string resizeFunc, string rotateFunc, int width, int height, int angle = 0, RectangleD crop = default, Warp warp = default) { if (clip == null) { return(null); } var dynamic = clip.Dynamic(); if (warp != null && !warp.IsEmpty) { dynamic = dynamic.Warp(warp.ToArray(), relative: true, resample: OverlayUtils.GetWarpResampleMode(resizeFunc)); } var vi = clip.GetVideoInfo(); if (crop.IsEmpty && width == vi.width && height == vi.height) { return(dynamic); } var intCrop = Rectangle.FromLTRB( (int)Math.Floor(crop.Left), (int)Math.Floor(crop.Top), (int)Math.Floor(crop.Right), (int)Math.Floor(crop.Bottom) ); if (!intCrop.IsEmpty) { dynamic = dynamic.Crop(intCrop.Left, intCrop.Top, -intCrop.Right, -intCrop.Bottom); crop = RectangleD.FromLTRB( crop.Left - intCrop.Left, crop.Top - intCrop.Top, crop.Right - intCrop.Right, crop.Bottom - intCrop.Bottom ); } if (crop.IsEmpty) { dynamic = dynamic.Invoke(resizeFunc, width, height); } else { dynamic = dynamic.Invoke(resizeFunc, width, height, src_left: crop.Left, src_top: crop.Top, src_width: -crop.Right, src_height: -crop.Bottom); } return(angle == 0 ? dynamic : dynamic.Invoke(rotateFunc, angle / 100.0)); }
public dynamic ResizeRotate( Clip clip, string resizeFunc, string rotateFunc, int width, int height, int angle = 0, RectangleD crop = default) { if (clip == null || crop == RectangleD.Empty && width == clip.GetVideoInfo().width&& height == clip.GetVideoInfo().height) { return(clip.Dynamic()); } var intCrop = Rectangle.FromLTRB( (int)Math.Floor(crop.Left), (int)Math.Floor(crop.Top), (int)Math.Floor(crop.Right), (int)Math.Floor(crop.Bottom) ); if (!intCrop.IsEmpty) { clip = DynamicEnv.Crop(clip, intCrop.Left, intCrop.Top, -intCrop.Right, -intCrop.Bottom); crop = RectangleD.FromLTRB( crop.Left - intCrop.Left, crop.Top - intCrop.Top, crop.Right - intCrop.Right, crop.Bottom - intCrop.Bottom ); } dynamic resized; if (crop == RectangleD.Empty) { resized = clip.Dynamic().Invoke(resizeFunc, width, height); } else { resized = clip.Dynamic().Invoke(resizeFunc, width, height, src_left: crop.Left, src_top: crop.Top, src_width: -crop.Right, src_height: -crop.Bottom); } if (angle == 0) { return(resized); } return(resized.Invoke(rotateFunc, angle / 100.0)); }
public OverlayInfo Invert(Size srcSize, Size overSize) { var rect = GetRectangle(overSize); var info = Clone(); var invertedRect = new RectangleD( -rect.X, -rect.Y, srcSize.Width, srcSize.Height ); info.Angle = -Angle; info.X = (int)Math.Ceiling(invertedRect.X); info.Y = (int)Math.Ceiling(invertedRect.Y); info.Width = (int)Math.Floor(invertedRect.Right) - info.X; info.Height = (int)Math.Floor(invertedRect.Bottom) - info.Y; info.SetCrop(RectangleD.FromLTRB( info.X - invertedRect.X, info.Y - invertedRect.Y, invertedRect.Right - info.Width - info.X, invertedRect.Bottom - info.Height - info.Y )); return(info.Resize(srcSize, invertedRect.Size, rect.Size, overSize)); }
public OverlayInfo Shrink(Size srcSize, Size overSize) { var info = Clone(); var excess = Rectangle.FromLTRB( Math.Max(0, -info.X), Math.Max(0, -info.Y), Math.Max(0, info.Width + info.X - srcSize.Width), Math.Max(0, info.Height + info.Y - srcSize.Height)); var widthCoef = (double)overSize.Width / info.Width; var heightCoef = (double)overSize.Height / info.Height; info.Width -= excess.Left + excess.Right; info.Height -= excess.Top + excess.Bottom; info.X = Math.Max(0, info.X); info.Y = Math.Max(0, info.Y); var crop = info.GetCrop(); info.SetCrop(RectangleD.FromLTRB( crop.Left + excess.Left * widthCoef, crop.Top + excess.Top * heightCoef, crop.Right + excess.Right * widthCoef, crop.Bottom + excess.Bottom * heightCoef)); return(info); }