comparison src/laser/rasterize.clj @ 2:5ed873917c34

enabled display
author Robert McIntyre <rlm@mit.edu>
date Fri, 20 Aug 2010 00:39:50 -0400
parents 6d9bdaf919f7
children e6254010c95a
comparison
equal deleted inserted replaced
1:6d9bdaf919f7 2:5ed873917c34
5 (import '(javax.imageio ImageIO) ) 5 (import '(javax.imageio ImageIO) )
6 (import '(javax.swing JFrame)) 6 (import '(javax.swing JFrame))
7 (import '(java.awt Color BorderLayout)) 7 (import '(java.awt Color BorderLayout))
8 (import '(ij ImagePlus IJ)) 8 (import '(ij ImagePlus IJ))
9 (import '(java.lang Math)) 9 (import '(java.lang Math))
10 10 (import '(java.awt Graphics2D Panel))
11 (import '(ij Macro)) 11 (import '(ij Macro))
12 12
13 (import '(java.io BufferedReader InputStreamReader)) 13 (import '(java.io BufferedReader InputStreamReader))
14 (import '(java.awt.image BufferedImage)) 14 (import '(java.awt.image BufferedImage))
15 15
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)
41 42
43 (defn- makePanel [image] (proxy [Panel] [] (paint [g] (.drawImage g image 0 0 nil))))
44
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)))
42 65
43 66
44 (defn raster-preamble [] 67 (defn raster-preamble []
45 (str-join \newline 68 (str-join \newline
46 ["M63 P0\nG61" 69 ["M63 P0\nG61"
47 (str \F feed) 70 (str \F feed)
48 "M101" 71 "M101"
49 "M3 S1"])) 72 "M3 S1"]))
50
51
52 73
53 (defn frame-hash 74 (defn frame-hash
54 "yields a convienent representation for the pixles in an image. 75 "yields a convienent representation for the pixles in an image.
55 Because of the size of the structvre generated, this must only be used 76 Because of the size of the structvre generated, this must only be used
56 in a transient way so that java can do it's garbage collection." 77 in a transient way so that java can do it's garbage collection."
95 116
96 117
97 118
98 119
99 120
121
122
123
124
125
126
127
128
100 129
101 130
102 131
103 132
104 133