It calculates for every pixel the difference between the pixel and the primary color. The more they are equal, the more alpha will rest. Just duplicate your layer, do my effect with a Primary color selected, maybe some fine tuning with Curves+ alpha channel and there you go affecting only this specially colored part of the image without need of feathering or anything because it's always a smooth gradient from layer to change to the original image layer.
Download here:
Attachment:
File comment: Effect DLL in a ZIP file
EffectDLL.zip [2.45 KiB]
Downloaded 4482 times
Unzip it into your Effects directory in the Paint.NET folder.
It will be listed under Effects -> Color
example:

1 to 2: Here i first chose the sky's color as primary with the Color Picker

then I ran my effect.
2 to 3: After that I did some
alpha fine tuning with Curves+

. And the only color effect I added to the sky was increasing saturation and a little hue adjustment

.
3 to 4: I put the original image as a layer under the modified one.
Link to where you get Curves+code (Codelab):
Code:
int dr,dg,db;
void Render(Surface dst, Surface src, Rectangle rect)
{
PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
// Delete any of these lines you don't need
Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
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))
{
CurrentPixel = src[x,y];
dr = CurrentPixel.R - PrimaryColor.R;
dg = CurrentPixel.G - PrimaryColor.G;
db = CurrentPixel.B - PrimaryColor.B;
if (dr < 0)
dr=-dr;
if (dg < 0)
dg=-dg;
if (db < 0)
db=-db;
CurrentPixel.A = (byte)(255-((dr+dg+db)/3));
dst[x,y] = CurrentPixel;
}
}
}
}
I'm currently searching for a good 16x16 png icon. Please tell me your ideas.