仔细看了看发现openrgss很多函数都是空着的,其中Bitmap#change_hue可能比较难实现。根据参考文献里的说法,有多种对色调(Hue)的定义。如果使用第2种定义,把RGB值当成空间中的矢量,单纯的对色调进行修改其实是沿着(111)方向的旋转。这样就只需要简单的矩阵乘法即可完成变换。为了提升计算速度,这里甚至打了个表:
void bitmap_change_hue(uint8_t *data, int size, int hue) { // make table array<double, 256 * 3> table; // thanks dongjx for generating the rotation matrix #define PI 3.14159265359 double k1 = (1 - cos(hue * PI / 180) - sqrt(3) * sin(hue * PI / 180)) / 3; double k2 = (1 - cos(hue * PI / 180) + sqrt(3) * sin(hue * PI / 180)) / 3; #undef PI double k0 = 1 - k1 - k2; double temp; temp = 0.0; for (int i = 0; i < 256; i++) { table[i] = temp; temp += k0; } temp = 0.0; for (int i = 256; i < 256 * 2; i++) { table[i] = temp; temp += k1; } temp = 0.0; for (int i = 256 * 2; i < 256 * 3; i++) { table[i] = temp; temp += k2; } // do convertion double x, y, z; for (int i = 0; i < size / 4; i++) { x = *(data); y = *(data + 1); z = *(data + 2); #define convert(x, y, z) (uint8_t)(min(255.0, max(0.0, table[x] + table[256 + y] + table[512 + z]))) *(data) = convert(x, y, z); *(data + 1) = convert(y, z, x); *(data + 2) = convert(z, x, y); #undef convert data += 4; } }
void bitmap_change_hue(uint8_t *data, int size, int hue)
{
// make table
array<double, 256 * 3> table;
// thanks dongjx for generating the rotation matrix
#define PI 3.14159265359
double k1 = (1 - cos(hue * PI / 180) - sqrt(3) * sin(hue * PI / 180)) / 3;
double k2 = (1 - cos(hue * PI / 180) + sqrt(3) * sin(hue * PI / 180)) / 3;
#undef PI
double k0 = 1 - k1 - k2;
double temp;
temp = 0.0;
for (int i = 0; i < 256; i++)
{
table[i] = temp;
temp += k0;
}
temp = 0.0;
for (int i = 256; i < 256 * 2; i++)
{
table[i] = temp;
temp += k1;
}
temp = 0.0;
for (int i = 256 * 2; i < 256 * 3; i++)
{
table[i] = temp;
temp += k2;
}
// do convertion
double x, y, z;
for (int i = 0; i < size / 4; i++)
{
x = *(data);
y = *(data + 1);
z = *(data + 2);
#define convert(x, y, z) (uint8_t)(min(255.0, max(0.0, table[x] + table[256 + y] + table[512 + z])))
*(data) = convert(x, y, z);
*(data + 1) = convert(y, z, x);
*(data + 2) = convert(z, x, y);
#undef convert
data += 4;
}
}
参考文献:
A200804-1390.pdf
(320.87 KB, 下载次数: 2)
|