commit 8cb784ccb1692f96f7f4e07de63f5339322b1a94 parent 595d3743d2638efbf8894668dcc96ce5ceaaafbd Author: Tomas Hlavaty <tom@logand.com> Date: Sun, 24 May 2020 06:48:40 +0200 support bmp and gif Diffstat:
M | emacs-framebuffer.el | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++------ |
1 file changed, 46 insertions(+), 6 deletions(-)
diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -72,10 +72,18 @@ (+ (* 256 (framebuffer-next-u8 brook)) (framebuffer-next-u8 brook))) +(defun framebuffer-next-u16le (brook) + (+ (framebuffer-next-u8 brook) + (* 256 (framebuffer-next-u8 brook)))) + (defun framebuffer-next-u32 (brook) (+ (* 65536 (framebuffer-next-u16 brook)) (framebuffer-next-u16 brook))) +(defun framebuffer-next-u32le (brook) + (+ (framebuffer-next-u16le brook) + (* 65536 (framebuffer-next-u16le brook)))) + (defun framebuffer-png-size (file) (with-temp-buffer (set-buffer-multibyte nil) @@ -116,12 +124,43 @@ (cons (framebuffer-next-u16 brook) h))))))) +(defun framebuffer-bmp-size (file) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally file) + (let ((brook (framebuffer-buffer-brook))) + (when (and (= ?B (framebuffer-next-u8 brook)) + (= ?M (framebuffer-next-u8 brook))) + (dotimes (i 16) + (framebuffer-next-u8 brook)) + (cons (framebuffer-next-u32le brook) + (framebuffer-next-u32le brook)))))) + +(defun framebuffer-gif-size (file) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally file) + (let ((brook (framebuffer-buffer-brook))) + (when (and (= ?G (framebuffer-next-u8 brook)) + (= ?I (framebuffer-next-u8 brook)) + (= ?F (framebuffer-next-u8 brook)) + (= ?8 (framebuffer-next-u8 brook)) + (member (framebuffer-next-u8 brook) '(?7 ?9)) + (= ?a (framebuffer-next-u8 brook))) + (cons (framebuffer-next-u16le brook) + (framebuffer-next-u16le brook)))))) + (defun framebuffer-image-size (file) - (cond - ((string-match "png\\|PNG" (file-name-extension file)) - (framebuffer-png-size file)) - ((string-match "jpe?g\\|JPE?G" (file-name-extension file)) - (framebuffer-jpeg-size file)))) + (let ((e (file-name-extension file))) + (cond + ((string-match "png\\|PNG" e) + (framebuffer-png-size file)) + ((string-match "jpe?g\\|JPE?G" e) + (framebuffer-jpeg-size file)) + ((string-match "bmp\\|BMP" e) + (framebuffer-bmp-size file)) + ((string-match "gif\\|GIF" e) + (framebuffer-gif-size file))))) (defun framebuffer-image-file (file) (interactive "fFile: ") @@ -143,7 +182,8 @@ (defun framebuffer-dired-image-p () (let ((f (dired-file-name-at-point))) (and (not (file-directory-p f)) - (string-match "jpe?g\\|JPE?G\\|png\\|PNG" (file-name-extension f))))) + (string-match "jpe?g\\|JPE?G\\|png\\|PNG\\|bmp\\|BMP\\|gif\\|GIF" + (file-name-extension f))))) (defun framebuffer-image-file-dired-next (arg) (interactive "^p")