RGB Chips - DCTL
RGB Chips - DCTL
// clang-format on
#define PI (3.1415926535)
float rot_mat_inv[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
float rot_mat2_inv[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
make_rotation_mat_axis_angle(rot_mat_inv, unit_vec(cross_product(red_axis,
achromatic)), _acosf(dot_product(red_axis, unit_vec(achromatic))));
make_rotation_mat_axis_angle(rot_mat2_inv, red_axis, -3.0 * PI / 4.0);
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R,
float p_G, float p_B) {
uint state = seed;
if (vertical) {
float temp = x;
x = y;
y = temp;
}
float curr_row_cont = y * (num_hues + gray_ramp) - gray_ramp;
float curr_col_cont = x * num_cols;
float curr_row = curr_row_cont;
float curr_col = curr_col_cont;
if (shuffle == SHUFFLE_HUES) {
randu(&state);
randu(&state);
randu(&state);
curr_row_cont = shuffle_rows(curr_row_cont, num_hues, gray_ramp, &state);
curr_row = curr_row_cont;
}
if (band_interval == EXPONENTIAL) {
curr_col -= _round(num_cols / 2.0);
}
float3 rgb;
float3 hsv;
if (band_interval == EQUAL) {
if (gray_ramp && curr_row < 0) {
hsv = make_float3(0.0, 0.0, curr_col / num_cols);
} else {
hsv = make_float3((curr_row / num_hues) * 360.0, saturation, curr_col /
num_cols);
}
} else if (band_interval == EXPONENTIAL) {
if (gray_ramp && curr_row < 0) {
hsv = make_float3(0.0, 0.0, _exp2f(curr_col) * mid_gray);
} else {
hsv = make_float3((curr_row / num_hues) * 360.0, saturation,
_exp2f(curr_col) * mid_gray);
}
}
if (!is_gap) {
if (model == SPHERICAL) {
rgb = spherical_to_rgb(hsv.x, hsv.y, hsv.z);
} else if (model == HSV) {
rgb = hsv_to_rgb(hsv.x, hsv.y, hsv.z);
}
}
if (clamp_output) {
if (rgb.x > clamp_output_max || rgb.y > clamp_output_max || rgb.z >
clamp_output_max || rgb.x < clamp_output_min || rgb.y < clamp_output_min ||
rgb.z < clamp_output_min) {
rgb = make_float3(clamp_output_min, clamp_output_min,
clamp_output_min);
}
}
return rgb;
}