]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Experimental patch provided by Fredrik Höglund: Use Xrender to scale the preview...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 21 Sep 2008 21:24:54 +0000 (21:24 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 21 Sep 2008 21:24:54 +0000 (21:24 +0000)
CCMAIL: fredrik@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=863342

src/kfilepreviewgenerator.cpp

index f614aae63740f126f2914139efb4fd27d39e635d..cbbb861ecf2b2a50585631453fdcdb68ca44e813 100644 (file)
 #include <QScrollBar>
 #include <QIcon>
 
+#ifdef Q_WS_X11
+#  include <QX11Info>
+#  include <X11/Xlib.h>
+#  include <X11/extensions/Xrender.h>
+#endif
+
 /**
  * If the passed item view is an instance of QListView, expensive
  * layout operations are blocked in the constructor and are unblocked
@@ -575,7 +581,35 @@ bool KFilePreviewGenerator::Private::applyImageFrame(QPixmap& icon)
 void KFilePreviewGenerator::Private::limitToSize(QPixmap& icon, const QSize& maxSize)
 {
     if ((icon.width() > maxSize.width()) || (icon.height() > maxSize.height())) {
+#ifdef Q_WS_X11
+        // Assume that the texture size limit is 2048x2048
+        if ((icon.width() <= 2048) && (icon.height() <= 2048)) {
+            QSize size = icon.size();
+            size.scale(maxSize, Qt::KeepAspectRatio);
+
+            const qreal factor = size.width() / qreal(icon.width());
+
+            XTransform xform = {{
+                { XDoubleToFixed(1 / factor), 0, 0 },
+                { 0, XDoubleToFixed(1 / factor), 0 },
+                { 0, 0, XDoubleToFixed(1) }
+            }};
+
+            QPixmap pixmap(size);
+            pixmap.fill(Qt::transparent);
+
+            Display *dpy = QX11Info::display();
+            XRenderSetPictureFilter(dpy, icon.x11PictureHandle(), FilterBilinear, 0, 0);
+            XRenderSetPictureTransform(dpy, icon.x11PictureHandle(), &xform);
+            XRenderComposite(dpy, PictOpOver, icon.x11PictureHandle(), None, pixmap.x11PictureHandle(),
+                             0, 0, 0, 0, 0, 0, pixmap.width(), pixmap.height());
+            icon = pixmap;
+        } else {
+            icon = icon.scaled(maxSize, Qt::KeepAspectRatio, Qt::FastTransformation);
+        }
+#else
         icon = icon.scaled(maxSize, Qt::KeepAspectRatio, Qt::FastTransformation);
+#endif
     }
 }