Dump QImage raw pixel data into `std::vector<char>`
-
Whoops, I've been saying
malloc
(which is apparently thread-safe) all along when in fact the actual function I'm using ismemcpy
... Does that change things and/or can I usemalloc
instead? -
@abmyii
Hence what @Christian-Ehrlicher has been saying above.malloc
andmemcpy
do totally different things, it makes no sense to ask whether one can be used in place of the other.... -
@JonB I understand - I got confused due to my unfamiliarity with the functions but I never asked if I could use
malloc
instead ofmemcpy
- I asked if I could usepush_back
instead ofmalloc
(sic).@abmyii said in Dump QImage raw pixel data into `std::vector<char>`:
I never asked if I could use
malloc
instead ofmemcpy
[sic.]in fact the actual function I'm using is
memcpy
... Does that change things and/or can I usemalloc
instead? [*sic.]If you say so! I'll leave others to untangle, who clearly understand what you are saying better than I :) Don't worry about explaining to me.
-
@abmyii said in Dump QImage raw pixel data into `std::vector<char>`:
I never asked if I could use
malloc
instead ofmemcpy
[sic.]in fact the actual function I'm using is
memcpy
... Does that change things and/or can I usemalloc
instead? [*sic.]If you say so! I'll leave others to untangle, who clearly understand what you are saying better than I :) Don't worry about explaining to me.
-
@JonB OK, you got me! Too much to keep track of...
I tried this and it worked, but is quite a lot slower than
memcpy
:std::vector<unsigned char> vectorBuffer(charBuffer, charBuffer + length); fb = vectorBuffer;
-
@JonB OK, you got me! Too much to keep track of...
I tried this and it worked, but is quite a lot slower than
memcpy
:std::vector<unsigned char> vectorBuffer(charBuffer, charBuffer + length); fb = vectorBuffer;
@abmyii said in Dump QImage raw pixel data into `std::vector<char>`:
std::vector<unsigned char> vectorBuffer(charBuffer, charBuffer + length);
fb = vectorBuffer;This does two memcpy for no good reason. Since I don't know what libvncserver function you use you're on your own. Read the documentation of them and also read what's needed for threadsafe access.
-
@abmyii
I am lost in the complexities of your questions :) But I would suggest heeding @Christian-Ehrlicher's advice, he is usually right! He last offered:Use mutexes or copy the data
So why not pursue that?
@JonB Haha, you think you are the only one?!
I am planning to try the mutex idea - I haven't had a chance to look it up and figure out how to do it yet. A basic
QMutex
lock/unlock didn't fix it (though I probably applied it wrong)...@Christian-Ehrlicher Ah, I see. What "libvncserver function" do you mean?
-
@abmyii said in Dump QImage raw pixel data into `std::vector<char>`:
What "libvncserver function" do you mean?
You are using libvncserver, not me.
Giving up here now.
-
@abmyii said in Dump QImage raw pixel data into `std::vector<char>`:
What "libvncserver function" do you mean?
You are using libvncserver, not me.
Giving up here now.
Going to mark this thread as closed since it seems the issue lies with VNC, not Qt. Thank you all for your suggestions and helping me to isolate the problem.
@Christian-Ehrlicher Sorry for stressing you out - I thought you were referring to a specific function for some reason. I really need to slow down when reading and comprehend rather than just having a quick look and then replying which is causing confusion on all sides. Thank you again for your patience and assistance throughout.
-
Hi I've done something recently I've needed so my approach was:
total_len = qimg.width() * qimg.height(); std::vector<unsigned int> data; data.reserve(total_len); for(int i=0; i < qimg.height(); i++) for(int j=0; j < qimg.width(); j++){ data.push_back(qimg.pixel(j, i)); }
I needed it as an rgb pixels in order to do some image manipulations, but I believe you can also take the uchar data.