diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-15 01:15:54 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-15 01:15:54 +0200 |
commit | 1ae5f2a85d833631c399eab6d756b6fabf105aca (patch) | |
tree | c751a3e20d701998097ff6ace2bf72b9e8a2ab95 | |
parent | 36390a564a191a92d470bb650e693546623774af (diff) | |
download | chawan-1ae5f2a85d833631c399eab6d756b6fabf105aca.tar.gz |
Revert "renderdocument: bgcolor blending"
This reverts commit c13a4cf4e144f7ab36167ebbb1333f7faeed11b3. Clearly it's broken. Needs a fix.
-rw-r--r-- | src/render/renderdocument.nim | 29 | ||||
-rw-r--r-- | src/types/color.nim | 18 |
2 files changed, 21 insertions, 26 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim index 00719023..d18dbdd5 100644 --- a/src/render/renderdocument.nim +++ b/src/render/renderdocument.nim @@ -14,9 +14,9 @@ import types/color import utils/twtstr func formatFromWord(computed: ComputedFormat): Format = - result.fgcolor = cellColor(computed.color) + result.fgcolor = computed.color.cellColor() if computed.bgcolor.a != 0: - result.bgcolor = cellColor(computed.bgcolor) + result.bgcolor = computed.bgcolor.cellColor() if computed.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }: result.italic = true if computed.fontweight > 500: @@ -127,25 +127,28 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat, lnode = lines[y].formats[fi].node if lines[y].formats[fi].pos == x: # Replace. - # We must check if the old string's last x position is greater than - # the new string's first x position. If not, we cannot inherit - # its bgcolor (which is supposed to end before the new string started.) - if nx > cx: - format.bgcolor = lines[y].formats[fi].format.bgcolor.blend(format.bgcolor) + if cformat.bgcolor.a == 0: #TODO alpha blending + # We must check if the old string's last x position is greater than + # the new string's first x position. If not, we cannot inherit + # its bgcolor (which is supposed to end before the new string started.) + if nx > cx: + format.bgcolor = lines[y].formats[fi].format.bgcolor lines[y].formats.delete(fi) lines[y].insertFormat(x, fi, format, cformat.node) else: # First format's pos < x => split it up. assert lines[y].formats[fi].pos < x - if nx > cx: # see above - format.bgcolor = format.bgcolor.blend(lines[y].formats[fi].format.bgcolor) + if cformat.bgcolor.a == 0: #TODO alpha blending + if nx > cx: # see above + format.bgcolor = lines[y].formats[fi].format.bgcolor inc fi # insert after first format lines[y].insertFormat(x, fi, format, cformat.node) inc fi # skip last format while fi < lines[y].formats.len and lines[y].formats[fi].pos < nx: # Other formats must be > x => replace them - format.bgcolor = lines[y].formats[fi].format.bgcolor + if cformat.bgcolor.a == 0: #TODO alpha blending + format.bgcolor = lines[y].formats[fi].format.bgcolor let px = lines[y].formats[fi].pos lformat = lines[y].formats[fi].format # save for later use lnode = lines[y].formats[fi].node @@ -197,7 +200,7 @@ proc setSpacing(lines: var FlexibleGrid, spacing: InlineSpacing, x, y: int, wind lines.setText(linestr, spacing.format, x, y) proc paintBackground(lines: var FlexibleGrid, color: RGBAColor, startx, starty, endx, endy: int, node: StyledNode, window: WindowAttributes) = - let color = cellColor(color) + let color = color.cellColor() var starty = starty div window.ppl var endy = endy div window.ppl @@ -330,8 +333,8 @@ proc renderBlockBox(grid: var FlexibleGrid, box: BlockBox, x, y: int, window: Wi posy = y if box.computed{"visibility"} == VISIBILITY_VISIBLE: - grid.paintBackground(box.computed{"background-color"}, x, y, - x + box.width, y + box.height, box.node, window) + if box.computed{"background-color"}.a != 0: #TODO color blending + grid.paintBackground(box.computed{"background-color"}, x, y, x + box.width, y + box.height, box.node, window) if box.computed{"background-image"}.t == CONTENT_IMAGE and box.computed{"background-image"}.s != "": # ugly hack for background-image display... TODO actually display images let s = "[img]" diff --git a/src/types/color.nim b/src/types/color.nim index b970b25d..b0f3a67f 100644 --- a/src/types/color.nim +++ b/src/types/color.nim @@ -27,18 +27,12 @@ func `==`*(a, b: RGBAColor): bool {.borrow.} func rgbcolor*(color: CellColor): RGBColor = cast[RGBColor](color.n) -func rgbacolor*(color: CellColor): RGBColor = - cast[RGBColor](color.n) - func color*(color: CellColor): uint8 = cast[uint8](color.n) func cellColor*(rgb: RGBColor): CellColor = return CellColor(rgb: true, n: uint32(rgb)) -func cellColor*(rgba: RGBAColor): CellColor = - return CellColor(rgb: true, n: uint32(rgba)) - func cellColor*(c: uint8): CellColor = return CellColor(rgb: false, n: uint32(c)) @@ -311,10 +305,6 @@ proc straight*(c: RGBAColor): RGBAColor = return rgba(r, g, b, c.a) func blend*(c0, c1: RGBAColor): RGBAColor = - if c0.a == 0: - return c1 - if c1.a == 0: - return c0 let pc0 = c0.premul() let pc1 = c1.premul() let k = 255 - pc1.a @@ -327,9 +317,11 @@ func blend*(c0, c1: RGBAColor): RGBAColor = let res = straight(pres) return res -# Kind of a hack, as we don't actually check if CellColor is rgbacolor. -func blend*(c0, c1: CellColor): CellColor = - return cellColor(c0.rgbacolor.blend(c1.rgbacolor)) +#func blend*(c0, c1: RGBAColor): RGBAColor = +# const norm = 1f64 / 255f64 +# let c0a = float64(c0.a) * norm +# let c1a = float64(c1.a) * norm +# let a0 = c0a + c1a * (1 - c0a) func rgb*(r, g, b: uint8): RGBColor = return RGBColor((uint32(r) shl 16) or (uint32(g) shl 8) or uint32(b)) |