comparison src/clojure/clojure.cpp @ 488:09b3bc0b71b5

added rgb->gbRGB translation code.
author Robert McIntyre <rlm@mit.edu>
date Mon, 07 May 2012 12:31:16 -0500
parents 893c753f8088
children a6d060a64246
comparison
equal deleted inserted replaced
487:09df21060be6 488:09b3bc0b71b5
23 * Method: startEmulator 23 * Method: startEmulator
24 * Signature: (Ljava/lang/String;)V 24 * Signature: (Ljava/lang/String;)V
25 */ 25 */
26 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator 26 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator
27 (JNIEnv *env, jclass clazz, jstring str){ 27 (JNIEnv *env, jclass clazz, jstring str){
28 UNUSED(env);UNUSED(clazz);UNUSED(str); 28 UNUSED(clazz);
29 29
30 const char *_romName = env->GetStringUTFChars(str, 0); 30 const char *_romName = env->GetStringUTFChars(str, 0);
31 size_t len = strlen(_romName); 31 size_t len = strlen(_romName);
32 32
33 char romName[len + 1]; 33 char romName[len + 1];
245 jint *new_registers = env->GetIntArrayElements(arr, 0); 245 jint *new_registers = env->GetIntArrayElements(arr, 0);
246 setRegisters(new_registers); 246 setRegisters(new_registers);
247 env->ReleaseIntArrayElements(arr, new_registers, 0); 247 env->ReleaseIntArrayElements(arr, new_registers, 0);
248 } 248 }
249 249
250
251 int intensity[32] = {
252 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
253 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
254 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
255
256 int influence[3][3] =
257 {
258 {16,4,4},
259 {8,16,8},
260 {0,8,16}
261 };
262
263 int* translateRGB(int* rgb, int* store){
264
265 int m[3][3];
266 int i,j;
267
268 for (i=0;i<3;i++){
269 for (j=0;j<3;j++){
270 m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}}
271
272 for (i=0;i<3;i++)
273 {
274 if (m[0][i]>m[1][i])
275 {
276 j=m[0][i];
277 m[0][i]=m[1][i];
278 m[1][i]=j;
279 }
280
281 if (m[1][i]>m[2][i])
282 {
283 j=m[1][i];
284 m[1][i]=m[2][i];
285 m[2][i]=j;
286 }
287
288 if (m[0][i]>m[1][i])
289 {
290 j=m[0][i];
291 m[0][i]=m[1][i];
292 m[1][i]=j;
293 }
294
295 store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
296 }
297 return store;
298 }
299
300 /*
301 * Class: com_aurellem_gb_Gb
302 * Method: translateRGB
303 * Signature: ([I[I)V
304 */
305 JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB
306 (JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){
307 jint *RGB_Arr = env->GetIntArrayElements(rgb, 0);
308 jint *store_Arr = env->GetIntArrayElements(store,0);
309 translateRGB(RGB_Arr, store_Arr);
310 env->ReleaseIntArrayElements(rgb, RGB_Arr, 0);
311 env->ReleaseIntArrayElements(store, store_Arr, 0);
312 }