private void FlFinished(Dictionary <Bitmap, byte[]> result)
 {
     foreach (KeyValuePair <Bitmap, byte[]> keyValuePair in result)
     {
         CLAPI.UpdateBitmap(CLAPI.MainThread, keyValuePair.Key, keyValuePair.Value);
     }
 }
Ejemplo n.º 2
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            SerializableFLProgram prog = FLSerializer.LoadProgram(stream, runner.InstructionSet);

            progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3);
            FLProgram p = runner.Run(prog, 512, 512, 1);

            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            filePath = filePath.Remove(filePath.Length - 3, 3) + "png";

            progressIndicator?.SetProgress(
                $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                3,
                3
                );
            Bitmap bmp = new Bitmap(512, 512);

            CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer);
            bmp.Save(filePath);
            stream.Close();
            p.FreeResources();
            progressIndicator?.Dispose();
        }
Ejemplo n.º 3
0
        public virtual void Process(Action onFinish = null)
        {
            while (ProcessQueue.Count != 0)
            {
                FlScriptExecutionContext    fle    = ProcessQueue.Dequeue();
                Dictionary <string, byte[]> ret    = Process(fle);
                Dictionary <Bitmap, byte[]> texMap = new Dictionary <Bitmap, byte[]>();
                foreach (KeyValuePair <string, byte[]> bytese in ret)
                {
                    if (fle.TextureMap.ContainsKey(bytese.Key))
                    {
                        texMap.Add(fle.TextureMap[bytese.Key], bytese.Value);
                    }
                }

                foreach (KeyValuePair <Bitmap, byte[]> textureUpdate in texMap)
                {
                    CLAPI.UpdateBitmap(CLAPI.MainThread, textureUpdate.Key, textureUpdate.Value);
                }

                fle.OnFinishCallback?.Invoke(texMap);
            }

            onFinish?.Invoke();
        }
Ejemplo n.º 4
0
        private void OnFinishCallback(FLProgram obj, string outputFile)
        {
            Logger.Log(LogType.Log, "Saving Output File: " + Path.GetFullPath(outputFile), 1);
            FLBuffer result = obj.GetActiveBuffer(false);
            Bitmap   bmp    = new Bitmap(result.Width, result.Height);

            CLAPI.UpdateBitmap(CLAPI.MainThread, bmp,
                               CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Size));
            bmp.Save(outputFile);
            result.Dispose();
        }
Ejemplo n.º 5
0
        private static void SaveOutput(string subcategory, Bitmap bmp, FLProgram program, FLSetup setup, string file)
        {
            FLBuffer outP = program.GetActiveBuffer(false);

            CLAPI.UpdateBitmap(CLAPI.MainThread, bmp, outP.Buffer);
            outP.Dispose();
            string p         = Path.GetFileNameWithoutExtension(file) + ".png";
            Stream bmpStream = setup.GetDataFileStream(Path.Combine(subcategory, p));

            bmp.Save(bmpStream, ImageFormat.Png);
            bmpStream.Close();
        }
Ejemplo n.º 6
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            FLProgram p = null;

            try
            {
                SerializableFLProgram prog = runner.Parser.Process(
                    new FLParserInput(
                        name,
                        new StreamReader(stream)
                        .ReadToEnd().Split('\n')
                        .Select(x => x.Trim()).ToArray(),
                        true
                        )
                    );

                progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3);


                p = runner.Build(prog);
                if (p.HasMain)
                {
                    runner.Run(p, 512, 512, 1);

                    string filePath = Path.Combine(
                        targetDir,
                        name.Replace("/", "\\").StartsWith("\\")
                                                       ? name.Replace("/", "\\").Substring(1)
                                                       : name.Replace("/", "\\")
                        );
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    filePath = filePath.Remove(filePath.Length - 2, 2) + "png";

                    progressIndicator?.SetProgress(
                        $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                        3,
                        3
                        );
                    Bitmap bmp = new Bitmap(512, 512);
                    CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer);
                    bmp.Save(filePath);
                }
            }
            catch (Exception)
            {
            }

            stream.Close();
            p?.FreeResources();
            progressIndicator?.Dispose();
        }
 public override void Process(Action onFinish = null)
 {
     ThreadManager.RunTask(() => _proc(onFinish), x =>
     {
         foreach (KeyValuePair <FlScriptExecutionContext, Dictionary <Bitmap, byte[]> > textureUpdate in x)
         {
             foreach (KeyValuePair <Bitmap, byte[]> bytese in textureUpdate.Value)
             {
                 CLAPI.UpdateBitmap(CLAPI.MainThread, bytese.Key, bytese.Value);
             }
         }
     });
 }
Ejemplo n.º 8
0
        private void DisplayContent()
        {
            if (Buffer.Buffer.IsDisposed)
            {
                MessageBox.Show("Can not show content of a disposed Buffer, form exiting", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                return;
            }
            pbBufferContent.Image?.Dispose();
            Bitmap bmp = new Bitmap(width, height);

            CLAPI.UpdateBitmap(CLAPI.MainThread, bmp, Buffer.Buffer);
            pbBufferContent.Image = bmp;
        }
Ejemplo n.º 9
0
        private void DisplayContent(CLAPI instance)
        {
            if (Buffer.Buffer.IsDisposed)
            {
                throw new InvalidOperationException("Can not Use a Buffer that has been Disposed.");
            }

            pbBufferContent.Image?.Dispose();

            Bitmap bmp = new Bitmap(width, height);


            byte[] data = CLAPI.ReadBuffer <byte>(instance, Buffer.Buffer, (int)Buffer.Size);

            int start  = 4 * Buffer.Width * Buffer.Height * (int)nudFrame.Value;
            int length = 4 * Buffer.Width * Buffer.Height;

            Span <byte> s = new Span <byte>(data, start, length);

            CLAPI.UpdateBitmap(instance, bmp, s.ToArray());
            pbBufferContent.Image = bmp;
        }