Mercurial > vba-clojure
changeset 488:09b3bc0b71b5
added rgb->gbRGB translation code.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 07 May 2012 12:31:16 -0500 |
parents | 09df21060be6 |
children | 641e1c511224 2304906d443b |
files | clojure/com/aurellem/gb/gb_driver.clj clojure/com/aurellem/run/image.clj java/build.xml java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp temp-c-stuff |
diffstat | 6 files changed, 153 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/gb_driver.clj Mon May 07 11:15:49 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj Mon May 07 12:31:16 2012 -0500 1.3 @@ -269,6 +269,9 @@ 1.4 (defn ~@forms) 1.5 (alter-var-root (var ~fun-name) memoize)))) 1.6 1.7 +(def original-rom (rom (root))) 1.8 1.9 - 1.10 -(def original-rom (rom (root))) 1.11 \ No newline at end of file 1.12 +(defn rgb->gb-rb [[r g b :as color]] 1.13 + (let [store (int-array 3)] 1.14 + (Gb/translateRGB (int-array color) store) 1.15 + (vec store))) 1.16 \ No newline at end of file
2.1 --- a/clojure/com/aurellem/run/image.clj Mon May 07 11:15:49 2012 -0500 2.2 +++ b/clojure/com/aurellem/run/image.clj Mon May 07 12:31:16 2012 -0500 2.3 @@ -1,4 +1,4 @@ 2.4 -(ns com.aurellem.run.music 2.5 +(ns com.aurellem.run.image 2.6 (:use (com.aurellem.gb saves gb-driver util constants 2.7 items vbm characters money 2.8 rlm-assembly)) 2.9 @@ -8,10 +8,6 @@ 2.10 (:import [com.aurellem.gb.gb_driver SaveState]) 2.11 (:import java.io.File)) 2.12 2.13 - 2.14 - 2.15 - 2.16 - 2.17 ;; want to display an image onto the screen. 2.18 ;; probably will be the six ponies, possibly with scrolling. 2.19 2.20 @@ -30,10 +26,86 @@ 2.21 ;; the code snipped itself is by Brett Bibby and is translated here 2.22 ;; from C into clojure. 2.23 2.24 -;; TODO include original code 2.25 2.26 +;; This section of code is used to convert an RGB (pc) triplet into 2.27 +;; a RGB (gameboy) triplet. This section of code was kindly donated 2.28 +;; by Brett Bibby (GameBrains). 2.29 2.30 -(def intensity [ 2.31 +;; BYTE intensity[32] = { 2.32 +;; 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94, 2.33 +;; 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7, 2.34 +;; 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff }; 2.35 + 2.36 +;; unsigned char influence[3][3] = 2.37 +;; { 2.38 +;; {16,4,4}, 2.39 +;; {8,16,8}, 2.40 +;; {0,8,16} 2.41 +;; }; 2.42 + 2.43 +;; RGBQUAD translate(BYTE rgb[3]) 2.44 +;; { 2.45 +;; RGBQUAD color; 2.46 +;; BYTE tmp[3]; 2.47 +;; BYTE m[3][3]; 2.48 +;; BYTE i,j; 2.49 + 2.50 +;; for (i=0;i<3;i++) 2.51 +;; for (j=0;j<3;j++) 2.52 +;; m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5; 2.53 + 2.54 +;; for (i=0;i<3;i++) 2.55 +;; { 2.56 +;; if (m[0][i]>m[1][i]) 2.57 +;; { 2.58 +;; j=m[0][i]; 2.59 +;; m[0][i]=m[1][i]; 2.60 +;; m[1][i]=j; 2.61 +;; } 2.62 + 2.63 +;; if (m[1][i]>m[2][i]) 2.64 +;; { 2.65 +;; j=m[1][i]; 2.66 +;; m[1][i]=m[2][i]; 2.67 +;; m[2][i]=j; 2.68 +;; } 2.69 + 2.70 +;; if (m[0][i]>m[1][i]) 2.71 +;; { 2.72 +;; j=m[0][i]; 2.73 +;; m[0][i]=m[1][i]; 2.74 +;; m[1][i]=j; 2.75 +;; } 2.76 + 2.77 +;; tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; 2.78 +;; } 2.79 + 2.80 +;; color.rgbRed = tmp[0]; 2.81 +;; color.rgbGreen = tmp[1]; 2.82 +;; color.rgbBlue = tmp[2]; 2.83 + 2.84 +;; return color; 2.85 +;; } 2.86 + 2.87 + 2.88 +(def intensity 2.89 + [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94 2.90 + 0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7 2.91 + 0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff]) 2.92 + 2.93 +(def influence 2.94 + [[16 4 4] 2.95 + [8 16 8] 2.96 + [0 8 16]]) 2.97 2.98 (defn rgb->gb-rb [[r g b]] 2.99 - 2.100 \ No newline at end of file 2.101 + (let [color-matrix 2.102 + (map 2.103 + (fn [color-row] 2.104 + (map 2.105 + (fn [color] 2.106 + (bit-shift-right 2.107 + (* (intensity (bit-shift-right r 3)) 2.108 + color) 5)))))])) 2.109 + 2.110 + 2.111 \ No newline at end of file
3.1 --- a/java/build.xml Mon May 07 11:15:49 2012 -0500 3.2 +++ b/java/build.xml Mon May 07 12:31:16 2012 -0500 3.3 @@ -23,15 +23,14 @@ 3.4 classpath="${build}"/> 3.5 </target> 3.6 3.7 - <target name="dist"> 3.8 + <target name="dist" depends="native"> 3.9 <jar jarfile="${dist}/gb-bindings.jar"> 3.10 <fileset dir="${build}"/> 3.11 <fileset dir="${src}"/> 3.12 </jar> 3.13 </target> 3.14 3.15 - <target name="all" depends="native, dist"/> 3.16 - 3.17 + <target name="all" depends="dist"/> 3.18 3.19 <target name="clean" > 3.20 <delete dir="${build}"/>
4.1 --- a/java/src/com/aurellem/gb/Gb.java Mon May 07 11:15:49 2012 -0500 4.2 +++ b/java/src/com/aurellem/gb/Gb.java Mon May 07 12:31:16 2012 -0500 4.3 @@ -119,4 +119,6 @@ 4.4 4.5 public static native void writeRegisters(int[] newRegisters); 4.6 4.7 + public static native void translateRGB(int[] rgb, int[] store); 4.8 + 4.9 }
5.1 --- a/src/clojure/clojure.cpp Mon May 07 11:15:49 2012 -0500 5.2 +++ b/src/clojure/clojure.cpp Mon May 07 12:31:16 2012 -0500 5.3 @@ -25,7 +25,7 @@ 5.4 */ 5.5 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator 5.6 (JNIEnv *env, jclass clazz, jstring str){ 5.7 - UNUSED(env);UNUSED(clazz);UNUSED(str); 5.8 + UNUSED(clazz); 5.9 5.10 const char *_romName = env->GetStringUTFChars(str, 0); 5.11 size_t len = strlen(_romName); 5.12 @@ -247,3 +247,66 @@ 5.13 env->ReleaseIntArrayElements(arr, new_registers, 0); 5.14 } 5.15 5.16 + 5.17 +int intensity[32] = { 5.18 + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94, 5.19 + 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7, 5.20 + 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff }; 5.21 + 5.22 +int influence[3][3] = 5.23 + { 5.24 + {16,4,4}, 5.25 + {8,16,8}, 5.26 + {0,8,16} 5.27 + }; 5.28 + 5.29 +int* translateRGB(int* rgb, int* store){ 5.30 + 5.31 + int m[3][3]; 5.32 + int i,j; 5.33 + 5.34 + for (i=0;i<3;i++){ 5.35 + for (j=0;j<3;j++){ 5.36 + m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}} 5.37 + 5.38 + for (i=0;i<3;i++) 5.39 + { 5.40 + if (m[0][i]>m[1][i]) 5.41 + { 5.42 + j=m[0][i]; 5.43 + m[0][i]=m[1][i]; 5.44 + m[1][i]=j; 5.45 + } 5.46 + 5.47 + if (m[1][i]>m[2][i]) 5.48 + { 5.49 + j=m[1][i]; 5.50 + m[1][i]=m[2][i]; 5.51 + m[2][i]=j; 5.52 + } 5.53 + 5.54 + if (m[0][i]>m[1][i]) 5.55 + { 5.56 + j=m[0][i]; 5.57 + m[0][i]=m[1][i]; 5.58 + m[1][i]=j; 5.59 + } 5.60 + 5.61 + store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; 5.62 + } 5.63 + return store; 5.64 +} 5.65 + 5.66 +/* 5.67 + * Class: com_aurellem_gb_Gb 5.68 + * Method: translateRGB 5.69 + * Signature: ([I[I)V 5.70 + */ 5.71 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB 5.72 +(JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){ 5.73 + jint *RGB_Arr = env->GetIntArrayElements(rgb, 0); 5.74 + jint *store_Arr = env->GetIntArrayElements(store,0); 5.75 + translateRGB(RGB_Arr, store_Arr); 5.76 + env->ReleaseIntArrayElements(rgb, RGB_Arr, 0); 5.77 + env->ReleaseIntArrayElements(store, store_Arr, 0); 5.78 +}
6.1 --- a/temp-c-stuff Mon May 07 11:15:49 2012 -0500 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,72 +0,0 @@ 6.4 -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 6.5 - 6.6 - 6.7 -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 6.8 - 6.9 - 6.10 -// This section of code is used to convert an RGB (pc) triplet into a RGB (gameboy) 6.11 -// triplet. This section of code was kindly donated by Brett Bibby (GameBrains). 6.12 - 6.13 -BYTE intensity[32] = 6.14 - { 6.15 - 0x00,0x10,0x20,0x30,0x40,0x50,0x5e,0x6c,0x7a,0x88,0x94,0xa0,0xae,0xb7,0xbf,0xc6, 6.16 - 0xce,0xd3,0xd9,0xdf,0xe3,0xe7,0xeb,0xef,0xf3,0xf6,0xf9,0xfb,0xfd,0xfe,0xff,0xff 6.17 - }; 6.18 - 6.19 -unsigned char influence[3][3] = 6.20 - { 6.21 - {16,4,4}, 6.22 - {8,16,8}, 6.23 - {0,8,16} 6.24 - }; 6.25 - 6.26 -RGBQUAD translate(BYTE rgb[3]) 6.27 -{ 6.28 - RGBQUAD color; 6.29 - BYTE tmp[3]; 6.30 - BYTE m[3][3]; 6.31 - BYTE i,j; 6.32 - 6.33 - for (i=0;i<3;i++) 6.34 - for (j=0;j<3;j++) 6.35 - m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5; 6.36 - 6.37 - for (i=0;i<3;i++) 6.38 - { 6.39 - if (m[0][i]>m[1][i]) 6.40 - { 6.41 - j=m[0][i]; 6.42 - m[0][i]=m[1][i]; 6.43 - m[1][i]=j; 6.44 - } 6.45 - 6.46 - if (m[1][i]>m[2][i]) 6.47 - { 6.48 - j=m[1][i]; 6.49 - m[1][i]=m[2][i]; 6.50 - m[2][i]=j; 6.51 - } 6.52 - 6.53 - if (m[0][i]>m[1][i]) 6.54 - { 6.55 - j=m[0][i]; 6.56 - m[0][i]=m[1][i]; 6.57 - m[1][i]=j; 6.58 - } 6.59 - 6.60 - tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; 6.61 - } 6.62 - 6.63 - color.rgbRed = tmp[0]; 6.64 - color.rgbGreen = tmp[1]; 6.65 - color.rgbBlue = tmp[2]; 6.66 - 6.67 - return color; 6.68 -} 6.69 - 6.70 - 6.71 - 6.72 - 6.73 - 6.74 -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 6.75 -