// Color Stretch v1.0 by rwp80
// Released 13th July 2008
#region UICode
int Amount1=3;   //[0,3]Blue;Green;Red;Alpha
int Amount2=0;   //[0,255]Lower Threshold
int Amount3=255;   //[0,255]Upper Threshold
int Amount4=255;   //[0,255]Target Value
int Amount5=500;   //[0,1000]Strength
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra CurrentPixel;
    double R, G, B, A;
    for(int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];
            R = (double)CurrentPixel.R;
            G = (double)CurrentPixel.G;
            B = (double)CurrentPixel.B;
            A = (double)CurrentPixel.A;            
                        
            switch(Amount1) 
            {
                case 0:
                    if ((B >= Amount2) && (B <= Amount3))
                    {
                        B = B+(((double)Amount4-B)*((double)Amount5/1000));                
                    }                            
                    break;
                                                    
                case 1:
                    if ((G >= Amount2) && (G <= Amount3))
                    {
                        G = G+(((double)Amount4-G)*((double)Amount5/1000));                
                    }                            
                    break;
                                                                            
                case 2:
                    if ((R >= Amount2) && (R <= Amount3))
                    {
                        R = R+(((double)Amount4-R)*((double)Amount5/1000));                
                    }                            
                    break;
                                    
                case 3:
                    if ((A >= Amount2) && (A <= Amount3))
                    {
                        A = A+(((double)Amount4-A)*((double)Amount5/1000));                
                    }                            
                    break;
            }                    
                                                                    
            CurrentPixel = ColorBgra.FromBgra(Utility.ClampToByte(B),Utility.ClampToByte(G),Utility.ClampToByte(R),Utility.ClampToByte(A));
            dst[x,y] = CurrentPixel;
        }
    }
}
