[Qt-interest] Fast displaying of 8bit images
Pavel Koshevoy
pavel at aragog.com
Tue Mar 31 22:03:33 CEST 2009
Never mind, I was confused by the colortable variable in your code.
Still, most of what I've said so far applies -- if you want to display
images fast, you need hardware acceleration. That mean OpenGL, or
DirectX if you don't care about cross-platform compatibility.
Pavel.
Pavel Koshevoy wrote:
> Ugh, I did't fully understand your message. You want to display
> color-mapped 8-bit images? You can still use OpenGL, although
> GL_LUMINANCE is probably the wrong texture type in that case. Not all
> OpenGL hardware supports what you want to do directly, but you can also
> accomplish what you want using GL_LUMINANCE textures and a small
> fragment shader program running on the GPU to do the color mapping. For
> fragment shader you could use OpenGL 2 GLSL, or NVIDIA Cg.
>
> Pavel.
>
>
> Pavel Koshevoy wrote:
>
>> Use OpenGL. Treat your image as GL_LUMINANCE texture. If your image
>> size is larger than max texture size supported by OpenGL you'll need to
>> do some creative tiling of GL_QUADs (or tiangles, or triangle strip,
>> etc...). On some platforms (OSX) there exist OpenGL extensions that
>> avoid copying texture data from main memory to the graphics card memory,
>> you may want to use that.
>>
>> Pavel.
>>
>> Jiri Horky wrote:
>>
>>
>>> Hi all,
>>>
>>> I have a big uchar array, where my image (2448x2048) is stored as 1 byte
>>> (gray degree) per 1 pixel. Pixels start from left corner, going
>>> line-by-line to right bottom corner of image ( it is PGM image, but
>>> without header). What I need to do is simple - just display the image,
>>> but as fast as possible. From what I've found so far, I tried to convert
>>> my image into QImage class and then using fromImage function loading it
>>> into QPixmap, as in following code:
>>> (please excuse using fprintf in C++, but time measuring was copied from
>>> another project :-)
>>>
>>> QVector<QRgb> colortable;
>>> QRgb rgb;
>>> for ( int i = 0; i < 256; i++ ) {
>>> rgb = qRgb(i,i,i); // grey
>>> colortable.append(rgb);
>>> }
>>>
>>> g_timer_start(timer); // start of measuring
>>>
>>> QImage * image = new QImage (img, 2448, 2048, QImage::Format_Indexed8);
>>> image->setColorTable(colortable);
>>> *pixmap = pixmap->fromImage(*image, Qt::ThresholdDither);
>>>
>>> g_timer_stop(timer);
>>> fprintf(stderr, "Via QImage it takes %lfs\n",
>>> g_timer_elapsed(timer, NULL));
>>>
>>> My measurement shows that it takes about 0.135 ms to convert from uchar
>>> array to Pixmap.
>>>
>>> I am wondering if there isn't any faster method, because manual of
>>> fromImage function says :
>>>
>>> In case of monochrome and 8-bit images, the image is first converted to
>>> a 32-bit pixmap and then filled with the colors in the color table. If
>>> this is too expensive an operation, you can use QBitmap::fromImage
>>> <qbitmap.html#fromImage>() instead.
>>>
>>> But as manual also says, QBitmap is suitable only for 1-bit images....
>>>
>>>
>>>
>>> My next question is: would be possible to prepare QPixmap in another
>>> thread, if I allocate it in GUI thread and make sure it wont be
>>> manipulated from another thread when displayed?
>>>
>>>
>>> I am testing it on Linux, in case it matters.
>>>
>>> Thank you for any ideas!
>>>
>>> Jiri Horky
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>
>>>
>>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list