"Retrieve data string."
(substring string (1+ (string-match "q" string))))
-(defvar sixel-colour-map nil
- "Map of two-character names to RGB colour triples.")
-
-(defvar sixel-current-colour nil
- "Current colour.")
-
(defun sixel-compute-row-length (string)
(apply 'max
(mapcar
(let ((sixel (elt (symbol-value row-variable) index)))
(sixel-tag-bits sixel (- char 63) tag)))
-(defun sixel-process-row (string)
- (let ((idx-in 0)
- (idx-out 0)
- result)
- (while (< idx-in (length string))
- (let (trunc-string (substring string index-in))
+(defun sixel-process-data (string)
+ "Convert sixel string into a list of lists representing individual sixels."
+ (with-temp-buffer
+ (insert string)
+ (goto-char (point-min))
+ (let ((idx-out 0)
+ this-row rows
+ current-colour colour-map
+ finished)
+ (while (not finished)
(cond
- ((string-match "^#\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\)"
- trunc-string)
- (let ((tag (intern (string-to (match-string 1 trunc-string))))
- (mode (match-string 2 trunc-string))
- (r (string-to-number (match-string 3 trunc-string)))
- (g (string-to-number (match-string 4 trunc-string)))
- (b (string-to-number (match-string 5 trunc-string))))
- (add-to-list 'sixel-colour-map (list (tag r g b)))
- (setq idx-in (match-end 0))))
- ((string-match "^#\\([0-9]+\\)" trunc-string)
+ ((looking-at "#\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\);\\([0-9]+\\)")
+ (let ((tag (intern (match-string 1)))
+ (mode (match-string 2))
+ (r (string-to-number (match-string 3)))
+ (g (string-to-number (match-string 4)))
+ (b (string-to-number (match-string 5))))
+ (push (list tag r g b) colour-map)))
+
+ ((looking-at "#\\([0-9]+\\)")
(let ((tag (intern (match-string 1 trunc-string))))
- (setq sixel-current-colour tag)
- (setq idx-in (match-end 0))))
- ((string-match "^$" trunc-string)
- (setq idx-out 0)
- (setq idx-in (match-end 0 trunc-string)))
- ((string-match "^!\\([0-9]+\\)\\([?-~]\\)" trunc-string)
- (let ((repeat-count (string-to-number (match-string 1 trunc-string)))
+ (setq current-colour tag)))
+
+ ((looking-at "$")
+ (setq idx-out 0))
+
+ ((looking-at "^-")
+ (push this-row 'rows)
+ (setq this-row nil)
+ (setq idx-out 0))
+
+ ((looking-at "^!\\([0-9]+\\)\\([?-~]\\)")
+ (let ((repeat-count (string-to-number (match-string 1)))
(char (elt (match-string 2 trunc-string) 0)))
(dotimes (i repeat-count)
- (sixel-tag-sixel-in-row 'result idx-out char sixel-current-colour)
- (setq idx-out (+1 idx-out)))))
- ((string-match "^\\([?-~]\\)" trunc-string)
+ (sixel-tag-sixel-in-row 'result idx-out char current-colour))))
+
+ ((looking-at "^\\([?-~]\\)")
(let ((char (elt (match-string 1 trunc-string) 0)))
- (sixel-tag-sixel-in-row 'result idx-out char sixel-current-colour))
- (setq idx-out (+1 idx-out))))))))
-
-(sixel-get-rows test-string)
+ (sixel-tag-sixel-in-row 'result idx-out char current-colour)))
+
+ ((= (point) (point-max))
+ (setq finished t))
-(defun sixel-to-xpm (string)
- "Converts the given sixel string into an XPM image."
+ (t (error "Invalid characters found in input string.")))
- (let* ((sp (split-string string "q"))
- (control-string (car sp))
- ())))
+ (goto-char (match-end 0)))
+ (push this-row 'rows))))