/// <summary> /// Initializes a new instance of the <see cref="ResizeProcessor{TPixel}"/> class. /// </summary> /// <param name="options">The resize options</param> /// <param name="sourceSize">The source image size</param> public ResizeProcessor(ResizeOptions options, Size sourceSize) { Guard.NotNull(options, nameof(options)); Guard.NotNull(options.Sampler, nameof(options.Sampler)); int tempWidth = options.Size.Width; int tempHeight = options.Size.Height; // Ensure size is populated across both dimensions. // These dimensions are used to calculate the final dimensions determined by the mode algorithm. if (tempWidth == 0 && tempHeight > 0) { tempWidth = (int)MathF.Round(sourceSize.Width * tempHeight / (float)sourceSize.Height); } if (tempHeight == 0 && tempWidth > 0) { tempHeight = (int)MathF.Round(sourceSize.Height * tempWidth / (float)sourceSize.Width); } Guard.MustBeGreaterThan(tempWidth, 0, nameof(tempWidth)); Guard.MustBeGreaterThan(tempHeight, 0, nameof(tempHeight)); (Size size, Rectangle rectangle)locationBounds = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options, tempWidth, tempHeight); this.Sampler = options.Sampler; this.Width = locationBounds.size.Width; this.Height = locationBounds.size.Height; this.ResizeRectangle = locationBounds.rectangle; this.Compand = options.Compand; }
public void AlignTests() { var box = new Rectangle(0, 0, 100, 100); var bounds = new Size(200, 200); ResizeHelper.Align(ref box, bounds, Top | Center); Assert.Equal(50d, box.X); Assert.Equal(0, box.Y); ResizeHelper.Align(ref box, bounds, Right | Center); Assert.Equal(100d, box.X); Assert.Equal(50d, box.Y); ResizeHelper.Align(ref box, bounds, Bottom); Assert.Equal(50d, box.X); Assert.Equal(100d, box.Y); ResizeHelper.Align(ref box, bounds, Center); Assert.Equal(50d, box.X); Assert.Equal(50d, box.Y); ResizeHelper.Align(ref box, bounds, Bottom | Right); Assert.Equal(100d, box.X); Assert.Equal(100d, box.Y); ResizeHelper.Align(ref box, bounds, Top | Left); Assert.Equal(0, box.X); Assert.Equal(0, box.Y); }
protected override void OnDestroy() { _resizer?.Dispose(); _resizer = null; base.OnDestroy(); }
/// <summary> /// Resizes the GUI. /// </summary> /// <param name="widthFactor">The relative growth of the width.</param> /// <param name="heightFactor">The relative growth of the height.</param> public void Resize(double widthFactor, double heightFactor) { if (this.ResizeHelper == null) { this.ResizeHelper = new ResizeHelper(this.DoResize); } this.ResizeHelper.Resize(widthFactor, heightFactor); }
public override void OnApplyTemplate() { resizeHelper = new ResizeHelper(this); base.OnApplyTemplate(); Thumb resizer = (Thumb)GetTemplateChild("PART_Resizer"); resizeHelper.Init(resizer); InitializeRowHeight(); }
public ViewBase(Rect rect) { var k = ResizeHelper.k; _rect = rect; _innerRect = new Rect(rect.x + 8f * k, rect.y + 8f * k, rect.width - 16f * k, rect.height - 16f * k); _border = ResizeHelper.Make(new Color32(20, 93, 134, 200)); _bg = ResizeHelper.Make(new Color(1, 1, 1, 0.8f)); }
public void CalculateResizeWorkerHeightInWindowBands( int windowDiameter, int width, int sizeLimitHintInBytes, int expectedCount) { int actualCount = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(windowDiameter, width, sizeLimitHintInBytes); Assert.Equal(expectedCount, actualCount); }
public void PrependResizingInstruction(string url, string preset, string expected) { var configuration = Substitute.For <IUniqueUrlFolderPresetsConfiguration>(); configuration.BaseSegment.Returns("optimized"); var sut = new ResizeHelper(configuration, new PresetParser(configuration)); var actual = sut.PrependResizingInstruction(url, preset); actual.ShouldBe(expected); }
protected override void InitializeComponent(IUIContext context, bool isPlaying) { base.InitializeComponent(context, isPlaying); if (!isPlaying) { return; } _movable .Where(_ => Header != null) .Subscribe(v => Header.Interactable = v, Debug.LogError) .AddTo(this); _resizer = new ResizeHelper(this); _resizer.Initialize(); _resizer.Activate(); _resizable .Where(_ => _resizer != null) .Subscribe(v => _resizer.Active = v, Debug.LogError) .AddTo(this); _backdrop .Where(_ => BackdropImage != null) .Subscribe(v => v.Update(BackdropImage, DefaultBackdrop), Debug.LogError) .AddTo(this); var parentStatusChanged = Transform .OnTransformParentChangedAsObservable() .Select(_ => Transform.parent != null); var hasValidParent = new ReactiveProperty <bool>(Transform.parent != null).Merge(parentStatusChanged); var visible = new ReactiveProperty <bool>(enabled).Merge(OnVisibilityChange); var shouldBackdropExists = Observable .CombineLatest(_modal, visible, hasValidParent) .Select(i => i.All(v => v)) .DistinctUntilChanged(); shouldBackdropExists .Where(v => v && BackdropImage == null) .Subscribe(_ => ShowBackdrop(), Debug.LogError) .AddTo(this); shouldBackdropExists .Where(v => !v && BackdropImage != null) .Subscribe(_ => HideBackdrop(), Debug.LogError) .AddTo(this); }
/// <summary> /// Initializes a new instance of the <see cref="ResizeProcessor"/> class. /// </summary> /// <param name="options">The resize options.</param> /// <param name="sourceSize">The source image size.</param> public ResizeProcessor(ResizeOptions options, Size sourceSize) { Guard.NotNull(options, nameof(options)); Guard.NotNull(options.Sampler, nameof(options.Sampler)); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options); this.Sampler = options.Sampler; this.TargetWidth = size.Width; this.TargetHeight = size.Height; this.TargetRectangle = rectangle; this.Compand = options.Compand; }
public MfdForm() { InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint, false); SetStyle(ControlStyles.ContainerControl, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, false); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.UserPaint, true); if (!DesignMode) { _resizeHelper = new ResizeHelper(this); } }
void Awake() { if (instance != null) { GameObject.Destroy(instance); } else { instance = this; instance.WindowSize = new Vector2(Screen.width, Screen.height); } DontDestroyOnLoad(this); }
/// <summary> /// Initializes a new instance of the <see cref="ResizeProcessor"/> class. /// </summary> /// <param name="options">The resize options.</param> /// <param name="sourceSize">The source image size.</param> public ResizeProcessor(ResizeOptions options, Size sourceSize) { Guard.NotNull(options, nameof(options)); Guard.NotNull(options.Sampler, nameof(options.Sampler)); Guard.MustBeValueType(options.Sampler, nameof(options.Sampler)); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options); this.Sampler = options.Sampler; this.DestinationWidth = size.Width; this.DestinationHeight = size.Height; this.DestinationRectangle = rectangle; this.Compand = options.Compand; this.PremultiplyAlpha = options.PremultiplyAlpha; }
public void CalculateMinRectangleWhenSourceIsSmallerThanTarget() { var sourceSize = new Size(200, 100); var target = new Size(400, 200); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds( sourceSize, new ResizeOptions { Mode = ResizeMode.Min, Size = target }); Assert.Equal(sourceSize, size); Assert.Equal(new Rectangle(0, 0, sourceSize.Width, sourceSize.Height), rectangle); }
public void BoxPadSizeAndRectangleAreCorrect() { var sourceSize = new Size(100, 100); var target = new Size(120, 110); var expectedSize = new Size(120, 110); var expectedRectangle = new Rectangle(10, 5, 100, 100); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds( sourceSize, new ResizeOptions { Mode = ResizeMode.BoxPad, Size = target }); Assert.Equal(expectedSize, size); Assert.Equal(expectedRectangle, rectangle); }
public void MaxSizeAndRectangleAreCorrect() { var sourceSize = new Size(5072, 6761); var target = new Size(0, 450); var expectedSize = new Size(338, 450); var expectedRectangle = new Rectangle(Point.Empty, expectedSize); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds( sourceSize, new ResizeOptions { Mode = ResizeMode.Max, Size = target }); Assert.Equal(expectedSize, size); Assert.Equal(expectedRectangle, rectangle); }
public void StretchSizeAndRectangleAreCorrect() { var sourceSize = new Size(100, 100); var target = new Size(57, 32); var expectedSize = new Size(57, 32); var expectedRectangle = new Rectangle(Point.Empty, expectedSize); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds( sourceSize, new ResizeOptions { Mode = ResizeMode.Stretch, Size = target }); Assert.Equal(expectedSize, size); Assert.Equal(expectedRectangle, rectangle); }
/// <summary> /// Resizes the GUI. /// </summary> /// <param name="widthFactor">The relative growth of the width.</param> /// <param name="heightFactor">The relative growth of the height.</param> protected override void DoResize(double widthFactor, double heightFactor) { Range range = this.PopupRange; switch (this.PopupOrientation) { case Orientation.Horizontal: ResizeHelper.Scale(ref range, widthFactor); break; case Orientation.Vertical: ResizeHelper.Scale(ref range, heightFactor); break; } this.PopupRange = range; base.DoResize(widthFactor, heightFactor); }
public void CalculateLargestSizeHavingAspect() { var size = new Size(1000, 1000); var targetAspect = new Rational(1, 1); // 1:1 var result = new Size(0, 0); result = ResizeHelper.Max(size, targetAspect); Assert.Equal(new Size(1000, 1000), result); // ----------------------------------------------------------------------------------------------- targetAspect = new Rational(2, 1); // 2:1 (width 2x height) result = ResizeHelper.Max(size, targetAspect); Assert.Equal(new Size(1000, 500), result); // ----------------------------------------------------------------------------------------------- targetAspect = new Rational(3, 1); // 3:1 (width 3x height) result = ResizeHelper.Max(size, targetAspect); Assert.Equal(new Size(1000, 333), result); // 333.3 (round down) // ----------------------------------------------------------------------------------------------- targetAspect = new Rational(4, 1); // 3:1 (width 3x height) result = ResizeHelper.Max(size, targetAspect); Assert.Equal(new Size(1000, 250), result); // 333.3 (round down) // ----------------------------------------------------------------------------------------------- targetAspect = new Rational(1, 2); // 1:2 (width 0.5 height) result = ResizeHelper.Max(size, targetAspect); Assert.Equal(new Size(500, 1000), result); // 333.3 (round down) }
public void ChangeState(ChangedStateFields filed, object value) { SetObeserversStateChanged(); switch (filed) { case ChangedStateFields.NavigationPanel: { navigationPanel.IsOpened = (bool)value; } break; case ChangedStateFields.WindowSize: { var size = value as Point?; WindowSize = size.Value; CurrentWindowSize = ResizeHelper.GetSizeType(size.Value.Y); } break; } }
// Use this for initialization void Start() { k = ResizeHelper.k; for (int i = 0; i < _rectsIcon.Length; i++) { _rectsIcon[i] = new Rect(16f * k, 16f * k + i * 70f * k, 64f * k, 64f * k); _rectsWithIcon[i] = new Rect(16f * k + 64f * k, 16f * k + i * 70f * k, 200f * k, 64f * k); _rectsWithoutIcon[i] = new Rect(16f * k, 16f * k + i * 70f * k, 200f * k + 64f * k, 64f * k); } _touch = Camera.main.GetComponent <NewMouseController>(); _touch.Click += HandleTouchClick; _details = this.GetComponent <MarkerDetailsView>(); DescriptionBG = ResizeHelper.Make(new Color32(20, 93, 134, 255)); var size = ResizeHelper.ButtonStyle.CalcSize(new GUIContent(Lang.Settings_Back)); _backRect = new Rect(Screen.width - 10f * k - size.x, Screen.height - 50f * k, size.x, 50f * k); }
/// <summary> /// Resizes an image in accordance with the given <see cref="ResizeOptions"/>. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image to resize.</param> /// <param name="options">The resize options.</param> /// <returns>The <see cref="Image{TPixel}"/></returns> /// <remarks>Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image</remarks> public static IImageProcessingContext <TPixel> Resize <TPixel>(this IImageProcessingContext <TPixel> source, ResizeOptions options) where TPixel : struct, IPixel <TPixel> { return(source.Apply(img => { // Cheat and bound through a run, inside here we should just be mutating, this really needs moving over to a processor // Ensure size is populated across both dimensions. if (options.Size.Width == 0 && options.Size.Height > 0) { options.Size = new Size((int)MathF.Round(img.Width * options.Size.Height / (float)img.Height), options.Size.Height); } if (options.Size.Height == 0 && options.Size.Width > 0) { options.Size = new Size(options.Size.Width, (int)MathF.Round(img.Height * options.Size.Width / (float)img.Width)); } Rectangle targetRectangle = ResizeHelper.CalculateTargetLocationAndBounds(img.Frames.RootFrame, options); img.Mutate(x => Resize(x, options.Size.Width, options.Size.Height, options.Sampler, targetRectangle, options.Compand)); })); }
public void PadTests2() { var source = new Size(100, 200); // 1x2 500x1000 var bounds = new Size(1000, 1000); var box = ResizeHelper.Pad(source, bounds, CropAnchor.Center, upscale: true); Assert.Equal(500d, box.Width); Assert.Equal(1000d, box.Height); Assert.Equal(0, box.Padding.Top); Assert.Equal(250, box.Padding.Right); Assert.Equal(0, box.Padding.Bottom); Assert.Equal(250, box.Padding.Left); Assert.Equal(1000d, box.OuterWidth); Assert.Equal(1000d, box.OuterHeight); box = ResizeHelper.Pad(source, bounds, Right, upscale: true); Assert.Equal(500, box.Padding.Left); Assert.Equal(0, box.Padding.Right); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// void SafeInit() { if (_inited) { return; } _inited = true; float k = ResizeHelper.k; _touch = Camera.main.GetComponent <NewMouseController>(); _touch.Click += HandleTouchClick; _touch.MouseDown += HandleMouseDown; _touch.MouseUp += HandleMouseUp; _touch.MouseMove += HandleMouseMove; _markerLister = this.GetComponent <MarkersLister>(); _darkBlue = ResizeHelper.Make(new Color32(15, 70, 102, 255)); _mediumBlue = ResizeHelper.Make(new Color32(20, 93, 134, 255)); _lightBlue = ResizeHelper.Make(new Color32(29, 133, 192, 255)); _closeRect = new Rect(Screen.width - 30f * k, 0, 30f * k, 30f * k); }
public ResizeableDataRow() { resizeHelper = new ResizeHelper(this); }
// Use this for initialization void Start() { _bg = ResizeHelper.Make(new Color(1, 1, 1, 0.5f)); _rect = new Rect(0, 0, Screen.width, Screen.height); }
public static Pipeline From(IMediaInfo source, IReadOnlyList <IProcessor> processors) { var pipeline = new Pipeline { Source = source }; if (source.Orientation != null) { switch (source.Orientation.Value) { case ExifOrientation.FlipHorizontal: pipeline.Flip = FlipTransform.Horizontally; break; case ExifOrientation.Rotate180: pipeline.Rotate = 180; break; case ExifOrientation.FlipVertical: pipeline.Flip = FlipTransform.Vertically; break; case ExifOrientation.Transpose: pipeline.Flip = FlipTransform.Horizontally; pipeline.Rotate = 270; break; case ExifOrientation.Rotate90: pipeline.Rotate = 90; break; case ExifOrientation.Transverse: pipeline.Flip = FlipTransform.Horizontally; pipeline.Rotate = 90; break; case ExifOrientation.Rotate270: pipeline.Rotate = 270; break; } } var interpolater = InterpolaterMode.Lanczos3; var encodingFlags = EncodeFlags.None; Rectangle?crop = null; var box = new PaddedBox(source.Width, source.Height); int?quality = null; foreach (var transform in processors) { if (transform is PageFilter page) { pipeline.Extract = new ExtractFilter(ExtractFilterType.Page, page.Number); } else if (transform is FrameFilter frame) { pipeline.Extract = new ExtractFilter(frame.Number == 0 ? ExtractFilterType.Poster : ExtractFilterType.Frame, frame.Number); } else if (transform is TimeFilter timestamp) { pipeline.Extract = new ExtractFilter(ExtractFilterType.Time, timestamp.Value); } else if (transform is BackgroundFilter background) { pipeline.Background = background.Color; } else if (transform is FlipTransform flip) { // Do we need to apply the operations in reverse? pipeline.Flip = flip; } else if (transform is CropTransform ct) { // Note: We may have applied a scaling operating before the crop double xScale = (double)pipeline.Source.Width / box.Width; double yScale = (double)pipeline.Source.Height / box.Height; var c = ct.GetRectangle(box.Size); box.Width = c.Width; box.Height = c.Height; if (xScale != 1d || yScale != 1d) { c = c.Scale(xScale, yScale); } crop = c; } else if (transform is QualityFilter q) { quality = q.Value; } else if (transform is ResizeTransform resize) { var bounds = resize.CalcuateSize(box.Size); bool upscale = resize.Upscale; switch (resize.Mode) { case ResizeFlags.Crop: crop = ResizeHelper.CalculateCropRectangle(box.Size, bounds.ToRational(), resize.Anchor ?? CropAnchor.Center); box.Width = bounds.Width; box.Height = bounds.Height; break; case ResizeFlags.Fit: ResizeHelper.Fit(ref box, bounds, resize.Upscale); break; case ResizeFlags.Pad: box = ResizeHelper.Pad(box.Size, bounds, resize.Anchor ?? CropAnchor.Center, resize.Upscale); break; default: // Exact box.Width = bounds.Width; box.Height = bounds.Height; break; } } else if (transform is ScaleTransform scale) { box.Width = scale.Width; box.Height = scale.Height; if (scale.Mode != InterpolaterMode.None) { interpolater = scale.Mode; } } else if (transform is PadTransform pad) { box.Padding = new Padding( top: box.Padding.Top + pad.Top, right: box.Padding.Right + pad.Right, bottom: box.Padding.Bottom + pad.Bottom, left: box.Padding.Left + pad.Left ); } else if (transform is RotateTransform rotate) { if (rotate.Angle == 90 || rotate.Angle == 270) { var oldSize = box.Size; // flip the height & width box.Width = oldSize.Height; box.Height = oldSize.Width; if (crop != null) { var oldCrop = crop.Value; crop = new Rectangle(oldCrop.Y, oldCrop.X, oldCrop.Height, oldCrop.Width); } } pipeline.Rotate = rotate.Angle; } else if (transform is MetadataFilter metadata) { pipeline.Metadata = metadata; } else if (transform is LosslessFlag) { quality = 100; encodingFlags |= EncodeFlags.Lossless; } else if (transform is ExpiresFilter expires) { pipeline.Expires = expires.Timestamp; } else if (transform is EncodeParameters encode) { pipeline.Encode = quality != null || encodingFlags != default ? new EncodeParameters(encode.Format, quality, flags: encode.Flags | encodingFlags) // set the quality : encode; } else if (transform is DebugFilter) { pipeline.IsDebug = true; } else { pipeline.Filters.Add(transform); } } pipeline.Crop = crop; if ((crop is null || crop.Value.Size != box.Size) && box.OuterWidth > 0 && box.OuterHeight > 0) { pipeline.Scale = new ScaleTransform(box.Size, interpolater); } pipeline.Padding = box.Padding; return(pipeline); }
void SetResizeEvent(Auchor anc, ResizeHelper rh) { rh.BindResizeFunction(anc, this); rh.MouseLeftButtonUp += new MouseButtonEventHandler(ResizeHelper_MouseLeftButtonUp); rh.ResizeChanged += new EventHandler <ResizeEventArgs>(ResizeHelper_ResizeChanged); }
/// <summary> /// Resizes the style. /// </summary> /// <param name="widthFactor">The relative growth of the width.</param> /// <param name="heightFactor">The relative growth of the height.</param> protected override void DoResize(double widthFactor, double heightFactor) { ResizeHelper.Scale(ref this.extent, heightFactor); }
public ColumnResizeGrip() { resizeHelper = new ResizeHelper(new ColumnResizeHelperOwner(this)); Loaded += new RoutedEventHandler(ColumnResizeGrip_Loaded); }