Jump to content

Question: How to make a circular selection in a plugin


Recommended Posts

I want to make and effect using the blur plugin by increasing the amount of blur in a circular fashion to simulate DOF.

Not sure how do i change the selection in order to be able to call it multiple times with different parameters. I might

not be understanding how some parts work. Any help ??

Not posting the code because right now all i got is how to call the blur effect.

The idea is to create and effect like this one

image

That was done by hand and it took 15 layers....

Link to comment
Share on other sites

I guess i did not explain myself properly at teh end i don't want the selection to be modified It was just an example of how i did it manually.

What i'm wondering is what is the best way to blur between to raidus in a circular motion.

For example first circle uses unblur comparatively to one

Second circle to 5

Third circle to 10

I think i might have to reimplement unfocus in order to do that but i don't really now how to figure the are in which the circle would be applied. Does this make my question clearer ?

Link to comment
Share on other sites

What i'm wondering is what is the best way to blur between to raidus in a circular motion.

For example first circle uses unblur comparatively to one

Second circle to 5

Third circle to 10

Sounds like a good description of the algorithm to me. Just implement it.

I think the trick is to realise that you don't need a selection to perform an effect on a subset of the pixels. After all, when OnRender is called, you can copy the original image to the destination and then modify (e.g. blur) part of the destination. After all, you control the rectangle on which you perform an effect.

Also, you could consider first blurring the biggest circle, and then blurring smaller circles more (or less, whichever you want).

Hope this helps.

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...

I want to make and effect using the blur plugin by increasing the amount of blur in a circular fashion to simulate DOF.

Not sure how do i change the selection in order to be able to call it multiple times with different parameters. I might

not be understanding how some parts work. Any help ??

Not posting the code because right now all i got is how to call the blur effect.

The idea is to create and effect like this one

image

That was done by hand and it took 15 layers....

Here is a start:

// Submenu: Blurs
// Name: Focus Point
#region UICode
int Amount1 = 50; // [1,200] Max Radius
Pair<double, double> Amount2 = Pair.Create( 0.0 , 0.0 ); // Focus Point
#endregion

private UserBlendOp normalOp = new UserBlendOps.NormalBlendOp();

void Render(Surface dst, Surface src, Rectangle rect)
{
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   int width = selection.Right - selection.Left;
   int height = selection.Bottom - selection.Top;
   int CenterX = (int)Math.Round(((Amount2.First + 1) / 2) * width);
   int CenterY = (int)Math.Round(((Amount2.Second + 1) / 2) * height);

   int MaxWidth = (int)(((src.Width > src.Height)?src.Width:src.Height) * 1.2)/2;
   int MinWidth = 1;
   int Dif = MaxWidth - MinWidth;

   // Call the Gaussian Blur effect
   GaussianBlurEffect blurEffect = new GaussianBlurEffect();
   PropertyCollection bProps = blurEffect.CreatePropertyCollection();
   PropertyBasedEffectConfigToken bParameters = new PropertyBasedEffectConfigToken(bProps);
   bParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount1);
   blurEffect.SetRenderInfo(bParameters, new RenderArgs(dst), new RenderArgs(src));
   blurEffect.Render(new Rectangle[1] {rect},0,1);

   // Loop through all pixels and calculate final pixel values
   ColorBgra CurrentPixel;
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           CurrentPixel = src[x,y];
           double dist = Math.Sqrt(((CenterX-x)*(CenterX-x))+((CenterY-y)*(CenterY-y)));
           if (dist > MaxWidth)
           {
               CurrentPixel.A = 0;
           }
           else
           {
               CurrentPixel.A = (byte)(255-(255*((-Math.Cos((dist-MinWidth)/Dif * Math.PI)+1)/2)));
           }
           CurrentPixel = normalOp.Apply(dst[x,y], CurrentPixel);
           dst[x,y] = CurrentPixel;
       }
   }
}

Use CodeLab to make that into a DLL and see if you like it.

BTW, this is just a quick mixture of calling Gaussian Blur and the vingette code from here http://forums.getpaint.net/index.php?/topic/11785- changed from black to alpha. It is probably wrong. I did the whole thing in, like, 5 minutes.

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