hollander Posted August 16, 2007 Share Posted August 16, 2007 (english isnt my first language, so sorry if there are anny spelling errors.) I will explain how to make some simple effects using codelab. (if you are an expierenced codelab-user, you probably wont need this tutorial.) I will explain: invert colors, saturation,brightness and contrast to make a plugin using codelab you will need ...........Codelab so just a few notes first: to write a plugin you will need to understand c#, but just te basics really. (the basics of c++ will work fine aswell.) also you will need to understand the RGBA system now finnaly some coding, i will now explain the base structure of a plugin (it is the example you get when you press clear) int Amount1=0; //[0,100]Slider 1 Description int Amount2=0; //[0,100]Slider 2 Description int Amount3=0; //[0,100]Slider 3 Description //Int Amount 1,2 and 3 will be values you can adjust using sliders when //compiled. //here you can define variables you are going to use, for example: //int variable; //float pi=3.14; void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); //these codes are for getting some usefull variables, leave them //untouched, until compiling the script (they might be very handy for your script. Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left); long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top); ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor; ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; //here come the main code, if you dont change the structure, it will scan //every pixel and modify is using the code you entered; //in this example we change every pixel into the primary color CurrentPixel.R = (byte)PrimaryColor.R; CurrentPixel.G = (byte)PrimaryColor.G; CurrentPixel.B = (byte)PrimaryColor.B; CurrentPixel.A = (byte)PrimaryColor.A; dst[x,y] = CurrentPixel; } } } note that everything with // is a comment and wont be executed. now that you understand the base structure we will be using, I will explain the first effect: INVERT COLORS to invert colors you should first know what invert actually is. it is changing the R,G and B values to the "inverted" values. it means a 0 will become a 255 and a 255 will become a 0, a 1 will become a 254 and a 254 will become a 1. Or simple: color=255-color. (its that simple) so our code will be after a finishing touch: void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 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 = (byte)(int)(255-CurrentPixel.R); CurrentPixel.G = (byte)(int)(255-CurrentPixel.G); CurrentPixel.B = (byte)(int)(255-CurrentPixel.; //note that the alpha channel is not inverted. dst[x,y] = CurrentPixel; } } } next up: GRAYSCALE Grayscale is also an easy one, when a picture is grayscale, the R,G and B channel are exactly the same. in the following example I will user the integer values r,g,b and m. I use these values so I can multiply, divide and so on. (wich is not posible with byte values). r,g an b will represent the r,g and b channels. m will be the average of the r,g an b values. int r; int g; int b; int m; void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; r=CurrentPixel.R; g=CurrentPixel.G; b=CurrentPixel.B; m=(r+g+b)/3; CurrentPixel.R = (byte)(int)m; CurrentPixel.G = (byte)(int)m; CurrentPixel.B = (byte)(int)m; dst[x,y] = CurrentPixel; } } } next up: SATURNATION in normal words: how much "color" you image will have. if saturation is set to 100, nothing will change, if set to 0 the image will be grayscale, if set to 200, the image will be twice are colorful. note: if you want to see result without compiling right away, just change the valea of Amount1 in the first line int Amount1=100; //[0,100]Slider 1 Description int r; int g; int b; int m; void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; r=CurrentPixel.R; g=CurrentPixel.G; b=CurrentPixel.B; m=(r+g+b)/3; r-=m; g-=m; b-=m; r=m+r*(Amount1/100); g=m+g*(Amount1/100); b=m+b*(Amount1/100); //these codes are very important, if you dont use the you will get an ugly result: if (r>255){r=255;}if (r<0){r=0;} if (g>255){g=255;}if (g<0){g=0;} if (b>255){b=255;}if (b<0){b=0;} CurrentPixel.R = (byte)(int)r; CurrentPixel.G = (byte)(int)g; CurrentPixel.B = (byte)(int)b; dst[x,y] = CurrentPixel; } } } BRIGHTNESS very simple, the lower the rgb values are, the darker and image is, the higher, the lighter an image is: int Amount1=0; //[-255,255]Slider 1 Description int r; int g; int b; int m; void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; r=CurrentPixel.R; g=CurrentPixel.G; b=CurrentPixel.B; r+=Amount1; g+=Amount1; b+=Amount1; if (r>255){r=255;}if (r<0){r=0;} if (g>255){g=255;}if (g<0){g=0;} if (b>255){b=255;}if (b<0){b=0;} CurrentPixel.R = (byte)(int)r; CurrentPixel.G = (byte)(int)g; CurrentPixel.B = (byte)(int)b; dst[x,y] = CurrentPixel; } } } CONTRAST it simply is the diference between dark and light colors, if set to the minumum a picture will become grey, if set to the maximum a picture will become black and white int Amount1=100; //[0,1000]Slider 1 Description int r; int g; int b; int m; void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; r=CurrentPixel.R; g=CurrentPixel.G; b=CurrentPixel.B; m=(r+g+b)/3; r-=m; g-=m; b-=m; m-=128; m=m*(Amount1/100); m+=128; r+=m; g+=m; b+=m; if (r>255){r=255;}if (r<0){r=0;} if (g>255){g=255;}if (g<0){g=0;} if (b>255){b=255;}if (b<0){b=0;} CurrentPixel.R = (byte)(int)r; CurrentPixel.G = (byte)(int)g; CurrentPixel.B = (byte)(int)b; dst[x,y] = CurrentPixel; } } } MY VERSION OF CONTRAST (it uses contrast on each channel seperately) int Amount1=100; //[0,1000]Slider 1 Description int r; int g; int b; int m; void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; r=CurrentPixel.R; g=CurrentPixel.G; b=CurrentPixel.B; r-=128; r=r*(Amount1/100); r+=128; g-=128; g=g*(Amount1/100); g+=128; b-=128; b=b*(Amount1/100); b+=128; if (r>255){r=255;}if (r<0){r=0;} if (g>255){g=255;}if (g<0){g=0;} if (b>255){b=255;}if (b<0){b=0;} CurrentPixel.R = (byte)(int)r; CurrentPixel.G = (byte)(int)g; CurrentPixel.B = (byte)(int)b; dst[x,y] = CurrentPixel; } } } I hope this will heb beginning codelabbers. (I tested all scripts, they all work.) Quote Link to comment Share on other sites More sharing options...
drakaan Posted August 16, 2007 Share Posted August 16, 2007 Hey, boltbait (and Rick), isn't the: ...selectionRegion.IsVisible(x, y)... stuff supposed to be unnecessary? I've seen a bit of back-n-forth on that point, but don't think I ever saw a definitive answer. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted August 16, 2007 Share Posted August 16, 2007 Correct. That code unnecessarily drags down the performance. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
hollander Posted August 16, 2007 Author Share Posted August 16, 2007 Hey, boltbait (and Rick), isn't the: ...selectionRegion.IsVisible(x, y)... stuff supposed to be unnecessary? I've seen a bit of back-n-forth on that point, but don't think I ever saw a definitive answer. I already removed that part from all the scripts now Quote Link to comment Share on other sites More sharing options...
Paint_boy Posted August 16, 2007 Share Posted August 16, 2007 Very very nice. I never understood what to do with code lab before. I'll try this thanks Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 16, 2007 Share Posted August 16, 2007 Yeah, I removed it from the default script. You'll see that in the next release. By the way, in your script examples, it would be helpful to change "Slider 1 Description" to the actual text you would want to see on the slider when the DLL is built. Here are some other tutorials on how to use codelab: - http://paintdotnet.12.forumer.com/viewtopic.php?t=5281 - http://paintdotnet.12.forumer.com/viewtopic.php?t=5308 Your post makes a good follow up to the two I wrote. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Computer Dominos Game Link to comment Share on other sites More sharing options...
Scyphrex Posted August 21, 2007 Share Posted August 21, 2007 Wow I need to try this because I dont code but a little html. I must try this. Quote My Sitehttp://z4.invisionfree.com/blackskydesigns Link to comment Share on other sites More sharing options...
DeathStar Posted August 4, 2009 Share Posted August 4, 2009 I'm going to combine these together! It will make a nice effect I think. Quote Death is one thing, Stars are another. BUT If you put them together, they become more powerfull than ever befor! Link to comment Share on other sites More sharing options...
leonbloy Posted May 6, 2011 Share Posted May 6, 2011 Here are some other tutorials on how to use codelab: - http://paintdotnet.1...opic.php?t=5281 - http://paintdotnet.1...opic.php?t=5308 Broken links Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.