[Development] QImage::transformed returns shallow copy for QTransform::TxNone matrix type.
Simon.Hausmann at qt.io
Mon Jul 11 13:10:13 CEST 2016
Thank you for the explanation of your use-case. What remains unclear to me is why it is necessary for you to ensure a deep copy?
Is it related to the fact that your image is created from a raw data pointer and after your worker thread is done, you cannot guarantee
for the life-time of the raw data anymore?
Perhaps you could use the QImage constructor that takes a cleanup function (and cleanupInfo pointer). If your worker thread
ends up making a copy of the image data as a result of your transformation, then your original copy can and will be deleted
when you discard the source of the transform() call. That is something that you can keep track of. Vice-versa if it's not being called,
then you know that transformed() (or generally speaking _any_ sequence of operations you may have done) still operate on a shallow
copy. Then you can do an explicit deep copy.
Generally speaking my impression - assuming I did understand your use-case correctly - is that your problem stems from the unknown
life-cycle of your data. I don't think the behavior of QImage::transformed() should be made worse for the common case where shallow
copying benefits performance and memory consumption.
From: Development <development-bounces+simon.hausmann=qt.io at qt-project.org> on behalf of Tomasz Olszak <olszak.tomasz at gmail.com>
Sent: Monday, July 11, 2016 12:53:51 PM
To: development at qt-project.org
Subject: Re: [Development] QImage::transformed returns shallow copy for QTransform::TxNone matrix type.
QImage::copy returns deep copy and has similar documentation so I assumed that when docs say copy it means deep copy.
Let's consider common case:
1. QImage img created from raw data pointer got from e.g. driver.
2. img used in thread to perform some transforms
3. Save result as deep copy
Ensuring step 3 is most efficient and does not perform unnecessary copying I need to write something like:
if (m.type() == QTransform::TxNone)
AFAIU img.transformed(m).copy() will copy twice when m.type() != QTransform::TxNone right?
Don't you think that is seems strange and is not documented enough?
2016-07-11 10:59 GMT+01:00 Simon Hausmann <Simon.Hausmann at qt.io<mailto:Simon.Hausmann at qt.io>>:
Could you elaborate on what you see as the discrepancy between docs and implementation? The docs don't say whether
it's a shallow or a deep copy, so it looks to me that the implementation is within the bounds of the docs.
Plus it seems sensible to return a shallow copy, doesn't it?
From: Development <development-bounces+simon.hausmann=qt.io at qt-project.org<mailto:qt.io at qt-project.org>> on behalf of Tomasz Olszak <olszak.tomasz at gmail.com<mailto:olszak.tomasz at gmail.com>>
Sent: Monday, July 11, 2016 11:38:06 AM
To: development at qt-project.org<mailto:development at qt-project.org>
Subject: [Development] QImage::transformed returns shallow copy for QTransform::TxNone matrix type.
QImage:: transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) docs:
"Returns a copy of the image that is transformed using the given transformation matrix and transformation mode."
But if matrix.type() == QTransform::TxNone then shallow instead of deep copy is returned.
I'm happy to submit a fix but I don't know what is expected behaviour? Should implementation follow docs or docs or docs follow implementation here?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Development