public WebImage RotateRight()
        {
            ImageTransformation transform = new RotateTransformation(RotateFlipType.Rotate90FlipNone);

            _transformations.Add(transform);
            return(this);
        }
        public WebImage FlipHorizontal()
        {
            ImageTransformation transform = new RotateTransformation(RotateFlipType.RotateNoneFlipX);

            _transformations.Add(transform);
            return(this);
        }
Example #3
0
        public void Should_switch_dimensions_when_rotation_is_90_or_270_degrees(ImageRotation rotation)
        {
            var source         = new MyImage(2, 4);
            var transformation = new RotateTransformation(rotation);
            var actual         = transformation.Process(source);

            Check.That(actual.Width).IsEqualTo(source.Height);
            Check.That(actual.Height).IsEqualTo(source.Width);
        }
Example #4
0
        public void Should_move_pixels_when_doing_a_270_degrees_rotation()
        {
            var source         = new MyImage(TestImages.ImageWithAllDifferentPixels);
            var transformation = new RotateTransformation(ImageRotation.Clockwise270);
            var actual         = transformation.Process(source);

            Check.That(actual[0, 0]).IsEqualTo(source[0, source.Width - 1]);
            Check.That(actual[0, actual.Width - 1]).IsEqualTo(source[source.Height - 1, source.Width - 1]);
            Check.That(actual[actual.Height - 1, 0]).IsEqualTo(source[0, 0]);
            Check.That(actual[actual.Height - 1, actual.Width - 1]).IsEqualTo(source[source.Height - 1, 0]);
        }
Example #5
0
 public WebImage FlipHorizontal() {
     ImageTransformation transform = new RotateTransformation(RotateFlipType.RotateNoneFlipX);
     _transformations.Add(transform);
     return this;
 }
Example #6
0
 public WebImage FlipVertical() {
     ImageTransformation transform = new RotateTransformation(RotateFlipType.RotateNoneFlipY);
     _transformations.Add(transform);
     return this;
 }
Example #7
0
 public WebImage RotateRight() {
     ImageTransformation transform = new RotateTransformation(RotateFlipType.Rotate90FlipNone);
     _transformations.Add(transform);
     return this;
 }
Example #8
0
 public static RotateTransform ConvertToRotation(RotateTransformation trans)
 {
     return(new RotateTransform(trans.Angle));
 }
