Hi there,

I'm trying to perform some image processing using the Android NDK. I have a snippet of Java code that converts a YUV bitmap to RGB format, however, I need to convert it to C.

This is what I have so far:

Code:
JNIEXPORT void JNICALL Java_com_twothreetwo_zoomplus_ZoomPlus_YUVtoRGB(JNIEnv * env, jobject obj, jintArray rgb, jbyteArray yuv420sp, jint width, jint height)
{
	int             sz;
	int             i;
	int             j;
	int             Y;
	int             Cr = 0;
	int             Cb = 0;
	int             pixPtr = 0;
	int             jDiv2 = 0;
	int             R = 0;
	int             G = 0;
	int             B = 0;
	int             cOff;

	sz = width * height;
	 //if(out == null) throw new NullPointerException("buffer 'out' is null");
	 //if(out.length < sz) throw new IllegalArgumentException("buffer 'out' size " + out.length + " < minimum " + sz);
	 //if(fg == null) throw new NullPointerException("buffer 'fg' is null");
	 //if(fg.length < sz) throw new IllegalArgumentException("buffer 'fg' size " + fg.length + " < minimum " + sz * 3/ 2);
	 for(j = 0; j < height; j++) {
			 pixPtr = j * width;
			 jDiv2 = j >> 1;
			 for(i = 0; i < width; i++) {
					 Y = yuv420sp[pixPtr]; if(Y < 0) Y += 255;
					 if((i & 0x1) != 1) {
							 cOff = sz + jDiv2 * width + (i >> 1) * 2;
							 Cb = yuv420sp[cOff];
							 if(Cb < 0) Cb += 127; else Cb -= 128;
							 Cr = yuv420sp[cOff + 1];
							 if(Cr < 0) Cr += 127; else Cr -= 128;
					 }
					 R = Y + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5);
					 if(R < 0) R = 0; else if(R > 255) R = 255;
					 G = Y - (Cb >> 2) + (Cb >> 4) + (Cb >> 5) - (Cr >> 1) + (Cr >> 3) + (Cr >> 4) + (Cr >> 5);
					 if(G < 0) G = 0; else if(G > 255) G = 255;
					 B = Y + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6);
					 if(B < 0) B = 0; else if(B > 255) B = 255;
					 rgb[pixPtr++] = 0xff000000 + (B << 16) + (G << 8) + R;
			 }
	 }

}
created from the Java version:

Code:
public static void decodeYUV(int[] out, byte[] fg, int width, int height) throws NullPointerException, IllegalArgumentException 
     { 
    		         final int sz = width * height; 
    		         if(out == null) throw new NullPointerException("buffer 'out' is null"); 
    		         if(out.length < sz) throw new IllegalArgumentException("buffer 'out' size " + out.length + " < minimum " + sz); 
    		         if(fg == null) throw new NullPointerException("buffer 'fg' is null"); 
    		         if(fg.length < sz) throw new IllegalArgumentException("buffer 'fg' size " + fg.length + " < minimum " + sz * 3/ 2); 
    		         int i, j; 
    		         int Y, Cr = 0, Cb = 0; 
    		         for(j = 0; j < height; j++) { 
    		                 int pixPtr = j * width; 
    		                 final int jDiv2 = j >> 1; 
    		                 for(i = 0; i < width; i++) { 
    		                         Y = fg[pixPtr]; if(Y < 0) Y += 255; 
    		                         if((i & 0x1) != 1) { 
    		                                 final int cOff = sz + jDiv2 * width + (i >> 1) * 2; 
    		                                 Cb = fg[cOff]; 
    		                                 if(Cb < 0) Cb += 127; else Cb -= 128; 
    		                                 Cr = fg[cOff + 1]; 
    		                                 if(Cr < 0) Cr += 127; else Cr -= 128; 
    		                         } 
    		                         int R = Y + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5); 
    		                         if(R < 0) R = 0; else if(R > 255) R = 255; 
    		                         int G = Y - (Cb >> 2) + (Cb >> 4) + (Cb >> 5) - (Cr >> 1) + (Cr >> 
    		 3) + (Cr >> 4) + (Cr >> 5); 
    		                         if(G < 0) G = 0; else if(G > 255) G = 255; 
    		                         int B = Y + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6); 
    		                         if(B < 0) B = 0; else if(B > 255) B = 255; 
    		                         out[pixPtr++] = 0xff000000 + (B << 16) + (G << 8) + R; 
    		                 } 
    		         } 
    		 }
However I'm getting the following errors:

Code:
apps/zoomplusndk/jni/zoomplusndk.c:53: warning: dereferencing 'void *' pointer
apps/zoomplusndk/jni/zoomplusndk.c:53: error: void value not ignored as it ought to be
apps/zoomplusndk/jni/zoomplusndk.c:56: warning: dereferencing 'void *' pointer
apps/zoomplusndk/jni/zoomplusndk.c:56: error: void value not ignored as it ought to be
apps/zoomplusndk/jni/zoomplusndk.c:58: warning: dereferencing 'void *' pointer
apps/zoomplusndk/jni/zoomplusndk.c:58: error: void value not ignored as it ought to be
apps/zoomplusndk/jni/zoomplusndk.c:67: warning: dereferencing 'void *' pointer
apps/zoomplusndk/jni/zoomplusndk.c:67: error: invalid use of void expression
Does anyone know why I'm getting these errors? As you can probably tell I'm not a C developer :/.

Thank a lot!

P.S line 53 is: Y = yuv420sp[pixPtr]; if(Y < 0) Y += 255;