Exemplo n.º 1
0
 private void Initialize()
 {
     this.metaData      = false;
     this.frames        = 25 * 2;
     this.resolution    = new Geometry2D.Integer.Size(640, 480);
     this.photo         = Bitmap.Image.OpenResource("Generator/strip.png");
     this.Format        = Colorspace.Yuv420;
     this.motionType    = MotionType.Mirror;
     this.controlPoints = new Collection.List <ControlPoint>();
     this.controlPoints.Add(new ControlPoint(0, 1, 0, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, 40, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, 0, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, -40, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, 0, 0));
 }
Exemplo n.º 2
0
        public sealed override void Open(Uri.Locator argument)
        {
            this.cache = new Collection.Vector <Tuple <Raster.Image, Tuple <string, object>[]> >(this.Prepare(argument));
            new Action <int>(frame =>
            {
                Tuple <Raster.Image, Tuple <string, object>[]> result = this.Generate(frame);
                Raster.Image generated = result.Item1;
                {
                    switch (this.Format)
                    {
                    default:
                    case Colorspace.Bgra:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Bgra>(), result.Item2);
                        break;

                    case Colorspace.Bgr:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Bgr>(), result.Item2);
                        break;

                    case Colorspace.Yuv420:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Yuv420>(), result.Item2);
                        break;

                    case Colorspace.Yvu420:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Yvu420>(), result.Item2);
                        break;

                    case Colorspace.Yuyv:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Yuyv>(), result.Item2);
                        break;

                    case Colorspace.Monochrome:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Monochrome>(), result.Item2);
                        break;
                    }
                }
                lock (this.cache)
                    this.cache[frame] = result;
            }).For(this.Count);
        }
Exemplo n.º 3
0
        protected override int Prepare(Uri.Locator argument)
        {
            try
            {
                Uri.Path path = argument.PlatformPath;
                if (path.NotNull())
                {
                    Bitmap.Image image = Bitmap.Image.Open(path);
                    this.photo = image;
                }
                if (!argument.Query.Empty)
                {
                    string value = argument.Query["resolution"];
                    if (value.NotEmpty())
                    {
                        this.resolution = (Geometry2D.Integer.Size)value;
                    }
                    value = argument.Query["format"];
                    if (value.NotEmpty())
                    {
                        base.Format = (Colorspace)Enum.Parse(typeof(Colorspace), value, true);
                    }
                    value = argument.Query["frames"];
                    if (value.NotEmpty())
                    {
                        this.frames = Kean.Math.Integer.Parse(value);
                    }
                    value = argument.Query["meta"];
                    if (value.NotEmpty())
                    {
                        this.metaData = bool.Parse(value);
                    }
                    value = argument.Query["motiontype"];
                    if (value.NotEmpty())
                    {
                        this.motionType = (MotionType)Enum.Parse(typeof(MotionType), value, true);
                    }
                    value = argument.Query["motion"];
                    if (value.NotEmpty())
                    {
                        string[] motion = value.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                        this.controlPoints.Clear();
                        switch (this.motionType)
                        {
                        default:
                        case MotionType.Repeat:
                        case MotionType.Periodic:
                            for (int i = 0; i < motion.Length - 3; i += 4)
                            {
                                this.controlPoints.Add(new ControlPoint(Kean.Math.Single.Parse(motion[i]), Kean.Math.Single.Parse(motion[i + 1]), Kean.Math.Single.Parse(motion[i + 2]), Kean.Math.Single.Parse(motion[i + 3])));
                            }
                            break;

                        case MotionType.Mirror:
                            for (int i = 0; i < motion.Length - 3; i += 4)
                            {
                                this.controlPoints.Add(new ControlPoint(Kean.Math.Single.Parse(motion[i]), Kean.Math.Single.Parse(motion[i + 1]), Kean.Math.Single.Parse(motion[i + 2]), Kean.Math.Single.Parse(motion[i + 3])));
                            }
                            for (int i = motion.Length - 5; i >= 3; i -= 4)
                            {
                                this.controlPoints.Add(new ControlPoint(Kean.Math.Single.Parse(motion[i - 3]), Kean.Math.Single.Parse(motion[i - 2]), Kean.Math.Single.Parse(motion[i - 1]), Kean.Math.Single.Parse(motion[i])));
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                this.Initialize();
            }
            this.motion = new Geometry2D.Single.Transform[this.frames];
            float step = this.frames / (float)(this.controlPoints.Count - 1);

            Tuple <float, Geometry2D.Single.Transform>[] measures = new Tuple <float, Geometry2D.Single.Transform> [this.controlPoints.Count];
            for (int i = 0; i < this.controlPoints.Count; i++)
            {
                measures[i] = Tuple.Create <float, Geometry2D.Single.Transform>(i * step, (Geometry2D.Single.Transform)(Geometry2D.Single.Transform.CreateTranslation(this.controlPoints[i].X, this.controlPoints[i].Y) * Geometry2D.Single.Transform.CreateRotation(Kean.Math.Single.ToRadians(this.controlPoints[i].Angle)) * Geometry2D.Single.Transform.CreateScaling(this.controlPoints[i].Scale)));
            }
            Interpolation.Splines.Method method;
            switch (this.motionType)
            {
            default:
            case MotionType.Repeat:
                method = Interpolation.Splines.Method.Natural;
                break;

            case MotionType.Periodic:
                method = Interpolation.Splines.Method.Periodic;
                break;

            case MotionType.Mirror:
                method = Interpolation.Splines.Method.Natural;
                break;
            }
            this.interpolate = new Kean.Math.Regression.Interpolation.Splines.Geometry2D.Single.Transform(method, measures);
            return(this.frames);
        }