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 /src/display | |
parent | 66d3e44336f5ceb3ae1e7531203c9fa4b73d696f (diff) | |
download | chawan-f981b996808394cb46a4e154ba51525b6574fddf.tar.gz |
Fix color U, slightly change contrast algorithm
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/term.nim | 19 |
1 files changed, 14 insertions, 5 deletions
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)] |