Results 1 to 20 of 20

Thread: Display and divide the image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default hi i want some help to display and divide image

    hi
    i m kiran suryawanshi
    i m final year student i m working on the project called as "tiled image viewer"
    In this i suppose to display image on tiled display i.e four monitors clustered together
    for that i hv to display and divide the image
    so i write the following code but i had problem saying that "Segmentation fault"

    i m represting problem area btn <problem></problem> tag
    plz help me
    Qt Code:
    1. #include "qgl.h"
    2. #include "qapplication.h"
    3. #include "qimage.h"
    4. #include "iostream.h"
    5. #include "GL/gl.h"
    6. class Radha : public QGLWidget
    7. {
    8. public:
    9. Radha(const QString &filename,QWidget *parent=0);
    10. void paintGL();
    11. void resizeGL(int w,int h);
    12. void divide();
    13. protected:
    14. QImage data,gldata;
    15. };
    16.  
    17. Radha::Radha(const QString &filename,QWidget *parent):QGLWidget(parent){
    18. data.load(filename);
    19. gldata=QGLWidget::convertToGLFormat(data);
    20. resize(data.size());
    21.  
    22. }
    23.  
    24. void Radha::paintGL(){
    25. int k,i,j,count=0,flag=1;
    26. <PROBLEM>
    27. uchar *temp;
    28. uchar *img;
    29. temp=gldata.bits();
    30.  
    31. for(j=0;j<data.width()*data.height();j++){ //for reading the half image in img array
    32. if(count==data.width()/2){
    33. flag==1-flag;
    34. count=0;
    35. }
    36. if(flag==1)
    37. img[j++]=temp[i];
    38. count++;
    39. }
    40.  
    41. glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,img);
    42.  
    43. }
    44.  
    45.  
    46. void Radha::resizeGL(int w,int h){
    47. glViewport(0,0,w,h);
    48. glMatrixMode(GL_PROJECTION);
    49. glLoadIdentity();
    50. glOrtho(0,w,0,h,-1,1);
    51. glMatrixMode(GL_MODELVIEW);
    52.  
    53. }
    54.  
    55. int main(int argc,char** argv){
    56. QApplication app(argc,argv);
    57. Radha pw(argv[1]);
    58. pw.showFullScreen();
    59. return app.exec();
    60. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 2nd March 2007 at 15:38. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hi i want some help to display and divide image

    Where do you initialize i and img and what do you need k for?

  3. #3
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: hi i want some help to display and divide image

    k is useless
    is there any need to initialize the img
    it is not showing some error but after executing it is showing "Segmentation fault"

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hi i want some help to display and divide image

    Quote Originally Posted by kiransu123 View Post
    k is useless
    So there is no point in declaring it.

    Quote Originally Posted by kiransu123 View Post
    is there any need to initialize the img
    Of course there is. It points at some random place in memory, so you can't use it until you initialize it.

  5. #5
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: hi i want some help to display and divide image

    can u tell me how to divide the image in 4 parts

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hi i want some help to display and divide image

    Quote Originally Posted by kiransu123 View Post
    can u tell me how to divide the image in 4 parts
    Use QImage::copy().

  7. #7
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: hi i want some help to display and divide image

    Quote Originally Posted by jacek View Post
    how QImage::copy() is used bcz for this how can u specify the image
    its syntax is copy(x,y,w,h)const
    wht this const signifies

  8. #8
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: hi i want some help to display and divide image

    QImage QImage::copy ( const QRect & rectangle = QRect() ) const
    Returns a sub-area of the image as a new image.
    If you want to subdivide an image into four sub-images, then you can use QImage::copy(). It is simply a matter of rectangles! Take one large rectangle and divide it into four small rectangles. You do not even need to know arithmetic, because QRect::center() will give you the QPoint in the center of the rectangle.

    p.s. The "const" in the method signature means that it is a constant function, which does not modify the object. The use of QImage::copy() will not modify the QImage it is called with.

  9. #9
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: hi i want some help to display and divide image

    Quote Originally Posted by Brandybuck;3:) 0606
    If you want to subdivide an image into four sub-images, then you can use QImage::copy(). It is simply a matter of rectangles! Take one large rectangle and divide it into four small rectangles. You do not even need to know arithmetic, because QRect::center() will give you the QPoint in the center of the rectangle.

    p.s. The "const" in the method signature means that it is a constant function, which does not modify the object. The use of QImage::copy() will not modify the QImage it is called with.
    then how can i display using glDrowPixels() bcz the last argument require for it is pointer to image so wht should i pass to it
    thanks for solution

  10. #10
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hi i want some help to display and divide image

    Quote Originally Posted by kiransu123 View Post
    then how can i display using glDrowPixels() bcz the last argument require for it is pointer to image so wht should i pass to it
    thanks for solution
    I think you're handling this in a wrong way. Qt has built-in facilities for rendering images (with or without OpenGL) and manipulating them. Instead of mixing Qt classes and OpenGl calls you should choose a single approach : either plain Qt (using QtOpenGl module) or plain C/OpenGl with possibly some helper libs to handle images loading...
    Current Qt projects : QCodeEdit, RotiDeCode

  11. #11
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: hi i want some help to display and divide image

    Quote Originally Posted by ;) fullmetalcoder View Post
    I think you're handling this in a wrong way. Qt has built-in facilities for rendering images (with or without OpenGL) and manipulating them. Instead of mixing Qt classes and OpenGl calls you should choose a single approach : either plain Qt (using QtOpenGl module) or plain C/OpenGl with possibly some helper libs to handle images loading...
    can u tell me how should i proceed further to divide the image in 4 parts using QT
    wht r built in facililies for this problem

  12. #12
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Display and divide the image

    Hi I m kiran
    i want to display an image then divide it and again display the part of the image.
    Is is possibe in QImage to read the image in the array so i can perform some manipulation on the image

    i m reading the image as follows the problem is that how can i read the image the array
    I indicate the problem area in <problem></problem> tag in paintGL() function.

    Qt Code:
    1. #include "qgl.h"
    2. #include "qapplication.h"
    3. #include "qimage.h"
    4. class PaintWidget : public QGLWidget{
    5. public:
    6. PaintWidget(const QString &filename,QWidget *parent=0);
    7. void paintGL();
    8. void resizeGL(int w,int h);
    9. protected:
    10. QImage data,gldata;
    11. };
    12.  
    13. PaintWidget::PaintWidget(const QString &filename,QWidget *parent):QGLWidget(parent){
    14. data.load(filename);
    15. gldata=QGLWidget::convertToGLFormat(data);
    16. resize(data.size());
    17. }
    18.  
    19.  
    20. void PaintWidget::paintGL(){
    21. int k,i,j,count_h=0,count_v=0,flag=1;
    22. uchar *temp;
    23. uchar *img;
    24. temp=gldata.bits();
    25. //<problem>
    26. for(i=0;i<gldata.width()*gldata.height();i++){
    27. if(count_h==gldata.width()/2){ //checking for first half of image
    28. flag=1-flag; // flag =1 : 1st half flag=0 : second half
    29. count_h=0; // for counting next half counter make zero
    30. }
    31. if(flag==1)
    32. img[++j]=temp[i]; //img[j++]will read only half of the image therefore j++
    33. count_h++;
    34. }
    35.  
    36.  
    37. glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,img);
    38.  
    39. //</problem> //glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,gldata.bits());
    40. }
    41.  
    42. void PaintWidget::resizeGL(int w, int h){
    43. glViewport(0,0,w,h);
    44. glMatrixMode(GL_PROJECTION);
    45. glLoadIdentity();
    46. glOrtho(0,w,0,h,-1,1);
    47. glMatrixMode(GL_MODELVIEW);
    48. }
    49.  
    50. int main(int argc, char** argv){
    51. QApplication app(argc,argv);
    52. PaintWidget pw(argv[1]);
    53. pw.show();
    54. return app.exec();
    55.  
    56. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by e8johan; 4th March 2007 at 08:56. Reason: missing [code] tags

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.