Whiterock Posted January 9, 2011 Share Posted January 9, 2011 Hello community, I've just tried to make a simple box blur effect in pdn. My code is: #region UICode #endregion void Render(Surface dst, Surface src, Rectangle rect) { // Delete any of these lines you don't need Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); int CenterX = ((selection.Right - selection.Left) / 2)+selection.Left; int CenterY = ((selection.Bottom - selection.Top) / 2)+selection.Top; ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor; ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; ColorBgra CurrentPixel; ColorBgra LeftPixel; ColorBgra RightPixel; ColorBgra AbovePixel; ColorBgra BelowPixel; for (int y = rect.Top + 1; y < rect.Bottom - 1; y++) { for (int x = rect.Left + 1; x < rect.Right - 1; x++) { CurrentPixel = src[x,y]; LeftPixel = src[x-1,y]; AbovePixel = src[x,y-1]; BelowPixel = src[x,y+1]; RightPixel = src[x+1,y]; CurrentPixel.R = (byte)((LeftPixel.R+AbovePixel.R+BelowPixel.R+RightPixel.R)/4); CurrentPixel.G = (byte)((LeftPixel.G+AbovePixel.G+BelowPixel.G+RightPixel.G)/4); CurrentPixel.B = (byte)((LeftPixel.B+AbovePixel.B+BelowPixel.B+RightPixel.B)/4); CurrentPixel.A = (byte)((LeftPixel.A+AbovePixel.A+BelowPixel.A+RightPixel.A)/4); dst[x,y] = CurrentPixel; } } } But i don't know the reason, why it doesn't work correctly. It's so strange, because it's just working every 2y-coords. I hope someone or BoltBait can help me:roll: MfG whiterock p.s: I'm from Austria Quote Link to comment Share on other sites More sharing options...
Cookies Posted January 9, 2011 Share Posted January 9, 2011 (edited) for (int y = rect.Top + 1; y < rect.Bottom - 1; y++) { for (int x = rect.Left + 1; x < rect.Right - 1; x++) { should be for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { Edited January 9, 2011 by Cookies Quote Link to comment Share on other sites More sharing options...
Tanel Posted January 9, 2011 Share Posted January 9, 2011 Render rect's coordinates don't always match those of canvas. Thererefore y loop starting at y = rect.Top + 1 will cause unpredictable results. You could work around though, by using coordinates from Rectangle selection : for (int y = selection.Top + 1; y < selection.Bottom - 1; y++) Someone will sure present a better solution. Quote Link to comment Share on other sites More sharing options...
Whiterock Posted January 9, 2011 Author Share Posted January 9, 2011 Ok, lets see: Why can do a "+1" say the program, that it it should calucate each second y-coord/x coord ? (strange) I will try it and infomate (? does this word exist) you if its working or not;) MfG Whiterock ("MfG" menas in Austria, something like "With friendly Greetings") Quote Link to comment Share on other sites More sharing options...
Cookies Posted January 11, 2011 Share Posted January 11, 2011 (edited) Render rect's coordinates don't always match those of canvas. Thererefore y loop starting at y = rect.Top + 1 will cause unpredictable results. You could work around though, by using coordinates from Rectangle selection : for (int y = selection.Top + 1; y < selection.Bottom - 1; y++) Someone will sure present a better solution. I wouldn't do that, if its in an irregular selection (round, shaped) it will do it outside the selection that way Ok, lets see: Why can do a "+1" say the program, that it it should calucate each second y-coord/x coord ? (strange) I will try it and infomate (? does this word exist) you if its working or not;) MfG Whiterock ("MfG" menas in Austria, something like "With friendly Greetings") read this: http://www.boltbait....lp/tutorial.asp it explains it edit: I guess your trying to avoid going "outside" the image, if so use src.GetBilinearSampleClamped(x, y); Edited January 11, 2011 by Cookies Quote Link to comment Share on other sites More sharing options...
skyoxZ Posted January 11, 2011 Share Posted January 11, 2011 src[x+0,y+0] should also be in the Box. Quote Link to comment Share on other sites More sharing options...
Whiterock Posted January 28, 2011 Author Share Posted January 28, 2011 src.GetBilinearSampleClamped(x, y); How can i use ist? Quote Link to comment Share on other sites More sharing options...
Cookies Posted January 29, 2011 Share Posted January 29, 2011 like this CurrentPixel = src.GetBilinearSampleClamped(x, y); 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.