ins0mniaque Posted March 7, 2007 Share Posted March 7, 2007 Hi, first time on forum, - "Welcome to the forum", well thank you. Time for substance. I'm writing a test plugin that write the source surface to a bitmap on disk, waits for an executable to end and then re-reads the bitmap and render it on the destination surface. The problem is that after my render loop is called, a ProgressDialog apprears with "Rendering...", and it renders for ~15-20 seconds a 50x50px image. Here is my reduced code [no error checking, etc...] but tested that it still has this behavior. public override void Render ( EffectConfigToken parameters, RenderArgs destination, RenderArgs source, Rectangle [ ] rois, int startIndex, int length ) { // Validate configuration token MyEffectConfigToken Token = parameters as MyEffectConfigToken; // Retrieve selection PdnRegion SelectionRegion = EnvironmentParameters.GetSelection ( source.Bounds ); Rectangle SelectionBounds = SelectionRegion.GetBoundsInt ( ); // Create temporary filenames string InputFileName = Path.Combine ( Path.GetTempPath ( ), Path.ChangeExtension ( Path.GetRandomFileName ( ), ".bmp" ) ); string OutputFileName = Path.Combine ( Path.GetTempPath ( ), Path.ChangeExtension ( Path.GetRandomFileName ( ), ".bmp" ) ); // Create bitmap and save it to InputFileName Bitmap Bitmap = source.Surface.CreateAliasedBitmap ( SelectionBounds, true ); Bitmap.Save ( InputFileName, ImageFormat.Bmp ); // Create process Process Process = new Process ( ); Process.StartInfo.FileName = Path.Combine ( Path.GetDirectoryName ( Assembly.GetExecutingAssembly ( ).Location ), "MyExecutable.exe" ); Process.StartInfo.Arguments = string.Format ( "-input \"{0}\" -output \"{1}\" {2}", InputFileName, OutputFileName, Token.CommandLine ); Process.StartInfo.CreateNoWindow = true; Process.StartInfo.UseShellExecute = false; Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; // Start process Process.Start ( ); // Wait for process to end Process.WaitForExit ( ); // Read OutputFileName and draw bitmap using ( Bitmap OutputBitmap = new Bitmap ( OutputFileName ) ) destination.Graphics.DrawImageUnscaledAndClipped ( OutputBitmap, SelectionBounds ); } Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted March 7, 2007 Share Posted March 7, 2007 This is because you're completely misunderstanding how the Effect system in Paint.NET works. There's no such thing as a post-render loop: your Render method is the implementation of the inside of the rendering loop. Your Render() method is going to be called from many threads at once and many times in a row. On a typical system it will be called 200 times from 2 difrerent threads (100 times per thread). So you are opening these input files 200 times and dumping this stuff out to disk 200 times as well, as well as creating 200 processes. You're also violating the Effect contract by writing outside of the region of interest that is specified in the parameters. When I call your Render() method, you must only and I mean ONLY ever write to the pixels described by the roi array from startIndex through startIndex+length-1. The reason your Render method is called many times is because each time you are called upon to render only a small portion of the roi array (roi stands for region of interest btw). So to quickly summarize: it's slow because everything is completely wrong. Paint.NET is probably the worst possible harness for what you are trying to do. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
ins0mniaque Posted March 7, 2007 Author Share Posted March 7, 2007 OMG! That's what you get for jumping directly to code... But let's say I really really wanted to do this, is there a way you would suggest me to do it ? Is there a single-thread effect model ? Or do I have to execute this from my configuration window and read from it from the render thread ? Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted March 7, 2007 Share Posted March 7, 2007 You'll need to write your own program to do this. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.