Jump to content
How to Install Plugins ×

CodeLab v6.12 for Paint.NET 5.0.12 (Updated February 11, 2024)


Rick Brewster

Recommended Posts

I am starting to try to learn how to use codelab at the moment, and find one thing fairly annoying.

I get error on line 13. I click the error message and somehow it takes me to line 2 or whatever. I assume that this is just a numerical glitch of some sort. But I also have an error on line 133 and I don't have that many lines, and when I click it doesn't take me anywhere.

I am really just starting so, can't comment on the wonderfulness of codelab.

Sage

When in doubt, Try it out.

greenandfire.png

I made this sig file using http://www.anim8or.com and making all of the textures with http://www.getpaint.net

I love freeware.

Link to comment
Share on other sites

The reason is this...

There is much more script than meets the eye.

Basically, to compile what you write (only the Render function) it needs to be surrounded with lots of extra code. But, there is no reason to show you that code--that's my responsibility.

But, when the compiler returns error messages during a compile, it takes those lines into account. Therefore your code starts on line 13 (or so, based on your options).

Link to comment
Share on other sites

Like I said, I am way newbie, so it might be difficult for me to understand it, but let's see if I have it right.

What you are saying is that Codelab is technically a "Hack", in that, there is already a set amount of code (before, and or after whatever I type in), that will Always be compiled to the finished DLL. And that the debug actually takes these into account.

