comparison clojure/com/aurellem/run/image.clj @ 522:5596cd4a3fc6

added RAM display.
author Robert McIntyre <rlm@mit.edu>
date Sat, 23 Jun 2012 19:12:26 -0500
parents fd1ae0047a1a
children 7f8030812ac2
comparison
equal deleted inserted replaced
521:bad7b7430245 522:5596cd4a3fc6
4 rlm-assembly)) 4 rlm-assembly))
5 (:use (com.aurellem.run util music title save-corruption 5 (:use (com.aurellem.run util music title save-corruption
6 bootstrap-0 bootstrap-1)) 6 bootstrap-0 bootstrap-1))
7 (:require clojure.string) 7 (:require clojure.string)
8 (:import [com.aurellem.gb.gb_driver SaveState]) 8 (:import [com.aurellem.gb.gb_driver SaveState])
9 (:import java.awt.image.BufferedImage)
9 (:import java.io.File)) 10 (:import java.io.File))
10 11
11 ;; want to display an image onto the screen. 12 ;; want to display an image onto the screen.
12 ;; probably will be the six ponies, possibly with scrolling. 13 ;; probably will be the six ponies, possibly with scrolling.
13 14
147 (PC! kernel-address)))) 148 (PC! kernel-address))))
148 ([[r g b]] 149 ([[r g b]]
149 (display-one-color @current-state [r g b]))) 150 (display-one-color @current-state [r g b])))
150 151
151 ;;(require 'cortex.sense) 152 ;;(require 'cortex.sense)
152 (import java.awt.image.BufferedImage) 153
153 154
154 ;; (defn show-screenshot [] 155 ;; (defn show-screenshot []
155 ;; (let [im (BufferedImage. 160 144 BufferedImage/TYPE_INT_RGB) 156 ;; (let [im (BufferedImage. 160 144 BufferedImage/TYPE_INT_RGB)
156 ;; pix (vec (pixels)) 157 ;; pix (vec (pixels))
157 ;; view (cortex.sense/view-image)] 158 ;; view (cortex.sense/view-image)]
199 (def gb-color-map 200 (def gb-color-map
200 (read-string (slurp gb-color-map-file))) 201 (read-string (slurp gb-color-map-file)))
201 202
202 (import javax.imageio.stream.FileImageOutputStream) 203 (import javax.imageio.stream.FileImageOutputStream)
203 (import '(javax.imageio ImageWriteParam IIOImage ImageIO)) 204 (import '(javax.imageio ImageWriteParam IIOImage ImageIO))
205
206
207 (defn write-image! [^BufferedImage image ^File target]
208 (doto
209 (.next (ImageIO/getImageWritersByFormatName "png"))
210 (.setOutput (FileImageOutputStream. target))
211 (.write (IIOImage. image nil nil))
212 (.dispose))
213 image)
204 214
205 215
206 (defn gen-gb-color-image! [] 216 (defn gen-gb-color-image! []
207 (let [im (BufferedImage. 68 69 BufferedImage/TYPE_INT_RGB) 217 (let [im (BufferedImage. 68 69 BufferedImage/TYPE_INT_RGB)
208 pix (vec 218 pix (vec
240 rgb (+ (bit-shift-left r 16) 250 rgb (+ (bit-shift-left r 16)
241 (bit-shift-left g 8) 251 (bit-shift-left g 8)
242 b)] 252 b)]
243 (.setRGB im x y rgb)))) 253 (.setRGB im x y rgb))))
244 ;;(view im) 254 ;;(view im)
245 (doto 255 (write-image! im target)))
246 (.next (ImageIO/getImageWritersByFormatName "png")) 256
247 (.setOutput (FileImageOutputStream. target)) 257
248 (.write (IIOImage. im nil nil))
249 (.dispose))
250 im))
251
252 (defn gen-gb-color-image*! [] 258 (defn gen-gb-color-image*! []
253 (let [im (BufferedImage. 213 213 BufferedImage/TYPE_INT_RGB) 259 (let [im (BufferedImage. 213 213 BufferedImage/TYPE_INT_RGB)
254 squares 260 squares
255 (vec 261 (vec
256 (for [r (range 32)] 262 (for [r (range 32)]
272 (.setRGB im 278 (.setRGB im
273 (+ 3 (* 35 (rem s-index 6)) x) 279 (+ 3 (* 35 (rem s-index 6)) x)
274 (+ 3 (* 35 (int (/ s-index 6))) y) 280 (+ 3 (* 35 (int (/ s-index 6))) y)
275 rgb)))))) 281 rgb))))))
276 ;;(view im) 282 ;;(view im)
277 (doto 283 (write-image! im target)))
278 (.next (ImageIO/getImageWritersByFormatName "png"))
279 (.setOutput (FileImageOutputStream. target))
280 (.write (IIOImage. im nil nil))
281 (.dispose))
282 im))
283 284
284 (defn gen-gimp-palette! [] 285 (defn gen-gimp-palette! []
285 (let [target 286 (let [target
286 (File. user-home "proj/vba-clojure/Gameboy-Color.gpl")] 287 (File. user-home "proj/vba-clojure/Gameboy-Color.gpl")]
287 (spit 288 (spit
668 D (flatten D)] 669 D (flatten D)]
669 670
670 (concat A B C D))) 671 (concat A B C D)))
671 672
672 (defn display-image [#^BufferedImage image] 673 (defn display-image [#^BufferedImage image]
673 (let [kernel-address 0xB000] 674 (let [kernel-address 0xB500]
674 (-> (tick (tick (tick (mid-game)))) 675 (-> (tick (tick (tick (mid-game))))
675 (set-memory-range 676 (set-memory-range
676 kernel-address 677 kernel-address
677 (display-image-kernel kernel-address image)) 678 (display-image-kernel kernel-address image))
678 (PC! kernel-address)))) 679 (PC! kernel-address))))
680