-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frame.cpp: Avoid unnecessary copy of image data #375
Frame.cpp: Avoid unnecessary copy of image data #375
Conversation
As mentioned in issue OpenShot#202 QImage::bits() and QImage::scanLine() make a deep copy of the source image. This is completely unnecessary when read-only access to the pixel data is required. Changing to QImage::constBits() and QImage::constScanLine() solves this. Both functions were introduced in Qt 4.7. https://doc.qt.io/qt-5/qimage.html#constBits
@musteresel I looked at this a bit after #202 was filed, and at the time I wasn't completely sold on the actual issue here. (For reasons I'll come to shortly.) Given that you'd filed this PR, though, I checked it out and ran some tests to compare the effects.
|
As suggested in the code review: - More traditional placment of the const specifier, e.g. const unsigned char * instead of unsigned char const * - Matching casts to also cast to const unsigned char * instead of of unsigned char * Co-Authored-By: Frank Dana <[email protected]>
Applied the suggested edits. Yes, it seems that this doesn't solve memory issues ... but as you said: being explicit doesn't hurt :) |
As mentioned in issue #202
QImage::bits()
andQImage::scanLine()
make a deep copy of the source image. This is completely unnecessary when read-only access to the pixel data is required. Changing toQImage::constBits()
andQImage::constScanLine()
solves this. Both functions were introduced in Qt 4.7.Tested using some test project in OpenShot, not sure if I covered all cases, though!
https://doc.qt.io/qt-5/qimage.html#constBits