View Full Version : Problem showing raw images
wkit23
11th August 2006, 02:36
Hi, I'm new to Qt4. I'm currentl using Qt as part of my project, but I'm facing problem using it. My project consist of reading a raw image, and then display it.
Since my raw image is in short byte array, I can't seems to show the image correctly using QImage. However, I manage to get the image to output correctly with OpenGL glDrawPixels, but the process is kinda sluggish and eats quite a lot of resources. Since I just wanna show the image, I was searching for a better way.
Here's my OpenGL code.
void pktGLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels(imgWidth, imgHeight, GL_LUMINANCE, GL_BYTE, glBuffer);
glFlush();
}
And here's my QImage code, which can't seems to work properly.
void pktQImage2D::processBuffer()
{
m_Image = QImage((uchar *) pixelData, imgWidth, imgHeight, QImage::Format_Mono);
}
e8johan
11th August 2006, 06:36
You will have to write your own image loading class. How to do it is shown here: http://doc.trolltech.com/qq/qq17-imageio.html . There is a free lib to support reading raw images here: http://www.cybercom.net/~dcoffin/dcraw/ .
wkit23
11th August 2006, 09:28
Well, actually it's not the camera's raw image data that I was dealing with. I've written a class to read and extract the image's data, which is in short byte array, with low values is white and higher values is black. It's just a pure black and white image.
I've manage to make a class to view the image in OpenGL, but the process really seems slow and sluggish, and it's eating my resources whenever I drag the window. Since I only want to view the images, I was looking for a much better way. I've try loading the data using QImage::fromData but the output is some sort of rubbish data. Anyone has better ideas?
Raistlin
13th August 2006, 13:11
Something like this should work, I use it this way to use imporant my own TIFF images.
//Raw data and dimensions of image
unsigned short* data;
int dim[2];
QImage rawImage(dim[1], dim[0], QImage::Format_Indexed8);
rawImage.setNumColors(256);
for (int i = 0; i < 256; i++ )
rawImage.setColor( i, qRgb( i, i, i )) ;
for (int i = 0; i < dim[0]; i++)
{
unsigned char* image = rawImage.scanLine(i);
for (int j = 0; j < dim[1]; j++)
image[j] = data[i * dim[1] + j] / 256;
}
You have to convert to unsigned char to be able to display it.
You can then use QPixmap::fromImage() and QLabel::setPixmap() to display the image on a QLabel.
wkit23
8th September 2006, 04:25
So far, I've tried different methods for displaying my image. Note that raw formats I mean here is not the digital camera's RAW format. It's actually bytes of data (grayscale values) that I decoded.
I've tried openGl to display the images. glDrawPixel functions is slow, and if the images is large enough, u'll have a hard time to manipulate it. So I try to implement glTexture, the result is a whole lot faster. But the problem came when the images contains size not power of two, which texture can't be loaded properly.
So, I recheck back my QImage implementation, and after some time, I've found out I didn't setup the QImage properly, and didn't build up the neccesaly grayscale colormap. So far with some simple data I test, so far so good. However, the problem came when I try a large image with 2500*2048. Somehow the image become back to jerky again...
Here's my implementation
void pktDisplayWidget::setInternalImage()
{
m_Image = new QImage(output, imgWidth, imgHeight, QImage::Format_Indexed8);
//setup the grayscale color table
m_Image->setNumColors(256);
for (int i=0; i<256; i++)
m_Image->setColor(i, qRgb(i, i, i));
if (m_Image->isNull())
QMessageBox::warning(this, tr("Error in pktDisplayWidget"),
tr("Unable to create the image object."));
if (swap)
m_Image->invertPixels(QImage::InvertRgb);
//pass the image to the label (this)
this->setPixmap(QPixmap::fromImage(*m_Image));
this->adjustSize();
}
wkit23
8th September 2006, 13:33
I've found the problem. It appears that my width and height are exchanged when I'm decoding the raw image... Strangely odd since other smaller images shows no problem at all...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.