public ProcessFullImageTask(string imageNameSource, DProcessPixel processor, string imageNameTarget) { SourceImageFileName = imageNameSource; TargetImageFileName = imageNameTarget; PixelProcessor = processor; ThreadsToUse = 768; MaxFragmentWidth = 16; MaxFragmentHeight = 16; }
private bool CompileShader(string line, string shaderPath, out DProcessPixel shader) { shader = null; try { var shaderCode = File.ReadAllText(shaderPath); shaderCode = @" using System.Drawing; using System.Drawing.Imaging; using ImageProcessing; using ImageProcessing.SharpShader; namespace Shader { public class ShaderClass { " + shaderCode + @" } }"; var providerOptions = new Dictionary <string, string> { //{"CompilerVersion", "v4.5"} }; var compilerParams = new CompilerParameters { GenerateExecutable = false, ReferencedAssemblies = { "System.Core.dll", "System.Drawing.dll", "ImageProcessing.dll" }, GenerateInMemory = true, //OutputAssembly = shaderPath + ".dll" }; var provider = CodeDomProvider.CreateProvider("C#", providerOptions);//new CSharpCodeProvider(providerOptions); var results = provider.CompileAssemblyFromSource(compilerParams, shaderCode); if (results.Errors.Count > 0) { LastLoadMessages = FormErrorMessage(line, "Shader code at '{0}' compilation failed, errors are:", shaderPath); foreach (var error in results.Errors) { LastLoadMessages += Environment.NewLine + error; } return(false); } var ass = results.CompiledAssembly; var shaderClass = ass.GetType("Shader.ShaderClass"); var shaderInfo = shaderClass.GetMethod("main");/*, BindingFlags.Static, null, new [] * { * typeof(int), typeof(int), typeof(ImageProcessingThreadContext) * }, null*/ if (shaderInfo == null) { LastLoadMessages = FormErrorMessage(line, @"Shader code at '{0}' compilation failed - no 'main' function found.", shaderPath); return(false); } var parms = shaderInfo.GetParameters(); if (!shaderInfo.IsStatic || shaderInfo.ReturnType != typeof(void) || !shaderInfo.IsPublic || parms.Length != 3 || parms[0].ParameterType != typeof(int) || parms[1].ParameterType != typeof(int) || parms[2].ParameterType != typeof(ImageProcessingThreadContext)) { LastLoadMessages = FormErrorMessage(line, @"Shader code at '{0}' compilation failed - 'main' function should be: public static void main(int, int, ImageProcessingThreadContext).", shaderPath); return(false); } _shaders.Add(shaderInfo);//to keap shaderInfo in the heap (neaded?) shader = (x, y, context) => shaderInfo.Invoke(null, new object[] { x, y, context }); } catch (Exception ex) { LastLoadMessages = FormErrorMessage(line, "Shader code at '{0}' compilation failed, exception: {1}", shaderPath, ex.Message); return(false); } return(true); }