Tanel Posted April 29, 2010 Share Posted April 29, 2010 Can you spot why is this code several times slower in v3.5.5 (and 3.5.4) than v3.36? Is there some version specific optimizations I should implement? I measured speed difference 3...5 times on different size images (My system is XP SP3, Core2Duo, 3.5 GB). Below effect is actually stripped down to just call AddNoiseEffect and render the result. In v3.36 it renders fast. In v.3.5.5 (and 3.5.4) it is slow. Codelab designed effect: #region UICode int Amount1 = 50; // [0,100] Amount #endregion unsafe void Render(Surface dst, Surface src, Rectangle rect) { // Setup for calling the Noise function AddNoiseEffect noiseEffect = new AddNoiseEffect(); PropertyCollection nProps = noiseEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken nParameters = new PropertyBasedEffectConfigToken(nProps); nParameters.SetPropertyValue(AddNoiseEffect.PropertyNames.Intensity, 40); nParameters.SetPropertyValue(AddNoiseEffect.PropertyNames.Saturation, 0); nParameters.SetPropertyValue(AddNoiseEffect.PropertyNames.Coverage, 100.0); noiseEffect.SetRenderInfo(nParameters, new RenderArgs(dst), new RenderArgs(src)); // Call the Noise function noiseEffect.Render(new Rectangle[1] {rect},0,1); // Now in the main render loop, the dst canvas has a noisy version of the src canvas for (int y = rect.Top; y < rect.Bottom; y++) { ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y); ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y); for (int x = rect.Left; x < rect.Right; x++) { ColorBgra DstPixel = *dstPtr; ColorBgra SourcePixel = *srcPtr; // will render some more stuff here *dstPtr = DstPixel; srcPtr++; dstPtr++; } } } Quote Link to comment Share on other sites More sharing options...
pyrochild Posted April 29, 2010 Share Posted April 29, 2010 It's not very slow here, but this is even faster: #region UICode int Amount1 = 50; // [0,100] Amount #endregion AddNoiseEffect noiseEffect; unsafe void Render(Surface dst, Surface src, Rectangle rect) { // Setup for calling the Noise function if (noiseEffect == null) { noiseEffect = new AddNoiseEffect(); PropertyCollection nProps = noiseEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken nParameters = new PropertyBasedEffectConfigToken(nProps); nParameters.SetPropertyValue(AddNoiseEffect.PropertyNames.Intensity, 40); nParameters.SetPropertyValue(AddNoiseEffect.PropertyNames.Saturation, 0); nParameters.SetPropertyValue(AddNoiseEffect.PropertyNames.Coverage, 100.0); noiseEffect.SetRenderInfo(nParameters, new RenderArgs(dst), new RenderArgs(src)); } // Call the Noise function noiseEffect.Render(new Rectangle[1] {rect},0,1); // Now in the main render loop, the dst canvas has a noisy version of the src canvas for (int y = rect.Top; y < rect.Bottom; y++) { ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y); ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y); for (int x = rect.Left; x < rect.Right; x++) { ColorBgra DstPixel = *dstPtr; ColorBgra SourcePixel = *srcPtr; // will render some more stuff here *dstPtr = DstPixel; srcPtr++; dstPtr++; } } } Quote 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 April 29, 2010 Share Posted April 29, 2010 If you're doing a null-checked, deferred instantiation there, don't forget to reset this.noiseEffect to null in OnSetRenderInfo (call its Dispose method first, too). 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...
pyrochild Posted April 30, 2010 Share Posted April 30, 2010 I don't think we can get to OnSetRenderInfo from CodeLab anymore Quote 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...
BoltBait Posted April 30, 2010 Share Posted April 30, 2010 "Anymore?" You never could. I've been brainstorming how to give access, but I haven't come up with a good way yet. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Tanel Posted April 30, 2010 Author Share Posted April 30, 2010 pyrochild, thank you so much for the example. I can confirm that this is equally fast in v3.5.5 and v3.36. The speed is now the same as my original code in v3.36. I couldn't follow Rick's advice, but there is no obvious problem either. 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.