From 819366690f61cab4ef197ad1cfac92dac4130848 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Mon, 20 May 2019 23:41:16 +0200 Subject: [PATCH] Close to working, insert-image broken somehow though. --- sixel.el | 68 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/sixel.el b/sixel.el index f2532e5..8147c8f 100644 --- a/sixel.el +++ b/sixel.el @@ -17,7 +17,7 @@ (concat "q" "#0;2;0;0;0#1;2;100;100;0#2;2;0;100;0" "#1~~@@vv@@~~@@~~$" - "#2??GG????-" + "#2??}}GG}}??}}??-" "#1!14@")) (defun sixel-get-params (string) @@ -111,32 +111,61 @@ Returns a sixel image object." (let ((sixels (sixel-image-sixels sixel-image))) (cons (apply #'max (mapcar (lambda (row) (length row)) sixels)) - (length sixels)))) + (* 6 (length sixels))))) (defun sixel-image-to-xpm-values (sixel-image) + "Produce string representing parameter values component of XPM +representation of SIXEL-IMAGE." (let* ((dims (sixel-image-dims sixel-image)) (colour-map (sixel-image-colour-map sixel-image)) - (n-colours (length colour-map))) + (n-colours (1+ (length colour-map)))) (concat "\"" (number-to-string (car dims)) " " (number-to-string (cdr dims)) " " (number-to-string n-colours) " 2\""))) (defun sixel-image-to-xpm-colours (sixel-image) + "Produce string representing colour definitions component of XPM +representation of SIXEL-IMAGE." (let ((colour-map (sixel-image-colour-map sixel-image))) - (string-join - (mapcar (lambda (colour) - (concat - "\"" - (elt colour 0) " " - "c #" - (format "%02x%02x%02x" - (elt colour 1) - (elt colour 2) - (elt colour 3)) - "\"")) - colour-map) - ","))) + (concat + (string-join + (mapcar (lambda (colour) + (concat + "\"" + (elt colour 0) " " + "c #" + (format "%02x%02x%02x" + (elt colour 1) + (elt colour 2) + (elt colour 3)) + "\"")) + colour-map) + ",") + "\",\n" + "\"-- c #000000\""))) + +(defun sixel-image-to-xpm-pixels (sixel-image) + "Produce string representating pixels component of XPM representation +of SIXEL-IMAGE." + (concat + "\"" + (string-join + (mapcar (lambda (sixel-row) + (string-join + (mapcar (lambda (i) + (string-join + (mapcar (lambda (sixel) + (let ((pixel (elt sixel i))) + (if pixel + pixel + "--"))) + sixel-row))) + (number-sequence 0 5)) + "\",\n\"")) + (sixel-image-sixels sixel-image)) + "\",\n\"") + "\"")) (defun sixel-to-xpm (string) "Returns an XPM image representation of the SIXEL graphic encoded in STRING." @@ -147,10 +176,7 @@ Returns a sixel image object." "/* XPM */" "static char * pixmap = {" (sixel-image-to-xpm-values sixel-image) ",\n" - (sixel-image-to-xpm-colours sixel-image) - ;; (sixel-data-to-XPM-pixels data) - "};"))) - - + (sixel-image-to-xpm-colours sixel-image) ",\n" + (sixel-image-to-xpm-pixels sixel-image) "};"))) ;; sixel.el ends here -- 2.20.1