QImage buffer structure
-
Does QImage store its data in a contiguous buffer? I know you can get a scanline pointer and a bits pointer. It says that those point to a single scanline at least. Can this pointer be used to access the entire image?
I guess the alternative would to make a holder class that feeds it a buffer that is contiguous and access that buffer of data.
I have a library that resizes images and it requires access to a buffer that is contiguous. So either I have to copy the data out line by line into a working buffer or provide a buffer to the QImage object in the first place.
-
I should have just looked at the source code first.
Yes, it is a continuous segment of memory. The scanline and bits functions return a pointer to this data that is stored as uchar*. The scanline functions actually return a calculated pointer into this data. So I could safely use the const version of these to prevent a detach and process the image data.So to access this I should just be using "const uchar *QImage::bits() const" for read only access.
-
@fcarney said in QImage buffer structure:
Can this pointer be used to access the entire image?
Yes, for sure - otherwise it would be a very poor implementation and suboptimal implementation. Also the ctors show you that it's a contiguous buffer since some of them take exactly such a buffer without copying the buffer.
-
@fcarney said in QImage buffer structure:
Can this pointer be used to access the entire image?
Yes, for sure - otherwise it would be a very poor implementation and suboptimal implementation. Also the ctors show you that it's a contiguous buffer since some of them take exactly such a buffer without copying the buffer.
@Christian-Ehrlicher said in QImage buffer structure:
ctors show you that it's a contiguous buffer since some of them take exactly such a buffer without copying the buffer
Yes, but I didn't know if the internal implementation was different in that case. I really needed to look at the code and make sure. The documentation didn't lead me to believe this for certain. It is a good point though. Which is part of the reason I wondered.