diff 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
line wrap: on
line diff
     1.1 --- a/src/clojure/clojure.cpp	Mon May 07 11:15:49 2012 -0500
     1.2 +++ b/src/clojure/clojure.cpp	Mon May 07 12:31:16 2012 -0500
     1.3 @@ -25,7 +25,7 @@
     1.4   */
     1.5  JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_startEmulator
     1.6  (JNIEnv *env, jclass clazz, jstring str){
     1.7 -  UNUSED(env);UNUSED(clazz);UNUSED(str);
     1.8 +  UNUSED(clazz);
     1.9  
    1.10    const char *_romName = env->GetStringUTFChars(str, 0);
    1.11    size_t len = strlen(_romName);
    1.12 @@ -247,3 +247,66 @@
    1.13    env->ReleaseIntArrayElements(arr, new_registers, 0);
    1.14  }
    1.15  
    1.16 +
    1.17 +int intensity[32] = {
    1.18 +  0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
    1.19 +  0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
    1.20 +  0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
    1.21 +
    1.22 +int influence[3][3] = 
    1.23 +  {
    1.24 +    {16,4,4},
    1.25 +    {8,16,8},
    1.26 +    {0,8,16}
    1.27 +  };
    1.28 +
    1.29 +int* translateRGB(int* rgb, int* store){
    1.30 +
    1.31 +  int	m[3][3];
    1.32 +  int	i,j;
    1.33 +
    1.34 +  for (i=0;i<3;i++){
    1.35 +    for (j=0;j<3;j++){
    1.36 +      m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;}}
    1.37 +
    1.38 +  for (i=0;i<3;i++)
    1.39 +    {
    1.40 +      if (m[0][i]>m[1][i])
    1.41 + 	{
    1.42 + 	  j=m[0][i]; 
    1.43 + 	  m[0][i]=m[1][i]; 
    1.44 + 	  m[1][i]=j;
    1.45 + 	}
    1.46 +
    1.47 +      if (m[1][i]>m[2][i])
    1.48 + 	{
    1.49 + 	  j=m[1][i]; 
    1.50 + 	  m[1][i]=m[2][i]; 
    1.51 + 	  m[2][i]=j;
    1.52 + 	}
    1.53 +
    1.54 +      if (m[0][i]>m[1][i])
    1.55 + 	{
    1.56 + 	  j=m[0][i]; 
    1.57 + 	  m[0][i]=m[1][i]; 
    1.58 + 	  m[1][i]=j;
    1.59 + 	}
    1.60 +
    1.61 +      store[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
    1.62 +    }
    1.63 +  return store;
    1.64 +}
    1.65 +
    1.66 +/*
    1.67 + * Class:     com_aurellem_gb_Gb
    1.68 + * Method:    translateRGB
    1.69 + * Signature: ([I[I)V
    1.70 + */
    1.71 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_translateRGB
    1.72 +(JNIEnv *env, jclass clazz, jintArray rgb, jintArray store){
    1.73 +  jint *RGB_Arr = env->GetIntArrayElements(rgb, 0);
    1.74 +  jint *store_Arr = env->GetIntArrayElements(store,0);
    1.75 +  translateRGB(RGB_Arr, store_Arr);
    1.76 +  env->ReleaseIntArrayElements(rgb, RGB_Arr, 0);
    1.77 +  env->ReleaseIntArrayElements(store, store_Arr, 0);
    1.78 +}