mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-29 03:23:22 +01:00
Use ints for the calculations rather than u_char, they could end up
signed.
This commit is contained in:
parent
55b96a5bd5
commit
ed6c036ee3
9
colour.c
9
colour.c
@ -313,6 +313,7 @@ colour_find_rgb(u_char r, u_char g, u_char b)
|
|||||||
{
|
{
|
||||||
struct colour_rgb rgb = { .r = r, .g = g, .b = b }, *found;
|
struct colour_rgb rgb = { .r = r, .g = g, .b = b }, *found;
|
||||||
u_int distance, lowest, colour, i;
|
u_int distance, lowest, colour, i;
|
||||||
|
int dr, dg, db;
|
||||||
|
|
||||||
found = bsearch(&rgb, colour_to_256, nitems(colour_to_256),
|
found = bsearch(&rgb, colour_to_256, nitems(colour_to_256),
|
||||||
sizeof colour_to_256[0], colour_cmp_rgb);
|
sizeof colour_to_256[0], colour_cmp_rgb);
|
||||||
@ -322,11 +323,11 @@ colour_find_rgb(u_char r, u_char g, u_char b)
|
|||||||
colour = 16;
|
colour = 16;
|
||||||
lowest = UINT_MAX;
|
lowest = UINT_MAX;
|
||||||
for (i = 0; i < 240; i++) {
|
for (i = 0; i < 240; i++) {
|
||||||
r = colour_from_256[i].r - rgb.r;
|
dr = (int)colour_from_256[i].r - r;
|
||||||
g = colour_from_256[i].g - rgb.g;
|
dg = (int)colour_from_256[i].g - g;
|
||||||
b = colour_from_256[i].b - rgb.b;
|
db = (int)colour_from_256[i].b - b;
|
||||||
|
|
||||||
distance = r * r + g * g + b * b;
|
distance = dr * dr + dg * dg + db * db;
|
||||||
if (distance < lowest) {
|
if (distance < lowest) {
|
||||||
lowest = distance;
|
lowest = distance;
|
||||||
colour = 16 + i;
|
colour = 16 + i;
|
||||||
|
Loading…
Reference in New Issue
Block a user