Results 1 to 12 of 12

Thread: can't reuse a pure c++ .h file's methods and classes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    117
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    84
    Thanked 1 Time in 1 Post

    Default Re: can't reuse a pure c++ .h file's methods and classes

    Still no luck removing the >>24 does not set the right colors, it returned to having shades of blue and black only.
    Image Analysis Development Framework Using Qt (IADFUQ)

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: can't reuse a pure c++ .h file's methods and classes

    I don't know. Can you post the updated code?
    It wouldn't hurt if you did some debugging, to see what values you actually put/take out from that image.

    Still no luck removing the >>24 does not set the right colors, it returned to having shades of blue and black only.
    Well, things like this (meaning image handling) can't be done by guessing to add or remove something in the code. What you do has to be logic.

    So I would start with debugging, see what are the pixels taken from the QImage and what are the pixels taken from the Image.

    If possible, post those debug values.

    Regards
    Last edited by marcel; 2nd August 2007 at 10:17.

  3. The following user says thank you to marcel for this useful post:

    sincnarf (2nd August 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    117
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    84
    Thanked 1 Time in 1 Post

    Default Re: can't reuse a pure c++ .h file's methods and classes

    Thanks again Marcel. Here's my current function and I can already load an image, though there's a problem with the colors (see attached image). The colors are somewhat "adjusted" using Format_RGB32. The original objective is just to create an exact copy from the left graphicsView to the rightgraphics view.

    Qt Code:
    1. void MainWindow::doF1()
    2. {
    3. QString fileName = QFileDialog::getOpenFileName(this,
    4. tr("Open Image"), QDir::currentPath());
    5. if (!fileName.isEmpty()) {
    6. QImage tempImage(fileName);
    7.  
    8. if (tempImage.isNull()) {
    9. QMessageBox::information(this, tr("Load Warning"),
    10. tr("Cannot load %1.").arg(fileName));
    11. return;
    12. }
    13. QImage image = tempImage.convertToFormat(QImage::Format_RGB32);
    14. RGBImage rgbImage;
    15. rgbImage.resize(image.width(), image.height());
    16.  
    17. int pixel = 0;
    18. int x = 0;
    19. int y = 0;
    20.  
    21. for (x= 0; x < image.width(); x++){
    22. for (y = 0; y < image.height(); y++){
    23. pixel = image.pixel(x, y);
    24.  
    25. unsigned char rcomp = (unsigned char)(qRed(pixel));
    26. unsigned char gcomp = (unsigned char)(qGreen(pixel));
    27. unsigned char bcomp = (unsigned char)(qBlue(pixel));
    28.  
    29. rgbImage.setPix(x, y, rcomp, gcomp, bcomp);
    30.  
    31. pixel = rgbImage(x,y);
    32. image.setPixel(x, y, pixel);
    33.  
    34. }
    35. }
    36.  
    37. QGraphicsPixmapItem *item = scene->addPixmap(QPixmap::fromImage(image));
    38. item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
    39. item->setFlag(QGraphicsItem::ItemIsMovable);
    40. graphicsViewVis->setScene(scene);
    41. graphicsViewVis->show();
    42. }
    43. }
    To copy to clipboard, switch view to plain text mode 

    Observe the colors that were set in the right image (attached Format_RGB32.jpg), I tried to print the values of the rgbImage and they're exactly the same as the original/left Image, I think that there's something wrong with using QImage::Format_RGB32.

    So I tried to use QImage::Indexed8 and the colors were correct , but the main problem in using QImage::Indexed8 is that the right image has white spots and the loading of the image takes too long (about 15 seconds, I thought the program hung but it didnt).

    Which makes me decide to use QImage::Format_RGB32 and possibly create a way to recompute/correct the rgb values. This is my current problem.
    Attached Images Attached Images
    Image Analysis Development Framework Using Qt (IADFUQ)

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: can't reuse a pure c++ .h file's methods and classes

    You should stick to RGB32.
    The problem is in line 31 of the code you posted:
    Qt Code:
    1. pixel = rgbImage(x,y);
    To copy to clipboard, switch view to plain text mode 
    As before, you can't assign that directly.
    First convert it to qRgb, using qRed, etc...
    It is the reverse transformation of what you did before.

    EDIT: Actually, I think it is better to use the macros from your header to extract the components and build a qRgb:
    Qt Code:
    1. #define RED(pixel) ((pixel) & 0xff)
    2. #define GREEN(pixel) (((pixel)>>8) & 0xff)
    3. #define BLUE(pixel) (((pixel)>>16) & 0xff)
    To copy to clipboard, switch view to plain text mode 

    Regards

  6. The following user says thank you to marcel for this useful post:

    sincnarf (4th October 2007)

  7. #5
    Join Date
    Apr 2007
    Posts
    117
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    84
    Thanked 1 Time in 1 Post

    Default Re: can't reuse a pure c++ .h file's methods and classes

    Quote Originally Posted by marcel View Post
    EDIT: Actually, I think it is better to use the macros from your header to extract the components and build a qRgb:
    At last! Solved the problem. Thanks !!! Thank you Marcel, expect your name in my acknowledgements page. Hehe
    Image Analysis Development Framework Using Qt (IADFUQ)

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.