… | |
… | |
3334 | free (s); |
3334 | free (s); |
3335 | } |
3335 | } |
3336 | } |
3336 | } |
3337 | } |
3337 | } |
3338 | |
3338 | |
|
|
3339 | static unsigned int |
|
|
3340 | colorcube_index (unsigned int idx_r, |
|
|
3341 | unsigned int idx_g, |
|
|
3342 | unsigned int idx_b) |
|
|
3343 | { |
|
|
3344 | assert (idx_r < Red_levels); |
|
|
3345 | assert (idx_g < Green_levels); |
|
|
3346 | assert (idx_b < Blue_levels); |
|
|
3347 | |
|
|
3348 | return idx_r * Blue_levels * Green_levels + |
|
|
3349 | idx_g * Blue_levels + |
|
|
3350 | idx_b; |
|
|
3351 | } |
|
|
3352 | |
3339 | /* |
3353 | /* |
3340 | * Find the nearest color slot in the hidden color cube, |
3354 | * Find the nearest color slot in the hidden color cube, |
3341 | * adapt its value to the 24bit RGB color. |
3355 | * adapt its value to the 24bit RGB color. |
3342 | */ |
3356 | */ |
3343 | unsigned int |
3357 | unsigned int |
3344 | rxvt_term::map_rgb24_color (unsigned int r, unsigned int g, unsigned int b) |
3358 | rxvt_term::map_rgb24_color (unsigned int r, unsigned int g, unsigned int b) |
3345 | { |
3359 | { |
|
|
3360 | r &= 0xff; |
|
|
3361 | g &= 0xff; |
|
|
3362 | b &= 0xff; |
|
|
3363 | |
|
|
3364 | unsigned int color = (r << 16) | (g << 8) | b; |
3346 | unsigned int idx_r = (r & 0xff) / (0xff / (Red_levels - 1)); |
3365 | unsigned int idx_r = r / (0xff / (Red_levels - 1)); |
3347 | unsigned int idx_g = (g & 0xff) / (0xff / (Green_levels - 1)); |
3366 | unsigned int idx_g = g / (0xff / (Green_levels - 1)); |
3348 | unsigned int idx_b = (b & 0xff) / (0xff / (Blue_levels - 1)); |
3367 | unsigned int idx_b = b / (0xff / (Blue_levels - 1)); |
3349 | unsigned int idx; |
3368 | unsigned int idx = colorcube_index (idx_r, idx_g, idx_b); |
3350 | |
3369 | |
3351 | idx = minTermCOLOR24 + idx_r * Blue_levels * Green_levels + |
3370 | // minor issue: could update idx 0 few more times |
3352 | idx_g * Blue_levels + |
3371 | if (rgb24_seqno[idx] == 0 |
3353 | idx_b; |
3372 | && rgb24_color[idx] == 0) |
|
|
3373 | goto update; |
3354 | |
3374 | |
|
|
3375 | if (rgb24_color[idx] == color) |
|
|
3376 | return idx + minTermCOLOR24; |
|
|
3377 | |
|
|
3378 | for (int i = idx_r - 1; i <= (signed) idx_r + 1; i++) |
|
|
3379 | { |
|
|
3380 | if (!IN_RANGE_EXC (i, 0, Red_levels)) |
|
|
3381 | continue; |
|
|
3382 | |
|
|
3383 | for (int j = idx_g - 1; j <= (signed) idx_g + 1; j++) |
|
|
3384 | { |
|
|
3385 | if (!IN_RANGE_EXC (j, 0, Green_levels)) |
|
|
3386 | continue; |
|
|
3387 | |
|
|
3388 | for (int k = idx_b - 1; k <= (signed) idx_b + 1; k++) |
|
|
3389 | { |
|
|
3390 | if (!IN_RANGE_EXC (k, 0, Blue_levels)) |
|
|
3391 | continue; |
|
|
3392 | |
|
|
3393 | unsigned int index = colorcube_index (i, j, k); |
|
|
3394 | |
|
|
3395 | // minor issue: could update index 0 few more times |
|
|
3396 | if (rgb24_seqno[index] == 0 |
|
|
3397 | && rgb24_color[index] == 0) |
|
|
3398 | { |
|
|
3399 | idx = index; |
|
|
3400 | goto update; |
|
|
3401 | } |
|
|
3402 | |
|
|
3403 | if (rgb24_color[index] == color) |
|
|
3404 | return index + minTermCOLOR24; |
|
|
3405 | |
|
|
3406 | if (IN_RANGE_INC (rgb24_seqno[idx], rgb24_seqno[index], 0x7fff)) |
|
|
3407 | idx = index; |
|
|
3408 | } |
|
|
3409 | } |
|
|
3410 | } |
|
|
3411 | |
|
|
3412 | update: |
|
|
3413 | rgb24_color[idx] = color; |
|
|
3414 | rgb24_seqno[idx] = ++rgb24_sequence; |
|
|
3415 | |
|
|
3416 | idx += minTermCOLOR24; |
3355 | pix_colors_focused [idx].free (this); |
3417 | pix_colors_focused [idx].free (this); |
3356 | pix_colors_focused [idx].set (this, rgba (r * 0x0101, |
3418 | pix_colors_focused [idx].set (this, rgba (r * 0x0101, |
3357 | g * 0x0101, |
3419 | g * 0x0101, |
3358 | b * 0x0101)); |
3420 | b * 0x0101)); |
3359 | update_fade_color (idx, false); |
3421 | update_fade_color (idx, false); |