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 (sixel n tag)
34 "Set bits of SIXEL corresponding to N with to the value TAG."
40 (defun sixel-tag-sixel-in-row (row-variable index char tag)
41 "Tag the bits of the sixel at INDEX in the list identified by
42 the variable ROW-VARIABLE corresponding to input character CHAR
44 (while (not (< index (length (symbol-value row-variable))))
45 (add-to-list row-variable (make-vector 6 nil)))
46 (let ((sixel (elt (symbol-value row-variable) index)))
47 (sixel-tag-bits sixel (- char 63) tag)))
49 (defun sixel-process-row (string)
53 (while (< idx-in (length string))
54 (let (trunc-string (substring string index-in))
56 ((string-match "^#\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\)"
58 (let ((tag (intern (string-to (match-string 1 trunc-string))))
59 (mode (match-string 2 trunc-string))
60 (r (string-to-number (match-string 3 trunc-string)))
61 (g (string-to-number (match-string 4 trunc-string)))
62 (b (string-to-number (match-string 5 trunc-string))))
63 (add-to-list 'sixel-colour-map (list (tag r g b)))
64 (setq idx-in (match-end 0))))
65 ((string-match "^#\\([0-9]+\\)" trunc-string)
66 (let ((tag (intern (match-string 1 trunc-string))))
67 (setq sixel-current-colour tag)
68 (setq idx-in (match-end 0))))
69 ((string-match "^$" trunc-string)
71 (setq idx-in (match-end 0 trunc-string)))
72 ((string-match "^!\\([0-9]+\\)\\([?-~]\\)" trunc-string)
73 (let ((repeat-count (string-to-number (match-string 1 trunc-string)))
74 (char (elt (match-string 2 trunc-string) 0)))
75 (dotimes (i repeat-count)
76 (sixel-tag-sixel-in-row 'result idx-out char sixel-current-colour)
77 (setq idx-out (+1 idx-out)))))
78 ((string-match "^\\([?-~]\\)" trunc-string)
79 (let ((char (elt (match-string 1 trunc-string) 0)))
80 (sixel-tag-sixel-in-row 'result idx-out char sixel-current-colour))
81 (setq idx-out (+1 idx-out))))))))
83 (sixel-get-rows test-string)
85 (defun sixel-to-xpm (string)
86 "Converts the given sixel string into an XPM image."
88 (let* ((sp (split-string string "q"))
89 (control-string (car sp))