I have a very basic knowledge of C and C++, and a very little bit of Assembly (don't ask why, it was just a natural progression with my 3d stuff).

Are there header files that already exist within codelab for dll compiling usage? Is this information posted somewhere so that this newbie doesn't have to bug you and take up all of your time.

Thanks

You're very helpful.

Sage

When in doubt, Try it out.

greenandfire.png

I made this sig file using http://www.anim8or.com and making all of the textures with http://www.getpaint.net

I love freeware.

Link to comment
Share on other sites

Well... the code does not exist in a separate file, but you can go to my site: http://boltbait.googlepages.com/codelab and download the VS2005 source code to CodeLab. You can look through it and find the code. It is located in several constant strings that get prepended and appended to your code before it is sent on to the compiler.

To get an idea of what a full project looks like, look at the source posted here: http://paintdotnet.12.forumer.com/viewtopic.php?t=4085 This is my Ink Sketch effect. It is not a CodeLab script, so you can look at it and see what the differences are...

Let me know if I can answer any more questions.

Link to comment
Share on other sites

Prompt, please, what commands in CodeLab correspond to functions GetHue () and GetSaturation () C#. It would be desirable to learn also, whether there is a list of functions CodeLab and corresponding it of functions C#

Link to comment
Share on other sites

True: CodeLab == C#

If a function exists in C# it exists in CodeLab. Unfortunatly, the functions you are looking for do not exist in C#.

I'm not sure about saturation, however, you can access the HSV of a color by using the following function:

public void EvanRGBtoHSV(int R, int G, int B, ref double outH, ref double outS, ref double outV)
{
   const double HSV_UNDEFINED = -999.0;
   // R, G, and B must range from 0 to 255
   // Ouput value ranges:
   //  outH - 0.0 to 360.0
   //  outS - 0.0 to 1.0
   //  outV - 0.0 to 1.0

   double dR = (double)R / 255.0;
   double dG = (double)G / 255.0;
   double dB = (double)B / 255.0;
   double dmaxRGB = EvanMax3(dR, dG, dB);
   double dminRGB = EvanMin3(dR, dG, dB);
   double delta = dmaxRGB - dminRGB;

   // Set value
   outV = dmaxRGB;

   // Handle special case
   if (dmaxRGB == 0)
   {
       outH = HSV_UNDEFINED;
       outS = 0.0;
       return;
   }

   outS = delta / dmaxRGB;
   if (dmaxRGB == dminRGB)
   {
       outH = HSV_UNDEFINED;
       return;
   }

   // Finally, compute hue
   if (dR == dmaxRGB)
   {
       outH = (dG - dB) / delta * 60.0;
   }
   else if (dG == dmaxRGB)
   {
       outH = (2.0 + (dB - dR) / delta) * 60.0;
   }
   else //if (dB == dmaxRGB)
   {
       outH = (4.0 + (dR - dG) / delta) * 60.0;
   }

   if (outH     {
       outH += 360.0;
   }
}

public void EvanHSVtoRGB(double H, double S, double V, ref byte bR, ref byte bG, ref byte bB)
{
   const double HSV_UNDEFINED = -999.0;
   // Parameters must satisfy the following ranges:
   // 0.0     // 0.0     // 0.0 
   // Handle special case first
   if (S == 0.0 || H == HSV_UNDEFINED)
   {
       byte x = (byte)(int)(V * 255.0);
       bR = x;
       bG = x;
       bB = x;
       return;
   }

   if (H >= 360.0)
   {
       H = AngleConstrain(H);
   }

   double R = V, G = V, B = V;
   double Hi = Math.Floor(H / 60.0);
   double f = H / 60.0 - Hi;
   double p = V * (1.0 - S);
   double q = V * (1.0 - f * S);
   double t = V * (1.0 - (1.0 - f) * S);
   if (Hi == 0.0)
   {
       R = V;
       G = t;
       B = p;
   }
   else if (Hi == 1.0)
   {
       R = q;
       G = V;
       B = p;
   }
   else if (Hi == 2.0)
   {
       R = p;
       G = V;
       B = t;
   }
   else if (Hi == 3.0)
   {
       R = p;
       G = q;
       B = V;
   }
   else if (Hi == 4.0)
   {
       R = t;
       G = p;
       B = V;
   }
   else if (Hi == 5.0)
   {
       R = V;
       G = p;
       B = q;
   }

   int iR = (int)(R * 255.0);
   int iG = (int)(G * 255.0);
   int iB = (int)(B * 255.0);
   bR = (byte)iR;
   bG = (byte)iG;
   bB = (byte)iB;
}


public double EvanMax3(double x, double y, double z)
{
   return (x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z);
}
public double EvanMin3(double x, double y, double z)
{
   return (x }

public double AngleConstrain(double MyAngle)
{
   // Makes sure that 0.0     // "Wraps around" the value if it's outside this range
   if (MyAngle >= 360.0)
   {
       MyAngle -= Math.Floor(MyAngle / 360.0) * 360.0;
   }
   if (MyAngle     {
       MyAngle += 360.0;
   }
   return MyAngle;
}

Link to comment
Share on other sites

Looking around PdnLib (Or PaintDotNet.Core...), I found two nice little classes used mainly in the Colors form.

CurrentPixel = src[x,y];
CurrentPx = CurrentPixel.ToColor();
HsvColor hsv = HsvColor.FromColor(CurrentPx);
Px2 = hsv.ToColor();
Pixel2 = ColorBgra.FromColor(Px2);
dst[x,y] = Pixel2;

There's a demo of the functions you need, and they seem to work with the Effects API.

~~

Link to comment
Share on other sites

Thanks big for answers. It seems to me, that CodeLab it is not absolutely identical C#. How much I have understood, in it functions Paint. Net can be used only and cannot be used direct functions C#. For example, in C# is function of reception of brightness of point GetBrightness (), but in CodeLab instead of it it is necessary to use фукцию GetIntensity () which is in Paint. Net. Very much it is pleasant to me Paint. Net and CodeLab, it is very convenient to debug with their help algorithms of image processing.

I would like to seize all power of these tools. In this connection I would like to receive from experienced users advice on their effective utilization. How much I have understood, for an effective utilization of these tools I should:

1. It is good to think over algorithm of processing.

2. In initial codes Paint. Net to find functions for realization of my algorithm, to analyse them.

3. To write a script for CodeNet, to correct mistakes, to modify a script for increase of efficiency of processing.

Whether so it or I am mistaken and it is possible direct to use functions C#?

Besides would like to ask following questions and to state offers on CodeLab:

1. After editing a line of a script its performance at once begins. However frequently it is necessary to bring some lines of changes. Whether it is possible to make so that performance of a script occured only by button OK, but thus window CodeLab was not closed, and closing CodeLab would occur only by button Cancel?

2. After entering the necessary changes often you forget to keep a script. Whether it is possible to make a window of the prevention of necessity of preservation of a script?

3. Whether it is possible to make so that after closing Paint. Net in CodeLab last edited script, instead of a pattern of a script was loaded?

4. After application of algorithm by the initial image it is considered already processed image. In case of need debuggings of algorithm on the same image should be closed many times CodeLab and then to cause its and necessary script. Whether it is possible to make so that in window CodeLab it would be possible to establish a tag " To use this image as initial " that in the further processing only this image was conducted?

I wish to thank once again founders Paint. Net and CodeLab for huge work on creation of these remarkable appendices with the open codes.

These appendices are for me very necessary source of knowledge both on programming in C#, and on image processing.

Link to comment
Share on other sites

First let me point out that Code Lab is a great tool. I've done some experiments and some things just did not work the way I expected. Have a look at this:

void Render(Surface dst, Surface src, Rectangle rect)
{
   byte t = (byte)rect.Top;

   ColorBgra CurrentPixel;

   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           CurrentPixel = src[x,y];
           CurrentPixel.R = t;
           CurrentPixel.G = t;
           CurrentPixel.B = t;
           dst[x,y] = CurrentPixel;
       }
   }
}

It's a pretty useless example, but the expected output would be, that all pixels are filled with the same color, depending on the position of 'rect'. What it does is, it fills the image with a gradient.

Any suggestions?

Link to comment
Share on other sites

This is because the render function gets called lots (hundreds) of times by paint.net. What happens is, paint.net breaks up your selection into smaller work units and calls the render function with only a small part of your selection. This spreads the work up among your various processors and causes it to finish faster.

IOW: rect is the rectagnle of interest which is a subset of your entire selection.

I hope this makes sense.

Link to comment
Share on other sites

This is a new codelab to render Newton's Fractal.

//Code transliterated from p.94 of "Graphics Programming with Java"

//by Roger T. Stevens (originaly made for PS, found on http://www.filtermeister.com).

I didn't create a new topic for that, to let everyone play with the codelab and the parameters...

BTW could we create a 'codorium' a topic on which we could post our codelabs?

No picture. You'll have to run it to see the result!

int Amount1=100;  //[1,9999]ZOOM
int Amount2=0;     //[-999,999]PAN
int Amount3=255;     //[0,255]COLORS

void Render(Surface dst, Surface src, Rectangle rect)
{
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

   double kAmount1 = (double)Amount1 / 100.0;
   long X = (long)(selection.Right - selection.Left);
   long Y = (long)(selection.Bottom - selection.Top);
   int i0=0;  
   ColorBgra CurrentPixel;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           if (selectionRegion.IsVisible(x, y))
           {
               CurrentPixel = src[x,y];
               int R = CurrentPixel.R;
               int G = CurrentPixel.G;
               int B = CurrentPixel.B;

   //Code transliterated from p.94 of "Graphics Programming with Java"
   //by Roger T. Stevens.

   double x1 = (x - X/2)*100.0/(kAmount1*X) + Amount2/100.0;
   double y1 = (y - Y/2)*100.0/(kAmount1*Y) - Amount2/100.0;

   for (i0 = 0; i0 < X; ++i0) {
       double x2 = x1*x1;
       double x3 = x2*x1;
       double x4 = x3*x1;
       double x5 = x4*x1;
       double x6 = x5*x1;
       double x7 = x6*x1;
       double x8 = x7*x1;
       double y2 = y1*y1;
       double y3 = y2*y1;
       double y4 = y3*y1;
       double y5 = y4*y1;
       double y6 = y5*y1;
       double y7 = y6*y1;
       double y8 = y7*y1;
       double z9 = x2 + y2;
       z9 = z9*z9;
       z9 = z9*z9;
       z9 = z9*z9*9.0;
       // a lot of param to play with !
       double y0 = 0.88888888*y1 - (8.0*x7*y1 -
                            56.0*x5*y3 +
                            56.0*x3*y5 -
                             8.0*x1*y7)/z9;
       double x0 = 0.88888888*x1 + (    x8 -
                            28.0*x6*y2 +
                            70.0*x4*y4 -
                            28.0*x2*y6 +
                                 y8)/z9;
       if (Math.Abs(x0 - x1) < 1e-10 &&
           Math.Abs(y0 - y1) < 1e-10 ) break;
       x1 = x0;
       y1 = y0;
   }
   CurrentPixel = Func(Math.Sqrt(x * x + y * y),i0 );
   dst[x,y] = CurrentPixel;
           }
       }
   }
}
ColorBgra Func(double r, double t)
{
   r /= 100;
   return ColorBgra.FromBgr(
       Utility.ClampToByte(
           Amount3 + Amount3 * Math.Sin(r + t)),
       Utility.ClampToByte(
           Amount3 + Amount3 * Math.Sin(Math.PI/2 + r + t)),
       Utility.ClampToByte(
           Amount3 + Amount3 * Math.Sin(Math.PI + r + t)));

}

