|
20 | 20 |
|
21 | 21 | function to_256_colors(color::ANSIColor) |
22 | 22 | @assert color.style == COLORS_24BIT |
23 | | - r, g, b = color.r, color.g, color.b |
24 | | - r24, g24, b24 = map(c->round(Int, c * 23 / 256), (r, g, b)) |
25 | | - if r24 == g24 == b24 |
26 | | - return ANSIColor(UInt8(232 + r24), COLORS_256, color.active) |
| 23 | + r, g, b = rgb = color.r, color.g, color.b |
| 24 | + ansi = if r == g == b && r % 10 == 8 |
| 25 | + 232 + min((r - 8) ÷ 10, 23) # gray level |
| 26 | + elseif all(map(c -> (c & 0x1) == 0 && (c > 0 ? c == 128 || c == 192 : true), rgb)) |
| 27 | + (r >> 7) + 2(g >> 7) + 4(b >> 7) # primary color |
27 | 28 | else |
28 | | - r6, g6, b6 = map(c->round(Int, c * 5 / 256), (r, g, b)) |
29 | | - return ANSIColor(UInt8(16 + 36 * r6 + 6 * g6 + b6), COLORS_256, color.active) |
| 29 | + r6, g6, b6 = map(c -> c < 48 ? 0 : (c < 114 ? 1 : trunc(Int, (c - 35) / 40)), rgb) |
| 30 | + 16 + 36r6 + 6g6 + b6 # cube 6x6x6 |
30 | 31 | end |
| 32 | + return ANSIColor(UInt8(ansi), COLORS_256, color.active) |
31 | 33 | end |
32 | 34 |
|
33 | 35 | # 24bit -> 16 system colors |
|
54 | 56 | function compute_value(r, g, b) |
55 | 57 | r′, g′, b′ = (r, g, b) ./ 255 |
56 | 58 | Cmax = max(r′, g′, b′) |
57 | | - return Cmax * 100 |
| 59 | + return 100Cmax |
58 | 60 | #= |
59 | 61 | # This is not needed |
60 | 62 | Cmin = min(r′, g′, b′) |
@@ -85,10 +87,11 @@ function to_system_colors(color::ANSIColor) |
85 | 87 | if (value == 0) |
86 | 88 | ansi = 0 |
87 | 89 | else |
88 | | - ansi = |
89 | | - ((round(Int, b / 255) << 2) | |
90 | | - (round(Int, g / 255) << 1) | |
91 | | - round(Int, r / 255)) |
| 90 | + ansi = ( |
| 91 | + (round(Int, b / 255) << 2) | |
| 92 | + (round(Int, g / 255) << 1) | |
| 93 | + round(Int, r / 255) |
| 94 | + ) |
92 | 95 | value == 2 && (ansi += 60) |
93 | 96 | end |
94 | 97 | return ANSIColor(UInt8(ansi), COLORS_16, color.active) |
|
0 commit comments