diff options
author | bptato <nincsnevem662@gmail.com> | 2024-10-03 20:55:34 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-10-03 20:58:46 +0200 |
commit | 3b468ef2079b6af989d15d885fcae85a4ad504ad (patch) | |
tree | 29879113c971747f43887d26dfb88c3128376cda | |
parent | 4ca1c2e58d9f6844b3253dd208fc19dbd8c95875 (diff) | |
download | chawan-3b468ef2079b6af989d15d885fcae85a4ad504ad.tar.gz |
sixel: transparency improvements
* don't set transparency when raster attributes suffice - it seems terminals don't background-fill in that case either. * fix transparency in encoder standalone mode * update comments
-rw-r--r-- | adapter/img/sixel.nim | 10 | ||||
-rw-r--r-- | src/local/term.nim | 8 |
2 files changed, 9 insertions, 9 deletions
diff --git a/adapter/img/sixel.nim b/adapter/img/sixel.nim index 11625547..3eeacaf1 100644 --- a/adapter/img/sixel.nim +++ b/adapter/img/sixel.nim @@ -9,10 +9,7 @@ # # * DCS q set-raster-attributes is omitted. # * 32-bit binary number in header indicates the end of the following -# palette. (Note: this includes this 32-bit number's and the following 8-bit -# number's length as well.) -# * This is followed by an 8-bit number indicating whether the image includes -# transparent pixels. +# palette. (Note: this includes this 32-bit number's length as well.) # * A lookup table is appended to the file end, which includes (height + 5) / 6 # 32-bit binary numbers indicating the start index of every 6th row. # @@ -384,7 +381,10 @@ proc encode(img: openArray[RGBAColorBE]; width, height, offx, offy, cropw: int; if halfdump: # reserve size for prelude outs &= "\0\0\0\0" else: - outs &= DCS & 'q' + outs &= DCS + if transparent: + outs &= "0;1" + outs &= 'q' # set raster attributes outs &= "\"1;1;" & $width & ';' & $height let nodes = root.flatten(outs, palette) diff --git a/src/local/term.nim b/src/local/term.nim index 2d5b6c14..2550ca69 100644 --- a/src/local/term.nim +++ b/src/local/term.nim @@ -815,10 +815,10 @@ proc outputSixelImage(term: Terminal; x, y: int; image: CanvasImage; if preludeLen > data.len: return var outs = term.cursorGoto(x, y) - # set transparency if we want to draw a non-6-divisible number - # of rows *or* the image is transparent; omit it otherwise, for then - # some terminals (e.g. foot) handle the image more efficiently - let trans = realh mod 6 != 0 or image.transparent + # set transparency if the image has transparent sixels; omit it + # otherwise, for then some terminals (e.g. foot) handle the image more + # efficiently + let trans = image.transparent outs &= DCS & "0;" & $int(trans) & "q" # set raster attributes outs &= "\"1;1;" & $realw & ';' & $realh |