Jump to content

Using complex number mathematics in Paint.Net plugins


PJayTycy

Recommended Posts

Hello,

for a plug-in I'm trying to write, I would like to be able to use complex numbers. I have a rudimentary version, where I changed all mathematics to work on a set of 2 doubles (either {real, imag} or {radius, theta}). I used 2 custom functions : PolarToRect() and RectToPolar(), to change between [real, imag] and [radius, theta] information.

However, as complex numbers are so common, and some complex number libraries exist for C#, I was wondering if Paint.NET already includes one of those libraries or has some functions to work with complex numbers from itself.

Thanks,

PJay

Link to comment
Share on other sites

Thanks for your answer.

I tried to use MathNet Iridium as library and do some testing in Codelabs, but I cannot put "using" statements in CodeLabs.

I could copy/paste the complex number class into my CodeLabs script for prototyping, but will I be able to use the compiled dll of an external library if I create a "real" plugin from it ? Or are there plans for CodeLabs to allow us to use external libraries ?

Thanks,

PJay

Link to comment
Share on other sites

Thanks for your answer.

I tried to use MathNet Iridium as library and do some testing in Codelabs, but I cannot put "using" statements in CodeLabs.

I could copy/paste the complex number class into my CodeLabs script for prototyping, but will I be able to use the compiled dll of an external library if I create a "real" plugin from it ? Or are there plans for CodeLabs to allow us to use external libraries ?

Thanks,

PJay

CodeLab automatically uses the refrences which you would need to build a plug-in, the ones which come with PDN itself. Adding an ability to allow your own choice of resources would make it more complicated than needed, and if you want to make a complex plug-in, I would seriously have to turn you towards Visual Stduio C# Express Edition 2008.

Link to comment
Share on other sites

Thanks for your answers.

I can succesfully compile and use my plugin with the external library when using Visual Studio. So, using an external library makes me lose the rapid prototyping in CodeLabs, but it is possible.

After I've debugged my plugin, I'll post the results here. For now, let's just say I'm trying to do advanced versions of this.

Link to comment
Share on other sites

Also, instead of using your own AddColor() method, I recommend making use of PaintDotNet.Data.UserBlendOps.AdditiveBlendOp:

UserBlendOp addOp = new AdditiveBlendOp();
result = addOp.Apply(lhs, rhs); // result = lhs + rhs

It will do all the work of ensuring the alpha channel is handled correctly (which is trickier than you may think).

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

Also, instead of using your own AddColor() method, I recommend making use of PaintDotNet.Data.UserBlendOps.AdditiveBlendOp:

UserBlendOp addOp = new AdditiveBlendOp();
result = addOp.Apply(lhs, rhs); // result = lhs + rhs

It will do all the work of ensuring the alpha channel is handled correctly (which is trickier than you may think).

Is this AdditiveBlendOp also asymetrical ? My addColor function will give the first color full priority over the second color (ie: only add a little bit of the second color if they both have only a little bit of transparency)

(0, 0, 0, 200) + (255, 255, 255, 200) => (55, 55, 55, 255)

(255, 255, 255, 200) + (0, 0, 0, 200) => (200, 200, 200, 255)

I thought the normal Paint.Net functions would give (127, 127, 127, 255) in both cases.

Link to comment
Share on other sites

AdditiveBlendOp implements the OVER operation with addition. It's as if 'rhs' is blended "on top of" lhs. If rhs is fully opaque, the result will be rhs regardless of what lhs is. I can almost guarantee you that this is what you want -- it's what Paint.NET uses for its layer composition when you choose the Additive blend mode.

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

AdditiveBlendOp implements the OVER operation with addition. It's as if 'rhs' is blended "on top of" lhs. If rhs is fully opaque, the result will be rhs regardless of what lhs is. I can almost guarantee you that this is what you want -- it's what Paint.NET uses for its layer composition when you choose the Additive blend mode.

As I can not see in the source code what it does, I tested the layer composition. It is not exactly what I want.

What it does:

black@50% + white@50% => 2/3 white@75%

So, the lhs is only counted for 25% (rhs_remaining_alpha*lhs_alpha).

I want it to be counted for 50% (minimum(rhs_remaining_alpha,lhs_alpha)) and have the result be 1/2 white@100%.

Maybe one of the other blends works like that ?

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.

×
×
  • Create New...