OSDN Git Service

unclipped texture blending optimization
authorIvailo Monev <xakepa10@gmail.com>
Fri, 17 Sep 2021 13:53:05 +0000 (16:53 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 17 Sep 2021 13:53:05 +0000 (16:53 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/image/qpixmapfilter.cpp
src/gui/painting/qdrawhelper.cpp

index 6c02373..a3f4db0 100644 (file)
@@ -559,7 +559,7 @@ Q_GUI_EXPORT void qt_grayscale(const QImage &image, QImage &dest)
     unsigned int *outData = (unsigned int *)dest.bits();
 
     if (dest.size() == image.size() && image.rect() == srcRect) {
-        const unsigned int *data = (const unsigned int *)image.bits();
+        const unsigned int *data = (const unsigned int *)image.constBits();
         // a bit faster loop for grayscaling everything
         int pixels = dest.width() * dest.height();
         for (int i = 0; i < pixels; ++i) {
@@ -569,7 +569,7 @@ Q_GUI_EXPORT void qt_grayscale(const QImage &image, QImage &dest)
     } else {
         int yd = destRect.top();
         for (int y = srcRect.top(); y <= srcRect.bottom() && y < image.height(); y++) {
-            const unsigned int *data = (const unsigned int*)image.scanLine(y);
+            const unsigned int *data = (const unsigned int*)image.constScanLine(y);
             outData = (unsigned int*)dest.scanLine(yd++);
             int xd = destRect.left();
             for (int x = srcRect.left(); x <= srcRect.right() && x < image.width(); x++) {
index 419976e..90e172b 100644 (file)
@@ -2826,81 +2826,17 @@ static void blend_tiled_generic(int count, const QSpan *spans, void *userData)
     }
 }
 
-/* Image formats here are target formats */
-static const ProcessSpans processTextureSpans[NBlendTypes][QImage::NImageFormats] = {
-    // Untransformed
-    {
-        0, // Invalid
-        blend_untransformed_generic, // Mono
-        blend_untransformed_generic, // MonoLsb
-        blend_untransformed_generic, // Indexed8
-        blend_untransformed_generic, // RGB32
-        blend_untransformed_generic, // ARGB32
-        blend_untransformed_generic, // ARGB32_Premultiplied
-        blend_untransformed_generic // RGB16
-    },
-    // Tiled
-    {
-        0, // Invalid
-        blend_tiled_generic, // Mono
-        blend_tiled_generic, // MonoLsb
-        blend_tiled_generic, // Indexed8
-        blend_tiled_generic, // RGB32
-        blend_tiled_generic, // ARGB32
-        blend_tiled_generic, // ARGB32_Premultiplied
-        blend_tiled_generic // RGB16
-    },
-    // Transformed
-    {
-        0, // Invalid
-        blend_src_generic, // Mono
-        blend_src_generic, // MonoLsb
-        blend_src_generic, // Indexed8
-        blend_src_generic, // RGB32
-        blend_src_generic, // ARGB32
-        blend_src_generic, // ARGB32_Premultiplied
-        blend_src_generic // RGB16
-    },
-     // TransformedTiled
-    {
-        0,
-        blend_src_generic, // Mono
-        blend_src_generic, // MonoLsb
-        blend_src_generic, // Indexed8
-        blend_src_generic, // RGB32
-        blend_src_generic, // ARGB32
-        blend_src_generic, // ARGB32_Premultiplied
-        blend_src_generic // RGB16
-    },
-    // Bilinear
-    {
-        0,
-        blend_src_generic, // Mono
-        blend_src_generic, // MonoLsb
-        blend_src_generic, // Indexed8
-        blend_src_generic, // RGB32
-        blend_src_generic, // ARGB32
-        blend_src_generic, // ARGB32_Premultiplied
-        blend_src_generic // RGB16
-    },
-    // BilinearTiled
-    {
-        0,
-        blend_src_generic, // Mono
-        blend_src_generic, // MonoLsb
-        blend_src_generic, // Indexed8
-        blend_src_generic, // RGB32
-        blend_src_generic, // ARGB32
-        blend_src_generic, // ARGB32_Premultiplied
-        blend_src_generic // RGB16
-    }
-};
-
 void qBlendTexture(int count, const QSpan *spans, void *userData)
 {
     QSpanData *data = reinterpret_cast<QSpanData *>(userData);
-    ProcessSpans proc = processTextureSpans[getBlendType(data)][data->rasterBuffer->format];
-    proc(count, spans, userData);
+    Q_ASSERT(data->rasterBuffer->format != QImage::Format_Invalid);
+    if (data->txop <= QTransform::TxTranslate && data->texture.type == QTextureData::Tiled) {
+        blend_tiled_generic(count, spans, userData);
+    } else if (data->txop <= QTransform::TxTranslate) {
+        blend_untransformed_generic(count, spans, userData);
+    } else {
+        blend_src_generic(count, spans, userData);
+    }
 }
 
 template <class DST>