commit f9e45a83702d2c8c26d6e35bd5ff71d4972d86ec parent 3e88d3fe5168adef96bf95c722a7129ff7dbea0c Author: Tomas Hlavaty <tom@logand.com> Date: Sat, 20 Jun 2020 00:15:10 +0200 add framebuffer-screenshot Diffstat:
M | emacs-framebuffer.el | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 40 insertions(+), 0 deletions(-)
diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -50,6 +50,12 @@ (defvar framebuffer-size nil) +(defun framebuffer-file-format (file) + (let ((ext (file-name-extension file))) + (cond + ((equal ext "ppm") 'ppm) + ))) + (defun framebuffer-virtual-size () (with-temp-buffer ;; TODO which framebuffer if more than one? @@ -346,4 +352,38 @@ (let ((coding-system-for-write 'raw-text-unix)) (write-region (point-min) (point-max) "/dev/fb0")))))))) +(defun framebuffer-screenshot (&optional file) + (interactive "FFile: ") + (destructuring-bind (w &rest h) (framebuffer-size) + (destructuring-bind (vw &rest vh) (framebuffer-virtual-size) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally "/dev/fb0") + (let ((bpp (framebuffer-bits-per-pixel)) + (fb (current-buffer))) + (with-temp-buffer + (set-buffer-multibyte nil) + (ecase (framebuffer-file-format file) + (ppm + (insert "P6\n") + (insert (format "%d %d\n" w h)) + (insert "255\n") + (ecase bpp + (32 + (dotimes (y h) + (with-current-buffer fb + (goto-char (+ (point-min) (* 4 vw y)))) + (dotimes (x w) + (let (r g b a) + (with-current-buffer fb + (setq b (char-after) + g (char-after (goto-char (1+ (point)))) + r (char-after (goto-char (1+ (point)))) + a (char-after (goto-char (1+ (point))))) + (goto-char (1+ (point)))) + (insert r g b)))))) + (let ((coding-system-for-write 'raw-text-unix)) + (write-region (point-min) (point-max) file))))))))) + (find-file file)) + (provide 'framebuffer)