Enormator Posted June 3, 2007 Author Share Posted June 3, 2007 there are two problems with the lense flare thing: 1. I can't draw lines from up to down because... I don't know why I can't! These lines should be only one from the top to the point where they end and at their end they shouldn't begin again with white but stay black! I have used alpha to grayscale on it to make it better viewable. 2. This is amazingly slow in rendering and I have no idea why. void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); // Create a random number to initiate the reseed value int reseed = 0; Random randinit = new Random(); if (reseed == 0) reseed = randinit.Next((int)(rect.Bottom * rect.Right + 1)); // rand = Random number generator Random rand = new Random(reseed); // Delete any of these lines you don't need 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 x = rect.Left; x < rect.Right; x++) { int lenght = rand.Next(selection.Bottom - selection.Top -1) + 1; for (int y = selection.Top; y < selection.Bottom; y++) { if ((selectionRegion.IsVisible(x, y)) && (y<=lenght)) { if ((y <= lenght) && (y == 0 || (src[x,y - 1].A != 0))) { CurrentPixel = src[x,y]; // TODO: Add pixel processing code here // Access RGBA values this way, for example: CurrentPixel.R = 255; CurrentPixel.G = 255; CurrentPixel.B = 255; CurrentPixel.A = (byte)(255*(lenght-y)/lenght); dst[x,y] = CurrentPixel; } } } } } Any ideas? :Link: website Link to comment Share on other sites More sharing options...
MadJik Posted June 3, 2007 Share Posted June 3, 2007 Some answers here... http://paintdotnet.12.forumer.com/viewtopic.php?t=4996 ...the normal way for the renderer is 'for y...for x...' meaning it works per lines and can't work per columns. Your code Horizontaly: void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); // Create a random number to initiate the reseed value int reseed = 0; Random randinit = new Random(); if (reseed == 0) reseed = randinit.Next((int)(rect.Bottom * rect.Right + 1)); // rand = Random number generator Random rand = new Random(reseed); ColorBgra CurrentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { int lenght = rand.Next(Math.Abs(selection.Left - selection.Right - 1)) + 1; for(int x = rect.Left; x < rect.Right; x++) { if ((selectionRegion.IsVisible(x, y)) && (x<=lenght)) { int xa = x -1; if (xa < rect.Left) xa=x; if ((x <= lenght) && (x == 0 || (src[x - 1,y].A != 0))) { CurrentPixel = src[x,y]; // TODO: Add pixel processing code here // Access RGBA values this way, for example: CurrentPixel.R = 255; CurrentPixel.G = 255; CurrentPixel.B = 255; CurrentPixel.A = (byte)(255*(lenght-x)/lenght); dst[x,y] = CurrentPixel; } } } } } My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
MadJik Posted June 3, 2007 Share Posted June 3, 2007 Some answers here... http://paintdotnet.12.forumer.com/viewtopic.php?t=4996 ...the normal way for the renderer is 'for y...for x...' meaning it works per lines and can't work per columns. Your code Horizontaly: void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); // Create a random number to initiate the reseed value int reseed = 0; Random randinit = new Random(); if (reseed == 0) reseed = randinit.Next((int)(rect.Bottom * rect.Right + 1)); // rand = Random number generator Random rand = new Random(reseed); ColorBgra CurrentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { int lenght = rand.Next(Math.Abs(selection.Left - selection.Right - 1)) + 1; for(int x = rect.Left; x < rect.Right; x++) { if ((selectionRegion.IsVisible(x, y)) && (x<=lenght)) { int xa = x -1; if (xa < rect.Left) xa=x; if ((x <= lenght) && (x == 0 || (src[x - 1,y].A != 0))) { CurrentPixel = src[x,y]; // TODO: Add pixel processing code here // Access RGBA values this way, for example: CurrentPixel.R = 255; CurrentPixel.G = 255; CurrentPixel.B = 255; CurrentPixel.A = (byte)(255*(lenght-x)/lenght); dst[x,y] = CurrentPixel; } } } } } My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
pyrochild Posted June 3, 2007 Share Posted June 3, 2007 (Madjik, yours works, but mine works better! JK, JK, Don't hit me...) Is this what you're looking for? (Note that I put a BLACK layer under it to properly illustrate...) //Removed ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 3, 2007 Share Posted June 3, 2007 (Madjik, yours works, but mine works better! JK, JK, Don't hit me...) Is this what you're looking for? (Note that I put a BLACK layer under it to properly illustrate...) //Removed ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Enormator Posted June 4, 2007 Author Share Posted June 4, 2007 thank you pyrochild. That (your picture) was exactly what I was looking for. But when I do your lines of code with my codelab, it gets ugly and draws again several lines after the first one. I'll check my version of Codelab and PdN. :Link: website Link to comment Share on other sites More sharing options...
Enormator Posted June 4, 2007 Author Share Posted June 4, 2007 thank you pyrochild. That (your picture) was exactly what I was looking for. But when I do your lines of code with my codelab, it gets ugly and draws again several lines after the first one. I'll check my version of Codelab and PdN. :Link: website Link to comment Share on other sites More sharing options...
pyrochild Posted June 4, 2007 Share Posted June 4, 2007 try this: //Removed I noticed that my earlier version didn't "play nice" with layers that already had transparency on them, but now it should work no matter what is already on the layer you run the effect on. I also simplified some of the code.[/code] ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 4, 2007 Share Posted June 4, 2007 try this: //Removed I noticed that my earlier version didn't "play nice" with layers that already had transparency on them, but now it should work no matter what is already on the layer you run the effect on. I also simplified some of the code.[/code] ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Rick Brewster Posted June 4, 2007 Share Posted June 4, 2007 Well for one thing, like I've said a hundred times before, you don't need the following line of code. if (selectionRegion.IsVisible(x, y)) Remove that will help performance. 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...
Rick Brewster Posted June 4, 2007 Share Posted June 4, 2007 Well for one thing, like I've said a hundred times before, you don't need the following line of code. if (selectionRegion.IsVisible(x, y)) Remove that will help performance. 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...
pyrochild Posted June 4, 2007 Share Posted June 4, 2007 Well the main problem that was causing the performance to be sooooo slow in Enormator's code was that he was using for (int y = selection.Top; y instead of [code]for (int y = rect.Top; y essentially causing each and every call to Render() to process the [i]entire[/i] image instead of just the region that was passed by the rect argument. ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 4, 2007 Share Posted June 4, 2007 Well the main problem that was causing the performance to be sooooo slow in Enormator's code was that he was using for (int y = selection.Top; y instead of [code]for (int y = rect.Top; y essentially causing each and every call to Render() to process the [i]entire[/i] image instead of just the region that was passed by the rect argument. ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
surgency Posted June 4, 2007 Share Posted June 4, 2007 AWESOME! ill use the random one all the time EDIT: bleh, i only thought that from the description. i would use it a lot if you made an option to change the size of the dots or the dots would be as big as your brush size Link to comment Share on other sites More sharing options...
surgency Posted June 4, 2007 Share Posted June 4, 2007 AWESOME! ill use the random one all the time EDIT: bleh, i only thought that from the description. i would use it a lot if you made an option to change the size of the dots or the dots would be as big as your brush size Link to comment Share on other sites More sharing options...
pyrochild Posted June 5, 2007 Share Posted June 5, 2007 Improved performance based on Rick's input: //Removed ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 5, 2007 Share Posted June 5, 2007 Improved performance based on Rick's input: //Removed ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Enormator Posted June 5, 2007 Author Share Posted June 5, 2007 bleh, i only thought that from the description. i would use it a lot if you made an option to change the size of the dots or the dots would be as big as your brush size Is there a way to easiliy draw a rectangle or do I have to use for x... for y...? (That would be annoying to prog and probably slow in rendering) :Link: website Link to comment Share on other sites More sharing options...
Enormator Posted June 5, 2007 Author Share Posted June 5, 2007 bleh, i only thought that from the description. i would use it a lot if you made an option to change the size of the dots or the dots would be as big as your brush size Is there a way to easiliy draw a rectangle or do I have to use for x... for y...? (That would be annoying to prog and probably slow in rendering) :Link: website Link to comment Share on other sites More sharing options...
pyrochild Posted June 5, 2007 Share Posted June 5, 2007 This will draw a rectangle around the selection using your brushwidth... void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = selectionRegion.GetBoundsInt(); ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; Graphics g = new RenderArgs(dst).Graphics; Pen p = new Pen(PrimaryColor.ToColor(),(float)BrushWidth); g.DrawRectangle(p, selection); } ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 5, 2007 Share Posted June 5, 2007 This will draw a rectangle around the selection using your brushwidth... void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = selectionRegion.GetBoundsInt(); ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; Graphics g = new RenderArgs(dst).Graphics; Pen p = new Pen(PrimaryColor.ToColor(),(float)BrushWidth); g.DrawRectangle(p, selection); } ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 6, 2007 Share Posted June 6, 2007 OK, In your earlier post you said that the bars were still repeating even with the version that I posted last, and that was because of a bug that I found and removed. This version is also just a teensy bit faster. void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = selectionRegion.GetBoundsInt(); Random rand = new Random(0); ColorBgra CurrentPixel; for(int x = rect.Left; x { int length = rand.Next(selection.Bottom - selection.Top -1) + 1; for (int y = rect.Top; y { CurrentPixel = ColorBgra.White; CurrentPixel.A = Utility.ClampToByte(255 * (length - y) / length); dst[x,y] = CurrentPixel; } } } Gives: ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
pyrochild Posted June 6, 2007 Share Posted June 6, 2007 OK, In your earlier post you said that the bars were still repeating even with the version that I posted last, and that was because of a bug that I found and removed. This version is also just a teensy bit faster. void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = selectionRegion.GetBoundsInt(); Random rand = new Random(0); ColorBgra CurrentPixel; for(int x = rect.Left; x { int length = rand.Next(selection.Bottom - selection.Top -1) + 1; for (int y = rect.Top; y { CurrentPixel = ColorBgra.White; CurrentPixel.A = Utility.ClampToByte(255 * (length - y) / length); dst[x,y] = CurrentPixel; } } } Gives: ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Crazy Man Dan Posted June 6, 2007 Share Posted June 6, 2007 Now that's an awesome effect! I played around a little with CodeLab, and after a bit of figuring, I was able to change it to take a Length parameter from a single slider and use the Primary Color for the cascade effect. It's probably sloppy, but it works, and it doesn't crash. 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 More sharing options...
Crazy Man Dan Posted June 6, 2007 Share Posted June 6, 2007 Now that's an awesome effect! I played around a little with CodeLab, and after a bit of figuring, I was able to change it to take a Length parameter from a single slider and use the Primary Color for the cascade effect. It's probably sloppy, but it works, and it doesn't crash. 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 More sharing options...
Recommended Posts