Results 1 to 15 of 15

Thread: Converting from RGB24 to RGB32

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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??

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

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

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

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

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

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

  8. #8
    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).

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

  10. #10
    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
  •  
Qt is a trademark of The Qt Company.