diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-10 21:53:18 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-10 23:25:31 +0200 |
commit | f981b996808394cb46a4e154ba51525b6574fddf (patch) | |
tree | 679f152c9f1a526c5e902ba0c9c15b54c2cd7f5a | |
parent | 66d3e44336f5ceb3ae1e7531203c9fa4b73d696f (diff) | |
download | chawan-f981b996808394cb46a4e154ba51525b6574fddf.tar.gz |
Fix color U, slightly change contrast algorithm
-rw-r--r-- | res/config.toml | 2 | ||||
-rw-r--r-- | src/display/term.nim | 19 | ||||
-rw-r--r-- | src/types/color.nim | 8 |
3 files changed, 19 insertions, 10 deletions
diff --git a/res/config.toml b/res/config.toml index 10b246a4..ae1d5984 100644 --- a/res/config.toml +++ b/res/config.toml @@ -27,7 +27,7 @@ emulate-overline = true alt-screen = "auto" highlight-color = "cyan" double-width-ambiguous = false -minimum-contrast = 75 +minimum-contrast = 100 force-clear = false set-title = true diff --git a/src/display/term.nim b/src/display/term.nim index 332ecd33..9f1c3c33 100644 --- a/src/display/term.nim +++ b/src/display/term.nim @@ -233,13 +233,22 @@ proc correctContrast(bgcolor, fgcolor: CellColor, contrast: int): CellColor = let bgcolor = getRGB(bgcolor, true) let fgcolor = getRGB(fgcolor, false) let bgY = int(bgcolor.Y) - let fgY = int(fgcolor.Y) + var fgY = int(fgcolor.Y) let diff = abs(bgY - fgY) if diff < contrast: - let neg = max(bgY - contrast, 0) - let pos = min(bgY + contrast, 255) - let condiff = if abs(bgY - neg) < abs(bgY - pos): pos else: neg - let newrgb = YUV(cast[uint8](condiff), fgcolor.U, fgcolor.V) + if bgY > fgY: + fgY = bgY - contrast + if fgY < 0: + fgY = bgY + contrast + if fgY > 255: + fgY = 0 + else: + fgY = bgY + contrast + if fgY > 255: + fgY = bgY - contrast + if fgY < 0: + fgY = 255 + let newrgb = YUV(cast[uint8](fgY), fgcolor.U, fgcolor.V) if cfgcolor.rgb: return newrgb.cellColor() return ColorsANSIFg[approximateANSIColor(newrgb)] diff --git a/src/types/color.nim b/src/types/color.nim index 1aa0c777..b0f3a67f 100644 --- a/src/types/color.nim +++ b/src/types/color.nim @@ -346,7 +346,7 @@ func U*(c: RGBColor): uint8 = let rmul = uint16(c.r) * 38u16 let gmul = uint16(c.g) * 74u16 let bmul = uint16(c.b) * 112u16 - return cast[uint8](((128 + gmul - rmul - bmul) shr 8) + 128) + return cast[uint8](((128 + bmul - rmul - gmul) shr 8) + 128) func V*(c: RGBColor): uint8 = let rmul = uint16(c.r) * 112u16 @@ -355,9 +355,9 @@ func V*(c: RGBColor): uint8 = return cast[uint8](((128 + rmul - gmul - bmul) shr 8) + 128) func YUV*(Y, U, V: uint8): RGBColor = - let C = uint16(Y) - 16 - let D = uint16(U) - 128 - let E = uint16(V) - 128 + let C = int(Y) - 16 + let D = int(U) - 128 + let E = int(V) - 128 let r = max(min((298 * C + 409 * E + 128) shr 8, 255), 0) let g = max(min((298 * C - 100 * D - 208 * E + 128) shr 8, 255), 0) let b = max(min((298 * C + 516 * D + 128) shr 8, 255), 0) |