Esempio n. 1
0
    void Run(int sample)
    {
        var decoder = new MG.GIF.Decoder();

        var sw = new Stopwatch();

        sw.Start();

        foreach (var file in mFiles)
        {
            decoder.Load(file);

            var img = decoder.NextImage();

            while (img != null)
            {
                img = decoder.NextImage();
            }
        }

        sw.Stop();

        mSum        += sw.ElapsedMilliseconds;
        mSumSquares += sw.ElapsedMilliseconds * sw.ElapsedMilliseconds;

        var average  = (float)mSum / mCount;
        var variance = mSumSquares / mCount - average * average;

        UnityEngine.Debug.Log($"[{sample:00}]: av <color=yellow>{average:0.0}</color>ms, sd <color=yellow>{Mathf.Sqrt( variance ):0.0}</color> - {sw.ElapsedMilliseconds}ms");

        Text.text = $"[{sample:00}] {average:0.0}";
    }
Esempio n. 2
0
    void Start()
    {
        if (string.IsNullOrWhiteSpace(Filename))
        {
            return;
        }

        var path = Path.Combine(Application.streamingAssetsPath, Filename);

        using (var decoder = new MG.GIF.Decoder(File.ReadAllBytes(path)))
        {
            var img = decoder.NextImage();

            while (img != null)
            {
                mFrames.Add(img.CreateTexture());
                mFrameDelay.Add(img.Delay / 1000.0f);
                img = decoder.NextImage();
            }
        }

        GetComponent <Renderer>().material.mainTexture = mFrames[0];
    }
Esempio n. 3
0
        //--------------------------------------------------------------------------------
        // test config values

        public void Run()
        {
            // read input gif

            var bytes   = File.ReadAllBytes($"{Dir}\\{Get( "input" )}");
            var decoder = new Decoder(bytes);

            var images = new List <Image>();
            var img    = decoder.NextImage();

            while (img != null)
            {
                images.Add((Image)img.Clone());
                img = decoder.NextImage();
            }

            // compare results

            foreach (var key in Config.Keys)
            {
                if (key[0] == '[')
                {
                    continue;
                }

                switch (key)
                {
                case "input":
                    // test gif for input
                    break;

                case "comment":             // plain text extension
                case "xmp-data":            // XMP data extension
                case "color-profile":       // ICC colour profile extension
                case "buffer-size":         // size of buffer before playing
                case "force-animation":     // default to true
                case "loop-count":
                    // ignore
                    break;

                case "version":
                    Assert.AreEqual(Get("version"), decoder.Version);
                    break;

                case "width":
                    Assert.AreEqual(Get("width"), decoder.Width.ToString());
                    break;

                case "height":
                    Assert.AreEqual(Get("height"), decoder.Height.ToString());
                    break;

                case "background":

                    var v   = Get("background");
                    var col = (Color)ColorConverter.ConvertFromString(v);

                    Assert.AreEqual(col.R, decoder.BackgroundColour.r);
                    Assert.AreEqual(col.G, decoder.BackgroundColour.g);
                    Assert.AreEqual(col.B, decoder.BackgroundColour.b);
                    Assert.AreEqual(col.A, decoder.BackgroundColour.a);

                    break;

                case "frames":

                    var frames = Get("frames").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < frames.Length; i++)
                    {
                        ValidateFrame(i, frames[i], images);
                    }

                    break;

                default:
                    TestContext.WriteLine($"Unhandled config {key}");
                    break;
                }
            }
        }