Example #9
0
            public async void SetSource(ImageSource source)
            {
                try
                {
                    await _lock.WaitAsync();

                    if (!string.IsNullOrWhiteSpace(_cacheKey))
                    {
                        await ImageService.Instance.InvalidateCacheEntryAsync(_cacheKey, FFImageLoading.Cache.CacheType.Memory, true);
                    }

                    if (!string.IsNullOrWhiteSpace(_refinedCacheKey))
                    {
                        await ImageService.Instance.InvalidateCacheEntryAsync(_cacheKey, FFImageLoading.Cache.CacheType.Memory, true);
                    }

                    if (source == null)
                    {
                        _cacheKey        = null;
                        _refinedCacheKey = null;
                        _source          = null;
                        _refinedSource   = null;
                        _originalSource  = null;
                        Source           = null;
                        return;
                    }

                    var imageGuid = Guid.NewGuid();
                    _cacheKey        = imageGuid.ToString();
                    _refinedCacheKey = $"{imageGuid.ToString()}-Refined";
                    _originalSource  = source;
                    TaskParameter task        = null;
                    TaskParameter taskRefined = null;

                    var fileSource = source as FileImageSource;
                    if (fileSource != null)
                    {
                        task        = ImageService.Instance.LoadFile(fileSource.File);
                        taskRefined = ImageService.Instance.LoadFile(fileSource.File);
                        Stream      = null;
                        Path        = fileSource.File;
                        SourceType  = FFImageLoading.Work.ImageSource.Filepath;
                    }

                    var urlSource = source as UriImageSource;
                    if (urlSource != null)
                    {
                        task        = ImageService.Instance.LoadUrl(urlSource.Uri?.OriginalString);
                        taskRefined = ImageService.Instance.LoadUrl(urlSource.Uri?.OriginalString);
                        Stream      = null;
                        Path        = urlSource.Uri?.OriginalString;
                        SourceType  = FFImageLoading.Work.ImageSource.Url;
                    }

                    var streamSource = source as StreamImageSource;
                    if (streamSource != null)
                    {
                        task        = ImageService.Instance.LoadStream(streamSource.Stream);
                        taskRefined = ImageService.Instance.LoadStream(streamSource.Stream);
                        Stream      = streamSource.Stream;
                        Path        = null;
                        SourceType  = FFImageLoading.Work.ImageSource.Stream;
                    }

                    if (ImageRotation != 0)
                    {
                        var rotateTransformation = new RotateTransformation(Math.Abs(ImageRotation), ImageRotation < 0)
                        {
                            Resize = true
                        };

                        task.Transform(rotateTransformation);
                        taskRefined.Transform(rotateTransformation);
                    }

                    using (var stream = await task.DownSample(PreviewResolution, PreviewResolution).AsJPGStreamAsync(90))
                    {
                        byte[] bytes = StreamToByteArray(stream);
                        _source = ImageSource.FromStream(() => new MemoryStream(bytes));
                    }

                    using (var streamRefined = await taskRefined.DownSample(RefinedResolution, RefinedResolution).AsJPGStreamAsync(90))
                    {
                        byte[] bytes = StreamToByteArray(streamRefined);
                        _refinedSource = ImageSource.FromStream(() => new MemoryStream(bytes));
                    }

                    LoadRefinedImage();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
                finally
                {
                    _lock.Release();
                }
            }
        public override bool OnMouseUp(Point mouseCurPos, MouseButtons button, BaseViewport viewport)
        {
            if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE &&
                button == MouseButtons.Left)
            {
                RubberBand       rubberBand          = controller.RubberBand;
                MapObject        selectionGroup      = controller.Selection;
                SolidGrabHandles handles             = rubberBand.Handles;
                Matrix4          fromGridSpaceMatrix = viewport.Camera.GetViewMatrix().ClearTranslation();

                // check for the program to decide if it needs to go the next grab handle mode
                bool isHoveringSelectedSolid = IsSelectedSolidAabbHit(mouseCurPos.X, mouseCurPos.Y, viewport);
                bool hasNoNewSelection       = currentAction != SolidToolActionType.Select;

                Vector3 snappedDownMousePosition = GeneralUtility.SnapToGrid(
                    new Vector3(mouseDownPos.X, mouseDownPos.Y, 0), viewport.GridSize);
                Vector3 snappedCurMousePosition = GeneralUtility.SnapToGrid(new Vector3(mouseCurPos.X, mouseCurPos.Y, 0),
                                                                            viewport.GridSize);
                bool mouseHasNotMoved = snappedDownMousePosition == snappedCurMousePosition;

                if (isHoveringSelectedSolid && mouseHasNotMoved && hasNoNewSelection)
                {
                    handles.NextMode();
                }
                else
                {
                    switch (currentAction)
                    {
                    case SolidToolActionType.Create:
                        controller.CreateSolid(fromGridSpaceMatrix);
                        break;

                    case SolidToolActionType.Drag:
                        // set new position
                        Vector3 displacement = rubberBand.Bounds.Center - selectionGroup.Bounds.Center;
                        controller.Selection.PerformOperation(new TranslateOperation(displacement));
                        break;

                    case SolidToolActionType.Transform:
                        Vector3             oldBoundVector = selectionGroup.Bounds.Max - selectionGroup.Bounds.Min;
                        Vector3             newBoundVector = rubberBand.Bounds.Max - rubberBand.Bounds.Min;
                        IMapObjectOperation operation      = null;

                        switch (handles.Mode)
                        {
                        case SolidGrabHandles.HandleMode.Resize:
                            operation = new ResizeTransformation(fromGridSpaceMatrix, oldBoundVector,
                                                                 newBoundVector,
                                                                 handles.LastHitStatus, viewport.GridSize);
                            break;

                        case SolidGrabHandles.HandleMode.Rotate:
                            operation = new RotateTransformation(fromGridSpaceMatrix, Vector3.Zero, Vector3.Zero,
                                                                 rubberBand.Transformation);
                            break;

                        case SolidGrabHandles.HandleMode.Skew:
                            operation = new SkewTransformation(fromGridSpaceMatrix, Vector3.Zero, Vector3.Zero,
                                                               rubberBand.Transformation,
                                                               handles.LastHitStatus);
                            break;
                        }

                        if (operation != null)
                        {
                            controller.Selection.PerformOperation(operation);
                        }
                        break;
                    }

                    controller.UpdateUserInterface();
                }

                rubberBand.SetToZeroVolume();
                rubberBand.ShowGrabhandles = true;
                currentAction = SolidToolActionType.None;
            }

            return(true);
        }
        public override bool OnMouseMove(Point mouseCurPos, Point mousePrevPos, BaseViewport viewport)
        {
            if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE)
            {
                UpdateCursor(mouseCurPos, viewport);

                if (viewport.IsButtonHeld(BaseViewport.ViewportButtons.LEFT))
                {
                    // set standard values
                    Vector3 mouseDownPosition    = new Vector3(mouseDownPos.X, mouseDownPos.Y, 0);
                    Vector3 prevMousePosition    = new Vector3(mousePrevPos.X, mousePrevPos.Y, 0);
                    Vector3 currentMousePosition = new Vector3(mouseCurPos.X, mouseCurPos.Y, 0);
                    Matrix4 fromGridSpaceMatrix  = viewport.Camera.GetViewMatrix().ClearTranslation();

                    // we only give the rubberband volume if the mouse has moved in creation mode
                    bool mouseHasMoved = (currentMousePosition - mouseDownPosition).Length > GeneralUtility.Epsilon;
                    if (currentAction == SolidToolActionType.Create && mouseHasMoved)
                    {
                        mouseDownPosition.Z    = -viewport.GridSize * 4;
                        currentMousePosition.Z = viewport.GridSize * 4;
                    }

                    // convert to world
                    mouseDownPosition    = viewport.ViewportToWorld(mouseDownPosition);
                    prevMousePosition    = viewport.ViewportToWorld(prevMousePosition);
                    currentMousePosition = viewport.ViewportToWorld(currentMousePosition);

                    // snap
                    Vector3 snappedDownMousePosition    = GeneralUtility.SnapToGrid(mouseDownPosition, viewport.GridSize);
                    Vector3 snappedPrevMousePosition    = GeneralUtility.SnapToGrid(prevMousePosition, viewport.GridSize);
                    Vector3 snappedCurrentMousePosition = GeneralUtility.SnapToGrid(currentMousePosition, viewport.GridSize);

                    RubberBand rubberband = controller.RubberBand;

                    switch (currentAction)
                    {
                    case SolidToolActionType.Create:
                        rubberband.Bounds.Reset();
                        rubberband.Bounds.Grow(snappedDownMousePosition);
                        rubberband.Bounds.Grow(snappedCurrentMousePosition);
                        break;

                    case SolidToolActionType.Drag:
                    {
                        Vector3 delta = snappedCurrentMousePosition - snappedPrevMousePosition;
                        if (delta != Vector3.Zero)
                        {
                            TranslateOperation translate = new TranslateOperation(delta)
                            {
                                GridSize  = viewport.GridSize,
                                Transform = fromGridSpaceMatrix
                            };
                            rubberband.PerformOperation(translate);
                            rubberband.ShowGrabhandles = false;
                        }
                    }
                    break;

                    case SolidToolActionType.Transform:
                    {
                        SolidGrabHandles    handles   = rubberband.Handles;
                        IMapObjectOperation operation = null;

                        Vector3 delta = currentMousePosition - prevMousePosition;
                        if (delta != Vector3.Zero)
                        {
                            rubberband.ShowGrabhandles = false;
                        }

                        switch (handles.Mode)
                        {
                        case SolidGrabHandles.HandleMode.Resize:
                            operation = new ResizeTransformation(fromGridSpaceMatrix, snappedPrevMousePosition,
                                                                 snappedCurrentMousePosition,
                                                                 handles.LastHitStatus, viewport.GridSize);
                            break;

                        case SolidGrabHandles.HandleMode.Rotate:
                            operation = new RotateTransformation(fromGridSpaceMatrix, mouseDownPosition,
                                                                 currentMousePosition, Matrix4.Identity);
                            break;

                        case SolidGrabHandles.HandleMode.Skew:
                            operation = new SkewTransformation(fromGridSpaceMatrix, snappedDownMousePosition,
                                                               snappedCurrentMousePosition, Matrix4.Identity,
                                                               handles.LastHitStatus);
                            break;
                        }

                        if (operation != null)
                        {
                            controller.RubberBand.PerformOperation(operation);
                        }
                    }

                    break;
                    }
                }
            }
            else
            {
                controller.SetCursor(Cursors.Default);
            }

            return(true);
        }