… | |
… | |
3334 | |
3334 | |
3335 | uint32_t color = (a << 24) | (r << 16) | (g << 8) | b; |
3335 | uint32_t color = (a << 24) | (r << 16) | (g << 8) | b; |
3336 | |
3336 | |
3337 | /* we allow one of the 6 closest neighbouring colours */ |
3337 | /* we allow one of the 6 closest neighbouring colours */ |
3338 | /* to replace the current color, if they not used recently */ |
3338 | /* to replace the current color, if they not used recently */ |
|
|
3339 | #if 0 |
3339 | static const signed char dxyz[][3] = { |
3340 | static const unsigned char dxyz[][3] = { |
3340 | 0, 0, 0, |
3341 | 0, 0, 0, |
3341 | 0, 0, 4, |
3342 | 0, 0, 4, |
3342 | 0, 4, 0, |
|
|
3343 | 4, 0, 0, |
|
|
3344 | 0, 4, 4, |
3343 | 0, 4, 4, |
3345 | 4, 4, 0, |
3344 | 4, 4, 0, |
3346 | 4, 0, 4, |
3345 | 4, 0, 4, |
|
|
3346 | 0, 4, 0, |
|
|
3347 | 4, 0, 0, |
3347 | }; |
3348 | }; |
|
|
3349 | #else |
|
|
3350 | // silly compressed verlapping triplets version of above |
|
|
3351 | static const unsigned char dxyz[] = { |
|
|
3352 | 0, 0, 0, 4, 4, 0, 4, 0, 0, |
|
|
3353 | }; |
|
|
3354 | #endif |
3348 | |
3355 | |
3349 | static const unsigned char color_level[8][32] = { |
3356 | static const unsigned char color_level[8][32] = { |
3350 | // neighbour index |
3357 | // neighbour index |
3351 | {0, 0, 1, 0, 0, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}, |
3358 | {0, 0, 1, 0, 0, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}, |
3352 | {0, 1, 0, 1, 1, 2, 1, 1, 2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4}, |
3359 | {0, 1, 0, 1, 1, 2, 1, 1, 2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4}, |
… | |
… | |
3359 | {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6}, |
3366 | {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6}, |
3360 | }; |
3367 | }; |
3361 | |
3368 | |
3362 | unsigned int idx; |
3369 | unsigned int idx; |
3363 | |
3370 | |
3364 | for (int n = 0; n < ecb_array_length (dxyz); ++n) |
3371 | for (int n = 0; n < ecb_array_length (dxyz) - 2; ++n) |
3365 | { |
3372 | { |
3366 | unsigned int idx_r = color_level[ Red_levels - dxyz[n][0]][r / 8]; |
3373 | unsigned int idx_r = color_level[ Red_levels - dxyz[n + 0]][r / 8]; |
3367 | unsigned int idx_g = color_level[Green_levels - dxyz[n][1]][g / 8]; |
3374 | unsigned int idx_g = color_level[Green_levels - dxyz[n + 1]][g / 8]; |
3368 | unsigned int idx_b = color_level[ Blue_levels - dxyz[n][2]][b / 8]; |
3375 | unsigned int idx_b = color_level[ Blue_levels - dxyz[n + 2]][b / 8]; |
3369 | unsigned int index = colorcube_index (idx_r, idx_g, idx_b); |
3376 | unsigned int index = colorcube_index (idx_r, idx_g, idx_b); |
3370 | |
3377 | |
3371 | if (n == 0) |
3378 | if (n == 0) |
3372 | idx = index; |
3379 | idx = index; |
3373 | |
3380 | |
… | |
… | |
3383 | idx = index; |
3390 | idx = index; |
3384 | goto update; |
3391 | goto update; |
3385 | } |
3392 | } |
3386 | |
3393 | |
3387 | // like (rgb24_seqno[idx] > rgb24_seqno[index]) |
3394 | // like (rgb24_seqno[idx] > rgb24_seqno[index]) |
3388 | // but also handles wrap around values good enough |
3395 | // but also handles wrap around values well enough |
3389 | if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x7fff) |
3396 | if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x8000) |
3390 | idx = index; |
3397 | idx = index; |
3391 | } |
3398 | } |
3392 | |
3399 | |
3393 | update: |
3400 | update: |
3394 | rgb24_color[idx] = color; |
3401 | rgb24_color[idx] = color; |