Link to comment
Share on other sites

  • 1 month later...

Ok so I downloaded the .zip file and tried opening it. It says I need to pick a program to run it with and I choose Paint.net, but it keeps saying it doesn't recognize the file and can't open it.

please help

Link to comment
Share on other sites

Paint.NET can not open zip files...

That sounds like a great plugin request! BB, want to write this one? :wink:

 

Take responsibility for your own intelligence. 😉 -Rick Brewster

Link to comment
Share on other sites

Paint.NET can not open zip files. Try WinZip.

Forgive me, I meant a dll file or whatever it is. I did all the steps in the installing a plugin thread also, and I get the same results :(

Link to comment
Share on other sites

Paint.NET can not open zip files. Try WinZip.

Forgive me, I meant a dll file or whatever it is. I did all the steps in the installing a plugin thread also, and I get the same results :(

Just follow the instructions on this page: http://boltbait.googlepages.com/install

Paint.NET can not open zip files...

That sounds like a great plugin request! BB, want to write this one? :wink:

Hmmm... that gives me an interesting idea...

I wonder if a file type plugin could be written that would "open" a dll file by copying it to the effects folder.

This would allow someone to right-click on an effects dll and choose "open with Paint.net" to install the effect.

Link to comment
Share on other sites

I don't see any reason that wouldn't be possible. You could even add zip support so it automatically extracts from zip files too. But don't you still have your text plugin to work on?

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

One question, though. Since, at present, Paint.NET must be restarted before newly installed plugins are ready to use, would that mean the user would have to right-click -> Open with Paint.NET, wait for Paint.NET to open, watch it copy the files, then have to close PDN and reopen it for the new plugin to be there?

Unless there's some magic you know about that will allow a file open hook to initiate before the Plugins list is parsed...

Or you could just wait for what Rick was suggesting... *trails off*

I am not a mechanism, I am part of the resistance;

I am an organism, an animal, a creature, I am a beast.

~ Becoming the Archetype

Link to comment
Share on other sites

Yes you'd have to restart it right away, unless the "plugin installer plugin" could restart paint.net on its own... i dont know enough about the filetype api to know if that's possible.

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

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