Jump to content

question about rois() and multithreading


jchunn
 Share

Recommended Posts

I have been playing with the effects api for a couple of days now... just trying to get something to work (and I have gotten something to work). I would deeply apprreciate it if somebody wouldn't mind taking a minute to review my comments below and provide some insight. Some of the folks here have obviously created some astounding plugins, and I think one of those folks could reply to this with their eyes closed. I have read through the forum, and I have toyed around with some of the plugin source that is available, but I am still not completely sure I have this right.

Please correct any incorrect assumptions here:

The "rois" variable (rectangles of interest, I presume) that is passed into the "OnRender" method appears to be at the heart of the multithreaded model. When the method is called, it looks like one or more rectangles are passed in via this "rois" array, and it looks like the expectation of the application is that the plugin will process the areas contained in the "rois" that are passed in, and only those areas, during that pass. It also appears that the "OnRender" method will be called multiple times for a single rendering, passing in different "rois" until the entire selected area (or is it the entire surface of the layer?) has been covered.

If I am correct so far, then it appears that this must be looked at from the perspective of the "location" of each rectangle. In other words, the plugin could be asked to render an arbitrary location within the overall selection (although I assume logically that they are passed in from top to bottom?). The plugin, then, must use the location of the rectangle (and the pixels within that rectangle) relative to the overall selection or the overall layer, depending on what your plugin does.

Again assuming I am right so far, then the x,y location of a pixel must be used in any math that determines how the effect acts on that pixel. While that is obviously true even in a single threaded implementation, the point is that you cant really use other variables within a loop (like i, for example) in the math, at least not easily, since i would start over at zero in each pass (unless, of course, you use relative position to set the initial value of i).

I am just trying to verify how this works. My testing this far seems to verify what I have said, but I don't want to get too far along only to find that I have misunderstood something. Any commentary would be greatly appreciated.

Regards.

Total hack.

Link to comment
Share on other sites

Right, you must assume that your effect will be called on and required to render from completely arbitrary locations in the image. You cannot assume that the rects will be passed from top to bottom, because the workload will be distributed among 2 or more threads, depending on the number of processor cores present. You can assume, however, that only one instance of your Effect will be working on the image at once, so if you absolutely need something to persist, you can put a variable in that class.

^Ed Harvey will shoot me for saying that. He is dead-set against global variables ;)

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to comment
Share on other sites

  • 2 weeks later...

Global variables are a form of shared state which causes a radical increase in the number of possible states that a program can be in. And not only that, it causes an explosive increase in the number of control flow paths that can be taken to reach any of those states.

In other words, the complexity of a program rises significantly with more global state, and maintainability decreases significantly.

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...