Exemplo n.º 1
0
        private static bool HandleSaveToFile(SharpShader ss, string s, Expression e, Dictionary <string, string> aliases)
        {
            if (!CheckArgumentCount(ss, s, e, 2, 3))
            {
                return(false);
            }
            var name = ApplyAliases(e.Args[0], aliases);

            if (e.ArgsCount == 2)
            {
                var         format  = e.Args[1].ToLowerInvariant();
                ImageFormat eformat = null;
                if (!TryParse(format, out eformat))
                {
                    ss.LastLoadMessages = FormErrorMessage(s, "Unrecognized image format - '{0}'.", format);
                    return(false);
                }
                ss.Tasks.Add(new SaveImageToFileTask(name, eformat));
            }
            else
            {
                var         path    = ApplyAliases(e.Args[1], aliases);
                var         format  = e.Args[2].ToLowerInvariant();
                ImageFormat eformat = null;
                if (!TryParse(format, out eformat))
                {
                    ss.LastLoadMessages = FormErrorMessage(s, "Unrecognized image format - '{0}'.", format);
                    return(false);
                }
                ss.Tasks.Add(new SaveImageToFileTask(name, eformat, path));
            }
            return(true);
        }
Exemplo n.º 2
0
 private static bool CheckArgumentCount(SharpShader ss, string s, Expression e, int expected = 0)
 {
     if (e.ArgsCount == expected)
     {
         return(true);
     }
     ss.LastLoadMessages = FormErrorMessage(s, "{0} arguments expected, got {1}.", expected, e.ArgsCount);
     return(false);
 }
Exemplo n.º 3
0
 private static bool Handle_Alias(SharpShader ss, string s, Expression e, Dictionary <string, string> aliases)
 {
     if (!CheckArgumentCount(ss, s, e, 2))
     {
         return(false);
     }
     aliases[e.Args[0]] = e.Args[1];
     return(true);
 }
Exemplo n.º 4
0
 private static bool CheckArgumentCount(SharpShader ss, string s, Expression e, int expectedAtLeast, int expectedAtMost)
 {
     if ((e.ArgsCount >= expectedAtLeast) && (e.ArgsCount <= expectedAtMost))
     {
         return(true);
     }
     ss.LastLoadMessages = FormErrorMessage(s, "{0}..{1} arguments expected, got {2}.", expectedAtLeast, expectedAtMost, e.ArgsCount);
     return(false);
 }
Exemplo n.º 5
0
        private static bool HandleSetNoAccess(SharpShader ss, string s, Expression e, Dictionary <string, string> aliases)
        {
            if (!CheckArgumentCount(ss, s, e, 1))
            {
                return(false);
            }
            var name = ApplyAliases(e.Args[0], aliases);

            ss.Tasks.Add(new LockImageTask(name, ImageLockMode.UserInputBuffer));
            return(true);
        }
Exemplo n.º 6
0
        private static bool HandleCreateTarget(SharpShader ss, string s, Expression e, Dictionary <string, string> aliases)
        {
            if (!CheckArgumentCount(ss, s, e, 2))
            {
                return(false);
            }
            var src = ApplyAliases(e.Args[0], aliases);
            var tt  = ApplyAliases(e.Args[1], aliases);

            ss.Tasks.Add(new CreateTargetForImageTask(src, tt));
            return(true);
        }
Exemplo n.º 7
0
        private static bool HandleProcess(SharpShader ss, string s, Expression e, Dictionary <string, string> aliases)
        {
            if (!CheckArgumentCount(ss, s, e, 3, 5))
            {
                return(false);
            }
            var imgName    = ApplyAliases(e.Args[0], aliases);
            var ttName     = ApplyAliases(e.Args[1], aliases);
            var shaderPath = ApplyAliases(e.Args[2], aliases);

            if (!File.Exists(shaderPath))
            {
                ss.LastLoadMessages = FormErrorMessage(s, "Shader code not found at '{0}'", shaderPath);
                return(false);
            }
            DProcessPixel shader;

            if (!ss.CompileShader(s, shaderPath, out shader))
            {
                return(false);
            }
            var task = new ProcessFullImageTask(imgName, shader, ttName);

            ss.Tasks.Add(task);
            if (e.ArgsCount == 3)
            {
                return(true);
            }

            int v;

            if (!int.TryParse(e.Args[3], out v) || v < 1)
            {
                ss.LastLoadMessages = FormErrorMessage(s, "Argument #4 (ThreadID) should be natural number (1+), got '{0}'",
                                                       e.Args[3]);
                return(false);
            }
            task.ThreadsToUse = v;
            if (e.ArgsCount == 4)
            {
                return(true);
            }

            if (!int.TryParse(e.Args[4], out v) || v < 1)
            {
                ss.LastLoadMessages = FormErrorMessage(s, "Argument #5 (FragmentSize) should be natural number (1+), got '{0}'",
                                                       e.Args[4]);
                return(false);
            }
            task.MaxFragmentHeight = task.MaxFragmentWidth = v;
            return(true);
        }
Exemplo n.º 8
0
        private static bool HandleLoadFromFile(SharpShader ss, string s, Expression e, Dictionary <string, string> aliases)
        {
            if (!CheckArgumentCount(ss, s, e, 1))
            {
                return(false);
            }

            var path = ApplyAliases(e.Args[0], aliases);

            /*
             * if (!File.Exists(path))
             * {
             *  ss.LastLoadMessages = FormErrorMessage(s, "{0} - file does not exist.", path);
             *  return false;
             * }*/

            var task = new LoadImageFromFileTask(path);

            ss.Tasks.Add(task);
            return(true);
        }