diff 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
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/image.clj	Sat Jun 23 17:45:38 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/image.clj	Sat Jun 23 19:12:26 2012 -0500
     1.3 @@ -6,6 +6,7 @@
     1.4                            bootstrap-0 bootstrap-1))
     1.5    (:require clojure.string)
     1.6    (:import [com.aurellem.gb.gb_driver SaveState])
     1.7 +  (:import java.awt.image.BufferedImage)
     1.8    (:import java.io.File))
     1.9  
    1.10  ;; want to display an image onto the screen.
    1.11 @@ -149,7 +150,7 @@
    1.12       (display-one-color @current-state [r g b])))
    1.13  
    1.14  ;;(require 'cortex.sense)
    1.15 -(import java.awt.image.BufferedImage)
    1.16 +
    1.17  
    1.18  ;; (defn show-screenshot []
    1.19  ;;   (let [im (BufferedImage. 160 144 BufferedImage/TYPE_INT_RGB)
    1.20 @@ -203,6 +204,15 @@
    1.21  (import '(javax.imageio ImageWriteParam IIOImage ImageIO))
    1.22  
    1.23  
    1.24 +(defn write-image! [^BufferedImage image ^File target]
    1.25 +  (doto
    1.26 +      (.next (ImageIO/getImageWritersByFormatName "png"))
    1.27 +    (.setOutput (FileImageOutputStream. target))
    1.28 +    (.write (IIOImage. image nil nil))
    1.29 +    (.dispose))
    1.30 +  image)
    1.31 +
    1.32 +
    1.33  (defn gen-gb-color-image! []
    1.34    (let [im (BufferedImage. 68 69 BufferedImage/TYPE_INT_RGB)
    1.35          pix (vec
    1.36 @@ -242,13 +252,9 @@
    1.37                            b)]
    1.38                 (.setRGB im x y rgb))))
    1.39      ;;(view im)
    1.40 -    (doto
    1.41 -        (.next (ImageIO/getImageWritersByFormatName "png"))
    1.42 -      (.setOutput (FileImageOutputStream. target))
    1.43 -      (.write (IIOImage. im nil nil))
    1.44 -      (.dispose))
    1.45 -    im))
    1.46 -          
    1.47 +    (write-image! im target)))
    1.48 +
    1.49 +
    1.50  (defn gen-gb-color-image*! []
    1.51    (let [im (BufferedImage. 213 213 BufferedImage/TYPE_INT_RGB)
    1.52          squares
    1.53 @@ -274,12 +280,7 @@
    1.54                       (+ 3 (* 35 (int (/ s-index 6))) y)
    1.55                       rgb))))))
    1.56      ;;(view im)
    1.57 -    (doto
    1.58 -        (.next (ImageIO/getImageWritersByFormatName "png"))
    1.59 -      (.setOutput (FileImageOutputStream. target))
    1.60 -      (.write (IIOImage. im nil nil))
    1.61 -      (.dispose))
    1.62 -    im))
    1.63 +    (write-image! im target)))
    1.64  
    1.65  (defn gen-gimp-palette! []
    1.66    (let [target
    1.67 @@ -670,9 +671,10 @@
    1.68      (concat A B C D)))
    1.69  
    1.70  (defn display-image [#^BufferedImage image]
    1.71 -  (let [kernel-address 0xB000]
    1.72 +  (let [kernel-address 0xB500]
    1.73      (-> (tick (tick (tick (mid-game))))
    1.74          (set-memory-range
    1.75           kernel-address
    1.76           (display-image-kernel kernel-address image))
    1.77          (PC! kernel-address))))
    1.78 +