示例#1
0
        /// <inheritdoc />
        public IVideoStream Rotate(RotateDegrees rotateDegrees)
        {
            var rotate = rotateDegrees == RotateDegrees.Invert ? "-vf \"transpose=2,transpose=2\" " : $"-vf \"transpose={(int)rotateDegrees}\" ";

            _parameters.Add(new ConversionParameter(rotate));
            return(this);
        }
示例#2
0
 /// <inheritdoc />
 public IConversion Rotate(RotateDegrees rotateDegrees)
 {
     if (rotateDegrees == RotateDegrees.Invert)
     {
         _rotate = "-vf \"transpose=2,transpose=2\" ";
     }
     else
     {
         _rotate = $"-vf \"transpose={(int) rotateDegrees}\" ";
     }
     return(this);
 }
示例#3
0
        public async Task TransposeTest(RotateDegrees rotateDegrees)
        {
            string outputPath = Path.ChangeExtension(Path.GetTempFileName(), Extensions.Mp4);
            bool conversionResult = await new Conversion()
                .SetInput(Resources.MkvWithAudio)
                .Rotate(rotateDegrees)
                .SetOutput(outputPath)
                .Start();

            Assert.True(conversionResult);
            var mediaInfo = new MediaInfo(outputPath);
            Assert.Equal(TimeSpan.FromSeconds(9), mediaInfo.Properties.Duration);
            Assert.Equal("h264", mediaInfo.Properties.VideoFormat);
            Assert.Equal("aac", mediaInfo.Properties.AudioFormat);
        }
        public async Task TransposeTest(RotateDegrees rotateDegrees)
        {
            string     outputPath = Path.ChangeExtension(Path.GetTempFileName(), FileExtensions.Mp4);
            IMediaInfo inputFile  = await MediaInfo.Get(Resources.MkvWithAudio);

            IConversionResult result = await Conversion.New()
                                       .AddStream(inputFile.VideoStreams.First().Rotate(rotateDegrees))
                                       .SetOutput(outputPath)
                                       .Start();

            Assert.True(result.Success);
            IMediaInfo mediaInfo = await MediaInfo.Get(outputPath);

            Assert.Equal(TimeSpan.FromSeconds(9), mediaInfo.Duration);
            Assert.Equal("h264", mediaInfo.VideoStreams.First().Format);
            Assert.False(mediaInfo.AudioStreams.Any());
        }
示例#5
0
        public async Task TransposeTest(RotateDegrees rotateDegrees)
        {
            string     outputPath = Path.ChangeExtension(Path.GetTempFileName(), FileExtensions.Mp4);
            IMediaInfo inputFile  = await FFmpeg.GetMediaInfo(Resources.MkvWithAudio);

            IConversionResult result = await FFmpeg.Conversions.New()
                                       .AddStream(inputFile.VideoStreams.First().Rotate(rotateDegrees))
                                       .SetOutput(outputPath)
                                       .Start();


            IMediaInfo mediaInfo = await FFmpeg.GetMediaInfo(outputPath);

            Assert.Equal(9, mediaInfo.Duration.Seconds);
            Assert.Equal("h264", mediaInfo.VideoStreams.First().Codec);
            Assert.False(mediaInfo.AudioStreams.Any());
        }
示例#6
0
 /// <inheritdoc />
 public IVideoStream Rotate(RotateDegrees rotateDegrees)
 {
     _rotate = rotateDegrees == RotateDegrees.Invert ? "-vf \"transpose=2,transpose=2\" " : $"-vf \"transpose={(int)rotateDegrees}\" ";
     return(this);
 }
