Jump to content

How does Paint.net add a sharpness effect to a image


Recommended Posts

Hey i know this question is kinda off but bare with me.

 

Does anybody know how paint.net adds a sharpness effect to a image through code. it would be nice to mabe give a example code on how it does this. 

 

Or any kind of code to add a sharpness effect to a image it has to be in c# just curious i know the color option to a image but not a effect like sharpness.

 

Again a off question but i would like to find out this.

Link to comment
Share on other sites

The code is not available. It belongs to Rick. It's not something he hands out on request.

Link to comment
Share on other sites

19 hours ago, lopper said:

Does anybody know how paint.net adds a sharpness effect to a image through code.

 

I don't know how paint.net does it, but if you are simply interested in an algorithm for sharpening a photograph, here's one:

 

// Author: BoltBait
// Submenu: Photo
// Name: Sharpen (unsharp mask)
// URL: http://www.BoltBait.com/pdn
#region UICode
IntSliderControl Amount1 = 100; // [0,200] Sharpen
#endregion

unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
    // Setup for calling the Gaussian Blur (radius = 1) function
    GaussianBlurEffect blurEffect = new GaussianBlurEffect();
    PropertyCollection bProps = blurEffect.CreatePropertyCollection();
    PropertyBasedEffectConfigToken bParameters = new PropertyBasedEffectConfigToken(bProps);
    bParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, 1);
    blurEffect.SetRenderInfo(bParameters, new RenderArgs(dst), new RenderArgs(src));
    blurEffect.Render(new Rectangle[1] {rect},0,1);

    // Now in the main render loop, the dst canvas has a blurred 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 AdjustmentPixel = *dstPtr; // blurred pixel
            ColorBgra SourcePixel = *srcPtr; // original pixel

            // Sharpen (unsharp mask)
            double NewR = (double)SourcePixel.+ ((double)SourcePixel.- (double)AdjustmentPixel.R) * (double)Amount1 / 100.0;
            double NewG = (double)SourcePixel.+ ((double)SourcePixel.- (double)AdjustmentPixel.G) * (double)Amount1 / 100.0;
            double NewB = (double)SourcePixel.+ ((double)SourcePixel.- (double)AdjustmentPixel.B) * (double)Amount1 / 100.0;
            AdjustmentPixel.= Int32Util.ClampToByte((int)NewR);
            AdjustmentPixel.= Int32Util.ClampToByte((int)NewG);
            AdjustmentPixel.= Int32Util.ClampToByte((int)NewB);

            *dstPtr = AdjustmentPixel;

            srcPtr++;
            dstPtr++;
        }
    }
} 

If you have my plugin pack installed, this is the same sharpen method my Photo > Landscape plugin uses.  I just isolated the sharpen code and posted it above.  If you need help understanding what is happening, just ask and I (or someone else) will explain it to you.

Link to comment
Share on other sites

What I meant by "just google it" is that sharpening an image is a well known algorithm in Computer Science and Graphics. Paint.NET isn't really doing anything novel here, aside from maybe some optimizations. So you'll just have better success if you broaden the scope of your search.

 

You can also use something like Reflector or ILSpy to take a peek at a disassembly of Paint.NET's DLLs. You'd want to look at what's in PaintDotNet.Effects.dll.

  • Upvote 1

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

  • 5 years later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...