|
|
The following message is my latest attempt of fast image showing in
QT. I would like to share it with people on this list. Any comments
and suggestions are welcome.
qingning
---------- Forwarded message ----------
From: Qingning Huo <qingninghuo@xxxxxxxxx>
Date: Fri, 18 Feb 2005 14:56:07 +0000
Subject: Re: fastest way to display images in QT
To: Eno <troll@xxxxxxxxxxxx>
On Thu, 17 Feb 2005 01:27:46 +0100, Eno <troll@xxxxxxxxxxxx> wrote:
>
> >
> > According to QT document, QPixmap::QPixmap( int w, int h, const uchar
> > *bits, bool ) is protected, and is uesd to "construct a monochrome
> > pixmap". Well, I can inherit from QPixmap to work around the
> > "pretected" problem. But, how can I construct a 24bits image?
> >
> > Many thanks,
> > Qingning
>
> Hi Qingning,
>
> actually, you are right. Having a look at the source code they run
> straight into constructing a bilevel pixmap. So this idea wasn't that
> much of a help, I guess.
>
> Maybe, if you have a look into qpixmap.cpp, there is a way to construct
> a pixmap off of a memory area. Finally, this is what Qt has to do
> anyways. A look into bool QPixmap::convertFromImage(const QImage&, int);
> might help here.
>
> I am sorry not to be of more help at this point.
>
> /eno
>
>
Hi eno,
Actually, you are very helpful. After some study of QPixmap and
QPaintDevice, I found the following unportable hack. The basic idea
is;
(1) Use QPixmap::load() to load the first image,
setOptimization(QPixmap::BestOptim) is important.
(2) Use ((XImage*)(data->ximage))->data to get the raw data pointer of
the XImage.
(3) Draw on the rawdata area (memcpy or whatever).
(4) "XPutImage" to draw the XImage to XDrawable.
(5) bitBlt() to draw the pixmap to widget.
I have to create a subclass of QPixmap(), because I have to access
protected variables/methods. The raw pointer is an array of width() *
height() elements, each of which is four bytes of BLUE, GREEN, RED,
and ALPHA(?).
For each subsequent image, the overhead is the memcpy(), XPutImage()
plus bitBlt(). I haven't measured yet, but this seems very efficient.
A complete test program is attached. This method is of course
unportable. It could break on next QT version. If anyone can improve
it, performance wise or portability wise, that would be great.
regards,
Qingning
pixmap.cpp
Description: Text Data
|
|