网上找了很久,都没有一个人给出最终结果,经过不断研究终于知道这个结果了
推导过程:
(1)色相旋转是如何旋转的
RGB立方体:
任意RGB色彩可以表示在3维空间,那么所谓的色相旋转就是这个RGB点绕着 图上RGB三点构成的平面的中垂线旋转角度T
如何求这个旋转矩阵呢? 我们知道这种旋转可以变为几个旋转的组合
(1)将立方体“立起来” 使中垂线变为Z轴 这个矩阵C为
[ 6^0.5/6 -2^0.5/2 3^0.5/3]
[6^0.5/6 2^0.5/2 3^0.5/3]
[-6^0.5/3 0 3^0.5/3]
(2) (1)中矩阵的反变换矩阵C‘(逆矩阵) C*C’ =[1] (单位阵)
(3) 点绕Z轴旋转矩阵R
[cos(T) sin(T) 0]
[-sin(T) cos(T) 0]
[0 0 1]
所以这个最终矩阵表示为
C*R*C'
而ARGB的色彩变换仿射矩阵最终为(矩阵分块)
[1 ]
[0 \ ]
[0 C*R*C' ]
[0 \ ]
[0 1 ]
void MakeMatrix_ChangeHue(CDibColorMatrix* pZeroMatrix, float Theta)
{
if(pZeroMatrix)
{
float sin_Theta = sin(Theta);
float cos_Theta = cos(Theta);
const float sq6_6 = 0.40825f;
const float sq3_3 = 0.57735f;
const float sq2_2 = 0.7071f;
const float sq6_3 = 0.8165f;
//
CDibColorMatrix mx_ToHSL;
mx_ToHSL[1][1] = sq6_6;
mx_ToHSL[1][2] = sq6_6;
mx_ToHSL[1][3] = -sq6_3;
mx_ToHSL[2][1] = -sq2_2;
mx_ToHSL[2][2] = sq2_2;
mx_ToHSL[3][1] = sq3_3;
mx_ToHSL[3][2] = sq3_3;
mx_ToHSL[3][3] = sq3_3;
//
CDibColorMatrix mx_ToRGB;
mx_ToRGB[1][1] = sq6_6;
mx_ToRGB[1][2] = -sq2_2;
mx_ToRGB[1][3] = sq3_3;
mx_ToRGB[2][1] = sq6_6;
mx_ToRGB[2][2] = sq2_2;
mx_ToRGB[2][3] = sq3_3;
mx_ToRGB[3][1] = -sq6_3;
mx_ToRGB[3][3] = sq3_3;
//
CDibColorMatrix mx_RotateZ;
mx_RotateZ[1][1] = cos_Theta;
mx_RotateZ[1][2] = -sin_Theta;
mx_RotateZ[2][1] = sin_Theta;
mx_RotateZ[2][2] = cos_Theta;
*pZeroMatrix = mx_ToHSL * mx_RotateZ * mx_ToRGB;
}
}