Sign in to follow this  
Followers 0
BoltBait

Color Balance (Plugin) - UPDATED

26 posts in this topic

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)

0

Share this post


Link to post
Share on other sites

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

0

Share this post


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

0

Share this post


Link to post
Share on other sites

I'm not sure, I tried contacting him on Gmail chat, but he's not currently on, wich is something almost unheard of...

0

Share this post


Link to post
Share on other sites

BoltBait, I think it is high time that you just buckled down and learned how to do this :)

0

Share this post


Link to post
Share on other sites
BoltBait, I think it is high time that you just buckled down and learned how to do this :)

After writing 11 effects... ya think? :D

Rick, Its all a matter of TIME, not ability.

Besides, everybody knows the UI is the hardest part... :D

0

Share this post


Link to post
Share on other sites
You've got Visual Studio 2005, right?

Yes.

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

0

Share this post


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

0

Share this post


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

0

Share this post


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

0

Share this post


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

0

Share this post


Link to post
Share on other sites

Nice! Thanks!

It is working well.

I will add the links to the first post.

By the way, I'm not sure what that icon is, but I like it. :D

0

Share this post


Link to post
Share on other sites

...the icon is from nebulous code lab on 16x16...

I find it could "illustrate" the color balance!

And the source is for whose wants to dig into UI creating... :wink:

I use Visual Studio 2005 Express!

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


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

0

Share this post


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

0

Share this post


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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Does it replicate Photoshop results 1 to 1?

Thanks.

Nope. Mine's bloody potato.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0