@ -36,31 +36,38 @@
/// <inheritdoc/>
public override Matrix4x4 Matrix = > this . matrix ;
/// <inheritdoc/>
public override bool Compand = > false ;
/// <inheritdoc/>
protected override void OnApply ( ImageBase source , ImageBase target , Rectangle targetRectangle , Rectangle sourceRectangle )
{
float degrees = this . Angle ;
double costheta = Math . Cos ( degrees ) ;
double sintheta = Math . Sin ( degrees ) ;
float radians = ( float ) ImageMaths . DegreesToRadians ( this . Angle ) ;
double cosradians = Math . Cos ( radians ) ;
double sinradians = Math . Sin ( radians ) ;
float lumR = . 2 1 3f ;
float lumG = . 7 1 5f ;
float lumB = . 0 7 2f ;
float oneMinusLumR = 1 - lumR ;
float oneMinusLumG = 1 - lumG ;
float oneMinusLumB = 1 - lumB ;
// The matrix is set up to preserve the luminance of the image.
// See http://graficaobscura.com/matrix/index.html
// Number are taken from https://msdn.microsoft.com/en-us/library/jj192162(v=vs.85).aspx
// TODO: This isn't correct. Need to double check MS numbers against maths.
Matrix4x4 matrix4X4 = new Matrix4x4 ( )
{
M11 = ( float ) ( . 2 1 3 + ( costheta * . 7 8 7 ) - ( sintheta * . 2 1 3 ) ) ,
M12 = ( float ) ( . 7 1 5 - ( costheta * . 7 1 5 ) - ( sintheta * . 7 1 5 ) ) ,
M13 = ( float ) ( . 0 7 2 - ( costheta * . 0 7 2 ) + ( sintheta * . 9 2 8 ) ) ,
M21 = ( float ) ( . 2 1 3 - ( costheta * . 2 1 3 ) + ( sintheta * . 1 4 3 ) ) ,
M22 = ( float ) ( . 7 1 5 + ( costheta * . 2 8 5 ) + ( sintheta * . 1 4 0 ) ) ,
M23 = ( float ) ( . 0 7 2 - ( costheta * . 0 7 2 ) - ( sintheta * . 2 8 3 ) ) ,
M31 = ( float ) ( . 2 1 3 - ( costheta * . 2 1 3 ) - ( sintheta * . 7 8 7 ) ) ,
M32 = ( float ) ( . 7 1 5 - ( costheta * . 7 1 5 ) + ( sintheta * . 7 1 5 ) ) ,
M33 = ( float ) ( . 0 7 2 + ( costheta * . 9 2 8 ) + ( sintheta * . 0 7 2 ) )
M11 = ( float ) ( + lumR + ( cosradians * oneMinusLumR ) - ( sinradians * lumR ) ) ,
M12 = ( float ) ( + lumR - ( cosradians * lumR ) - ( sinradians * lumR ) ) ,
M13 = ( float ) ( + lumR - ( cosradians * lumR ) - ( sinradians * 0.787 ) ) ,
M21 = ( float ) ( + lumG - ( cosradians * lumG ) - ( sinradians * lumG ) ) ,
M22 = ( float ) ( + lumG + ( cosradians * oneMinusLumG ) + ( sinradians * 0.14 0 ) ) ,
M23 = ( float ) ( + lumG - ( cosradians * lumG ) + ( sinradians * lumG ) ) ,
M31 = ( float ) ( + lumB - ( cosradians * lumB ) + ( sinradians * oneMinusLumB ) ) ,
M32 = ( float ) ( + lumB - ( cosradians * lumB ) - ( sinradians * 0.283 ) ) ,
M33 = ( float ) ( + lumB + ( cosradians * oneMinusLumB ) + ( sinradians * lumB ) )
} ;
this . matrix = matrix4X4 ;