Mercurial > lasercutter
changeset 5:8cc418e04b87
made preserve-meta
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 20 Aug 2010 01:47:28 -0400 |
parents | 6533b4ef83ad |
children | 4ae2497acf7d |
files | src/laser/rasterize.clj |
diffstat | 1 files changed, 40 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/src/laser/rasterize.clj Fri Aug 20 01:30:12 2010 -0400 1.2 +++ b/src/laser/rasterize.clj Fri Aug 20 01:47:28 2010 -0400 1.3 @@ -38,30 +38,12 @@ 1.4 (def cut_feed 20) 1.5 (def corner_radius 0) 1.6 1.7 -(defmulti display "Creates a JFrame and displays a buffered image" class) 1.8 1.9 -(defn- makePanel [image] (proxy [Panel] [] (paint [g] (.drawImage g image 0 0 nil)))) 1.10 +(defn preserve-meta [f] 1.11 + (fn [& x] (with-meta 1.12 + (apply f x) 1.13 + (meta (last x))))) 1.14 1.15 -(defmethod display 1.16 - BufferedImage [image] 1.17 - (let [panel (makePanel image) 1.18 - frame (JFrame. "Oh Yeah!")] 1.19 - (.add frame panel) 1.20 - (.pack frame) 1.21 - (.setVisible frame true ) 1.22 - (.setSize frame(.getWidth image) (.getHeight image)))) 1.23 - 1.24 -(defmethod display 1.25 - ImagePlus [image] 1.26 - (display (.getBufferedImage image))) 1.27 - 1.28 -(defmethod display 1.29 - clojure.lang.PersistentHashMap [frame-hash] 1.30 - (display (frame-hash->bufferedImage frame-hash))) 1.31 - 1.32 -(defmethod display 1.33 - clojure.lang.PersistentArrayMap [frame-hash] 1.34 - (display (frame-hash->bufferedImage frame-hash))) 1.35 1.36 1.37 (defn frame-hash 1.38 @@ -85,6 +67,11 @@ 1.39 {:width (.getWidth image+) :height (.getHeight image+)}))) 1.40 1.41 1.42 + 1.43 + 1.44 + 1.45 + 1.46 + 1.47 (def white {:r 255, :g 255, :b 255}) 1.48 (def black {:r 0, :g 0, :b 0}) 1.49 1.50 @@ -128,18 +115,11 @@ 1.51 1.52 (defn filter-keys [fun m] 1.53 (select-keys m (filter fun (keys m)))) 1.54 +(def filter-keys (preserve-meta filter-keys)) 1.55 1.56 (defn filter-vals [fun m] 1.57 - (into {} (filter (comp fun val) m))) 1.58 - 1.59 - 1.60 - 1.61 - 1.62 - 1.63 - 1.64 - 1.65 - 1.66 - 1.67 + (into {} (filter (comp fun val) m))) 1.68 +(def filter-vals (preserve-meta filter-vals)) 1.69 1.70 (defn frame-hash->bufferedImage 1.71 [frame-hash] 1.72 @@ -155,6 +135,34 @@ 1.73 (:b rgb))] 1.74 (.setRGB image (first coord) (last coord) packed-RGB)))) 1.75 image)) 1.76 + 1.77 +(defmulti display "Creates a JFrame and displays a buffered image" class) 1.78 1.79 +(defn- makePanel [image] (proxy [Panel] [] (paint [g] (.drawImage g image 0 0 nil)))) 1.80 1.81 1.82 +(defmethod display 1.83 + BufferedImage [image] 1.84 + (let [panel (makePanel image) 1.85 + frame (JFrame. "Oh Yeah!")] 1.86 + (.add frame panel) 1.87 + (.pack frame) 1.88 + (.setVisible frame true ) 1.89 + (.setSize frame(.getWidth image) (.getHeight image)))) 1.90 + 1.91 +(defmethod display 1.92 + ImagePlus [image] 1.93 + (display (.getBufferedImage image))) 1.94 + 1.95 +(defmethod display 1.96 + clojure.lang.PersistentHashMap [frame-hash] 1.97 + (display (frame-hash->bufferedImage frame-hash))) 1.98 + 1.99 +(defmethod display 1.100 + clojure.lang.PersistentArrayMap [frame-hash] 1.101 + (display (frame-hash->bufferedImage frame-hash))) 1.102 + 1.103 + 1.104 + 1.105 + 1.106 +