I have measured.
typedef struct
{
BITMAPINFO* pBmp;
unsigned char* lpBytes;
unsigned int cbBytes;
unsigned int firstline;
unsigned int linecount;
} PROCESS_STRUCT;
static unsigned long FAR PASCAL __process24(void* p)
{
PROCESS_STRUCT* ps = (PROCESS_STRUCT*)p;
unsigned int bpl = ((ps->pBmp->bmiHeader.biWidth*3)+3) & ~3;
unsigned char* lpl = ps->lpBytes + bpl * ps->firstline;
unsigned char* lpp;
unsigned int x,y;
for(y=0;y<ps->linecount;y++)
{
lpp = lpl;
for(x=0;(int)x<ps->pBmp->bmiHeader.biWidth;x++,lpp+=3)
{
lpp[0] =
lpp[1] =
lpp[2] = (unsigned char)(((unsigned int)lpp[0]+(unsigned int)lpp[1]+(unsigned int)lpp[2])/3);
}
lpl += bpl;
}
return 0;
}
static unsigned long FAR PASCAL __process32(void* p)
{
PROCESS_STRUCT* ps = (PROCESS_STRUCT*)p;
unsigned int bpl = ps->pBmp->bmiHeader.biWidth * 4;
unsigned char* lpl = ps->lpBytes + bpl * ps->firstline;
unsigned char* lpp;
unsigned int x,y;
for(y=0;y<ps->linecount;y++)
{
lpp = lpl;
for(x=0;(int)x<ps->pBmp->bmiHeader.biWidth;x++,lpp+=4)
{
lpp[0] =
lpp[1] =
lpp[2] = (unsigned char)(((unsigned int)lpp[0]+(unsigned int)lpp[1]+(unsigned int)lpp[2])/3);
}
lpl += bpl;
}
return 0;
}
static void __ProcessBitmap(const unsigned int nthreads,BITMAPINFO* pBmp,unsigned char* lpBytes,unsigned int cbBytes)
{
HANDLE ah[32]; unsigned int ih;
unsigned long tid;
PROCESS_STRUCT pst[32];
unsigned int lpp = pBmp->bmiHeader.biHeight / nthreads;
ASSERT((0<nthreads) && ((sizeof(ah)/sizeof(ah[0]))>=nthreads));
switch(pBmp->bmiHeader.biBitCount)
{
case 24:
pst[0].firstline = 0;
for(ih=0;ih<nthreads;ih++)
{
if((1+ih)==nthreads) pst[ih].linecount = pBmp->bmiHeader.biHeight-pst[ih].firstline;
else pst[ih].linecount = min(lpp,pBmp->bmiHeader.biHeight-pst[ih].firstline);
pst[ih].pBmp = pBmp;
pst[ih].lpBytes = lpBytes;
pst[ih].cbBytes = cbBytes;
ah[ih] = CreateThread(0,0,__process24,&pst[ih],0,&tid);
if((1+ih)<nthreads) pst[ih+1].firstline = pst[ih].firstline + pst[ih].linecount;
}
WaitForMultipleObjects(ih,ah,1,INFINITE);
break;
case 32:
pst[0].firstline = 0;
for(ih=0;ih<nthreads;ih++)
{
if((1+ih)==nthreads) pst[ih].linecount = pBmp->bmiHeader.biHeight-pst[ih].firstline;
else pst[ih].linecount = min(lpp,pBmp->bmiHeader.biHeight-pst[ih].firstline);
pst[ih].pBmp = pBmp;
pst[ih].lpBytes = lpBytes;
pst[ih].cbBytes = cbBytes;
ah[ih] = CreateThread(0,0,__process32,&pst[ih],0,&tid);
if((1+ih)<nthreads) pst[ih+1].firstline = pst[ih].firstline + pst[ih].linecount;
}
WaitForMultipleObjects(ih,ah,1,INFINITE);
break;
}
}
void ProcessImage(BITMAPINFO* pBmp,unsigned char* lpBytes,unsigned int cbBytes)
{
__ProcessBitmap(_max_threads,pBmp,lpBytes,cbBytes);
}
the results for _max_threads:
bitmap is 32 bit 640x480 from the webcam.
on i3 that has 2 physical cores.
Regards.