mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-10 23:58:30 +01:00
Avoid floating point arithmetic in RGB→8-bit ANSI approximation
This commit is contained in:
parent
5b421b455d
commit
5c95b8803b
@ -13,14 +13,10 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
|
|||||||
} else if r > 248 {
|
} else if r > 248 {
|
||||||
WHITE
|
WHITE
|
||||||
} else {
|
} else {
|
||||||
let fr = f32::from(r);
|
((r - 8) as u16 * 24 / 247) as u8 + 232
|
||||||
(((fr - 8.) / 247.) * 24.) as u8 + 232
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let fr = f32::from(r);
|
36 * (r / 51) + 6 * (g / 51) + (b / 51) + 16
|
||||||
let fg = f32::from(g);
|
|
||||||
let fb = f32::from(b);
|
|
||||||
16 + (36 * (fr / 255. * 5.) as u8) + (6 * (fg / 255. * 5.) as u8) + (fb / 255. * 5.) as u8
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user