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:
Basically, the arrows shown in this illustration are the sliders in the Color correction effect.
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.
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(<img src='http://forums.getpaint.net/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' />,
Utility.ClampToByte(g),
Utility.ClampToByte®,
src[x,y].A);
}
}
}
} Enjoy.




















