Ejemplo n.º 1
0
void yuv2rgb(uint8_t *out, uint8_t *line, int width, int height) {
	int size = width*height;
	int offset = size;
	int u, v, y1, y2, y3, y4;
	int i, k;

	// i percorre os Y and the final pixels
	// k percorre os pixles U e V
	for(i=0, k=0; i < size; i+=2, k+=2) {
		y1 = line[0][i];
		y2 = line[0][i+1];
		y3 = line[0][i];
		y4 = line[0][i+1];

		u = data[offset+k  ]&0xff;
		v = data[offset+k+1]&0xff;
		u = u-128;
		v = v-128;

		out[i  ] = convertYUVtoRGB(y1, u, v);
		out[i+1] = convertYUVtoRGB(y2, u, v);
		out[width+i  ] = convertYUVtoRGB(y3, u, v);
		out[width+i+1] = convertYUVtoRGB(y4, u, v);

		if (i!=0 && (i+2)%width==0)
			i+=width;
	}
}
Ejemplo n.º 2
0
static void notifyFrameFetched(JNIEnv *env, jobject thiz, int id, jbyteArray data)
{
    SLM_TRACE_FUNC();

    if (current_camera == NULL)
    {
        SLM_FATAL(" current_camera == NULL");
    }
    else
    {

        jboolean isCopy;
        jbyte* data_ptr = env->GetByteArrayElements(data, &isCopy);

        unsigned char* argb = new unsigned char[g_width * g_height * 4 * sizeof(unsigned char)];

        int size     = g_width * g_height;
        int v_offset = size;
        int u_offset = size +1;

        int y1_1,y1_2,y1_3,y1_4;
        int y2_1,y2_2,y2_3,y2_4;
        int y3_1,y3_2,y3_3,y3_4;
        int y4_1,y4_2,y4_3,y4_4;
        int u_1,u_2,u_3,u_4;
        int v_1,v_2,v_3,v_4;

        for(int i = 0, k = 0; i < size; i += 8, k += 8)
        {
            //-----------------------------------------------------------------------------
            // indexes
            //-----------------------------------------------------------------------------
            int id1 = i;
            int id2 = i+2;
            int id3 = i+4;
            int id4 = i+6;

            int k1 = k;
            int k2 = k+2;
            int k3 = k+4;
            int k4 = k+6;

            //-----------------------------------------------------------------------------
            // yuv components
            //-----------------------------------------------------------------------------

            // index 1
            y1_1 = data_ptr[id1  ]&0xff;
            y2_1 = data_ptr[id1+1]&0xff;
            y3_1 = data_ptr[g_width+id1  ]&0xff;
            y4_1 = data_ptr[g_width+id1+1]&0xff;

            u_1 = data_ptr[u_offset + k1]&0xff;
            v_1 = data_ptr[v_offset + k1]&0xff;

            u_1 -= 128;
            v_1 -= 128;

            // index 2
            y1_2 = data_ptr[id2  ]&0xff;
            y2_2 = data_ptr[id2+1]&0xff;
            y3_2 = data_ptr[g_width+id2  ]&0xff;
            y4_2 = data_ptr[g_width+id2+1]&0xff;

            u_2 = data_ptr[u_offset + k2]&0xff;
            v_2 = data_ptr[v_offset + k2]&0xff;

            u_2 -= 128;
            v_2 -= 128;

            //index 3
            y1_3 = data_ptr[id3  ]&0xff;
            y2_3 = data_ptr[id3+1]&0xff;
            y3_3 = data_ptr[g_width+id3  ]&0xff;
            y4_3 = data_ptr[g_width+id3+1]&0xff;

            u_3 = data_ptr[u_offset + k3]&0xff;
            v_3 = data_ptr[v_offset + k3]&0xff;

            u_3 -= 128;
            v_3 -= 128;

            //index 4
            y1_4 = data_ptr[id4  ]&0xff;
            y2_4 = data_ptr[id4+1]&0xff;
            y3_4 = data_ptr[g_width+id4  ]&0xff;
            y4_4 = data_ptr[g_width+id4+1]&0xff;

            u_4 = data_ptr[u_offset + k4]&0xff;
            v_4 = data_ptr[v_offset + k4]&0xff;

            u_4 = u_4 - 128;
            v_4 = v_4 - 128;

            //-----------------------------------------------------------------------------
            // Convert to rgb
            //-----------------------------------------------------------------------------
            convertYUVtoRGB(y1_1, u_1, v_1, id1*4, argb);
            convertYUVtoRGB(y2_1, u_1, v_1, (id1+1)*4, argb);
            convertYUVtoRGB(y3_1, u_1, v_1, (g_width+id1)*4, argb);
            convertYUVtoRGB(y4_1, u_1, v_1, (g_width+id1+1)*4, argb);

            convertYUVtoRGB(y1_2, u_2, v_2, (id2)*4, argb);
            convertYUVtoRGB(y2_2, u_2, v_2, (id2+1)*4, argb);
            convertYUVtoRGB(y3_2, u_2, v_2, (g_width+id2)*4, argb);
            convertYUVtoRGB(y4_2, u_2, v_2, (g_width+id2+1)*4, argb);

            convertYUVtoRGB(y1_3, u_3, v_3, (id3)*4, argb);
            convertYUVtoRGB(y2_3, u_3, v_3, (id3+1)*4, argb);
            convertYUVtoRGB(y3_3, u_3, v_3, (g_width+id3)*4, argb);
            convertYUVtoRGB(y4_3, u_3, v_3, (g_width+id3+1)*4, argb);

            convertYUVtoRGB(y1_4, u_4, v_4, (id4)*4, argb);
            convertYUVtoRGB(y2_4, u_4, v_4, (id4+1)*4, argb);
            convertYUVtoRGB(y3_4, u_4, v_4, (g_width+id4)*4, argb);
            convertYUVtoRGB(y4_4, u_4, v_4, (g_width+id4+1)*4, argb);

            //-----------------------------------------------------------------------------

            if (i!=0 && (i+8)%g_width==0)
            {
                i += g_width;
            }
        }
        // call the fechFrame method to emit signal
        current_camera->fetchFrame(argb);

        env->ReleaseByteArrayElements(data, data_ptr, JNI_ABORT);

    }
}