# HG changeset patch # User Robert McIntyre # Date 1336412224 18000 # Node ID 641e1c511224741dd2da5f65a1e4e6b032d3f0d7 # Parent 09b3bc0b71b53c9825e7c83deedcdc6eb27340b8 cleanup. diff -r 09b3bc0b71b5 -r 641e1c511224 clojure/com/aurellem/gb/gb_driver.clj --- a/clojure/com/aurellem/gb/gb_driver.clj Mon May 07 12:31:16 2012 -0500 +++ b/clojure/com/aurellem/gb/gb_driver.clj Mon May 07 12:37:04 2012 -0500 @@ -271,6 +271,11 @@ (def original-rom (rom (root))) + +;; RGB colors in an image are not the same as those in a GameBoy, so I +;; need to convert them. Fortunately, this code is already written +;; for me in this C-code from the public domain hi-color converter by +;; Glen Cook, Jeff Frohwein, and Rob Jones. (defn rgb->gb-rb [[r g b :as color]] (let [store (int-array 3)] (Gb/translateRGB (int-array color) store) diff -r 09b3bc0b71b5 -r 641e1c511224 clojure/com/aurellem/run/image.clj --- a/clojure/com/aurellem/run/image.clj Mon May 07 12:31:16 2012 -0500 +++ b/clojure/com/aurellem/run/image.clj Mon May 07 12:37:04 2012 -0500 @@ -18,94 +18,3 @@ ;; sprites, and can still be scrolled, so why not? -;; First of all, RGB colors in an image are not the same as those in a -;; GameBoy, so I need to convert them. Fortunately, this code is -;; already written for me in this C-code from the public domain -;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones. - -;; the code snipped itself is by Brett Bibby and is translated here -;; from C into clojure. - - -;; This section of code is used to convert an RGB (pc) triplet into -;; a RGB (gameboy) triplet. This section of code was kindly donated -;; by Brett Bibby (GameBrains). - -;; BYTE intensity[32] = { -;; 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94, -;; 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7, -;; 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff }; - -;; unsigned char influence[3][3] = -;; { -;; {16,4,4}, -;; {8,16,8}, -;; {0,8,16} -;; }; - -;; RGBQUAD translate(BYTE rgb[3]) -;; { -;; RGBQUAD color; -;; BYTE tmp[3]; -;; BYTE m[3][3]; -;; BYTE i,j; - -;; for (i=0;i<3;i++) -;; for (j=0;j<3;j++) -;; m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5; - -;; for (i=0;i<3;i++) -;; { -;; if (m[0][i]>m[1][i]) -;; { -;; j=m[0][i]; -;; m[0][i]=m[1][i]; -;; m[1][i]=j; -;; } - -;; if (m[1][i]>m[2][i]) -;; { -;; j=m[1][i]; -;; m[1][i]=m[2][i]; -;; m[2][i]=j; -;; } - -;; if (m[0][i]>m[1][i]) -;; { -;; j=m[0][i]; -;; m[0][i]=m[1][i]; -;; m[1][i]=j; -;; } - -;; tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; -;; } - -;; color.rgbRed = tmp[0]; -;; color.rgbGreen = tmp[1]; -;; color.rgbBlue = tmp[2]; - -;; return color; -;; } - - -(def intensity - [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94 - 0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7 - 0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff]) - -(def influence - [[16 4 4] - [8 16 8] - [0 8 16]]) - -(defn rgb->gb-rb [[r g b]] - (let [color-matrix - (map - (fn [color-row] - (map - (fn [color] - (bit-shift-right - (* (intensity (bit-shift-right r 3)) - color) 5)))))])) - - \ No newline at end of file