[Qt-interest] bliking when overpainting on the XvImage with QPainter

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Jul 8 17:47:33 CEST 2009


Byoung-young Lee wrote on Wednesday, July 08, 2009 5:24 PM:

> I'm writing some codes for playing video frames with Xv like next:
> ...
> The member function, m_scene->put(), just calls XvPutImage.

... which on its turn updates the screen, I assume, followed by...

> Then, I draw "Video Title" text on the screen at (5, 5).

... your text drawing, which is then causing...

> ...
> maybe I should say flikering... I'm now sure that wich word is
> proper).  

what you call technically correct as "flicker" (not to be confused with flickr, which is a Web 2.0(tm)(C) thingie).

> 
> I also tried with next window options:
> setAutoFillBackground(true);

That would make things even worse, you would want to set this option to false! Why? What is the point to restore the background to the "background colour" of the widget, if you are going to paint a video image which (most likely) covers the entire widget anyway? It is like painting a wall twice with different colours (hmmm, sort of... but you get my point ;)
 
> but, the problem still occurs.
> 
> Is there any solution?

Yes, it is called "double-buffering": before displaying anything onto the screen, you draw into an "offscreen" buffer (a buffer which is not visible on the screen). Once you are done with drawing into that buffer, you "switch buffers", so the currently visible buffer becomes invisible and vice versa. After that you draw into the other buffer, which is now invisible, etc.

Here are some links which might be useful (I did not study them though, just came up with them after a 5 second google session):

  http://www.codeproject.com/KB/graphics/DoubleBuffering.aspx
  http://en.wikipedia.org/wiki/Double_buffering

In your concrete example you need to find a way to draw the "XvImage" first into an offscreen buffer (a QPixmap), draw the text into the same buffer, and only then draw it into the widget.

Also refer to the Qt specific way (ooooold, from 1996 - and it still metions hardware such as Amstrad CPC and Amiga - nice :). Computers from the times when programmers still knew about assembler and stuff and tweaked every CPU cycle to get smooth scrolling. Flicker-free off course ;) - but I think the technique described there still applies, at least you'd get some inspiration from it):

  http://lists.trolltech.com/qt-interest/1996-09/thread00036-0.html


Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list