开发者

C++ Dereferencing char-Pointer (image array) is very slow

I have some trouble getting fast access to an unsigned character array.

I want to actually copy a BGRABGRA....BGRABGRA.... linewise coded image array to the OpenCV-version which uses three layers. The code below works fine but is really slow (around 0.5 seconds for a 640*480 image). I pointed out that the dereferencing operator * makes it slow. Do you have any plan how to fix this? (Hint: BYTE is an unsigned char)

// run thorugh all pixels and copy image data
for (int y = 0; y<imHeight; y++){
    BYTE* pLine= vrIm->mp_buffer + y * vrIm->m_pitch;
    for (int x = 0; x<imWidth; x++){
        BYTE* b= pLine++; /开发者_如何学JAVA/ fast pointer operation
        BYTE* g= pLine++;
        BYTE* r= pLine++;
        BYTE* a= pLine++; // (alpha)
        BYTE bc = *b; // this is really slow!
        BYTE gc = *g; // this is really slow!
        BYTE rc = *r; // this is really slow!

    }
}

Thanks!


Shouldn't be - there is no way that is taking 0.5sec for a 640x480 unless you are doing this on a 8086. Is there some other code you aren't showing? The destination memory doesn't currently go anywhere

ps take a look at cvCvtColor() it uses optimized SSE2/SIMD instructions to do this


What hardware is the memory you're reading located on? Perhaps that device has limited bandwidth to the memory it uses or just has slow RAM. If the memory is shared by many devices there may also be bottle necks on it's access. Try reading the entire screen(?) to local memory using memcpy(), performing your operations on it in local RAM, then writing it back using memcpy(). This will reduce the number of times you must negotiate access to it from 640*480 to 1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