Sorry about that. I've been busy with a few other projects. Yes, I got the viewfinder bitmap as a texture and it works very well.
- Code:
void CameraN95::ViewFinderFrameReady(CFbsBitmap &image)
{
if (copying) return;
copying = true;
image.LockHeap();
Mem::Copy(tmpBuffer, image.DataAddress(),width*height*4);
image.UnlockHeap();
unsigned int temp;
unsigned char *iter = tmpBuffer;
for (int i=0;i<width*height;i++)
{
// BGRx to RGB(A=255)
temp = *iter;
*iter = *(iter+2);
*(iter+2) = temp;
*(iter+3) = 255;
iter = iter+4;
}
for (int i=0;i<height;i++)
{
Mem::Copy(pInternalImgData+4*VideoTexture::texWidth*i,tmpBuffer+4*width*i,width*4);
}
copying = false;
// Profiling: 256x192: 7ms
// Profiling: 168x126: 3ms
newFrameReady = true;
}
I'm not certain if the mutex variable (copying) is needed. I just haven't clean up that portion. The width,height variables correspond to the dimensions of the viewfinder. The texWidth, texHeight are the least powers of 2 that are >= width, height.
pInternalImgData is a unsigned char* buffer that stores the bitmap. Its size is width*height*4 (due to RGBA). You need to copy this to an OpenGL texture using something like this:
- Code:
glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pImgData);
Hope this helps. The profiling times indicate that the capture can be fairly quick. You should be able to do about as well as the default camera application.