public float4[,] ApplyBrightnessContrastGamma( float4[,] _Source, float _Brightness, float _Contrast, float _Gamma ) { int W = _Source.GetLength( 0 ); int H = _Source.GetLength( 1 ); float4[,] Result = new float4[W,H]; for ( int Y=0; Y < H; Y++ ) for ( int X=0; X < W; X++ ) { float4 RGBA = _Source[X,Y]; RGBA.x = ApplyBrightnessContrastGamma( RGBA.x, _Brightness, _Contrast, _Gamma ); RGBA.y = ApplyBrightnessContrastGamma( RGBA.y, _Brightness, _Contrast, _Gamma ); RGBA.z = ApplyBrightnessContrastGamma( RGBA.z, _Brightness, _Contrast, _Gamma ); Result[X,Y] = RGBA; } return Result; }
float4 BilinearSample( float4[,] _Source, float _X, float _Y ) { int X = (int) Math.Floor( _X ); float x = _X - X; int Y = (int) Math.Floor( _Y ); float y = _Y - Y; int W = _Source.GetLength( 0 ); int H = _Source.GetLength( 1 ); float4 V00 = X >= 0 && Y >= 0 && X < W && Y < H ? _Source[X,Y] : float4.Zero; X++; float4 V01 = X >= 0 && Y >= 0 && X < W && Y < H ? _Source[X,Y] : float4.Zero; Y++; float4 V11 = X >= 0 && Y >= 0 && X < W && Y < H ? _Source[X,Y] : float4.Zero; X--; float4 V10 = X >= 0 && Y >= 0 && X < W && Y < H ? _Source[X,Y] : float4.Zero; float4 V0 = (1.0f - x) * V00 + x * V01; float4 V1 = (1.0f - x) * V10 + x * V11; float4 Result = (1.0f - y) * V0 + y * V1; return Result; }