Illnab1024 Posted September 10, 2006 Share Posted September 10, 2006 I figure we need a place to put all of our small tidbits of code we use to simplify tasks. Here are some of my codelab scripts: Red channel: void Render(Surface dst, Surface src, Rectangle rect) { for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { ColorBgra color = src[x, y]; color.B = 0; color.G = 0; dst[x, y] = color; } } } Blue channel: void Render(Surface dst, Surface src, Rectangle rect) { for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { ColorBgra color = src[x, y]; color.R = 0; color.G = 0; dst[x, y] = color; } } } Green channel: void Render(Surface dst, Surface src, Rectangle rect) { for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { ColorBgra color = src[x, y]; color.B = 0; color.R = 0; dst[x, y] = color; } } } Invert alpha channel: void Render(Surface dst, Surface src, Rectangle rect) { for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { ColorBgra color = src[x, y]; color.A = (byte)(255-color.A); dst[x, y] = color; } } } Pixel value to alpha: void Render(Surface dst, Surface src, Rectangle rect) { for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { byte full = (byte)(255); ColorBgra c = src[x, y]; int luma = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11); c.A = (byte)(255-luma); dst[x, y] = c; } } } I have several others.. You are encouraged to post your scripts and constructively criticize others' scripts. P.S. put the channels in three layers (R, B, and G), stting each layer's mode to additive if you want to edit in channels... Sources EDITED for less stupidity... Quote ~~ Link to comment Share on other sites More sharing options...
Rick Brewster Posted September 10, 2006 Share Posted September 10, 2006 I must ask why you are declaring the "color" variable outside of the Render function ... that instantly makes it not thread safe. Just put it inside the Render function and you're good. 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...
Illnab1024 Posted September 10, 2006 Author Share Posted September 10, 2006 It didn't build right when I put it inside the function...I dunno why. I am very much a novice to C# EDIT: Now I see...you must define the variable, not just initialize it, for it to withhold in a function. Quote ~~ Link to comment Share on other sites More sharing options...
Rick Brewster Posted September 11, 2006 Share Posted September 11, 2006 Yes, that looks much better now 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...
BoltBait Posted September 11, 2006 Share Posted September 11, 2006 Is there a way in codelab to manipulate the HSV values of a pixel? Or, do you always have to use RGB? Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Rick Brewster Posted September 11, 2006 Share Posted September 11, 2006 Pixels do not contain HSV values. They are always stored as BGRA. You must convert to HSV, do manipulation in that form, and then convert back to BGRA. 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...
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.