1 ;;; compface.el --- functions for converting X-Face headers
2 ;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; TAKAI Kousuke <tak@kmc.gr.jp>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (defgroup compface nil
30 "X-Face image conversion."
33 (defcustom uncompface-use-external nil
34 "*nil means use the internal ELisp-based uncompface program.
35 If you aren't satisfied with the speed, try to alter the value. In
36 that case, you need to have the external `uncompface' and `icontopbm'
41 (defun uncompface (face)
43 If `uncompface-use-external' is non-nil, it requires the external
44 programs `uncompface', and `icontopbm'. On a GNU/Linux system these
45 might be in packages with names like `compface' or `faces-xface' and
46 `netpbm' or `libgr-progs', for instance."
47 (if uncompface-use-external
50 (and (eq 0 (apply 'call-process-region (point-min) (point-max)
52 'delete '(t nil) nil))
54 (goto-char (point-min))
55 (insert "/* Width=48, Height=48 */\n")
56 ;; I just can't get "icontopbm" to work correctly on its
57 ;; own in XEmacs. And Emacs doesn't understand un-raw pbm
59 (if (not (featurep 'xemacs))
60 (eq 0 (call-process-region (point-min) (point-max)
63 (shell-command-on-region (point-min) (point-max)
64 "icontopbm | pnmnoraw"
68 (uncompface-internal face)))
70 ;; The following section is a bug-for-bug compatible version of
71 ;; `uncompface' program entirely implemented in Emacs-Lisp.
74 ;; The size of 48x48 is actually hard-coded into the code itself,
75 ;; so you cannot simply change those values. So we hard-code
76 ;; them into the compiled code.
77 (defconst uncompface-width 48
78 "Width of X-Face bitmap image.")
79 (defconst uncompface-height 48
80 "Height of X-Face bitmap image.")
82 ;; Again, this is also hard-coded into the compiled code.
83 (defconst uncompface-guesses
86 (let ((vector (make-vector (length x) nil))
96 (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
97 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
99 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1
100 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1
101 0 0 0 0 0 1 0 1 0 0 0 0 1 1 1 1
102 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1
103 0 0 0 0 1 1 1 1 1 1 0 1 1 1 1 1
104 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
105 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
106 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1
107 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1
108 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
110 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1
111 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 1
112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
113 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1
114 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0
115 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
116 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
117 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
118 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1
119 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
120 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
121 1 0 0 0 0 0 0 0 1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 1 1 0 0 1 1
457 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1
458 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1
459 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1 1
460 0 1 1 1 0 0 0 0 0 0 1 1 0 0 1 1
461 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 1
462 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
463 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
465 (0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1
466 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1)
470 (0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
471 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1
472 0 0 0 0 0 0 1 1 0 0 0 1 1 1 1 1
473 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1))
482 "Static prediction table for X-Face image compression algorithm.")
484 ;; Macros for inlining critical values.
485 (defmacro uncompface-width () (list 'quote uncompface-width))
486 (defmacro uncompface-height () (list 'quote uncompface-height))
487 (defmacro uncompface-guesses () (list 'quote uncompface-guesses))
489 (defmacro uncompface-loop (&rest body)
490 "Eval BODY and repeat if last expression of BODY yields non-nil."
491 (list 'while (cons 'progn body))))
493 ;; (defun uncompface-print-bignum (bignum &optional prefix)
494 ;; (princ (format (concat prefix "<%s>\n")
495 ;; (mapconcat (lambda (x) (format "%02x" x))
496 ;; (reverse bignum) " "))))
498 ;; Shut up the byte-compiler.
499 ;; These variables are once bound in `uncompface' and all subfunctions
500 ;; accesses them directly rather than creating their own bindings.
505 ;; Big-number facilities.
506 ;; These functions were used to be implemented with `lsh' and `logand',
507 ;; but rewritten to use `/' and `%'. The last two are mapped into
508 ;; byte-code directly, but the formers are normal functions even in
509 ;; compiled code which involve expensive `funcall' operations.
511 (defsubst uncompface-big-mul-add (multiplier adder)
512 "Multiply BIGNUM by MULTIPLIER and add ADDER and put result in `bignum'."
513 (setq bignum (if (= multiplier 0)
517 (setcar bignum (% (setq adder (+ (* (car bignum)
521 (setq adder (/ adder 256))
523 (setq bignum (cdr bignum)))
525 (setcdr bignum (list adder))))))))
527 ;; This trick is for XEmacs 21.4 which doesn't allow inlining a function
528 ;; using `defsubst' into another function also defined with `defsubst'.
530 (when (featurep 'xemacs)
531 (defvar uncompface-big-mul-add (symbol-function 'uncompface-big-mul-add))
532 (defmacro uncompface-big-mul-add (multiplier adder)
533 `(,uncompface-big-mul-add ,multiplier ,adder))))
535 ;; Separate `eval-when-compile' for the byte compiler
536 ;; to properly define `uncompface-big-mul-add' before `uncompface-big-pop'.
538 (defsubst uncompface-big-pop (prob)
539 (let ((n (car bignum)) (i 0))
541 (setq bignum (cdr bignum))
543 (while (or (< n (cdr (car prob)))
544 (>= n (+ (cdr (car prob)) (car (car prob)))))
545 (setq prob (cdr prob)
547 (uncompface-big-mul-add (car (car prob)) (- n (cdr (car prob))))
550 ;; This function cannot be inlined due to recursive calls.
551 (defun uncompface-pop-grays (offset size)
553 (let ((bits (uncompface-big-pop
554 ;; This is freqs[16] in compface_private.h.
555 '(( 0 . 0) (38 . 0) (38 . 38) (13 . 152)
556 (38 . 76) (13 . 165) (13 . 178) ( 6 . 230)
557 (38 . 114) (13 . 191) (13 . 204) ( 6 . 236)
558 (13 . 217) ( 6 . 242) ( 5 . 248) ( 3 . 253)))))
559 ;; (if (/= (logand bits 1) 0)
560 ;; (aset face offset t))
561 ;; (if (/= (logand bits 2) 0)
562 ;; (aset face (1+ offset) t))
563 ;; (if (/= (logand bits 4) 0)
564 ;; (aset face (+ offset (uncompface-width)) t))
565 ;; (if (/= (logand bits 8) 0)
566 ;; (aset face (+ offset (uncompface-width) 1) t))
568 (aset face (+ offset (uncompface-width) 1) t)
569 (setq bits (- bits 8)))
571 (aset face (+ offset (uncompface-width)) t)
572 (setq bits (- bits 4)))
573 (or (eq (if (< bits 2)
575 (aset face (1+ offset) t)
578 (aset face offset t))
580 (setq size (/ size 2))
581 (uncompface-pop-grays offset size)
582 (uncompface-pop-grays (+ offset size) size)
583 (uncompface-pop-grays (+ offset (* (uncompface-width) size)) size)
584 (uncompface-pop-grays (+ offset (* (uncompface-width) size) size) size)))
586 ;; Again, this function call itself recursively.
587 (defun uncompface-uncompress (offset size level)
588 ;; This used to be (funcall (aref [(lambda ...) ...] (u-big-pop ...)))
589 ;; but this was slow due to function call.
590 (let ((i (uncompface-big-pop (car level))))
591 (cond ((eq i 0) ; black
592 (uncompface-pop-grays offset size))
594 (setq size (/ size 2)
596 (uncompface-uncompress offset size level)
597 (uncompface-uncompress (+ offset size) size level)
598 (uncompface-uncompress (+ offset (* size (uncompface-width)))
600 (uncompface-uncompress (+ offset (* size (uncompface-width)) size)
603 ;; (t (error "Cannot happen"))
607 (defmacro uncompface-shift-in (k dy dx)
608 `(+ k k (if (aref face (+ i (* ,dy (uncompface-width)) ,dx)) 1 0))))
610 (defun uncompface-internal (string &optional raw)
611 "Decode X-Face data STRING and return an image in the pbm format.
612 If the optional RAW is non-nil, return a raw bitmap as a vector."
613 (let (;; `bignum' and `face' are semi-global variables.
614 ;; Do not use '(0) below, because BIGNUM is modified in-place.
616 (face (make-vector (* (uncompface-width) (uncompface-height)) nil))
617 ;;(uncompface-big-shift -16)
618 ;;(uncompface-big-mask 65535)
621 (and (>= c ?!) (<= c ?~)
622 (uncompface-big-mul-add (1+ (- ?~ ?!)) (- c ?!))))
624 ;;(uncompface-print-bignum bignum)
629 (uncompface-uncompress (+ (* (uncompface-width) y) x) 16
630 ;; This is levels[4][3] in compface_private.h.
631 '(;; Top of tree almost always grey
632 (( 1 . 255) (251 . 0) ( 4 . 251))
633 (( 1 . 255) (200 . 0) ( 55 . 200))
634 (( 33 . 223) (159 . 0) ( 64 . 159))
635 ;; Grey disallowed at bottom
636 ((131 . 0) ( 0 . 0) (125 . 131))))
637 (< (setq x (+ x 16)) (uncompface-width)))
638 (< (setq y (+ y 16)) (uncompface-height)))
640 (let ((i 0) guesses k)
642 (setq guesses (cond ((= y 1) (nth 2 (uncompface-guesses)))
643 ((= y 2) (nth 1 (uncompface-guesses)))
644 (t (nth 0 (uncompface-guesses))))
654 (setq k (uncompface-shift-in k -2 -2)))
655 (setq k (uncompface-shift-in k -1 -2)))
656 (setq k (uncompface-shift-in k 0 -2))))
660 (setq k (uncompface-shift-in k -2 -1)))
661 (setq k (uncompface-shift-in k -1 -1)))
662 (setq k (uncompface-shift-in k 0 -1))))
665 (setq k (uncompface-shift-in k -2 0)))
666 (setq k (uncompface-shift-in k -1 0)))
669 (setq k (uncompface-shift-in k -2 1)))
670 (setq k (uncompface-shift-in k -1 1)))
671 (when (<= x (- (uncompface-width) 2))
674 (setq k (uncompface-shift-in k -2 2)))
675 (setq k (uncompface-shift-in k -1 2)))))
676 (if (aref (car (cond ((= x 1)
680 ((= x (1- (uncompface-width)))
681 (cdr (cdr (cdr guesses))))
684 (aset face i (not (aref face i))))
686 (< (setq x (1+ x)) (uncompface-width)))
687 (< (setq y (1+ y)) (uncompface-height))))
690 (concat (eval-when-compile
691 (format "P1\n%d %d\n" uncompface-width uncompface-height))
692 (mapconcat (lambda (bit) (if bit "1" "0")) face " ")
698 ;; eval: (put 'uncompface-loop 'lisp-indent-hook 0)
701 ;;; compface.el ends here