BoltBait's Pages - Color Balance

Sarcasm, just one of the services I offer.

 

Paint.NET Color Balance Adjustment Effect

Whenever I take pictures indoors, the pictures always come out looking yellow.  So, I needed a color correcting effect.

 

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!)

 

The Effect DLL

You can download the effect DLL here: ColorBalance.DLL

Just drop this DLL file in your \program files\Paint.NET\effects directory and you should be all set.

 

Note:  This effect shows up under the "Adjustments" menu instead of the "Effects" menu.

 

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.  Here is the codelab script:

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(); 
	ColorBgra CurrentPixel; 
	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); 
			} 
		} 
	} 
}

 

Tuesday, January 16, 2007