3 "#0;2;0;0;0#1;2;100;100;0#2;2;0;100;0"
9 (defun sixel-get-params (string)
10 "Retrieve the sixel parameters."
11 (car (split-string string "q")))
13 (defun sixel-get-data (string)
14 "Retrieve data string."
15 (substring string (1+ (string-match "q" string))))
17 (defvar sixel-colour-map nil
18 "Map of two-character names to RGB colour triples.")
20 (defvar sixel-current-colour nil
23 (defun sixel-compute-row-length (string)
30 (split-string substr "$"))))
31 (split-string string -))))
33 (defun sixel-tag-bits (n tag bit-count)
34 "Create a list of length BIT-COUNT with the elements corresponding to the
35 true bits of N set to TAG."
38 (cons (if (= (% n 2) 1)
41 (sixel-tag-bits (/ n 2) tag (1- bit-count)))))
43 (defun sixel-make-sixel-from-char (char tag)
44 "Retrieve sequence of bits to be set."
45 (sixel-tag-bits (- char 63) tag 6))
47 (defun sixel-union (sixel1 sixel2)
48 "Returns a union of the two sixels, SIXEL1 and SIXEL2.
49 When both sixels specify a tag for the same pixel, the tag
51 (seq-mapn (lambda (tag1 tag2)
55 (defun sixel-process-row (string)
59 (while (< idx-in (length string))
60 (let (trunc-string (substring string index-in))
62 ((string-match "^#\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\)"
64 (let ((tag (intern (string-to (match-string 1 trunc-string))))
65 (mode (match-string 2 trunc-string))
66 (r (string-to-number (match-string 3 trunc-string)))
67 (g (string-to-number (match-string 4 trunc-string)))
68 (b (string-to-number (match-string 5 trunc-string))))
69 (add-to-list 'sixel-colour-map (list (tag r g b)))
70 (setq idx-in (match-end 0))))
71 ((string-match "^#\\([0-9]+\\)" trunc-string)
72 (let ((tag (intern (match-string 1 trunc-string))))
73 (setq current-colour tag)
74 (setq idx-in (match-end 0))))
75 ((string-match "^!\\([0-9]+\\)\\([?-~]\\)" trunc-string)
76 (let ((repeat-count (string-to-number (match-string 1 trunc-string)))
77 (char (elt (match-string 2 trunc-string) 0)))
78 (dotimes (i repeat-count)
79 (unless (< idx-out (length result))
80 (add-to-list result (make-vector 6 nil)))
81 (let ((sixel (elt result idx-out))))))))))))
85 (sixel-get-rows test-string)
87 (defun sixel-to-xpm (string)
88 "Converts the given sixel string into an XPM image."
90 (let* ((sp (split-string string "q"))
91 (control-string (car sp))