From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: alkibiades@gmx.de Newsgroups: gmane.emacs.devel Subject: Re: gamegrid.el and some games Date: Tue, 17 Sep 2002 01:13:11 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: References: <87n0ql94mz.fsf@pot.cnuce.cnr.it> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1032212093 19127 127.0.0.1 (16 Sep 2002 21:34:53 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 16 Sep 2002 21:34:53 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17r3W7-0004yG-00 for ; Mon, 16 Sep 2002 23:34:51 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17r49c-0004VZ-00 for ; Tue, 17 Sep 2002 00:15:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17r3WM-0002cM-00; Mon, 16 Sep 2002 17:35:06 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17r3Ua-0002a4-00 for emacs-devel@gnu.org; Mon, 16 Sep 2002 17:33:16 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17r3UY-0002Zs-00 for emacs-devel@gnu.org; Mon, 16 Sep 2002 17:33:16 -0400 Original-Received: from dialin-145-254-208-151.arcor-ip.net ([145.254.208.151] helo=localhost.localdomain) by monty-python.gnu.org with esmtp (Exim 4.10) id 17r3UU-0002ZS-00; Mon, 16 Sep 2002 17:33:11 -0400 Original-Received: (from egoge@localhost) by localhost.localdomain (8.11.4/8.11.4) id g8GNDBX01083; Tue, 17 Sep 2002 01:13:11 +0200 X-Authentication-Warning: localhost.localdomain: egoge set sender to epameinondas@gmx.de using -f Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Mon, 16 Sep 2002 15:27:53 -0400") X-Operating-System: Linux from Scratch X-Attribution: os X-Face: "HgH2sgK|bfH$;PiOJI6|qUCf.ve<51_Od(%ynHr?=>znn#~#oS>",F%B8&\vus),2AsPYb -n>PgddtGEn}s7kH?7kH{P_~vu?]OvVN^qD(L)>G^gDCl(U9n{:d>'DkilN!_K"eNzjrtI4Ya6;Td% IZGMbJ{lawG+'J>QXPZD&TwWU@^~A}f^zAb[Ru;CT(UA]c& Original-Lines: 59 User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i686-pc-linux-gnu) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:7961 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:7961 --=-=-= Richard Stallman writes: > > * Use a PBM form of the same image. How hard is that? Does it have > > drawbacks? > > You mean, if a package provides only XPM we should calculate a PBM/XBM > image from that XPM via manipulation of the data strings? > > I was thinking that the programmer would supply the image in PBM > format. This could be in addition to XPM, or instead of XPM. How > hard is that? That's easy. However, my misunderstanding caused me to read a bit about the PBM format. I discovered that my Emacs supports PPM and PGM, too. The three related image formats PBM (black & white), PGM (grayscale) and PPM (colour) are supposed to be intermediate formats for image conversion. Well, it should be straightforward to convert XPM to PPM. I already started to write a small library. I don't know anything about Emacs' internals. Does an Emacs that supports images always support colours, too? Does an Emacs that supports PBM alway support PPM, too? If this is so and if I am not missing something this would mean, that every Emacs able to display images could display XPMs via some Lisp. > It is a pity that Emacs does not provide any means to create and > change an image in the image cache directly. This could make this task > (and some others) much easier. > > I guess so. It would be nice if all image formats (or at least more > of them) supported getting the image from Lisp data rather than from > a file. Does someone want to work on that? [...] Perhaps you like the approach that I chose in my unfinished code (attached)? For example: (let ((pic (make-pixmap 16 16 'colour '(0 0 0)))) (experimental!-draw-line pic 15 0 0 15 '(255 0 0)) (experimental!-draw-line pic 0 0 15 15 '(0 0 255)) (insert-image (experimental!-pixmap-to-image pic :ascent 'center))) -- Oliver --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=the-gimp.el Content-Transfer-Encoding: 8bit (eval-when-compile (require 'cl)) (defstruct (pixmap (:constructor make-pixmap-internal)) ;; Is is supposed to be accessed only through `make-pixmap' and the ;; functions to set single pixels. type colour-depth width height pixmap) (defun make-pixmap (width height &optional type bg-colour) "Create a pixmap object. A pixmap is an representation of an image in Lisp code. Functions like FIXME or FIXME may change an pixmap object (they \"draw on the image\"). Use FIXME to convert a pixmap object to an actual image. The optional third argument TYPE may be on of 'b/w, 'grayscale or 'colour for black&white-images, grayscale-image or colour-images respectively; if TYPE is omitted or nil, it defaults to 'colour. The optional fourth argument BG-COLOUR indicates the colour used to initialize (\"fill\") the pixmap. Allowed values for BG-COLOUR depend on TYPE: b/w -- BG-COLOUR may not be non-nil grayscale -- an integer between 0 and 255 colour -- the name of a colour as used by the X windowing system (\"Firebrick\") or a HTML-type colour specification (\"#002f5d\") in a string or a list of three integers between 0 and 255, indicating the RGB-value." (case type (b/w (when bg-colour (error "Black&white-images do not support a background color."))) (grayscale (if bg-colour (if (numberp bg-colour) (unless (< bg-colour 256) (error "Argument BG-COLOUR is out of range: %d" bg-colour)) (error "BG-COLOUR must be an integer for grayscale-images."))) ;; If bg-colour is nil, we use black as a default. (setq bg-colour 0)) ;; COLOUR is the default type. (t (if bg-colour nil ; FIXME ;; If bg-color is nil, set it to the background-color of the ;; default-face. (setq bg-colour (experimental!-convert-colour (face-attribute 'default :background)))))) (make-pixmap-internal :type (or type 'colour) ;; For the sake of coding-convenience we do ;; not support every possible color-depth. :colour-depth (if (eq type 'b/w) nil 255) :width width :height height :pixmap (case type ;; b/w FIXME (grayscale (make-string (* width height) bg-colour)) (t (let ((str (make-string (* width height 3) 0))) (loop for i from 0 below (length str) by 3 do (aset str i (car bg-colour)) (aset str (1+ i) (car (cdr bg-colour))) (aset str (+ i 2) (car (cddr bg-colour)))) str))))) (defun experimental!-convert-colour (colour) "Convert a colour-string to a list of RGB-values. COLOUR is a string, either the name of a colour as used by the X windowing system (\"Firebrick\") or a HTML-type colour specification (\"#002f5d\")" colour) ;; FIXME ;; (defun experimental!-set-pixel (pic x y colour) ;; (let ((type (pixmap-type pic))) ;; (ecase type ;; (b/w (unless (and (numberp colour) ;; (or (= colour 0) ;; (= colour 1))) ;; (error "Only 0 or 1 are valid COLOURS for b/w B/W-images.")) ;; (experimental!-set-pixel-b/w pic x y colour)) ;; (grayscale (unless (if (numberp bg-colour) ;; (unless (< bg-colour 256) ;; (error "Argument BG-COLOUR is out of range: %d" bg-colour)) ;; (error "BG-COLOUR must be a number for grayscale GRAYSCALE-images."))) ;; (experimental!-set-pixel-grayscale pic x y bg-colour)) ;; (colour (apply 'experimental!-set-pixel-colour pic x y (experimental!-convert-colour colour)))))) ;; (defun experimental!-set-pixel-b/w (graphic x y &optional clear) ;; (let* ((width (pixel-graphic-width graphic)) ;; (pos (+ x (* y width))) ;; (pixmap (pixel-graphic-data graphic)) ;; (byte (aref pixmap (/ pos 8)))) ;; (aset pixmap pos (logior byte (expt 2 (% pos 8)))))) (defun experimental!-set-pixel-grayscale (pic x y colour) "Set a pixel in a grayscale-pixmap object to a different colour. X and Y are the x- and y- position of the image with (0, 0) being the upper left corner. COLOUR is an integers in the range from 0 (i. e. black) to 255 (i. e. white)." (aset (pixmap-pixmap pic) (+ x (* y (pixmap-width pic))) colour)) (defun experimental!-set-pixel-colour (pic x y r g b) "Set a pixel in a colour-pixmap-object to a different colour. X and Y are the x- and y- position of the image with (0, 0) being the upper left corner. R, G and B are integers in the range from 0 to 255 and specify the RGB-value." (let ((pixmap (pixmap-pixmap pic)) (pos (* 3 (+ x (* y (pixmap-width pic)))))) (aset pixmap pos r) (aset pixmap (1+ pos) g) (aset pixmap (+ pos 2) b))) (defun experimental!-draw-line (pic x y to-x to-y colour) "Draw a line in PIC (a pixmap object) from (X, Y) to (TO-X, TO-Y)." ;; FIXME FIXME FIXME: rewrite this from scratch. (let* ((x-offset (abs (- to-x x))) (y-offset (abs (- to-y y))) (x-direction (if (> x to-x) -1 1)) (y-direction (if (> y to-y) -1 1)) (horizontal-p (>= x-offset y-offset)) (diff-right (if horizontal-p (* 2 y-offset) (* 2 x-offset))) (diff-up-right (if horizontal-p (- diff-right (* 2 x-offset)) (- diff-right (* 2 y-offset)))) (predicate (if horizontal-p (- diff-right x-offset) (- diff-right y-offset))) (move-right (if horizontal-p (lambda () (setq x (+ x x-direction) ; increment independent variable predicate (+ predicate diff-right))) (lambda () (setq y (+ y y-direction) predicate (+ predicate diff-right))))) (not-done-p (if horizontal-p (lambda () (prog1 (>= x-offset 0) (decf x-offset))) (lambda () (prog1 (>= y-offset 0) (decf y-offset)))))) (while (funcall not-done-p) (apply 'experimental!-set-pixel-colour pic x y colour) ; FIXME (if (> predicate 0) ; is the pixel going right AND up? ;; Move up and right. (setq x (+ x x-direction) ; increment independent variable y (+ y y-direction) ; increment dependent variable predicate (+ predicate diff-up-right)) (funcall move-right))))) (defun experimental!-pixmap-to-image (graphic &rest props) "Convert an pixmap object to an actual image. Optional PROPS are additional image attributes to assign to the image, like, e.g. `:ascent center'." (apply 'create-image (concat (ecase (pixmap-type graphic) (b/w "P4 ") (grayscale "P5 ") (colour "P6 ")) (number-to-string (pixmap-width graphic)) " " (number-to-string (pixmap-height graphic)) " " (number-to-string (pixmap-colour-depth graphic)) " " (pixmap-pixmap graphic)) 'pbm t props)) --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by localhost.localdomain id g8GNDBX01083 --=20 Oliver Scholz 30 Fructidor an 210 de la R=E9volution Taunusstr. 25 Libert=E9, Egalit=E9, Fraternit=E9! 60329 Frankfurt a. M. http://www.jungdemokratenhessen.de Tel. (069) 97 40 99 42 http://www.jdjl.org --=-=-=--