Results 1 to 15 of 15

Thread: Converting from RGB24 to RGB32

  1. #1
    Join Date
    Mar 2007
    Location
    Bangalore
    Posts
    21
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Converting from RGB24 to RGB32

    I have an application which captures video with 24 bit depth and when i try to display it using QImage which uses 32 bit depth,image is not displayed properly.When i make video capture to 32 bits depth the image is displayed with good quality.Is there a means by which i can use 24 bit in Qt, m using Qt 3.3 version which only supports 32 bits.My vidoe codec works for 24 bits only.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Converting from RGB24 to RGB32

    What do you mean by 'not displayed correctly' ?
    24Bit RGB is the same like 32Bit ARGB with alpha set to 0.

  3. #3
    Join Date
    Mar 2007
    Location
    Bangalore
    Posts
    21
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Converting from RGB24 to RGB32

    In the sense when i display it using QImage i get a carbon kind of image being displayed.Is there a means by which i can convert from 24 bit to 32 bit and display in Qt.

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Converting from RGB24 to RGB32

    Then your incoming format is maybe not RGB.
    Create a QImage and set every pixel with setPixel().

  5. #5
    Join Date
    Mar 2007
    Location
    Bangalore
    Posts
    21
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Converting from RGB24 to RGB32

    Let me explain..I have a webcam which can capture both at 24 and 32 bit depth.I get the captured image buffer pointer and i send this buffer to QImage and set the widget with this image.Qt 3.3 supports 32 bit depth but the codec i am using is for 24 bits which when encoded and decoded gives me a 24 bit Image and since QImage supports 32 bit image i am not able to display the decoded 24 bit Image properly as i mentioned earlier.The image buffer i am getting from the camera is in RGB format only.I know that 32 bit depth is ARGB data with alpha set to 0,hence i want to know is there a means by which i can convert this 24 bit RGB data into 32 bit ARGB data either in Qt or any other source.Thanks in advance.

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Converting from RGB24 to RGB32

    I already said this - read your RGB data and put it into a QImage with setPixel() ... what else do you need??

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Converting from RGB24 to RGB32

    Don't use setPixel. It's very slow. Have a look here for some hints on how to do it: http://www.qtcentre.org/forum/f-qt-p...ghlight=ffmpeg
    and this might be use useful (example code using OpenCV to capture from webcams)
    http://www.qtcentre.org/forum/f-qt-p...ghlight=ffmpeg

  8. #8
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting from RGB24 to RGB32

    If you want to roll your own, you could use the following code:
    Qt Code:
    1. int w=..., h=...;
    2. uchar* input=...;
    3.  
    4. QImage img(w, h, QImage::Format_RGB32);
    5. for (int y=0;y<h;y++)
    6. {
    7. QRgb* line = img.scanLine(y);
    8. for (int x=0;x<w;x++)
    9. *(line++) = qRgb(input[y*w + 3*x], input[y*w + 3*x+1], input[y*w + 3*x+2]);
    10. }
    To copy to clipboard, switch view to plain text mode 
    This won't be painfully slow like using setPixel(), but it will never be as fast as using optimized libraries like OpenCV either.

  9. #9
    Join Date
    Mar 2007
    Location
    Bangalore
    Posts
    21
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Converting from RGB24 to RGB32

    Thanks for your advice, but i would like to show my code so that u get my problem:
    here is the code which captures image from the webcam:

    Qt Code:
    1. static struct video_mmap vm;
    2. mmap_test(int i)
    3. {
    4. vm.format = VIDEO_PALETTE_RGB32;
    5. vm.frame = 0;
    6. vm.width = 176;
    7. vm.height = 144;
    8. ioctl(device_fd, VIDIOCMCAPTURE, &vm);
    9. ioctl(device_fd, VIDIOCSYNC, &numframe);
    10. return buffer;
    11. }
    To copy to clipboard, switch view to plain text mode 
    when video format is VIDEO_PALETTE_RGB32 the display code displays good quality image.

    here is the display code:

    Qt Code:
    1. display()
    2. {
    3. img = new QImage;
    4. img->create(176, 144, 32, 0, QImage::IgnoreEndian);
    5. raw_buf = mmap_test(0); //this gets the Image buffer
    6. memcpy(img->bits(), raw_buf, 101376); //101376 is width*height*32 bits is 4 chars 176*144*4
    7. paint.drawImage(0, 0, *img, 0, 0, -1, -1);
    8. }
    To copy to clipboard, switch view to plain text mode 

    but when i change format = VIDEO_PALETTE_RGB24 i get a carbon kind of image.I want to know is there a problem in the capture or the QImage does not support VIDEO_PALETTE_RGB24 format.If it doesnt is there any other alternate way to do this.
    Last edited by jpn; 28th May 2008 at 16:37. Reason: missing [code] tags

  10. #10
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Converting from RGB24 to RGB32

    We just explained how to do exactly that. Choose a method that you like.

    You can't copy directly because the image formats are different. QImage expects 32bit format. If you're copying from 24bit source then you need to use one of the methods that was posted.

  11. #11
    Join Date
    Mar 2007
    Location
    Bangalore
    Posts
    21
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Converting from RGB24 to RGB32

    Thanks for your advice and i have done exactly what has been mentioned by copying individual pixels.Here is the code:

    Qt Code:
    1. for (int y=0;y<h;y++)
    2. {
    3. QRgb* line = (QRgb*)img.scanLine(y);
    4. for (int x=0;x<w;x++)
    5. *(line++) = qRgb(input[y*w + 3*x], input[y*w + 3*x+1], input[y*w + 3*x+2]);
    6. }
    7. status = pix.convertFromImage(img, Qt::ColorOnly);
    8. paint.drawPixmap(0, 0, pix, 0, 0, -1, -1);
    To copy to clipboard, switch view to plain text mode 

    Now am i displaying the image correctly???After copying the individual pixels into the image,first i convert it into pixmap and than draw it using QPainter.
    Last edited by jpn; 30th May 2008 at 17:03. Reason: missing [code] tags

  12. #12
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting from RGB24 to RGB32

    Quote Originally Posted by mahiapkum View Post
    Now am i displaying the image correctly???
    Well, what do you see? Your code seems correct.
    You might want to split up the conversion and rendering into different routines, since you only need to convert once, but you might have to paint multiple times.
    Last edited by spud; 30th May 2008 at 14:08. Reason: spelling error

  13. #13
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Converting from RGB24 to RGB32

    Looks about right to me. You can use drawImage directly so you dont have to convert (although the conversion happens implicitly anyway).

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Converting from RGB24 to RGB32

    You might have a problem with "endianess" (big endian (MSB first) or little endian (LSB first)), RGB vs BGR or similar problem.
    Make sure you know exactly which format your image is, and then adjust the above suggested code.
    Have a look at image formats here:
    http://doc.trolltech.com/4.3/qimage.html#image-formats

  15. #15
    Join Date
    Mar 2007
    Location
    Bangalore
    Posts
    21
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Converting from RGB24 to RGB32

    I am using Qt 3.3 version and to have an endian problem the image data which i get is an unsigned char and i copy the image also as an unsigned char itself.

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.