rlm@488: (ns com.aurellem.run.image rlm@486: (:use (com.aurellem.gb saves gb-driver util constants rlm@486: items vbm characters money rlm@486: rlm-assembly)) rlm@486: (:use (com.aurellem.run util title save-corruption rlm@486: bootstrap-0 bootstrap-1)) rlm@486: (:require clojure.string) rlm@486: (:import [com.aurellem.gb.gb_driver SaveState]) rlm@486: (:import java.io.File)) rlm@486: rlm@486: ;; want to display an image onto the screen. rlm@486: ;; probably will be the six ponies, possibly with scrolling. rlm@486: rlm@486: ;; probably don't need hi-color mode since the images shuld be rlm@486: ;; simple. rlm@486: rlm@486: ;; use background tiles? they provide greater color depth than rlm@486: ;; sprites, and can still be scrolled, so why not? rlm@486: rlm@486: rlm@486: ;; First of all, RGB colors in an image are not the same as those in a rlm@486: ;; GameBoy, so I need to convert them. Fortunately, this code is rlm@486: ;; already written for me in this C-code from the public domain rlm@486: ;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones. rlm@486: rlm@486: ;; the code snipped itself is by Brett Bibby and is translated here rlm@486: ;; from C into clojure. rlm@486: rlm@486: rlm@488: ;; This section of code is used to convert an RGB (pc) triplet into rlm@488: ;; a RGB (gameboy) triplet. This section of code was kindly donated rlm@488: ;; by Brett Bibby (GameBrains). rlm@486: rlm@488: ;; BYTE intensity[32] = { rlm@488: ;; 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94, rlm@488: ;; 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7, rlm@488: ;; 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff }; rlm@488: rlm@488: ;; unsigned char influence[3][3] = rlm@488: ;; { rlm@488: ;; {16,4,4}, rlm@488: ;; {8,16,8}, rlm@488: ;; {0,8,16} rlm@488: ;; }; rlm@488: rlm@488: ;; RGBQUAD translate(BYTE rgb[3]) rlm@488: ;; { rlm@488: ;; RGBQUAD color; rlm@488: ;; BYTE tmp[3]; rlm@488: ;; BYTE m[3][3]; rlm@488: ;; BYTE i,j; rlm@488: rlm@488: ;; for (i=0;i<3;i++) rlm@488: ;; for (j=0;j<3;j++) rlm@488: ;; m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5; rlm@488: rlm@488: ;; for (i=0;i<3;i++) rlm@488: ;; { rlm@488: ;; if (m[0][i]>m[1][i]) rlm@488: ;; { rlm@488: ;; j=m[0][i]; rlm@488: ;; m[0][i]=m[1][i]; rlm@488: ;; m[1][i]=j; rlm@488: ;; } rlm@488: rlm@488: ;; if (m[1][i]>m[2][i]) rlm@488: ;; { rlm@488: ;; j=m[1][i]; rlm@488: ;; m[1][i]=m[2][i]; rlm@488: ;; m[2][i]=j; rlm@488: ;; } rlm@488: rlm@488: ;; if (m[0][i]>m[1][i]) rlm@488: ;; { rlm@488: ;; j=m[0][i]; rlm@488: ;; m[0][i]=m[1][i]; rlm@488: ;; m[1][i]=j; rlm@488: ;; } rlm@488: rlm@488: ;; tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; rlm@488: ;; } rlm@488: rlm@488: ;; color.rgbRed = tmp[0]; rlm@488: ;; color.rgbGreen = tmp[1]; rlm@488: ;; color.rgbBlue = tmp[2]; rlm@488: rlm@488: ;; return color; rlm@488: ;; } rlm@488: rlm@488: rlm@488: (def intensity rlm@488: [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94 rlm@488: 0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7 rlm@488: 0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff]) rlm@488: rlm@488: (def influence rlm@488: [[16 4 4] rlm@488: [8 16 8] rlm@488: [0 8 16]]) rlm@486: rlm@486: (defn rgb->gb-rb [[r g b]] rlm@488: (let [color-matrix rlm@488: (map rlm@488: (fn [color-row] rlm@488: (map rlm@488: (fn [color] rlm@488: (bit-shift-right rlm@488: (* (intensity (bit-shift-right r 3)) rlm@488: color) 5)))))])) rlm@488: rlm@488: