Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Displaying Buffer data on Qlabel
Forum Updated to NodeBB v4.3 + New Features

Displaying Buffer data on Qlabel

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 889 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sankar-110
    wrote on 25 May 2018, 06:24 last edited by
    #1

    Hi,
    I have a buffer data of color format YUY2 /UYVY/NV12/NV21 etc.

    How do I display/render the buffer using qlabel??

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 May 2018, 06:43 last edited by
      #2

      Hi,

      You'll have to convert it to one of the supported QPixmap type first.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sankar-110
        wrote on 25 May 2018, 07:15 last edited by sankar-110
        #3

        @SGaist
        Thank you for your reply.

        Below is my code for displaying/rendering "RGB" buffer on a Qlabel.

             QImage  *img = new QImage(camera->width ,camera->height, 
             QImage::Format_RGB32);
        
         uint8_t *l_ui_arr = new uint8_t[g_size_v4l2];
         if (!l_ui_arr)
         {
            qDebug() << "Memory allocation failed for arr\n";
         }
        
         camera->head.start // This is my buffer
         g_size_v4l2 // The size of the buffer
        camera->height // Height of my image
        camera->width // width of my image
        
        memcpy(l_ui_arr,camera->head.start,g_size_v4l2);
        for(uint32_t l_height = 0; l_height < camera->height; l_height++)
        {
          for(uint32_t l_width = 0; l_width < camera->width; l_width++)
          {
               QRgb value = qRgb(l_ui_arr[l_ui_arrayIndex], l_ui_arr[l_ui_arrayIndex+1], l_ui_arr[l_ui_arrayIndex+2]);
               l_ui_arrayIndex = l_ui_arrayIndex+3;
               img->setPixel(l_width, l_height,value);
          }
        }
        ui->label->setPixmap(QPixmap::fromImage(*img,Qt::AutoColor));
        

        Now, when I get buffer of any other format such as NV12/NV21/UYVY etc.

        How do I convert it to the supported QPixmap type??

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mranger90
          wrote on 25 May 2018, 12:00 last edited by
          #4

          You probably have to do the conversion from NV12/UYVY etc to RGB yourself then generate the pixmap.
          There's lots of code available to show how to do this. Check StackOverflow.

          1 Reply Last reply
          1

          1/4

          25 May 2018, 06:24

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved