emacs-framebuffer

Emacs library to show images and documents in console using Linux framebuffer
Log | Files | Refs

commit e75ca19318dcfaef7750b422baa5463125638e7f
parent dd8128fa30ea2099f000cd3b40a9cc0435f282ae
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun, 11 Oct 2020 00:04:47 +0200

use framebuffer stride for correct buffer width

Diffstat:
Memacs-framebuffer.el | 18+++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -85,7 +85,7 @@ ((string-match "\\.\\(xpm\\|XPM\\)\\'" name) 'xpm) ))) -(defun framebuffer-virtual-size () +(defun framebuffer-virtual-size () ;; TODO rm unused? (with-temp-buffer ;; TODO which framebuffer if more than one? (insert-file-contents "/sys/class/graphics/fb0/virtual_size") @@ -98,6 +98,12 @@ (insert-file-contents "/sys/class/graphics/fb0/bits_per_pixel") (read (current-buffer)))) +(defun framebuffer-stride () + (with-temp-buffer + ;; TODO which framebuffer if more than one? + (insert-file-contents "/sys/class/graphics/fb0/stride") + (read (current-buffer)))) + (defun framebuffer-size () (if (and framebuffer-width framebuffer-height) (cons framebuffer-width framebuffer-height) @@ -635,6 +641,7 @@ (destructuring-bind (x1 y1 x2 y2) (window-edges (get-buffer-window) t) (let* ((fw (frame-width)) (fh (frame-height)) + (stride (framebuffer-stride)) (cw (floor fbw fw)) (ch (floor fbh fh)) (wx (* x1 cw)) @@ -647,7 +654,7 @@ (ecase (framebuffer-bits-per-pixel) (32 (dotimes (y wh) - (goto-char (+ (point-min) (* 4 vw (+ y wy)) (* 4 wx))) + (goto-char (+ (point-min) (* stride (+ y wy)) (* 4 wx))) (dotimes (x ww) (delete-char 4) (insert (mod x 256)) @@ -671,6 +678,7 @@ (set-buffer-multibyte nil) (insert-file-contents-literally "/dev/fb0") (let ((bpp (framebuffer-bits-per-pixel)) + (stride (framebuffer-stride)) (fb (current-buffer))) (with-temp-buffer (set-buffer-multibyte nil) @@ -682,7 +690,7 @@ (32 (dotimes (y h) (with-current-buffer fb - (goto-char (+ (point-min) (* 4 vw y)))) + (goto-char (+ (point-min) (* stride y)))) (let ((i 0) (n 0)) (dotimes (x w) @@ -711,7 +719,7 @@ (32 (dotimes (y h) (with-current-buffer fb - (goto-char (+ (point-min) (* 4 vw y)))) + (goto-char (+ (point-min) (* stride y)))) (dotimes (x w) (let (r g b a) (with-current-buffer fb @@ -731,7 +739,7 @@ (32 (dotimes (y h) (with-current-buffer fb - (goto-char (+ (point-min) (* 4 vw y)))) + (goto-char (+ (point-min) (* stride y)))) (dotimes (x w) (let (r g b a) (with-current-buffer fb