Jump to content

Slow rendering in v3.5.5 vs v3.36 (calling AddNoiseEffect from codelab)


Tanel

Recommended Posts

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++;
       }
   }
}

Link to comment
Share on other sites

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++;
       }
   }
}

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to comment
Share on other sites

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).

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...