Jump to content
How to Install Plugins ×
Paint.NET 5.1 is now available! ×

Recommended Posts

Posted

This effect is similar to the Photoshop's Dynamic Contrast filter and allows you to create images with high contrast.

 

You can find this effect in Adjustments menu.

 

Download from my PluginPack

 

Dynamic-Contrast-UI.png

Amount - the range of adjustment of contrast.
Threshold - sets the threshold for enabling a color (and its shades) or a mixture of colors in the Blue -> Red -> Green direction.
Intensity - sets the pixel intensity of the image.

 

When Amount = 0, the Threshold and Intensity controls have no effect on the image and are therefore disabled.

 

Examples of the plugin work:
Before:
Roses.jpg

After:

DCAfter1.png

DCAfter2.png

 

CodeLab source code:

Spoiler
// Name:Dynamic Contrast
// Submenu:
// Author:ReMake
// Title:Dynamic Contrast
// Version:1.1
// Desc:The effect of adjusting the contrast of the image
// Keywords:paint.net|effect|dynamic|contrast
// URL:https://www.getpaint.net/redirect/plugins.html
#region UICode
int amount = 0; // [-64,64] Amount
int threshold = 128; // [0,255] {!amount} Threshold
int intensity = 255; // [0,255] {!amount} Intensity
#endregion

public int Mix (int c, int luma)
{
    return (int)(c - (float)Math.Sqrt(Math.Abs(threshold - luma))*((luma > threshold) ? -amount : amount)) * intensity / 255 + c * (255 - intensity) / 255;
}

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra CurrentPixel;
    int R, G, B, luma;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];

            R = CurrentPixel.R;
            G = CurrentPixel.G;
            B = CurrentPixel.B;

            luma = (76 * R + 150 * G + 29 * B) / 256;
            R = Mix(R, luma);
            G = Mix(G, luma);
            B = Mix(B, luma);
            
            CurrentPixel = ColorBgra.FromBgraClamped(B, G, R, CurrentPixel.A);
            
            dst[x,y] = CurrentPixel;
        }
    }
}

private void OnWindowHelpButtonClicked(IWin32Window owner, string helpContent)
{
    MessageBox.Show(owner, "Dynamic Contrast v1.1\n\nThe effect of adjusting the contrast of the image.\n\nCopyright ©2020 by ReMake\nAll rights reserved.", "Dynamic Contrast", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

 

To have a clearer understanding of how this effect works, upload the image below.

 

Color-Wheel.png

Run the effect. Set the Amount and Threshold controls to the leftmost position. Slowly move the Threshold control to the rightmost position and watch the colors contrast change.

Set the Amount control to the rightmost position and move the Threshold control again from left to right, watching the colors change. View how the effect works with different settings on all three sliders. Here are some examples:

 

DCwork1.png

DCwork2.png

 

I hope you will like this effect and find a use for it.

 

  • Like 2
  • Upvote 4
Posted (edited)

Thank you @ReMake!  I will try this.  🙂 

 

EDIT:  Just tried it...it works great!  👍

 

Edited by lynxster4
  • Upvote 1
Posted

The effect has been updated to version 1.1.

With some settings in the previous version, the image looked posterized.

 

oldversion.jpg

@Reptillian kindly gave me a suggestion on how to improve the effect. Now the image looks smoother.

 

newversion.jpg

Thanks to @Reptillian for his assistance.

 

Download the new version of the effect from the first post.

  • Like 2
  • Upvote 1
Posted
21 hours ago, ReMake said:

The effect has been updated to version 1.1.

 

Download the new version of the effect from the first post.

Thank you. Have you updated the source?

 

Best wishes

Posted
21 hours ago, ReMake said:

Yes, of course.

Thanks. Whilst I'm no longer an active programmer I do like to see (sorta) what is being done. I see in the source above still states version 1.0 so that's why I asked.

 

Best

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