Mercurial > vba-clojure
comparison clojure/com/aurellem/run/image.clj @ 488:09b3bc0b71b5
added rgb->gbRGB translation code.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 07 May 2012 12:31:16 -0500 |
parents | 3f0156038802 |
children | 641e1c511224 2304906d443b |
comparison
equal
deleted
inserted
replaced
487:09df21060be6 | 488:09b3bc0b71b5 |
---|---|
1 (ns com.aurellem.run.music | 1 (ns com.aurellem.run.image |
2 (:use (com.aurellem.gb saves gb-driver util constants | 2 (:use (com.aurellem.gb saves gb-driver util constants |
3 items vbm characters money | 3 items vbm characters money |
4 rlm-assembly)) | 4 rlm-assembly)) |
5 (:use (com.aurellem.run util title save-corruption | 5 (:use (com.aurellem.run util 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.io.File)) | 9 (:import java.io.File)) |
10 | |
11 | |
12 | |
13 | |
14 | 10 |
15 ;; want to display an image onto the screen. | 11 ;; want to display an image onto the screen. |
16 ;; probably will be the six ponies, possibly with scrolling. | 12 ;; probably will be the six ponies, possibly with scrolling. |
17 | 13 |
18 ;; probably don't need hi-color mode since the images shuld be | 14 ;; probably don't need hi-color mode since the images shuld be |
28 ;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones. | 24 ;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones. |
29 | 25 |
30 ;; the code snipped itself is by Brett Bibby and is translated here | 26 ;; the code snipped itself is by Brett Bibby and is translated here |
31 ;; from C into clojure. | 27 ;; from C into clojure. |
32 | 28 |
33 ;; TODO include original code | 29 |
30 ;; This section of code is used to convert an RGB (pc) triplet into | |
31 ;; a RGB (gameboy) triplet. This section of code was kindly donated | |
32 ;; by Brett Bibby (GameBrains). | |
33 | |
34 ;; BYTE intensity[32] = { | |
35 ;; 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94, | |
36 ;; 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7, | |
37 ;; 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff }; | |
38 | |
39 ;; unsigned char influence[3][3] = | |
40 ;; { | |
41 ;; {16,4,4}, | |
42 ;; {8,16,8}, | |
43 ;; {0,8,16} | |
44 ;; }; | |
45 | |
46 ;; RGBQUAD translate(BYTE rgb[3]) | |
47 ;; { | |
48 ;; RGBQUAD color; | |
49 ;; BYTE tmp[3]; | |
50 ;; BYTE m[3][3]; | |
51 ;; BYTE i,j; | |
52 | |
53 ;; for (i=0;i<3;i++) | |
54 ;; for (j=0;j<3;j++) | |
55 ;; m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5; | |
56 | |
57 ;; for (i=0;i<3;i++) | |
58 ;; { | |
59 ;; if (m[0][i]>m[1][i]) | |
60 ;; { | |
61 ;; j=m[0][i]; | |
62 ;; m[0][i]=m[1][i]; | |
63 ;; m[1][i]=j; | |
64 ;; } | |
65 | |
66 ;; if (m[1][i]>m[2][i]) | |
67 ;; { | |
68 ;; j=m[1][i]; | |
69 ;; m[1][i]=m[2][i]; | |
70 ;; m[2][i]=j; | |
71 ;; } | |
72 | |
73 ;; if (m[0][i]>m[1][i]) | |
74 ;; { | |
75 ;; j=m[0][i]; | |
76 ;; m[0][i]=m[1][i]; | |
77 ;; m[1][i]=j; | |
78 ;; } | |
79 | |
80 ;; tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; | |
81 ;; } | |
82 | |
83 ;; color.rgbRed = tmp[0]; | |
84 ;; color.rgbGreen = tmp[1]; | |
85 ;; color.rgbBlue = tmp[2]; | |
86 | |
87 ;; return color; | |
88 ;; } | |
34 | 89 |
35 | 90 |
36 (def intensity [ | 91 (def intensity |
92 [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94 | |
93 0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7 | |
94 0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff]) | |
95 | |
96 (def influence | |
97 [[16 4 4] | |
98 [8 16 8] | |
99 [0 8 16]]) | |
37 | 100 |
38 (defn rgb->gb-rb [[r g b]] | 101 (defn rgb->gb-rb [[r g b]] |
39 | 102 (let [color-matrix |
103 (map | |
104 (fn [color-row] | |
105 (map | |
106 (fn [color] | |
107 (bit-shift-right | |
108 (* (intensity (bit-shift-right r 3)) | |
109 color) 5)))))])) | |
110 | |
111 |