… | |
… | |
3365 | unsigned int idx_r = r * (Red_levels - 1) / 0xff; |
3365 | unsigned int idx_r = r * (Red_levels - 1) / 0xff; |
3366 | unsigned int idx_g = g * (Green_levels - 1) / 0xff; |
3366 | unsigned int idx_g = g * (Green_levels - 1) / 0xff; |
3367 | unsigned int idx_b = b * (Blue_levels - 1) / 0xff; |
3367 | unsigned int idx_b = b * (Blue_levels - 1) / 0xff; |
3368 | unsigned int idx = colorcube_index (idx_r, idx_g, idx_b); |
3368 | unsigned int idx = colorcube_index (idx_r, idx_g, idx_b); |
3369 | |
3369 | |
3370 | if (rgb24_color[idx] == color) |
|
|
3371 | return idx + minTermCOLOR24; |
|
|
3372 | |
|
|
3373 | /* we allow one of the 6 directly neighbouring colours */ |
3370 | /* we allow one of the 6 directly neighbouring colours */ |
3374 | /* to replace the current color, if they not used recently */ |
3371 | /* to replace the current color, if they not used recently */ |
3375 | static const signed char dxyz[][3] = { |
3372 | static const signed char dxyz[][3] = { |
3376 | 0, 0, 0, |
3373 | 0, 0, 0, |
3377 | 0, 0, +1, |
3374 | 0, 0, +1, |
… | |
… | |
3392 | if (!IN_RANGE_EXC (g, 0, Green_levels)) continue; |
3389 | if (!IN_RANGE_EXC (g, 0, Green_levels)) continue; |
3393 | if (!IN_RANGE_EXC (b, 0, Blue_levels )) continue; |
3390 | if (!IN_RANGE_EXC (b, 0, Blue_levels )) continue; |
3394 | |
3391 | |
3395 | unsigned int index = colorcube_index (r, g, b); |
3392 | unsigned int index = colorcube_index (r, g, b); |
3396 | |
3393 | |
|
|
3394 | if (rgb24_color[index] == color) |
|
|
3395 | { |
|
|
3396 | rgb24_seqno[idx] = ++rgb24_sequence; |
|
|
3397 | return index + minTermCOLOR24; |
|
|
3398 | } |
|
|
3399 | |
3397 | // minor issue: could update index 0 few more times |
3400 | // minor issue: could update index 0 few more times |
3398 | if ((rgb24_seqno[index] | rgb24_color[index]) == 0) |
3401 | if ((rgb24_seqno[index] | rgb24_color[index]) == 0) |
3399 | { |
3402 | { |
3400 | idx = index; |
3403 | idx = index; |
3401 | goto update; |
3404 | goto update; |
3402 | } |
3405 | } |
3403 | |
|
|
3404 | if (rgb24_color[index] == color) |
|
|
3405 | return index + minTermCOLOR24; |
|
|
3406 | |
3406 | |
3407 | // like (rgb24_seqno[idx] > rgb24_seqno[index]) |
3407 | // like (rgb24_seqno[idx] > rgb24_seqno[index]) |
3408 | // but also handles wrap around values good enough |
3408 | // but also handles wrap around values good enough |
3409 | if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x7fff) |
3409 | if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x7fff) |
3410 | idx = index; |
3410 | idx = index; |