Why hello here! So, I was building my plugin with Boltbait's CodeLab, the the speed of rendering is too slow for me.
The plugin I was making will be used to make a pixel transparent depending on its brightness/darkness, while one can set the range of transparency gradient. That is:
And the code:
Hidden Content:
#region UICode
int Amount1 = 0; // [0,255] Start
int Amount2 = 255; // [0,255] Range
byte Amount3 = 0; // Alpha value depends on...|Brightness|Darkness
bool Amount4 = false; // Convert to grayscale before alpha filting
#endregion
public byte Pick(double Vxx)
{
if ( Amount1 > Vxx )
return 0;
else if ( Vxx <= Amount1 + Amount2 )
return (byte)Math.Ceiling((float) (Vxx-Amount1)*255/Amount2);
else
return 255;
}
public double Grscl(byte VxR, byte VxG, byte VxB)
{
return (double)Math.Ceiling(VxR*0.2988-0.4516-0.4999+VxG*0.5863-0.3252-0.4999+VxB*0.1137-0.4669-0.4999);
}
void Render(Surface dst, Surface src, Rectangle rect)
{
Rectangle selct = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
ColorBgra CurrentPixel;
for (int y = selct.Top; y < selct.Bottom; y++)
{
for (int x = selct.Left; x < selct.Right; x++)
{
CurrentPixel = src[x,y];
if ( Amount4 == false )
{
if ( Amount3 == 0 )
CurrentPixel.A = Pick(HsvColor.FromColor(CurrentPixel.ToColor()).Value*2.55);
else
CurrentPixel.A = Pick(255-HsvColor.FromColor(CurrentPixel.ToColor()).Value*2.55);
}
else
{
if ( Amount3 == 0 )
CurrentPixel.A = Pick(Grscl(CurrentPixel.R, CurrentPixel.G, CurrentPixel.);
else
CurrentPixel.A = Pick(255-Grscl(CurrentPixel.R, CurrentPixel.G, CurrentPixel.);
}
dst[x,y] = CurrentPixel;
}
}
}
I don't know which part makes the plugin render slowly. But once the problem is solved, this plugin will be very useful for diffusion effect.