about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-09-24 01:44:35 +0200
committerbptato <nincsnevem662@gmail.com>2024-09-24 01:49:20 +0200
commit3079e91c8aa0d60223deddd46cc3e652f32f05b7 (patch)
treefe54a3d14509dcd193401ab0ffd69f21fca9828b
parentd7085253b704f8f0e31fa1cacf82a55399565da1 (diff)
downloadchawan-3079e91c8aa0d60223deddd46cc3e652f32f05b7.tar.gz
sixel: use inline background for blending
still not really great, because inline background is a mess too
-rw-r--r--src/io/bufreader.nim4
-rw-r--r--src/io/bufwriter.nim4
-rw-r--r--src/layout/renderdocument.nim4
-rw-r--r--src/local/pager.nim2
-rw-r--r--src/local/term.nim2
-rw-r--r--src/types/color.nim3
6 files changed, 13 insertions, 6 deletions
diff --git a/src/io/bufreader.nim b/src/io/bufreader.nim
index 718e6d55..d4eb9953 100644
--- a/src/io/bufreader.nim
+++ b/src/io/bufreader.nim
@@ -24,6 +24,7 @@ proc sread*(reader: var BufferedReader; obj: var ref object)
 proc sread*[T](reader: var BufferedReader; o: var Option[T])
 proc sread*[T, E](reader: var BufferedReader; o: var Result[T, E])
 proc sread*(reader: var BufferedReader; c: var ARGBColor)
+proc sread*(reader: var BufferedReader; c: var RGBColor)
 
 proc initReader*(stream: DynStream; len, auxLen: int): BufferedReader =
   assert len != 0
@@ -149,3 +150,6 @@ proc sread*[T, E](reader: var BufferedReader; o: var Result[T, E]) =
 
 proc sread*(reader: var BufferedReader; c: var ARGBColor) =
   reader.sread(uint32(c))
+
+proc sread*(reader: var BufferedReader; c: var RGBColor) =
+  reader.sread(uint32(c))
diff --git a/src/io/bufwriter.nim b/src/io/bufwriter.nim
index 3eea01fa..3bedf883 100644
--- a/src/io/bufwriter.nim
+++ b/src/io/bufwriter.nim
@@ -34,6 +34,7 @@ proc swrite*(writer: var BufferedWriter; obj: ref object)
 proc swrite*[T](writer: var BufferedWriter; o: Option[T])
 proc swrite*[T, E](writer: var BufferedWriter; o: Result[T, E])
 proc swrite*(writer: var BufferedWriter; c: ARGBColor)
+proc swrite*(writer: var BufferedWriter; c: RGBColor)
 
 const InitLen = sizeof(int) * 2
 const SizeInit = max(64, InitLen)
@@ -151,3 +152,6 @@ proc swrite*[T, E](writer: var BufferedWriter; o: Result[T, E]) =
 
 proc swrite*(writer: var BufferedWriter; c: ARGBColor) =
   writer.swrite(uint32(c))
+
+proc swrite*(writer: var BufferedWriter; c: RGBColor) =
+  writer.swrite(uint32(c))
diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim
index 9622d305..76042ae2 100644
--- a/src/layout/renderdocument.nim
+++ b/src/layout/renderdocument.nim
@@ -231,6 +231,7 @@ type
     width*: int
     height*: int
     bmp*: NetworkBitmap
+    bgcolor*: RGBColor
 
   AbsolutePos = object
     offset: Offset
@@ -379,7 +380,8 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState;
           y: (offset.y div state.attrs.ppl).toInt,
           width: atom.size.w.toInt,
           height: atom.size.h.toInt,
-          bmp: atom.bmp
+          bmp: atom.bmp,
+          bgcolor: bgcolor0.toRGBColor()
         ))
   if fragment.computed{"position"} != PositionStatic:
     if fragment.splitType != {stSplitStart, stSplitEnd}:
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 58ab9d77..31d21b6e 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -578,7 +578,7 @@ proc loadCachedImage(pager: Pager; container: Container; image: PosBitmap;
       url = newURL("img-codec+x-sixel:encode").get
       headers.add("Cha-Image-Sixel-Halfdump", "1")
       headers.add("Cha-Image-Sixel-Palette", $pager.term.sixelRegisterNum)
-      headers.add("Cha-Image-Background-Color", $pager.term.defaultBackground)
+      headers.add("Cha-Image-Background-Color", $image.bgcolor)
       headers.add("Cha-Image-Offset", $offx & 'x' & $erry)
       headers.add("Cha-Image-Crop-Width", $dispw)
     of imKitty:
diff --git a/src/local/term.nim b/src/local/term.nim
index 0495cc8e..0e245256 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -102,7 +102,7 @@ type
     stdinUnblocked: bool
     stdinWasUnblocked: bool
     origTermios: Termios
-    defaultBackground*: RGBColor
+    defaultBackground: RGBColor
     defaultForeground: RGBColor
     ibuf*: string # buffer for chars when we can't process them
     sixelRegisterNum*: int
diff --git a/src/types/color.nim b/src/types/color.nim
index e1317e0d..ab8d4984 100644
--- a/src/types/color.nim
+++ b/src/types/color.nim
@@ -436,9 +436,6 @@ func toEightBit*(c: RGBColor): EightBitColor =
 func toEightBit*(c: RGBAColorBE): EightBitColor =
   return toEightBit(c.r, c.g, c.b)
 
-template `$`*(rgbcolor: RGBColor): string =
-  "rgb(" & $rgbcolor.r & ", " & $rgbcolor.g & ", " & $rgbcolor.b & ")"
-
 template `$`*(color: CellColor): string =
   case color.t
   of ctNone: "none"