Jump to content

About Threading


Recommended Posts

I have some questions.

1. How can I set that the SingleThreadedEffect attribute is applied?

2. Could I set that RenderArgs.Graphics or RenderArgs.Bitmap are thread-safe?

3. BTW, I have a problem when implement the my effect plugin. If I use ' foreach (Rectangle rect in roi.GetRegionScansReadOnlyInt()) ' , the result is fast. But, if I don't use it, I want to calculate whole of image, the speed is very slow. And, in some cases, the Render() does nothing, I think the problem may be about threading.

4. Could you explain how to use the threading method of Paint.Net effectively?

Please help me to answer. Thanks in advanced.

Link to comment
Share on other sites

It sounds like you're working with some old documentation, possible going off of Dennis' old article about writing plugins for Paint.NET v2.1. Things have changed since then.

1. You need to specify EffectDirectives.SinglThreaded as a parameter to the base Effect class constructor.

2. If you specify SingleThreaded, then these will be thread safe because your effect will only ever be executing on 1 thread at a time. Otherwise, you must not use them in your Render() method, as GDI+ will complain loudly.

3. You should be using the overload of Render that takes an array of Rectangles, a starting index, and a length. No Regions.

4. You shouldn't have to worry about "using" the threading model of Paint.NET. Everything is set up for you automatically. If you are having problems it's likely because you are incorrectly assuming things about the way Paint.NET is calling in to your Effect.

The effect system is designed such that Paint.NET will call your Render() method to tell it to render a specific region of the output surface. You must NOT render anywhere else in the output surface.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Yes, I am working with Paint.Net v2.1b. Thanks for your response soon but I still have some concerns.

1. 'EffectDirectives' is not found in the v2.1, I think you guide me for v2.6. Coming back to v2.1, although I set ' this.singleThreaded = true; ' in the contructor method of base Effect class but it is not thread safe. Because, in the Render() method, there is only one feature to write 'test' message to file 'test.txt', but when I open this file, I see that there are 50 'test' strings. I expect to receice only one 'test' string in the file. How can I do?

2. Because I built my plugin with v2.1, could you guide me what should focus when it is moved into v2.63?

Thank you!

Link to comment
Share on other sites

1) You're misunderstanding how the effect system works in Paint.NET. We will call your Render method many times. This is so we can do things like: report progress to the user, let the user cancel the rendering, split rendering among multiple cores/processors by using multiple threads, and clip rendering to a selected region.

EffectDirective is indeed a v2.6 thing, it replaces the old method of using attributes. Also, Paint.NET v2.6 is not compatible with plugins written for older versions of Paint.NET.

2) The changes required are not major. There is simply a different overload of Render() that takes an array of rectangles and which part of the array to be concerned with. You should be able to just try compiling, look at the errors, and make fixes from there.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

1) Oh! I know that the Render() method is called many times. But, I want to ask how I can set that this method will be called only one time. In other words, my plugin does something below:

step 1: get parameters from dialog to render new image.

step 2: rendering new image.

step 3: calculating new image and writing the information to a file.

step 4: evaluating the information

if the information is good enough, go to stop rendering.

else re-calculate new parameters and go to step 2 with new updated paremeters.

Thus, in this case, I want that my Render() method will be called only one time. At the moment, it confused me a lot. Can I reset any value in order to archive my expectation?

Thanks,

Link to comment
Share on other sites

There is no way to get your Render method to be called only once. That would completely break progress reporting, the ability for the user to cancel, and multithreading performance benefits (assuming you are not using EffectDirectives.SingleThreaded).

It may be that Paint.NET's effect plugin system is not compatible with what you are trying to achieve.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...