Mercurial > lasercutter
comparison src/laser/rasterize.clj @ 5:8cc418e04b87
made preserve-meta
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 20 Aug 2010 01:47:28 -0400 |
parents | 6533b4ef83ad |
children | 4ae2497acf7d |
comparison
equal
deleted
inserted
replaced
4:6533b4ef83ad | 5:8cc418e04b87 |
---|---|
36 (def tile_spacing [0.125, 0.125]) | 36 (def tile_spacing [0.125, 0.125]) |
37 (def feed 120) | 37 (def feed 120) |
38 (def cut_feed 20) | 38 (def cut_feed 20) |
39 (def corner_radius 0) | 39 (def corner_radius 0) |
40 | 40 |
41 (defmulti display "Creates a JFrame and displays a buffered image" class) | |
42 | 41 |
43 (defn- makePanel [image] (proxy [Panel] [] (paint [g] (.drawImage g image 0 0 nil)))) | 42 (defn preserve-meta [f] |
43 (fn [& x] (with-meta | |
44 (apply f x) | |
45 (meta (last x))))) | |
44 | 46 |
45 (defmethod display | |
46 BufferedImage [image] | |
47 (let [panel (makePanel image) | |
48 frame (JFrame. "Oh Yeah!")] | |
49 (.add frame panel) | |
50 (.pack frame) | |
51 (.setVisible frame true ) | |
52 (.setSize frame(.getWidth image) (.getHeight image)))) | |
53 | |
54 (defmethod display | |
55 ImagePlus [image] | |
56 (display (.getBufferedImage image))) | |
57 | |
58 (defmethod display | |
59 clojure.lang.PersistentHashMap [frame-hash] | |
60 (display (frame-hash->bufferedImage frame-hash))) | |
61 | |
62 (defmethod display | |
63 clojure.lang.PersistentArrayMap [frame-hash] | |
64 (display (frame-hash->bufferedImage frame-hash))) | |
65 | 47 |
66 | 48 |
67 (defn frame-hash | 49 (defn frame-hash |
68 "yields a convienent representation for the pixles in an image. | 50 "yields a convienent representation for the pixles in an image. |
69 Because of the size of the structvre generated, this must only be used | 51 Because of the size of the structvre generated, this must only be used |
81 (let [data (.getRGB buf x y)] | 63 (let [data (.getRGB buf x y)] |
82 (hash-map :r (bit-shift-right (bit-and 0xff0000 data) 16) | 64 (hash-map :r (bit-shift-right (bit-and 0xff0000 data) 16) |
83 :g (bit-shift-right (bit-and 0x00ff00 data) 8) | 65 :g (bit-shift-right (bit-and 0x00ff00 data) 8) |
84 :b (bit-and 0x0000ff data)))))))) | 66 :b (bit-and 0x0000ff data)))))))) |
85 {:width (.getWidth image+) :height (.getHeight image+)}))) | 67 {:width (.getWidth image+) :height (.getHeight image+)}))) |
68 | |
69 | |
70 | |
71 | |
72 | |
86 | 73 |
87 | 74 |
88 (def white {:r 255, :g 255, :b 255}) | 75 (def white {:r 255, :g 255, :b 255}) |
89 (def black {:r 0, :g 0, :b 0}) | 76 (def black {:r 0, :g 0, :b 0}) |
90 | 77 |
126 (defn raster-comment [string] | 113 (defn raster-comment [string] |
127 (str "(" (re-gsub #"[()]" "" string) ")")) | 114 (str "(" (re-gsub #"[()]" "" string) ")")) |
128 | 115 |
129 (defn filter-keys [fun m] | 116 (defn filter-keys [fun m] |
130 (select-keys m (filter fun (keys m)))) | 117 (select-keys m (filter fun (keys m)))) |
118 (def filter-keys (preserve-meta filter-keys)) | |
131 | 119 |
132 (defn filter-vals [fun m] | 120 (defn filter-vals [fun m] |
133 (into {} (filter (comp fun val) m))) | 121 (into {} (filter (comp fun val) m))) |
134 | 122 (def filter-vals (preserve-meta filter-vals)) |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | 123 |
144 (defn frame-hash->bufferedImage | 124 (defn frame-hash->bufferedImage |
145 [frame-hash] | 125 [frame-hash] |
146 (let [data (meta frame-hash) | 126 (let [data (meta frame-hash) |
147 image (BufferedImage. (:width data) (:height data) BufferedImage/TYPE_INT_BGR)] | 127 image (BufferedImage. (:width data) (:height data) BufferedImage/TYPE_INT_BGR)] |
153 (+ (bit-shift-left (:r rgb) 16) | 133 (+ (bit-shift-left (:r rgb) 16) |
154 (bit-shift-left (:g rgb) 8) | 134 (bit-shift-left (:g rgb) 8) |
155 (:b rgb))] | 135 (:b rgb))] |
156 (.setRGB image (first coord) (last coord) packed-RGB)))) | 136 (.setRGB image (first coord) (last coord) packed-RGB)))) |
157 image)) | 137 image)) |
138 | |
139 (defmulti display "Creates a JFrame and displays a buffered image" class) | |
140 | |
141 (defn- makePanel [image] (proxy [Panel] [] (paint [g] (.drawImage g image 0 0 nil)))) | |
142 | |
143 | |
144 (defmethod display | |
145 BufferedImage [image] | |
146 (let [panel (makePanel image) | |
147 frame (JFrame. "Oh Yeah!")] | |
148 (.add frame panel) | |
149 (.pack frame) | |
150 (.setVisible frame true ) | |
151 (.setSize frame(.getWidth image) (.getHeight image)))) | |
152 | |
153 (defmethod display | |
154 ImagePlus [image] | |
155 (display (.getBufferedImage image))) | |
156 | |
157 (defmethod display | |
158 clojure.lang.PersistentHashMap [frame-hash] | |
159 (display (frame-hash->bufferedImage frame-hash))) | |
160 | |
161 (defmethod display | |
162 clojure.lang.PersistentArrayMap [frame-hash] | |
163 (display (frame-hash->bufferedImage frame-hash))) | |
158 | 164 |
159 | 165 |
160 | 166 |
167 | |
168 |