Paint.NET Delete Primary Color
One of the users at the Paint.NET chat board asked if it was possible to completely delete a color even if its mixed with another color.
In other words, can we go from this:
to this:
by selecting the blue and running an effect? Sure. No problem. Notice how the blue is deleted even though it is "under" the red in the middle.
The Idea
I thought that it would be easy to simply delete the selected RGB value from each pixel and then adjust the Alpha value based on how much color was deleted from the pixel.
The Effect DLL
You can download the precompiled effect DLL here: StripPrimaryColor.dll
Just drop this file in your \program files\Paint.NET\effects directory and you should be all set.
Instructions for Use
The best way to use this is to follow these steps:
1) Use the color picker tool to select the color that you want to remove from your drawing.
2) Run the effect.
Source Code
The codelab script is fairly straight forward: (I know this is rough, but what do you expect for 10 minutes work?)
void Render(Surface dst, Surface src, Rectangle rect)
{
PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
ColorBgra CurrentPixel;
ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
for(int y = rect.Top; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
if (selectionRegion.IsVisible(x, y))
{
CurrentPixel = src[x,y];
if (CurrentPixel.R >= PrimaryColor.R) {
CurrentPixel.R -= PrimaryColor.R;
CurrentPixel.A=(byte)((CurrentPixel.A - PrimaryColor.R < 0)?
0:CurrentPixel.A - PrimaryColor.R);
} else {
CurrentPixel.A=(byte)((CurrentPixel.A - CurrentPixel.R < 0)?
0:CurrentPixel.A - CurrentPixel.R);
CurrentPixel.R = 0;
}
if (CurrentPixel.G >= PrimaryColor.G) {
CurrentPixel.G -= PrimaryColor.G;
CurrentPixel.A = (byte)((CurrentPixel.A - PrimaryColor.G < 0)?
0:CurrentPixel.A - PrimaryColor.G);
} else {
CurrentPixel.A=(byte)((CurrentPixel.A - CurrentPixel.G < 0)?
0:CurrentPixel.A - CurrentPixel.G);
CurrentPixel.G = 0;
}
if (CurrentPixel.B >= PrimaryColor.B) {
CurrentPixel.B -= PrimaryColor.B;
CurrentPixel.A=(byte)((CurrentPixel.A - PrimaryColor.B < 0)?
0:CurrentPixel.A - PrimaryColor.B);
} else {
CurrentPixel.A=(byte)((CurrentPixel.A - CurrentPixel.B < 0)?
0:CurrentPixel.A - CurrentPixel.B);
CurrentPixel.B = 0;
}
dst[x,y] = CurrentPixel;
}
}
}
}
Friday, November 17, 2006


