PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Pixel by Pixel performance-

I'm using PocketFrog on my e800 together with the FlyGrabber video capture CF card. The video capture is pretty expensive timewise, but by itself can get up to 30 fps; I'm looking for some way to boost my frame rate which right now is somewhere around 5 fps (after blitting a couple images onto the captured video frame for display).
The capture card fills in an unsigned char array of dimensions 320x240x3 with 24 bit BGR (I'm not sure why they swap the R and B) data. I'm then moving those data pixel by pixel onto the LockInfo.Pixels of the BackBuffer:
Code:
PreviewFrame(vidBuffer); //FlyGrabber capture command.
unsigned char *bufPtr=vidBuffer;
for (int jj=0;jj<height;++jj) {
for (int ii=0;ii<width;++ii) {
backBuffer[jj * pitch + ii] = Color(bufPtr[2],bufPtr[1],bufPtr[0]);
bufPtr+=3;
}
}

I've searched around the forum for a better (faster) way. Some have suggested trying lower level functionality of PocketHAL, but I can't seem to figure out how to do that.
Thanks,
Joseph
You should avoid the multiplication on each pixel - i.e. "backBuffer[jj * pitch + ii]" is bad.

Also, depending on the pocket pc you use, the backbuffer might be aligned in a way that pitch is much larger than one pixel. So you would have to check the pitch value and if it's larger than one pixel you would have to go in the column direction instead of row-direction.

If you do the right optimizations your performance would increase at least 4-5 times, probably more.
This comes up often, so I thought I'd post what I think is the fastest - although someone may wish to set me straight...

2 changes, use pointers with addition to eliminate the mult. Invert your iterator loops to check for zero instead of a variable value (i.e. width).
Code:


Pixel * backBufferY = backBuffer;

for (int jj=height+1;jj;jj--)
{
Pixel * backBufferX = backBufferY;
for (int ii=width+1;ii;ii--)
{
*backBufferX++ = Color(bufPtr[2],bufPtr[1],bufPtr[0]);
bufPtr+=3;
}
backBufferY += pitch;
}
Joseph · 13 Jan 2005, 16:05 UTC — Thanks
Thanks for the tips. I implemented the above optimizations (using prefix instead of postfix decrementing in the for loop; I've heard it makes a difference, but haven't ever noticed if it does). It's slick-looking code, but I'm still sitting at 6 fps. I think that the video capture is, by far, the biggest bottleneck. I'm going to try tucking it away into its own thread so that the program doesn't block while it's capturing. Hopefully that will restore performance.
Thanks again for your help.
Joseph
i really doubt that the FlyGrabber can do 30fps at 320x240. LifeView was always very creative its performance specs.

i tried very long to achieve the performance they promised for the FlyCAM.

i suggest you time just the reading of the grabber (without any conversion or other processings) to see how fast it really is.

btw: i also tried doing multithreading and played for thread priorities. it came down to that the more time it spent for reading the less time i had for other processing and the other way around but the overall performance did not really go up.

bye,
Daniel
mmmmmm.. please excuse my ignorance but... what's "pitch"??
pitch is the length of a pixel row, usually measured in bytes. while most of the time this is just the width times the number of bytes per pixels, some formats have special restrications for the pitch.

e.g. as far as i remember the pitch of the BMP format is always a multiple of 4. if the pitch calculated from the width does not result in a multiple of 4, then it is rounded upwards.

to say it simple: pitch is the number of bytes you have to add to a pixel offset to skip exactly one line...

bye,
Daniel