Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to draw 1024x1024 dots on screen

I am developing a program that must calculate a color of each point on a 1024x1024 picture using a special algorithm. The color of a point represents some value. So each point is independent of other points and must be drawn separately. I do not have to refresh the picture too frequently. Actually, I need to display it only once.

What is the fastest approach to drawing separate pixels in Qt?

Can I get some sort of "screen memory" and write all the picture as an array of 4-byte sets, representing each pixel as 4 bytes in that memory?

like image 760
pavelkolodin Avatar asked Jan 09 '12 15:01

pavelkolodin


3 Answers

The QImage class is optimized for pixel manipulation. You can instantiate one with the requred size and then either set the pixels individually setPixel, or access the raw data and manipulate them in place via bits(). Just be sure to use the correct format (e.g. RGBA values or color indices for 8-bit images)

like image 160
king_nak Avatar answered Oct 12 '22 04:10

king_nak


The fastest solution may be to create a QImage, manipulate it (set the pixels) and then get Qt to draw it.

The QImage class is for fast IO, from the manual:

The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.

The QImage class supports several image formats described by the Format enum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x.

There is information on pixel manipulation in the Detailed Description section.

To display it the simplest way would be to convert it to a pixmap with QPixmap::fromImage and then put it in a label with QLabel::setPixmap.

For more control, you could sub-class QWidget, overload the paintEvent, and draw the QImage with a QPainter with QPainter::drawImage.

like image 22
Silas Parker Avatar answered Oct 12 '22 03:10

Silas Parker


You might try to use an OpenGL widget and the glDrawPixels function.

like image 38
tibur Avatar answered Oct 12 '22 03:10

tibur