what is the best way to create a QPixmap image from raw data?
-
I have raw image data that need to be converted into QPixmap. The way I am doing is below,
QPixmap convert2Pixmap(int w, int h, string colorSpace, std::vector<unsigned char> buffer) { // create an image QImage img( &buffer.front(), w, h, w*getBytePerLine(colorSpace), getImageFormat(colorSpace) ); return QPixmap::fromImage(img); }
right now it takes about 50-60 ms to convert RGB 24 bit image with 4608x2400. However, I want to speed up this process. Is there any better way to do this?
Thank you in advance.
-
Hi
You are already use the smart QImage constructor that dont copy data
and I assume both getBytePerLine and getImageFormat are cheap.You seems to send the buffer as copy ?
.. std::vector<unsigned char> buffer)
I would expect
..std::vector<unsigned char> & buffer)Or do i read it wrong ?
-
@mrjj said:
Hi
You are already use the smart QImage constructor that dont copy data
and I assume both getBytePerLine and getImageFormat are cheap.Yes, they are. They just return corresponding value based on color format.
You seems to send the buffer as copy ?
.. std::vector<unsigned char> buffer)
I would expect
..std::vector<unsigned char> & buffer)Or do i read it wrong ?
You are right, how did I miss that part. After changing to reference it improved by ~20 ms.
Thank you.
-
Super
that was a nice reduction :)
Its often far easier to read other people's code
than the code you write yourself.
The brain skip things. -
@mrjj said:
Super
that was a nice reduction :)
Its often far easier to read other people's code
than the code you write yourself.
The brain skip things.Yes, you are right.
Looking at a function is much easier than looking at 1000 lines of code :)Thank you again, for your help.