emacs-framebuffer

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

commit ae6ceb067b8622ad5182b90a2c0c2e99eb3d0d3c
parent b96b08d54202a1e017de90b1166d06753d65d601
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun, 24 May 2020 04:50:33 +0200

use framebuffer-jpeg-size instead of file program

Diffstat:
Memacs-framebuffer.el | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -10,8 +10,6 @@ ;;; ;;; - w3mimgdisplay from w3m terminal web browser ;;; -;;; - file program -;;; ;;; Example configuration: ;;; ;;; (require 'framebuffer) @@ -79,15 +77,30 @@ (cons (framebuffer-next-u32 brook) (framebuffer-next-u32 brook)))))) +(defun framebuffer-jpeg-size (file) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally file) + (let ((brook (framebuffer-buffer-brook))) + (when (and (= #xff (framebuffer-next-u8 brook)) + (= #xd8 (framebuffer-next-u8 brook))) + (let ((n 0) + (m 0)) + (while (not (<= #xc0 m #xcf)) + (goto-char (+ (point) n)) + (while (= #xff (setq m (framebuffer-next-u8 brook)))) + (setq n (- (framebuffer-next-u16 brook) 2))) + (framebuffer-next-u8 brook) + (let ((h (framebuffer-next-u16 brook))) + (cons (framebuffer-next-u16 brook) + h))))))) + (defun framebuffer-image-size (file) (cond ((string-match "png\\|PNG" (file-name-extension file)) (framebuffer-png-size file)) - (t - (with-temp-buffer - (call-process "file" nil t nil (expand-file-name file)) - (search-backward-regexp ", \\([0-9]+\\)+x\\([0-9]+\\),") - (cons (read (match-string 1)) (read (match-string 2))))))) + ((string-match "jpe?g\\|JPE?G" (file-name-extension file)) + (framebuffer-jpeg-size file)))) (defun framebuffer-image-file (file) (interactive "fFile: ")