about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-23 02:56:39 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-23 02:58:18 +0200
commit2cc62cd65007913f6d46318f1cc46299b7878159 (patch)
tree4cefc9aa94659bfe6ca2a5ba0dd8438e18eb9c99
parent03ac991def7e517ef2e035beed8bd6d4338b07a0 (diff)
downloadchawan-2cc62cd65007913f6d46318f1cc46299b7878159.tar.gz
term: fix positionImage sixel size clamping
clamping maxwpx/maxhpx crops the image starting from the canvas
corner, not the image corner
-rw-r--r--src/local/term.nim16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/local/term.nim b/src/local/term.nim
index 109c6710..4d915ec7 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -647,13 +647,17 @@ proc positionImage(term: Terminal; image: CanvasImage; x, y, maxw, maxh: int):
   image.offy = -min(ypx, 0)
   # calculate maximum image size that fits on the screen relative to the image
   # origin (*not* offx/offy)
-  var maxwpx = maxw * term.attrs.ppc
-  var maxhpx = maxh * term.attrs.ppl
+  let maxwpx = maxw * term.attrs.ppc
+  let maxhpx = maxh * term.attrs.ppl
+  var width = int(image.bmp.width)
+  var height = int(image.bmp.height)
   if term.imageMode == imSixel:
-    maxwpx = min(maxwpx, term.sixelMaxWidth)
-    maxhpx = min(maxhpx, term.sixelMaxHeight)
-  image.dispw = min(int(image.bmp.width) + xpx, maxwpx) - xpx
-  image.disph = min(int(image.bmp.height) + ypx, maxhpx) - ypx
+    #TODO a better solution would be to split up the image here so that it
+    # still gets fully displayed on the screen, or at least downscale it...
+    width = min(width, term.sixelMaxWidth)
+    height = min(height, term.sixelMaxHeight)
+  image.dispw = min(width + xpx, maxwpx) - xpx
+  image.disph = min(height + ypx, maxhpx) - ypx
   image.damaged = true
   return image.dispw > image.offx and image.disph > image.offy