示例#7
0
        /// <summary>
        /// Rotate the the drive (positive degrees turn counterclockwise)
        /// </summary>
        /// <param name="degrees">(positive degrees turn counterclockwise)</param>
        /// <param name="power">(-1.0 to 1.0)</param>
        IEnumerator<ITask> RotateUntilDegrees(double degrees, double power)
        {
            //reset encoders
            encoder.Reset Lreset = new encoder.Reset();
            _leftEncoderPort.Post(Lreset);
            yield return (Arbiter.Choice(Lreset.ResponsePort,
                delegate(DefaultUpdateResponseType response) { },
                delegate(Fault fault) { LogError(fault); }
            ));

            encoder.Reset Rreset = new encoder.Reset();
            _rightEncoderPort.Post(Rreset);
            yield return (Arbiter.Choice(Rreset.ResponsePort,
                delegate(DefaultUpdateResponseType response) { },
                delegate(Fault fault) { LogError(fault); }
            ));

            double arcDistance = Math.Abs(degrees) * _state.DistanceBetweenWheels * 3.14159 / 360;

            //compute tick to stop at
            int stopLeftWheelAt = (int)Math.Round(arcDistance / (2.0 * 3.14159 * _state.LeftWheel.Radius / _state.LeftWheel.EncoderState.TicksPerRevolution));
            int stopRightWheelAt = (int)Math.Round(arcDistance / (2.0 * 3.14159 * _state.RightWheel.Radius / _state.RightWheel.EncoderState.TicksPerRevolution));

            // Subscribe to the encoders on internal ports
            encoder.EncoderOperations leftNotificationPort = new encoder.EncoderOperations();
            encoder.EncoderOperations rightNotificationPort = new encoder.EncoderOperations();

            encoder.Subscribe op = new encoder.Subscribe();
            op.Body = new SubscribeRequestType();
            op.NotificationPort = leftNotificationPort;
            _leftEncoderPort.Post(op);

            yield return (Arbiter.Choice(op.ResponsePort,
                delegate(SubscribeResponseType response)
                {
                    //subscription was successful, start listening for encoder replace messages
                    Activate(Arbiter.Receive<encoder.UpdateTickCount>(false, leftNotificationPort,
                        delegate(encoder.UpdateTickCount update)
                        {
                            StopMotorWithEncoderHandler(leftNotificationPort, update, _leftMotorPort, stopLeftWheelAt);
                        }));
                },
                delegate(Fault fault) { LogError(fault); }
            ));

            encoder.Subscribe op2 = new encoder.Subscribe();
            op2.Body = new SubscribeRequestType();
            op2.NotificationPort = rightNotificationPort;
            _leftEncoderPort.Post(op2);
            yield return (Arbiter.Choice(op2.ResponsePort,
                delegate(SubscribeResponseType response)
                {
                    //subscription was successful, start listening for encoder replace messages
                    Activate(Arbiter.Receive<encoder.UpdateTickCount>(false, rightNotificationPort,
                        delegate(encoder.UpdateTickCount update)
                        {
                            StopMotorWithEncoderHandler(rightNotificationPort, update, _rightMotorPort, stopRightWheelAt);
                        }
                    ));
                },
                delegate(Fault fault) { LogError(fault); }
            ));

            //start moving

            // start rotate operation
            _state.RotateDegreesStage = DriveStage.Started;

            RotateDegrees rotateUpdate = new RotateDegrees();
            rotateUpdate.Body.RotateDegreesStage = DriveStage.Started;
            _internalDriveOperationsPort.Post(rotateUpdate);

            PortSet<DefaultUpdateResponseType, Fault> responsePort = new PortSet<DefaultUpdateResponseType, Fault>();

            double rightPow;
            double leftPow;

            if (degrees > 0)
            {
                rightPow = power;
                leftPow = -power;
            }
            else
            {
                rightPow = -power;
                leftPow = power;
            }

            Motor.SetMotorPower leftPower = new Motor.SetMotorPower(leftPow);
            leftPower.ResponsePort = responsePort;
            _leftMotorPort.Post(leftPower);

            Motor.SetMotorPower rightPower = new Motor.SetMotorPower(rightPow);
            rightPower.ResponsePort = responsePort;
            _rightMotorPort.Post(rightPower);

            Activate(Arbiter.MultipleItemReceive<DefaultUpdateResponseType, Fault>(responsePort, 2,
                delegate(ICollection<DefaultUpdateResponseType> successList, ICollection<Fault> failureList)
                {
                    foreach (Fault fault in failureList)
                    {
                        LogError(fault);
                    }
                }
            ));

            _state.RotateDegreesStage = DriveStage.Completed;
            //complete
            rotateUpdate.Body.RotateDegreesStage = DriveStage.Completed;
            _internalDriveOperationsPort.Post(rotateUpdate);
        }
