comparison 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
comparison
equal deleted inserted replaced
501:4c43b2b8d3c0 502:e9a63daf680a
279 279
280 (count 280 (count
281 (filter 281 (filter
282 (fn [[r g b]] 282 (fn [[r g b]]
283 (= (max r g b) r ))(set (vals gb-color-map)))) 283 (= (max r g b) r ))(set (vals gb-color-map))))
284
285 (def test-image
286 (ImageIO/read
287 (File. user-home "/proj/vba-clojure/images/test-gb-image.png")))
288
289 (defn rgb->triplet [rgb]
290 (let [r (bit-shift-right (bit-and rgb 0xFF0000) 16)
291 g (bit-shift-right (bit-and rgb 0xFF00) 8)
292 b (bit-and rgb 0xFF)]
293 [r g b]))
294
295 (def reverse-gb-color-map
296 (zipmap (vals gb-color-map)
297 (keys gb-color-map)))
298
299 (defn vga-rgb->gb-rgb [[r g b]]
300 (reverse-gb-color-map [r g b]))
301
302 (defn gb-tiles [^BufferedImage image]
303 (for [tile (range 360)]
304 (for [x (range 8) y (range 8)]
305 (vga-rgb->gb-rgb
306 (rgb->triplet
307 (.getRGB image (+ x (rem (* tile 8 8) 160))
308 (+ y (int (/ (* tile 8 8) 144)))))))))
309
310
311 (defn display-image-kernel [^BufferedImage image]
312
313
314
315 )