[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Drawing in images?
From: |
joakim |
Subject: |
Re: Drawing in images? |
Date: |
Thu, 17 Sep 2009 23:46:34 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
MON KEY <address@hidden> writes:
> On Wed, Sep 16, 2009 at 3:04 PM, <address@hidden> wrote:
>>
>> Here's an attempt. Its hardly industrial strength, but seems to work.
>> Test with m-x dragbox-start, enter an image file name compatible with
>> svg, I tried png. Then set the corner coords for the box with LMB and RMB.
>>
>
> Joakim thanks for taking a shot at this. This is very exciting.
> Unfortunately I can't evaluate. After invoking the `dragbox-start'
> comman with both .png and .jpg image-file types the *dragbox* buffer
> returns some svg data and a message:
Thanks for testing. I added the requires you mention, and cleaned up the
code a little bit for readability. Still not industrial strength, but
works here(but I only tested it on a single png file). Looking forward
to your further comments.
> => "Invalid image type `svg'"
>
> Not sure if the local w32 builds are compiled with libsvg support out
> of the box.
> I've not been able to get svg functionality to evaluate on the
> following w32 systems.
>
> - 23.1.50.1 (i386-mingw-nt5.1.2600) of 2009-06-30 on LENNART-69DE564
> (patched);
> - 23.0.91.1 (i386-mingw-nt5.1.2600) of 2009-02-26 on SOFT-MJASON;
> - 23.1.1 (i386-mingw-nt5.1.2600) of 2009-07-30 on SOFT-MJASON;
>
> Can these functions be evaluated successfully on a non CVS emacs?
> Likewise, if so, can these functions be evaluated on a non CVS emacs on w32?
>
> Also, as a side note in lieu of a future dragbox package; in a fresh
> environment when evaluating these functions on the two 23.*
> SOFT-MJASON builds referd above the key bindings on
> image-mode-mode-map of `dragbox-lmb-click-handler' and
> `dragbox-rmb-click-handler' didn't take until after a (require
> 'image-mode). Additionally, I needed a (require 'xml) to get the
> invocation of `xml-print' in `dragbox-update-box' to evaluate.
>
> Just to make sure I also tried evaluating CYD's svg example here:
> (URL `http://lists.gnu.org/archive/html/emacs-devel/2009-07/msg01166.html')
> I know this works on a GNU box but on the w32 systems get:
> => "Invalid image type `svg'"
>
> Any advice as to what needs to be done to get supprot for `svg' on w32?
>
> I look forward to testing the dragbox functions on a GNU box later this
> evening.
>
> s_P
--
Joakim Verona
;;; dragbox-test.el --- dragbox - draw a bounding box interactively
;;; Commentary:
;; draw a bounding box on an image.
;; needs an Emacs with svg support compiled in.
;; Author: Joakim Verona, (C) FSF 2009, GPL
;;; History:
;;
(require 'image-mode)
(require 'xml)
(if (not (image-type-available-p 'svg))
(error "No svg available!"))
;;arbitrary image size, for testing
;;; Code:
(setq dragbox-image-width 744)
(setq dragbox-image-height 1052)
;;initial bounding box
(setq dragbox-x1y1 '(0 . 0))
(setq dragbox-x2y2 '(100 . 100))
(setq dragbox-image-url "")
(defun dragbox-start (image-file)
"Start here with an IMAGE-FILE suitable for svg embedding."
(interactive "fImage file:")
(get-buffer-create "*dragbox*")
(switch-to-buffer "*dragbox*")
(setq dragbox-image-url (concat "file://" (expand-file-name image-file)))
(dragbox-update-box-from-state))
(defun dragbox-make-svg-data (x y width height image-url)
"Return svg describing a image file with a bounding box ontop.
X Y WIDTH HEIGHT describes the box, IMAGE-URL which image to draw on."
`((svg
((xmlns:dc . "http://purl.org/dc/elements/1.1/")
(xmlns:cc . "http://creativecommons.org/ns#")
(xmlns:rdf . "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
(xmlns:svg . "http://www.w3.org/2000/svg")
(xmlns:xlink . "http://www.w3.org/1999/xlink")
(xmlns . "http://www.w3.org/2000/svg")
(width . ,(number-to-string dragbox-image-width))
(height . ,(number-to-string dragbox-image-height))
(id . "svg2"))
(g
((id . "layer1"))
(rect
((style . "fill:#cfcfcf;fill-opacity:1")
(width . ,(number-to-string dragbox-image-width))
(height . ,(number-to-string dragbox-image-height))
(x . "0")
(y . "0")))
(image ((y . "0")
(x . "0")
(width . ,(number-to-string dragbox-image-width))
(height . ,(number-to-string dragbox-image-height))
(xlink:href . ,image-url)
))
(rect
((style .
"color:#000000;fill:#000000;fill-opacity:0.5;fill-rule:nonzero;stroke:#000000;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;stroke-opacity:0.5")
(id . "dragbox")
(width . , (number-to-string width) )
(height . ,(number-to-string height))
(x . ,(number-to-string x))
(y . ,(number-to-string y))))
))))
(defun dragbox-lmb-click-handler ()
"Set upper left coords for bounding box."
(interactive)
(setq dragbox-x1y1 (dragbox-extract-event-coords last-input-event))
(dragbox-update-box-from-state)
)
(defun dragbox-rmb-click-handler ()
"Set lower right coords for bounding box."
(interactive)
(setq dragbox-x2y2 (dragbox-extract-event-coords last-input-event))
(dragbox-update-box-from-state)
)
(defun dragbox-extract-event-coords (event)
"Get the coordinates from click EVENT."
(caddr(cadr last-input-event))
)
;;bind the handlers to lmb and rmb
(define-key image-mode-map [down-mouse-1] 'dragbox-lmb-click-handler)
(define-key image-mode-map [down-mouse-2] 'dragbox-rmb-click-handler)
(defun dragbox-update-box (x y width height)
"Redraw the bounding box, given X Y WIDTH and HEIGHT ontop of the image."
;;this implementation doest seem very efficient
(fundamental-mode)
(erase-buffer)
(xml-print (dragbox-make-svg-data x y width height dragbox-image-url))
(image-mode)
)
(defun dragbox-update-box-from-state ()
"Redraw bounding box from global state ontop of image."
(let*
((x1 (car dragbox-x1y1))
(y1 (cdr dragbox-x1y1))
(x2 (car dragbox-x2y2))
(y2 (cdr dragbox-x2y2))
(w (- x2 x1))
(h (- y2 y1)))
(message "(%d %d) (%d %d) w:%d h:%d" x1 y1 x2 y2 w h)
(dragbox-update-box
x1
y1
w
h)))
(provide 'dragbox-test)
;;; dragbox-test.el ends here
Re: Drawing in images?, Jason Rumney, 2009/09/17