Results 1 to 6 of 6

Thread: Problem showing raw images

  1. #1
    Join Date
    Aug 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem showing raw images

    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.
    Qt Code:
    1. void pktGLWidget::paintGL()
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT);
    4. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    5. glDrawPixels(imgWidth, imgHeight, GL_LUMINANCE, GL_BYTE, glBuffer);
    6. glFlush();
    7. }
    To copy to clipboard, switch view to plain text mode 

    And here's my QImage code, which can't seems to work properly.
    Qt Code:
    1. void pktQImage2D::processBuffer()
    2. {
    3. m_Image = QImage((uchar *) pixelData, imgWidth, imgHeight, QImage::Format_Mono);
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem showing raw images

    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/ .

  3. #3
    Join Date
    Aug 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem showing raw images

    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?

  4. #4
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem showing raw images

    Something like this should work, I use it this way to use imporant my own TIFF images.

    Qt Code:
    1. //Raw data and dimensions of image
    2. unsigned short* data;
    3. int dim[2];
    4.  
    5. QImage rawImage(dim[1], dim[0], QImage::Format_Indexed8);
    6.  
    7. rawImage.setNumColors(256);
    8. for (int i = 0; i < 256; i++ )
    9. rawImage.setColor( i, qRgb( i, i, i )) ;
    10.  
    11. for (int i = 0; i < dim[0]; i++)
    12. {
    13. unsigned char* image = rawImage.scanLine(i);
    14. for (int j = 0; j < dim[1]; j++)
    15. image[j] = data[i * dim[1] + j] / 256;
    16. }
    To copy to clipboard, switch view to plain text mode 

    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.

  5. #5
    Join Date
    Aug 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem showing raw images

    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
    Qt Code:
    1. void pktDisplayWidget::setInternalImage()
    2. {
    3. m_Image = new QImage(output, imgWidth, imgHeight, QImage::Format_Indexed8);
    4.  
    5. //setup the grayscale color table
    6. m_Image->setNumColors(256);
    7. for (int i=0; i<256; i++)
    8. m_Image->setColor(i, qRgb(i, i, i));
    9.  
    10. if (m_Image->isNull())
    11. QMessageBox::warning(this, tr("Error in pktDisplayWidget"),
    12. tr("Unable to create the image object."));
    13.  
    14. if (swap)
    15. m_Image->invertPixels(QImage::InvertRgb);
    16.  
    17. //pass the image to the label (this)
    18. this->setPixmap(QPixmap::fromImage(*m_Image));
    19. this->adjustSize();
    20. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Aug 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem showing raw images

    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...

Similar Threads

  1. Problem in Cut Operation
    By ankurjain in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2006, 12:23
  2. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  3. QPixmap designer property not showing up
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2006, 19:56
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Replies: 10
    Last Post: 1st February 2006, 10:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.