Mercurial > vba-clojure
diff clojure/com/aurellem/run/image.clj @ 502:e9a63daf680a
created function to deconstruct image into tiles and translate into gb-rgb color space.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 13 Jun 2012 01:10:00 -0500 |
parents | 4c43b2b8d3c0 |
children | 4703b74f1fb1 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/image.clj Tue Jun 12 10:12:25 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/image.clj Wed Jun 13 01:10:00 2012 -0500 1.3 @@ -281,3 +281,35 @@ 1.4 (filter 1.5 (fn [[r g b]] 1.6 (= (max r g b) r ))(set (vals gb-color-map)))) 1.7 + 1.8 +(def test-image 1.9 + (ImageIO/read 1.10 + (File. user-home "/proj/vba-clojure/images/test-gb-image.png"))) 1.11 + 1.12 +(defn rgb->triplet [rgb] 1.13 + (let [r (bit-shift-right (bit-and rgb 0xFF0000) 16) 1.14 + g (bit-shift-right (bit-and rgb 0xFF00) 8) 1.15 + b (bit-and rgb 0xFF)] 1.16 + [r g b])) 1.17 + 1.18 +(def reverse-gb-color-map 1.19 + (zipmap (vals gb-color-map) 1.20 + (keys gb-color-map))) 1.21 + 1.22 +(defn vga-rgb->gb-rgb [[r g b]] 1.23 + (reverse-gb-color-map [r g b])) 1.24 + 1.25 +(defn gb-tiles [^BufferedImage image] 1.26 + (for [tile (range 360)] 1.27 + (for [x (range 8) y (range 8)] 1.28 + (vga-rgb->gb-rgb 1.29 + (rgb->triplet 1.30 + (.getRGB image (+ x (rem (* tile 8 8) 160)) 1.31 + (+ y (int (/ (* tile 8 8) 144))))))))) 1.32 + 1.33 + 1.34 +(defn display-image-kernel [^BufferedImage image] 1.35 + 1.36 + 1.37 + 1.38 + ) 1.39 \ No newline at end of file