Jump to content

Recommended Posts

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.

 

DynamicContrast.zip

 

 

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.0\n\nThe effect of adjusting the contrast of the image.\n\nCopyright ©2020 by ReMake\nAll rights reserved.", "Dynamic Contrast", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

and icon  Dynamic-Contrast.png

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.

Edited by ReMake
Edited the source code
  • Like 2
  • Upvote 4
Link to post
Share on other sites

Thank you @ReMake!  I will try this.  🙂 

 

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

 

Edited by lynxster4
  • Upvote 1
Link to post
Share on other sites

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
Link to post
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...