Page 223 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 223
PDA 10 5/27/03 8:51 AM Page 199
Chapter 10 / The PDA Robotics Command Center
static DWORD trigger_threshold;
static BYTE *last_frame_data;
BYTE *frame_data = (BYTE *) malloc((size_t)lpVHdr->dwBytesUsed);
//
// We will run into a problem if the frame buffer size has
// increased ( user switched the video format settings while
// detecting motion ).so realloc to the correct size.
//
if( !initialized ){
last_frame_data = (BYTE *) malloc((size_t)lpVHdr->dwBytesUsed);
last_frame_bytes = (size_t)lpVHdr->dwBytesUsed;
}
else
{
// Ensure that the bytes used hasn't changed. User may change
// video settings along the way. Resize our frame buffer
if( last_frame_bytes != (size_t)lpVHdr->dwBytesUsed )
{
// AfxMessageBox( " Reallocating the frame buffer sise !" );
last_frame_data = (BYTE *) realloc(last_frame_data,
(size_t)lpVHdr->dwBytesUsed);
last_frame_bytes = (size_t)lpVHdr->dwBytesUsed;
}
}
if( (frame_data == NULL ) || ( last_frame_data == NULL ) )
{
//
// Frame data couldn't be allocated
//
return FALSE;
}
memcpy( frame_data, lpVHdr->lpData, lpVHdr->dwBytesUsed);
if( !initialized )
{
memcpy( last_frame_data, frame_data, lpVHdr->dwBytesUsed);
frames_sampled = 0;
frame_same_total = 0;
initialized = 1;
}
void *frame_data_start = frame_data;
void *last_frame_data_start = last_frame_data;
//
199