Mercurial > vba-clojure
comparison clojure/com/aurellem/run/image.clj @ 514:a00981db92da
can now display black and white images (still working on color).
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 22 Jun 2012 21:03:04 -0500 |
parents | 3dbb863eb801 |
children | f68d600b089c |
comparison
equal
deleted
inserted
replaced
513:3dbb863eb801 | 514:a00981db92da |
---|---|
282 | 282 |
283 (def test-image | 283 (def test-image |
284 (ImageIO/read | 284 (ImageIO/read |
285 (File. user-home "/proj/vba-clojure/images/test-gb-image.png"))) | 285 (File. user-home "/proj/vba-clojure/images/test-gb-image.png"))) |
286 | 286 |
287 (def test-image-2 | |
288 (ImageIO/read | |
289 (File. user-home "/proj/vba-clojure/images/test-gb-image-2.png"))) | |
290 | |
291 | |
292 | |
287 (defn rgb->triplet [rgb] | 293 (defn rgb->triplet [rgb] |
288 (let [r (bit-shift-right (bit-and rgb 0xFF0000) 16) | 294 (let [r (bit-shift-right (bit-and rgb 0xFF0000) 16) |
289 g (bit-shift-right (bit-and rgb 0xFF00) 8) | 295 g (bit-shift-right (bit-and rgb 0xFF00) 8) |
290 b (bit-and rgb 0xFF)] | 296 b (bit-and rgb 0xFF)] |
291 [r g b])) | 297 [r g b])) |
297 (defn vga-rgb->gb-rgb [[r g b]] | 303 (defn vga-rgb->gb-rgb [[r g b]] |
298 (reverse-gb-color-map [r g b])) | 304 (reverse-gb-color-map [r g b])) |
299 | 305 |
300 (defn gb-tiles [^BufferedImage image] | 306 (defn gb-tiles [^BufferedImage image] |
301 (for [tile (range 360)] | 307 (for [tile (range 360)] |
302 (for [x (range 8) y (range 8)] | 308 (for [y (range 8) x (range 8)] |
303 (vga-rgb->gb-rgb | 309 (vga-rgb->gb-rgb |
304 (rgb->triplet | 310 (rgb->triplet |
305 (.getRGB image (+ x (* 8 (rem tile 20))) | 311 (.getRGB image (+ x (* 8 (rem tile 20))) |
306 (+ y (* 8 (int (/ tile 20)))))))))) | 312 (+ y (* 8 (int (/ tile 20)))))))))) |
307 | 313 |
461 (disect-bytes-2 | 467 (disect-bytes-2 |
462 (+ len base-address program-length))) | 468 (+ len base-address program-length))) |
463 data]))) | 469 data]))) |
464 | 470 |
465 (defn write-image | 471 (defn write-image |
466 "Assume the image data is 160x144 pixels specified as 360 blocks." | 472 "Assume the image data is specified as 360 blocks." |
467 [base-address target-address image-data] | 473 [base-address target-address image-data] |
468 | 474 |
469 (let [len (count image-data) | 475 (let [len (count image-data) |
470 gen-program | 476 gen-program |
471 (fn [program-length] | 477 (fn [program-length] |
509 | 515 |
510 0xC1 ;; pop BC | 516 0xC1 ;; pop BC |
511 | 517 |
512 0x1D ;; dec E | 518 0x1D ;; dec E |
513 0x20 | 519 0x20 |
514 (->signed-8-bit -18) ;; contunue writing picture | 520 (->signed-8-bit -18) ;; contunue writing image |
515 | 521 |
516 0xC3 | 522 0xC3 |
517 (reverse | 523 (reverse |
518 (disect-bytes-2 | 524 (disect-bytes-2 |
519 (+ len base-address program-length)))]))] | 525 (+ len base-address program-length)))]))] |
607 | 613 |
608 C (flatten C) | 614 C (flatten C) |
609 | 615 |
610 D [;; [ ] specifiy pallets for each character | 616 D [;; [ ] specifiy pallets for each character |
611 (select-LCD-bank 1) | 617 (select-LCD-bank 1) |
612 (write-image | 618 ;;(write-image |
613 (+ base-address (+ (count A) (count B) (count C))) | 619 ;; (+ base-address (+ (count A) (count B) (count C))) |
614 BG-1-address | 620 ;; BG-1-address |
615 (map second (:data gb-image))) | 621 ;;(map second (:data gb-image))) |
616 | 622 |
617 | 623 |
618 ;; [X] reactivate the LCD display | 624 ;; [X] reactivate the LCD display |
619 ;; we're using only BG images, located at | 625 ;; we're using only BG images, located at |
620 ;; BG-1 (0x9800), with background character data | 626 ;; BG-1 (0x9800), with background character data |