Results 1 to 5 of 5

Thread: Paint streaming pixel data

  1. #1
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Paint streaming pixel data

    Hello,

    Please help me figure out what the best method is to load a file of pixel data (each pixel is 8bits) and paint it to the screen. The data is supposed to stream down the screen (i.e waterfall). (So basically read one line at a time from the file and stream the image from the top of the screen)

    I'm currently just testing with a regular QImage file and scrolling it down the screen. I first tried the basic method of loading a QImage and calling paintEvent on a set timer. PaintEvent will just redraw the image (drawImage) one line lower each time.

    However, the image scrolls down the screen very slowly, and i'm sure there is a better way to do this.

    I also found a basic example of QGraphicsScene and QGraphicsView which uses animation->setPosAt(...) after a certain QTimeLine. However I'm not sure if this is what I want for my application (to repeatedly read the pixel data file 1 line at a time and stream it down the screen).

    Thank you very much for your help
    -James
    Last edited by jmsbc; 16th September 2008 at 01:10.

  2. #2
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default paint streaming pixel data

    Hello,

    Please help me figure out what the best method is to stream in pixel data (each pixel is 8bits) and paint it to the screen. The data is supposed to stream down the screen (i.e waterfall). (So basically read one line of pixels at a time and display at the top of the screen, pushing the rest of the image down.

    I'm currently just testing with a regular QImage file and scrolling it down the screen. I tried the basic method of loading a QImage and repeately calling paintEvent. PaintEvent will just redraw the image (drawImage) one line lower each time.

    However, the image scrolls down the screen very slowly, and i'm sure there is a better way to do this.


    Thank you very much for your help
    -James
    Last edited by jmsbc; 17th September 2008 at 01:27.

  3. #3
    Join Date
    Jul 2008
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: Paint streaming pixel data

    Jimsbc

    I have a an qt app here that im able to stream pixel data from a QByteArray over the network line by line "waterfall" and it uses udp for the protocal and is pretty quick. Are you trying this over the network? If not this app i have my still help you. Basically on one side it opens a QImage and reads the data into a QByteArray then it streams each line to the other end with QDataStream. Each line that is painted on the client side is converted to a QPixMap and each QPixMap is painted on the screen, so everyline is dropped down each time a new one comes in until the image is displayed. I had to put in a QTimer on the sending side because it was so quick and i wanted make sure it was doing what i needed. This was created on linux. Let me know if your interested in the code and i will send it your way.

  4. The following user says thank you to newqtuser for this useful post:

    jmsbc (17th September 2008)

  5. #4
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: Paint streaming pixel data

    Newqtuser,

    Sure that would be great! I'm curious how much of a difference there is in performance, thanks a lot. The speed that I'm interested is on your receiving end, and how fast it can paint the image to screen. (My application will keep receiving streaming pixel data to draw) Also If anyone knows of a more optimized way to please share. Thanks.

    -James
    Last edited by jmsbc; 17th September 2008 at 16:52.

  6. #5
    Join Date
    Jul 2008
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: Paint streaming pixel data

    Qt Code:
    1. // server
    2.  
    3. #include <QDialog>
    4. #include <QWidget>
    5. #include <QString>
    6. #include <QThread>
    7. #include <QtGui>
    8. #include <unistd.h>
    9. #include <Qt/QtNetwork>
    10.  
    11. class ImgServer : public QObject
    12. {
    13. Q_OBJECT
    14. public:
    15. ImgServer();
    16. QUdpSocket* socket;
    17. QImage* image;
    18. quint64 value;
    19. private slots:
    20. void streamImage();
    21. };
    22.  
    23. ImgServer::ImgServer()
    24. {
    25. socket = new QUdpSocket(this);
    26. image = new QImage("/tmp/someimage.jpg");
    27. QTimer *timer = new QTimer(this);
    28. timer->setInterval(0);
    29. timer->start();
    30. QTimer::singleShot(0, this, SLOT(streamImage()));
    31. }
    32.  
    33. void ImgServer::streamImage()
    34. {
    35. for (int y=0; y < image->height(); y++)
    36. {
    37. QByteArray sndBuffer(image->width(), 0);
    38. QDataStream sndStream(&sndBuffer, QIODevice::WriteOnly);
    39. sndStream.setVersion(QDataStream::Qt_4_4);
    40. sndStream << (quint16)image->height() << (quint16)image->width();
    41.  
    42. quint16 y_in = y;
    43. sndStream << y_in;
    44.  
    45. for(int x=0; x < image->width(); x++)
    46. {
    47. QRgb rgb = image->pixel(x, y);
    48. sndStream << (quint8)qRed(rgb) << (quint8)qGreen(rgb) << (quint8)qBlue(rgb);
    49. usleep(45);
    50. }
    51.  
    52. QHostAddress clientIp;
    53. clientIp = "127.0.0.1";
    54. socket->writeDatagram(sndBuffer, clientIp, 9988 );
    55. }
    56. }
    57.  
    58. int main(int argc, char *argv[])
    59. {
    60. QApplication app(argc, argv);
    61. ImgServer imageServer;
    62. return app.exec();
    63. }
    64. #include "moc_ImgServer.cpp"
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. /******************* client code *********************/
    2.  
    3. #include <QApplication>
    4. #include <QDialog>
    5. #include <QWidget>
    6. #include <QString>
    7. #include <QThread>
    8. #include <QtGui>
    9. #include <unistd.h>
    10. #include <Qt/QtNetwork>
    11. #include <QObject>
    12.  
    13. class ImgReciever : public QLabel
    14. {
    15. Q_OBJECT
    16. public:
    17. ImgReciever(QWidget* parent=0);
    18. QUdpSocket* socket;
    19. QImage* image;
    20. QLabel myLabel;
    21. QImage mirroredImage;
    22.  
    23. private slots:
    24. void dataPending();
    25. };
    26.  
    27. ImgReciever::ImgReciever(QWidget* parent) : QLabel( parent )
    28. {
    29. scene = new QGraphicsScene();
    30. image = 0;
    31. socket = new QUdpSocket(this);
    32. socket->bind(9988);
    33. connect(socket, SIGNAL(readyRead()), this, SLOT(dataPending() ) );
    34. }
    35.  
    36. void ImgReciever::dataPending()
    37. {
    38. qDebug() << "ScpImageRcvr::dataPending()";
    39. while( socket->hasPendingDatagrams() )
    40. {
    41. QByteArray buffer(socket->pendingDatagramSize(), 0);
    42. socket->readDatagram(buffer.data(), buffer.size());
    43. QDataStream stream(buffer);
    44. stream.setVersion(QDataStream::Qt_4_4);
    45.  
    46. quint16 width, height, y;
    47. stream >> height >> width >> y;
    48.  
    49. QImage new_line(width, 1, QImage::Format_RGB32);
    50. if ( !image )
    51. image = new QImage(new_line);
    52. else if( image->width() !=width || image->height() != height )
    53. {
    54. QImage* new_image = new QImage( width, image->height()+1, QImage::Format_RGB32 );
    55.  
    56. if(image->height()+1 == height )
    57. qDebug() << "Image complete!";
    58.  
    59. for ( int imgHeight = 0; imgHeight < image->height()+1; imgHeight++ )
    60. {
    61. for ( int incomingImgWidth = 0; incomingImgWidth < width; incomingImgWidth++ )
    62. {
    63. if ( imgHeight == 0 )
    64. {
    65. quint8 red, green, blue;
    66. stream >> red >> green >> blue;
    67. new_image->setPixel( incomingImgWidth, imgHeight, qRgb(red, green, blue) );
    68. }
    69. else
    70. {
    71. new_image->setPixel(incomingImgWidth,
    72. imgHeight,
    73. image->pixel( incomingImgWidth, imgHeight-1) );
    74. }
    75. }
    76. }
    77. delete image;
    78. image = new_image;
    79. mirroredImage = image->mirrored(false, true);
    80. }
    81.  
    82. myLabel.setPixmap(QPixmap::fromImage(mirroredImage));
    83. myLabel.resize(900, 900);
    84. myLabel.show();
    85. }
    86. }
    87.  
    88. int main(int argc, char *argv[])
    89. {
    90. QApplication app(argc, argv);
    91. ImgReciever rcvImgData;
    92.  
    93. return app.exec();
    94. }
    95.  
    96. #include "moc_ImgReciever.cpp"
    To copy to clipboard, switch view to plain text mode 
    Thats it, sorry i took so long.
    Oh and i ran moc by hand for the 2 cpp file and included them in the bottem as you can see. Here was the moc command i ran from the command line

    moc ImgReciever.cpp > moc_ImgReciever.cpp

    that way i could have the declartions and implementation all in the same cpp files. This was for testing so i wanted it all together. Hope that works for you let me know how it goes.
    Last edited by jacek; 28th September 2008 at 21:01. Reason: missing [code] tags

  7. The following user says thank you to newqtuser for this useful post:

    babu198649 (26th October 2008)

Similar Threads

  1. Replies: 7
    Last Post: 29th August 2008, 10:24
  2. QPixmap pixel by pixel ?
    By tommy in forum Qt Programming
    Replies: 19
    Last Post: 3rd December 2007, 22:52
  3. Replies: 4
    Last Post: 19th October 2007, 19:47
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.