Results 1 to 9 of 9

Thread: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

  1. #1
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    When I create a simple, zoomable, qgraphicsview with a single qgraphicspixmapitem in it, it crashes when zooming out on certain images (not very large ones, aprox. 480*270 and then zoomed out twice with scalefactor 0.5).

    The thing is, when I use:
    Qt Code:
    1. pixitem->setTransformationMode(Qt::SmoothTransformation);
    To copy to clipboard, switch view to plain text mode 
    there are no problems, which makes me think there is something wrong with the fasttransformation pixmap scaling.

    In the debugger, the fault traces to qt_scale_image_32bit, but I do not understand enough of it to decipher the error. Anyone had similar problems?

  2. #2
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    I put together a quick demo application to verify this bug, it loads an image. Could anyone run this program, load an image file and zoom out (zooming in seems to work quite well.)

    main.cpp:
    Qt Code:
    1. #include <QtGui>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui>
    5.  
    6. class MainWindow : public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. MainWindow(QWidget *parent = 0);
    12. ~MainWindow();
    13.  
    14. private slots:
    15. void zoomIn();
    16. void zoomOut();
    17.  
    18. private:
    19.  
    20.  
    21. QAction *Action_zoomIn;
    22. QAction *Action_zoomOut;
    23. QMenu *Menu_view;
    24.  
    25. QGraphicsScene * scene;
    26. QGraphicsView * view;
    27.  
    28. };
    29.  
    30. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    And mainwindow.cpp:
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. Action_zoomIn = new QAction(tr("Zoom In"), this);
    7. Action_zoomIn->setShortcut(tr("="));
    8. Action_zoomOut = new QAction(tr("Zoom Out"), this);
    9. Action_zoomOut->setShortcut(tr("-"));
    10. Menu_view = new QMenu(tr("View"), this);
    11. Menu_view->addAction(Action_zoomIn);
    12. Menu_view->addAction(Action_zoomOut);
    13. menuBar()->addMenu(Menu_view);
    14.  
    15. scene = new QGraphicsScene();
    16. scene->addText("No files loaded...");
    17.  
    18. view = new QGraphicsView(scene, this);
    19. this->setCentralWidget(view);
    20.  
    21. this->show();
    22.  
    23. QFileDialog::Options options;
    24. QString selectFilt;
    25. QString imgname = QFileDialog::getOpenFileName(this
    26. , tr("Open File")
    27. , ""
    28. , tr("All Files (*)")
    29. , &selectFilt
    30. , options);
    31. scene->clear();
    32. QGraphicsPixmapItem * pixitem = scene->addPixmap( QPixmap(imgname) );
    33.  
    34. //This seems to work much better: (no crashes at least)
    35. //pixitem->setTransformationMode(Qt::SmoothTransformation);
    36.  
    37. connect(Action_zoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
    38. connect(Action_zoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
    39. }
    40.  
    41. MainWindow::~MainWindow()
    42. {
    43. }
    44.  
    45. void MainWindow::zoomIn()
    46. {
    47. view->scale(2.0,2.0);
    48. }
    49.  
    50. void MainWindow::zoomOut()
    51. {
    52. view->scale(0.5,0.5);
    53. }
    To copy to clipboard, switch view to plain text mode 


    (I also tried with qpixmap allocated differently. I use fromImage() in some other code, where the image is never "deleted" to make sure the data exists.
    Is the above code correct? Does qt keep an internal reference count on pixmaps...?)

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    work fine for me, no crash on 4.5.0 in Linux

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

    captiva (11th March 2009)

  5. #4
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    Weird... did you try zooming out a couple of times?
    I am building on Windows XP SP2, with mingw/QT Creator.

    In the debugger it shows a problem in some event loop, which traces down to the scaling functions... (and if I enable pixitem->setTransformationMode(Qt::SmoothTransformation) ; in the above code, there is no problem, but i do not want that interpolation)

    Qt Code:
    1. qt_scale_image_32bit<Blend_RGB32_on_RGB32_NoAlpha>
    2. qt_scale_image_rgb32_on_rgb32
    3. QRasterPaintEngine::drawPixmap
    4. QPainter::drawPixmap
    5. _q_paintItem
    6. QGraphicsScenePrivate::drawItemHelper
    7. QGraphicsScene::drawItems
    8. ...
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    Did zoom in zoom out many times...

  7. #6
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    Thanks Ini, in my case sometimes it works and sometimes it crashes (most of the time actually, and only when zooming out).

    Am I doing something wrong with the memory allocation of the pixmapitem or something? If there is no problem in my code it is probably a real bug, but I would like for some more people to verify before I report it.

    Help wanted

    Edit: I tested it also on a vista laptop, also crashes (although somehow less often).

  8. #7
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    I try it on Windows Vista, and everything work fine till I make Print Scrn, save it in Paintbrush as jpg file and then load it in your program. I use zoom out function several times and program crashed. I watched than it happen in function "qt_scale_image_32bit"

  9. The following user says thank you to mazurekwrc for this useful post:

    captiva (12th March 2009)

  10. #8
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    I think you should seriously fire a bug!
    So.. win Qt 4.5, I have no crashes neither in release or debug mode.
    BUT: when running the app with valgrind, and 'zooming out twice', with a '480x270 jpeg picture', as you said, I saw what look like an out-of-boundary access to the Image memory.

    Please fire a bug in the qtsoftware task tracker and tell us how it's going.

    ==9781== Invalid read of size 4
    ==9781== at 0x424D728: (within /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x42E2336: (within /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x42E7E1D: (within /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x42825E4: QPainter::drawPixmap(QRectF const&, QPixmap const&, QRectF const&) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4706E49: QGraphicsPixmapItem:aint(QPainter*, QStyleOptionGraphicsItem const*, QWidget*) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x472377C: (within /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4723EF8: (within /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4725DF5: QGraphicsScene::drawItems(QPainter*, int, QGraphicsItem**, QStyleOptionGraphicsItem const*, QWidget*) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x473B26C: QGraphicsView::drawItems(QPainter*, int, QGraphicsItem**, QStyleOptionGraphicsItem const*) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4747899: QGraphicsView:aintEvent(QPaintEvent*) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x41BBD3D: QWidget::event(QEvent*) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x45313C3: QFrame::event(QEvent*) (in /usr/lib/qt4/libQtGui.so.4.5.0)

    ==9781== Address 0x9bc32a8 is 8 bytes after a block of size 518,400 alloc'd
    ==9781== at 0x40264EF: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
    ==9781== by 0x42048E2: (within /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4204C97: QImage::QImage(QSize const&, QImage::Format) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x7C78640: (within /usr/lib/qt4/plugins/imageformats/libqjpeg.so)
    ==9781== by 0x7C793E7: (within /usr/lib/qt4/plugins/imageformats/libqjpeg.so)
    ==9781== by 0x7C79B96: (within /usr/lib/qt4/plugins/imageformats/libqjpeg.so)
    ==9781== by 0x42160CA: QImageReader::read(QImage*) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4216697: QImageReader::read() (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x4224F96: QPixmap::load(QString const&, char const*, QFlags<Qt::ImageConversionFlag>) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x422537B: QPixmap::QPixmap(QString const&, char const*, QFlags<Qt::ImageConversionFlag>) (in /usr/lib/qt4/libQtGui.so.4.5.0)
    ==9781== by 0x804AEA3: MainWindow::MainWindow(QWidget*) (in /root/a/a)
    ==9781== by 0x804A94C: main (in /root/a/a)

  11. The following user says thank you to koral for this useful post:

    captiva (12th March 2009)

  12. #9
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a bug in the (fasttransformation) pixmap scaling in qt 4.5?

    Thanks, I submitted a bug report.

    I also checked with an image allocated as follows:
    Qt Code:
    1. QPixmap * img = new QPixmap(imgname);
    To copy to clipboard, switch view to plain text mode 
    That gave the same problem, so I'm quite certain that it is a bug.
    (Otherwise it might be that the qpixmap dissapears after the constructor call. Although Im not sure qpixmapitem becomes of a deep copy? If anyone knows the proper way to do it...)

    [Edit: Thanks for checking it with valgrind! I normally test things using valgrind under linux, but on windows i have never used it.]
    Last edited by captiva; 12th March 2009 at 15:05.

Similar Threads

  1. Performance problems with small pixmap
    By RThaden in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2008, 15:14
  2. finding maximum scaling of a pixmap
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 31st March 2008, 14:32
  3. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 21:15
  4. Pixmap scaling
    By yellowmat in forum Newbie
    Replies: 3
    Last Post: 4th January 2007, 16:01

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.