[Development] Painting an image onto itself

André Pönitz andre.poenitz at mathematik.tu-chemnitz.de
Tue Apr 10 23:08:26 CEST 2012


On Tue, Apr 10, 2012 at 05:12:51PM -0300, Thiago Macieira wrote:
> On terça-feira, 10 de abril de 2012 21.46.09, Andreas Aardal Hanssen wrote:
> > You want to take a screenshot of the widget from within the widget's own
> > paintEvent? That cannot possibly work. Or even if it did, the result would
> > be completely non-deterministic. The painting code required to take the
> > screenshot is in the same function.
> 
> That reminds me of a question I've been meaning to ask: what is expected to 
> happen if you paint an image or a subsection of one onto itself?
> 
> For example:
> 
> 	QImage img = img;
> 	QPainter painter(&img);
> 	painter.drawImage(0, 0, img);
> 
> Is this expected to work?

I'd expect a sentence like "The result of painting an image or a
subsection of one onto itself is undefined." in the docs.

> Is it expected to work if there are no pixels that are both source and
> destination (e.g., painting the right half on the left half, or
> top-left quadrant on the bottom-right quadrant)? Does the answer
> change according to composition mode?

In practice, I'd be surprised if it did not "sort of work" if source and
destination areas are "far enough apart", but with the sentence above in
the docs I'd have no valid reason to complain if it doesn't.

> The reason I'm asking is that many of the painting methods suffer from
> the same problem as memcpy / memmove. Optimising those methods via
> SIMD code might cause the behaviour to change.
> 
> Note that even the "no pixel is source and destination at the same
> time" answer requires special handling, since a destination pixel
> could be adjacent to a source pixel and could thus be read and written
> back.

Right.

But I am not sure that kind of guarantee needs to be given.

Would it be really needed in practice? How many occurences of such
code are there in Qt/Qt Creator?

Andre'



More information about the Development mailing list