## Recommended Posts

I would like to do the equilavent of this in gmic using c#.

1. Create a surface of w,h,d,s.

2. Per each pixel, increment value at offset x,y,z pixel while still being multithreading. To clarify:

Spoiler
```
[snip] are stuff you don't need to see to know what I'm talking about

rep_popcorn_fractal:
[snip]

channels. 0 f. 0

{int(w/\$density)},{int(h/\$density)},1,1

f. ":begin(
[snip]
\$9?(
if(narg(\$10),
[snip]
popcorn_x(a,b)=(Kb=K*b;a-H*func_a(b+func_b(Kb+func_c(Kb))));
popcorn_y(a,b)=(Ka=K*a;b-H*func_d(a+func_e(Ka+func_f(Ka))));
):(
[snip]
popcorn_x(a,b)=a-H*func_a(b+func_b(K*b));
popcorn_y(a,b)=b-H*func_c(a+func_d(K*a));
);
);
xx=zoom*(x-cx)/cx;
yy=zoom*(y-cy)/cy;
xx*=sx;
yy*=sy;
xx+=origin_x;
yy+=origin_y;
for(ptn=0,ptn<pts,ptn++,
xnew=popcorn_x(xx,yy);
ynew=popcorn_y(xx,yy);
xval="\$fvx";
yval="\$fvy";
xpos=round(xval);
ypos=round(yval);
i(#-2,xpos,ypos)++;
xx=xnew;
yy=ynew;
);
"
rm.```

Note that the : symbol at beginning of f means it will be forced to evaluate on parallel.

Also, the I(#-2)++ means value at second last image at xpos,ypos will be incremented by one.

Test with gmic and my paintdotnet plugin implementation of popcorn fractal:

5000x5000 image

Gmic: 35 seconds (parallel processing)

Paint.NET: 135 seconds (serial due to code design)

Edited by Reptillian

G'MIC Filter Developer

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

##### Share on other sites

I don't really have time to go through the code to figure out what it's doing, so for me to respond you'll have to explain the algorithm more clearly in words. I don't even know what you mean by "Create a surface of w,h,d,s."

##### Share on other sites

39 minutes ago, MJW said:

I don't really have time to go through the code to figure out what it's doing, so for me to respond you'll have to explain the algorithm more clearly in words. I don't even know what you mean by "Create a surface of w,h,d,s."

Create a surface just means create a surface of specified width,height,depth, and number of channels. In my case, it would be doing `int [,] Popcorn_Array;` and new int[w,h].

That being said, I would like to be able to do multithreaded for loop alongside of any width,height and increment value at x,y specified by formula within loop.

RIght now, my problem with my current Popcorn Fractal is that it uses serial processing:

The one on g'mic-qt uses parallel processing and increment pixel x,y along parallel operation.

G'MIC Filter Developer

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

##### Share on other sites

36 minutes ago, Reptillian said:

Create a surface just means create a surface

Jeez, I know what a surface is. I don't know what w,h,d,s are. More importantly, I don't know how they're used.

36 minutes ago, Reptillian said:

That being said, I would like to be able to do multithreaded for loop alongside of any width,height and increment value at x,y specified by formula within loop.

Without the details of what's being done, it's not possible to say if it can be done multithreaded. Some things can; some things can't. An algorithm that iteratively processes a surface, and uses the values in the surface cells to modify other cells in the same surface probably can't be done mutithreadeding.

Also, any iterative process probably can't take advantage of PDN's built-in multithreading, since each ROI is only processed once per frame.  Perhaps a plugin could initiate its own threads in the pre-render stage, though I shouldn't probably say that without thinking out the details, which I haven't done.

I suspect that unless you're willing to provide a clear explanation of what the algorithm does, you won't get a useful reply to your question.

##### Share on other sites

Ok, I'll try to clarify once more. In render for x, for y, each tiles are split and processed with different threads.

So basically:

1. Create a surface

2. Split tiles along multiple threads

3. While processing the tiles, it increment pixel fx,fy in another surface. fx,fy are found value in the new surface.

In theory, this means you might access the same pixel in another surface at the same time with different thread.

53 minutes ago, MJW said:

An algorithm that iteratively processes a surface, and uses the values in the surface cells to modify other cells in the same surface probably can't be done mutithreadeding.

That's exactly what I'm talking about, but with modifying cells in a different surface.

G'MIC Filter Developer

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

##### Share on other sites

If you want to do your own multithreading, specify RenderingSchedule = EffectRenderingSchedule.None when creating your EffectOptions in your constructor. Then your Render method will be called precisely 1 time and it will be given all of the ROIs (rectangle/region of interest).

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

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

## Join the conversation

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×