Recent

Author Topic: Ugly resampling  (Read 7254 times)

grytom

  • New member
  • *
  • Posts: 9
Ugly resampling
« on: March 22, 2016, 08:58:02 pm »
I had an application compiled with gtk2 and after recompiling it with QT widgetset, I noticed that resampled images are not as smooth as with gtk2.

Attached resampled image is created with this simple code:
Code: Pascal  [Select][+][-]
  1. png := TPortableNetworkGraphic.Create;
  2. png.SetSize(300, 140);
  3. png.Canvas.StretchDraw(Rect(0, 0, 300, 140), Image1.Picture.Bitmap);
  4. png.SaveToFile('/tmp/resampled.png');
  5. png.Free;

It's noticeable even in IDE if I load some picture into TImage and check "Stretch". Is there any workaround?

System: Linux x86_64, Lazarus 1.6, FPC 3.0.0

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Ugly resampling
« Reply #1 on: March 23, 2016, 10:16:35 am »
Please open an issue about it, attach example project and original image, so I'll take a look into.

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Ugly resampling
« Reply #2 on: January 10, 2018, 02:55:12 pm »
Hi zeljko

Sorry to reopen an old thread, but could you tell us what you changed in the new version of Lazarus. I have the opposite problem to grytom. My image which was sharp on previous versions of Lazarus is now fuzzy. The windows version displays correctly. See below. My understanding of StretchDraw is that the interpolation method should be controlled by the alias flag on the destination device context. I've tried defining this, but it doesn't change anything.

I'm running Fedora 26 with QT 5.6, Lazarus 1.8 and Windows 7 with Lazarus 1.8.

Regards
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Ugly resampling
« Reply #3 on: January 11, 2018, 12:12:26 pm »
Try to disable smooting in qtobjects.pas inside DrawImage and then see what happens. Maybe Qt5 does not need such param.
EDIT: Is it lazarus win32 or lazarus qt on win32 ?

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Ugly resampling
« Reply #4 on: January 11, 2018, 12:16:20 pm »
Try to change params inside TQtDeviceContext.drawImage() (lcl/qt5/qtobjects.pas)...at the very bottom part of routine:
        // smooth a bit. issue #29883
       // try to set another render hint and try without any render hints.
        ARenderHint := QPainter_testRenderHint(Widget, QPainterSmoothPixmapTransform);
        if (QImage_format(image) = QImageFormat_ARGB32) and (flags = QtAutoColor) and
          not EqualRect(LocalRect, sourceRect^) then
            QPainter_setRenderHint(Widget, QPainterSmoothPixmapTransform, True);
        QPainter_drawImage(Widget, PRect(@LocalRect), image, sourceRect, flags);
        QPainter_setRenderHint(Widget, QPainterSmoothPixmapTransform, ARenderHint);

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Ugly resampling
« Reply #5 on: January 11, 2018, 02:44:04 pm »
Hi zeljko

Many thanks for your help. I changed QPainterSmoothPixmapTransform to QPainterQt4CompatiblePainting in TQtDeviceContext.drawImage() and now get a sharp image on linux with QT5.

PS: It was lazarus win32 that gave the sharp image previously.
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Ugly resampling
« Reply #6 on: January 11, 2018, 09:47:46 pm »
ok, can you please open an Qt5 issue and attach patch ?

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Ugly resampling
« Reply #7 on: January 12, 2018, 02:49:37 pm »
Done, listed as issue 0033011
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

 

TinyPortal © 2005-2018