Jump to content
How to Install Plugins ×

Color Balance (Plugin) - UPDATED


BoltBait

Recommended Posts

Color Balance

Whenever I take pictures indoors, the pictures always come out looking yellow. So, I needed a color correcting effect. I wanted to create something that would be MUCH easier than fiddling with the RGB levels adjustment that is already included in Paint.NET.

The Idea

I wanted to make an effect that would make my pictures less yellow. Well, if they are going to be less yellow they will have to be more... what? Blue? Yup. That's the opposite of yellow. Perfect! I figured a slider between yellow and blue would do the trick. And, while I'm at it, I might as well add a slider between Cyan and Red and a slider between Magenta and Green. (Not that I'll ever need those, but, what the hay!)

Opposites

Yellow is opposite of blue? Sure. Let's take a look at the color wheel:

RGBvsCMY.png

Basically, the arrows shown in this illustration are the sliders in the Color correction effect.

ColorBalance.jpg

In the RGB color model, Yellow is a combination of Red and Green. So, in the code, when we increase the level of Blue in our image, we decrease the levels of Red and Green (each by half of the Blue adjustment). If you notice, we have each of the primary colors on one end of the sliders and the combination of the remaining primary colors (called secondary colors) on the other end.

The Effect DLL

If you like it, you can download the precompiled effect here: BoltBait's Plugin Pack

How to Use

Typically, this effect is used to correct the colors of a photograph. Notice in the illustration of the color wheel above, all 3 arrows cross at white. The best way to adjust a photograph's colors is to look at the white areas of the photograph and try to adjust the sliders until you achieve a true white in those areas.

For example, many times when taking photographs indoors, white walls will appear slightly yellow. Simply move the Yellow/Blue slider to the right until the walls appear white. Then adjust the other sliders to fine tune the resulting shade of white. It may take some tinkering with the sliders to get something close to a true white. Then, once you get the colors right, it may be necessary to adjust the brightness and contrast.

  • By the way, this is a great way to "whiten" teeth, too. Waaaay easier than brushing. ;)

Tinting

Another use of this effect is to tint images. First, change the image to Black and White (desaturate the image). Then run the effect and adjust the sliders for the desired coloring. As an example, you can make an image appear Sepia by making the image Black and White, then running the Color Balance effect and setting the sliders to 100, 85, and 75.

Source Code

The codelab script is fairly straight forward:

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
    int CyanRed = 0;         // Slider, Range -100 to 100, default 0
    int MagentaGreen = 0;    // Slider, Range -100 to 100, default 0
    int YellowBlue = 0;       // Slider, Range -100 to 100, default 0

    int r, g, b;
    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 
    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
    for(int y = rect.Top; y < rect.Bottom; y++) 
    { 
        for (int x = rect.Left; x < rect.Right; x++) 
        { 
            if (selectionRegion.IsVisible(x, y)) 
            { 
                r = (int)src[x,y].R;
                g = (int)src[x,y].G;
                b = (int)src[x,y].B;

                // Cyan-Red adjustment
                r += CyanRed;
                g -= (CyanRed / 2);
                b -= (CyanRed / 2);
                // Magenta-Green adjustment
                r -= (MagentaGreen / 2);
                g += MagentaGreen;
                b -= (MagentaGreen / 2);
                // Yellow-Blue adjustment
                r -= (YellowBlue / 2);
                g -= (YellowBlue / 2);
                b += YellowBlue;

                dst[x, y] = ColorBgra.FromBgra( 
                    Utility.ClampToByte(b), 
                    Utility.ClampToByte(g), 
                    Utility.ClampToByte(r),
                    src[x,y].A); 
            } 
        } 
    } 
} 
 

Enjoy. B)

Link to comment
Share on other sites

Doesent Illnab do all your UI's? I had though you two were a good team!

It is true, I like his work... but, where is he?

MadJik also does fine work.

I may just do this one myself when I find the time. I have upgraded my dev enviroment to VS2005. So, its just a matter of time before I get off my lazy butt and do one for myself. :D

Link to comment
Share on other sites

Man, if i had Visual Studio, i'd learn, and do them for you guys, but I dont... haha, I realise you can get trials, but everyone knows thats not worth the agervation, learning it in the trial period, and not being able to buy it later...

Link to comment
Share on other sites

You've got Visual Studio 2005, right?

Yes.

Along with 2 full-time jobs and a family...

Very true.

Anyway for the UI you want, the "ThreeAmountsConfigDialog" already does exactly what you want. Just look through the code in the Effects project (d/l the PDN 2.72 source) for one of the effects that uses it, like say Hue/Saturation.

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

Well, I'll take a look at it when I get a chance. Maybe tomorrow.

Man, if i had Visual Studio, i'd learn, and do them for you guys, but I dont... haha, I realise you can get trials, but everyone knows thats not worth the agervation, learning it in the trial period, and not being able to buy it later...

You know you can download Visual Studio for free... ;)

http://msdn.microsoft.com/vstudio/express/visualcsharp/

Link to comment
Share on other sites

Why Look at that! *ithoughiwassosly* I guess i should learn some, it would be realy cool to know... (stopping about this due to getting too offtopic)

Link to comment
Share on other sites

  • 2 weeks later...

Thanks, MadJik, for the source code.

I have modified it so that the Color Balance effect shows up under the Adjustments menu instead of the Effects menu.

Download here: ColorBalance.dll (updated)

Just drop this file into your C:/Program Files/Paint.NET/Effects directory and you should be all set.

Enjoy.

Link to comment
Share on other sites

I have modified it so that the Color Balance effect shows up under the Adjustments menu instead of the Effects menu.

Excellent idea! Thank you.

BK_BloodSaw_sig.png

- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

Link to comment
Share on other sites

Thanks, MadJik, for the source code.

you're welcome.
I have modified it so that the Color Balance effect shows up under the Adjustments menu instead of the Effects menu.

I thought we could only add plugins to the effect menu!

1.Why can't then we put some into the tool menu (polygone)?

2.Could you tell me what you did change for that?

Enjoy.

sure I'll do.

Link to comment
Share on other sites

BuzzKill,

You're welcome. :)

Madjik,

I only had to add one line of source code to the file in order to move the effect to the Adjustment menu. If you look through the source code to some of the effects that are in the adjustment menu, I'm sure you'll see the difference. Here is your code, edited (this is only the interesting part):

namespace ColorBalance
{
   [EffectCategory(EffectCategory.Adjustment)]
   public class ColorBalance
       : Effect
   {

You can not put things in any other menus--only Effects and Adjustments.

Please be advised, that Rick told me in a PM that in a future version of Paint.NET, this will not be possible. So, use at your own risk.

By the way, this should be used sparingly. In fact, I've written 11 effects and this is the only one that I feel should be in the Adjustments menu. OK, now two. ;)

Link to comment
Share on other sites

  • 6 months later...
  • 2 weeks later...

Wonder if it would be possible to date this plugin on the Title so that users can know when there is another update. The present "Updated" tag will still be valid for all versions without anyone knowing of later improvements. Thanks.

Link to comment
Share on other sites

  • 8 months later...
  • 2 years later...

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