From: Tim Vaughan Date: Tue, 21 May 2019 09:26:11 +0000 (+0200) Subject: Pad out short sixel rows. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=6e4e229e1afb1a5d12147441afb30fd20ff248d3;p=sixel.git Pad out short sixel rows. --- diff --git a/sixel.el b/sixel.el index 81fa32e..8f00687 100644 --- a/sixel.el +++ b/sixel.el @@ -101,6 +101,19 @@ Returns a sixel image object." (cons colour-map (reverse rows))))) +(defun sixel-pad-rows (sixel-image) + "Pad out contents of rows in SIXEL-IMAGE so that all rows are the same length." + (let ((width (car (sixel-image-dims sixel-image))) + (rows (cdr sixel-image))) + (dotimes (row-idx (length rows)) + (let* ((row-cdr (nthcdr row-idx rows)) + (row-width (length (car row-cdr)))) + (if (< row-width width) + (setcar row-cdr (append (car row-cdr) + (make-list (- width row-width) + [nil nil nil nil nil nil]))))))) + sixel-image) + (defun sixel-image-colour-map (sixel-image) "Extract colour map from SIXEL-DATA." (car sixel-image)) @@ -174,7 +187,7 @@ of SIXEL-IMAGE." "Returns an XPM image representation of the SIXEL graphic encoded in STRING." (let* ((param-string (sixel-get-params string)) (data-string (sixel-get-data string)) - (sixel-image (sixel-process-data data-string))) + (sixel-image (sixel-pad-rows (sixel-process-data data-string)))) (if (string-prefix-p "P" string) (concat "/* XPM */"