BoltBait
Yes, sorry - too quick to ask for help! I found what I needed, and have implemented a very simple 'White Balance' plugin, which uses, as per your suggestion, the current Primary colour as the grey point.
For what it's worth, the code is shown below (can't see how to attach the DLL at the moment).
I have tested this on a few images that only needed a small white balance correction, and it seems to work OK. It could well need some work for images that have a significant colour cast, but I'm not yet familiar with how the core code copes with illegal, or out of bounds, values for the RGB values.
Thanks for your help.
void Render(Surface dst, Surface src, Rectangle rect)
// White Balance plugin
// Uses Primary colour as user-selected grey point
{
int r, g, b;
int RShift, GShift, BShift;
//local variable for primary colour
ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
// RGB values of primary colour
r = PrimaryColor.R;
g = PrimaryColor.G;
b = PrimaryColor.B;
//RGB correction for primary colour - reduces this colour to grey
RShift = (r+g+b)/3-r;
GShift = (r+g+b)/3-g;
BShift = (r+g+b)/3-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))
{
//apply RGB shifts to current pixel
r = (int)src[x,y].R+RShift;
g = (int)src[x,y].G+GShift;
b = (int)src[x,y].B+BShift;
dst[x, y] = ColorBgra.FromBgra(
Utility.ClampToByte(,
Utility.ClampToByte(g),
Utility.ClampToByte(r),
src[x,y].A);
}
}
}
}