Results 1 to 15 of 15

Thread: how to bind a bitmap to texture in QT?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to bind a bitmap to texture in QT?

    As far as it is relevant to the current problem:

    I want to get RGB values from a 24 bit BGR data. This data is from a raw image without a header.
    I don't know how to convert the index of the buffer to its corresponding RGB values.
    here is what I have done:

    Qt Code:
    1. window_width = 800;
    2.  
    3. window_height = 600;
    4.  
    5. size = window_width * window_height;
    6.  
    7. pixels = new float[size*3];
    8.  
    9. for(int i = 0, j = 0; i < size*3, j < size; i += 3, j++)
    10. {
    11. pixels[i+2] = bytes[i];
    12. }
    13.  
    14. updateGL();
    To copy to clipboard, switch view to plain text mode 


    void GlWidget:aintGL()
    {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glDrawPixels(window_width,window_height,GL_RGB,GL_ FLOAT,pixels);
    }

    what am i missing?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how to bind a bitmap to texture in QT?

    I want to get RGB values from a 24 bit BGR data.
    Are there alignment bytes added to BGR data ? Not relevant in case if width is a multiple of 4, but in general you can have each row size padded to multiple of 4 (in bytes). For example opencv does that (so size of 6x6 24 bit rgb image is not 108 but 120 bytes, additional 2 padding bytes for each row).
    Ok sorry I'm probably confusing you, so the problem is this:

    you have - [ B1,G1,R1, B2,G2,R2, ..., Bn,Gn,Rn ]
    and you want - [ R1,G1,B1, R2,G2,B2, ..., Rn,Gn,Bn ]
    ?
    You can do that conversion in-place, if you have buffered the data from the socket, you can change it without need of another buffer.
    As you can see, you can leave the middle byte in each pixel alone, so you can do a simle swap (in case of in-place conversion), or three assignments (in case of copying). No need to have two loop variables btw., you can do that in single pass. This is three-four lines of code but i won't write it. Get a piece of paper and try to first perform this algorithm manually, its not that hard.
    Last edited by stampede; 18th November 2013 at 13:05. Reason: updated contents

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to bind a bitmap to texture in QT?

    Stampede you do not understand what the problem is. I know how to do a simple swap of these bits.
    The packet size of raw data sent by server is of size 800*600 (size) only. Because the server gets the indices of RGB values. So, your equality is not correct. What I need to do logically, is to store the received packet in a packet of size size * 3 and assign values to it! but assign values to what? R? G? B? I have no idea because the received packet only contains indices of these RGB values. the below function only gave me some mixed colors:

    Qt Code:
    1. void GlWidget::func(QByteArray btmp)
    2. {
    3. bytes.clear();
    4.  
    5. bytes.resize(size*3*sizeof(unsigned char));
    6.  
    7. for(int i = 0, j = 0; i < size*3, j < size; i += 3, j++)
    8. {
    9. bytes[i+2] = btmp[i];
    10. }
    11.  
    12. updateGL();
    13. }
    14. void GlWidget::paintGL()
    15. {
    16.  
    17. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    18. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    19. glDrawPixels(window_width,window_height,GL_BGR,GL_UNSIGNED_BYTE,bytes.constData());
    20. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how to bind a bitmap to texture in QT?

    received packet only contains indices of these RGB values
    so you have indices but don't have a color table ? that's nice, to be honest I don't know what you should do in that case apart from asking the creators of server side to give you the color tables they use

Similar Threads

  1. Replies: 2
    Last Post: 2nd November 2015, 11:20
  2. QImage bind texture fails
    By saman_artorious in forum Qt Programming
    Replies: 7
    Last Post: 22nd September 2013, 16:44
  3. [QGLWidget] Cannot bind texture
    By Macok in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2009, 19:53
  4. Bitmap border
    By SailinShoes in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2008, 18:37
  5. Bitmap buttons
    By BloodHo in forum Newbie
    Replies: 1
    Last Post: 4th November 2006, 14:17

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.