[Development] QImage::transformed returns shallow copy for QTransform::TxNone matrix type.

Tomasz Olszak olszak.tomasz at gmail.com
Mon Jul 11 15:08:54 CEST 2016


Oh good spot, thanks for that. It doesn't depend on QIMage::transformed
 impl.

Thanks!

2016-07-11 13:54 GMT+01:00 Simon Hausmann <Simon.Hausmann at qt.io>:

> Hi,
>
>
> I realize that there may be an even simpler way of ensure that you get a
> deep copy, but only if transformed() hasn't already
>
> made one (so that you don't have to worry about your potentially dangling
> pointer):
>
>
> Instead of using copy(), why not call the non-const bits() function (and
> don't use the returned value). That will detach (and thus
>
> deep-copy) the data if your transformation produced no copy. If a copy was
> produced, then that will be the only copy and no
>
> copying happens.
>
>
>
>
> Simon
> ------------------------------
> *From:* Tomasz Olszak <olszak.tomasz at gmail.com>
> *Sent:* Monday, July 11, 2016 2:45:18 PM
> *To:* Giuseppe D'Angelo
> *Cc:* Simon Hausmann; development at qt-project.org
> *Subject:* Re: [Development] QImage::transformed returns shallow copy for
> QTransform::TxNone matrix type.
>
> QTransform m.
> img.transformed(m).copy()
>
> will create one copy. But:
>
> QTransform m.
> m.rotate(10);
> img.transformed(m).copy()
>
> will copy image twice; On embedded device, if you do some video decoding
> it is a problem :)
>
> 2016-07-11 12:52 GMT+01:00 Giuseppe D'Angelo <dangelog at gmail.com>:
>
>> On Mon, Jul 11, 2016 at 1:40 PM, Tomasz Olszak <olszak.tomasz at gmail.com>
>> wrote:
>> > The problem here is that you can't say if transformed returns shallow or
>> > deep copy. Result depends on argument value. Of course the transform
>> > returning shallow copy on identity matrix is nice but should be
>> documented
>> > somewhere. After reading docs I expected deep copy like from copy
>> function.
>> > But maybe it's only me :)
>>
>> Then always deep copy and then move on with the processing? Because
>> relying on shallow copies is a bit of a gamble -- by the same
>> reasoning, can you be sure that setPixel(x, y, color) always detaches?
>> What if it gets implemented in a way that first checks if the pixel
>> already has that color, and if so, it doesn't do anything?
>>
>> --
>> Giuseppe D'Angelo
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160711/87f2a7c6/attachment.html>


More information about the Development mailing list