示例#8
0
        public IEnumerator<ITask> RotateDegreesHandler(RotateDegrees rotateDegrees)
        {
            ValidateDriveConfiguration(true);
            if (_state.DistanceBetweenWheels <= 0)
            {
                rotateDegrees.ResponsePort.Post(new Fault());
                throw new InvalidOperationException("The wheel encoders are not properly configured");
            }
            else
            {
                _state.TimeStamp = DateTime.Now;

                // send immediate response
                rotateDegrees.ResponsePort.Post(DefaultUpdateResponseType.Instance);

                // send immediate response
                rotateDegrees.ResponsePort.Post(DefaultUpdateResponseType.Instance);

                // post request to internal port.
                _internalDriveOperationsPort.Post(rotateDegrees);

            }
            yield break;
        }
        public FileContentResult ImageEditRequest([FromBody] string RequestData)
        {
            //map request to DTO RequestModel
            JObject model = new JObject();

            try
            {
                model = JObject.Parse(RequestData);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.ToString());
            }
            RequestModel request = new RequestModel();

            try
            {
                request.ImageData  = model["ImageData"].ToString();
                request.Operations = model["Operations"].ToObject <List <JObject> >();
            }
            catch (Exception ex)
            {
                throw new SystemException("Invalid String", ex);
            }


            //create data stream
            var imageDataByteArray = Convert.FromBase64String(request.ImageData);

            var imageDataStream = new MemoryStream(imageDataByteArray);

            imageDataStream.Position = 0;

            //Save edited image result here
            var imageOutStream = new MemoryStream();

            ImageFactory imageFactory = new ImageFactory();

            imageFactory.Load(imageDataStream);

            foreach (JObject JOp in request.Operations)
            {
                if (JOp.ContainsKey("Resize"))
                {
                    var    JTemp  = JOp["Resize"];
                    Resize resize = JTemp.ToObject <Resize>();
                    resize.PerformAction(imageFactory);
                }
                else if (JOp.ContainsKey("Filter"))
                {
                    var    JTemp  = JOp["Filter"];
                    Filter filter = JTemp.ToObject <Filter>();
                    filter.PerformAction(imageFactory);
                }
                else if (JOp.ContainsKey("Flip"))
                {
                    var  JTemp = JOp["Flip"];
                    Flip flip  = JTemp.ToObject <Flip>();
                    flip.PerformAction(imageFactory);
                }
                else if (JOp.ContainsKey("RotateRight"))
                {
                    var         JTemp  = JOp["RotateRight"];
                    RotateRight rotate = JTemp.ToObject <RotateRight>();
                    rotate.PerformAction(imageFactory);
                }
                else if (JOp.ContainsKey("RotateDegrees"))
                {
                    var           JTemp         = JOp["RotateDegrees"];
                    RotateDegrees rotateDegrees = JTemp.ToObject <RotateDegrees>();
                    rotateDegrees.PerformAction(imageFactory);
                }
                else if (JOp.ContainsKey("Thumbnail"))
                {
                    var       JTemp     = JOp["Thumbnail"];
                    Thumbnail thumbnail = JTemp.ToObject <Thumbnail>();
                    thumbnail.PerformAction(imageFactory);
                }
            }
            imageFactory.Save(imageOutStream);

            return(File(imageOutStream.ToArray(), "image/png"));
        }
示例#10
0
 public void RotateScreen(RotateDegrees degrees)
 {
     ConnectionInfo.SendCommand(this, new[] { (byte)FunActionsCommunication.RotateScreen, (byte)degrees });
 }