diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-08-25 01:10:52 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-08-25 01:10:52 (GMT) |
commit | 81c094621d64b5a6547c232c7282582339b16045 (patch) | |
tree | eb51430577968a330061db1f01b7675ecb189b79 | |
parent | 5770b12325cfde6984721b46d0d1477e275c91ad (diff) | |
download | Qt-81c094621d64b5a6547c232c7282582339b16045.zip Qt-81c094621d64b5a6547c232c7282582339b16045.tar.gz Qt-81c094621d64b5a6547c232c7282582339b16045.tar.bz2 |
Implement the blur pixmap filter for OpenVG using vgGaussianBlur()
Reviewed-by: Sarah Smith
-rw-r--r-- | src/openvg/qpaintengine_vg.cpp | 2 | ||||
-rw-r--r-- | src/openvg/qpixmapfilter_vg.cpp | 59 | ||||
-rw-r--r-- | src/openvg/qpixmapfilter_vg_p.h | 13 |
3 files changed, 74 insertions, 0 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index b0e190f..5669f45 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -3112,6 +3112,8 @@ QPixmapFilter *QVGPaintEngine::createPixmapFilter(int type) const return new QVGPixmapColorizeFilter; else if (type == QPixmapFilter::DropShadowFilter) return new QVGPixmapDropShadowFilter; + else if (type == QPixmapFilter::BlurFilter) + return new QVGPixmapBlurFilter; else #endif return QPaintEngineEx::createPixmapFilter(type); diff --git a/src/openvg/qpixmapfilter_vg.cpp b/src/openvg/qpixmapfilter_vg.cpp index 2dbdf7e..5a263a5 100644 --- a/src/openvg/qpixmapfilter_vg.cpp +++ b/src/openvg/qpixmapfilter_vg.cpp @@ -335,6 +335,65 @@ void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, con vgDestroyImage(dstImage); } +QVGPixmapBlurFilter::QVGPixmapBlurFilter(QObject *parent) + : QPixmapBlurFilter(parent) +{ +} + +QVGPixmapBlurFilter::~QVGPixmapBlurFilter() +{ +} + +void QVGPixmapBlurFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const +{ + if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { + // The pixmap data is not an instance of QVGPixmapData, so fall + // back to the default blur filter implementation. + QPixmapBlurFilter::draw(painter, dest, src, srcRect); + return; + } + + QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData()); + + VGImage srcImage = pd->toVGImage(); + if (srcImage == VG_INVALID_HANDLE) + return; + + QSize size = pd->size(); + VGImage dstImage = vgCreateImage + (VG_sARGB_8888_PRE, size.width(), size.height(), + VG_IMAGE_QUALITY_FASTER); + if (dstImage == VG_INVALID_HANDLE) + return; + + // Clamp the radius range. We divide by 2 because the OpenVG blur + // is "too blurry" compared to the default raster implementation. + VGfloat maxRadius = VGfloat(vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION)); + VGfloat radiusF = VGfloat(radius()) / 2.0f; + if (radiusF < 0.001f) + radiusF = 0.001f; + else if (radiusF > maxRadius) + radiusF = maxRadius; + + vgGaussianBlur(dstImage, srcImage, radiusF, radiusF, VG_TILE_PAD); + + VGImage child = VG_INVALID_HANDLE; + + if (srcRect.isNull() || + (srcRect.topLeft().isNull() && srcRect.size() == size)) { + child = dstImage; + } else { + QRect src = srcRect.toRect(); + child = vgChildImage(dstImage, src.x(), src.y(), src.width(), src.height()); + } + + qt_vg_drawVGImage(painter, dest, child); + + if(child != dstImage) + vgDestroyImage(child); + vgDestroyImage(dstImage); +} + #endif QT_END_NAMESPACE diff --git a/src/openvg/qpixmapfilter_vg_p.h b/src/openvg/qpixmapfilter_vg_p.h index 6a3cc5f..3dc0e8f 100644 --- a/src/openvg/qpixmapfilter_vg_p.h +++ b/src/openvg/qpixmapfilter_vg_p.h @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE class Q_OPENVG_EXPORT QVGPixmapConvolutionFilter : public QPixmapConvolutionFilter { + Q_OBJECT public: QVGPixmapConvolutionFilter(); ~QVGPixmapConvolutionFilter(); @@ -72,6 +73,7 @@ public: class Q_OPENVG_EXPORT QVGPixmapColorizeFilter : public QPixmapColorizeFilter { + Q_OBJECT public: QVGPixmapColorizeFilter(); ~QVGPixmapColorizeFilter(); @@ -86,6 +88,7 @@ private: class Q_OPENVG_EXPORT QVGPixmapDropShadowFilter : public QPixmapDropShadowFilter { + Q_OBJECT public: QVGPixmapDropShadowFilter(); ~QVGPixmapDropShadowFilter(); @@ -101,6 +104,16 @@ private: mutable QVarLengthArray<VGshort, 16> kernel; }; +class Q_OPENVG_EXPORT QVGPixmapBlurFilter : public QPixmapBlurFilter +{ + Q_OBJECT +public: + QVGPixmapBlurFilter(QObject *parent = 0); + ~QVGPixmapBlurFilter(); + + void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const; +}; + #endif QT_END_NAMESPACE |