Qt5 C++ - How to split color image efficiently into 3 channels without using OpenCV
-
I have successfully extract the 3 channels from a color image by looping each of the pixel. However, this is way too slow and would like to ask for other more efficient and faster way to do it?
Below are my inefficient way of doing it:
for (int y = 0; y < HEIGHT; ++y)
{
int x_stride = y * WIDTH;
for (int x = 0; x < WIDTH; ++x)
{
int index = x_stride + x;
QRgb rgb_1 = snap_buf_1.pixel(x, y);img_bit_red = qRed(rgb_1); img_bit_green = qGreen(rgb_1); img_bit_blue = qBlue(rgb_1); ucSnapBuffer1[0].GetBuffer_UNSAFE().data()[index] = img_bit_red; ucSnapBuffer1[1].GetBuffer_UNSAFE().data()[index] = img_bit_green; ucSnapBuffer1[2].GetBuffer_UNSAFE().data()[index] = img_bit_blue; }
}
-
Hi and welcome to devnet,
What data structure do you need to fill with these data ?
-
Then why not use memcpy ?
-
No indeed since there's the split. But you can use pointer arithmetic to move around the data more efficiently.
-
op makes no mention of the format of the image data. That will dictate in large part how efficient the process can be made. The most efficient to do what he wants would be if the image is already in planar format, where the memory is a seriies of color planes. memory backed video hardware is often in planar format. If not in planar format then any real optimization will still involve addressing the image directly and bypassing the Qt pixel addressing operations, then using any available processor native multimedia instructions. I hope the op is comfortable with pointers. LOL
At the very least, op should quit using array indexes and instead use pointer math to access array elements, as it is faster than array indexing.