diff options
Diffstat (limited to 'src/openvg')
-rw-r--r-- | src/openvg/qpaintengine_vg.cpp | 3 | ||||
-rw-r--r-- | src/openvg/qpixmapfilter_vg.cpp | 86 | ||||
-rw-r--r-- | src/openvg/qpixmapfilter_vg_p.h | 5 |
3 files changed, 40 insertions, 54 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index e0c99d7..fdd61ea 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -3328,9 +3328,6 @@ QPixmapFilter *QVGPaintEngine::pixmapFilter(int type, const QPixmapFilter *proto d->convolutionFilter.reset(new QVGPixmapConvolutionFilter); return d->convolutionFilter.data(); case QPixmapFilter::ColorizeFilter: - // Strength parameter does not work with current implementation. - if ((static_cast<const QPixmapColorizeFilter *>(prototype))->strength() != 1.0f) - break; if (!d->colorizeFilter) d->colorizeFilter.reset(new QVGPixmapColorizeFilter); return d->colorizeFilter.data(); diff --git a/src/openvg/qpixmapfilter_vg.cpp b/src/openvg/qpixmapfilter_vg.cpp index 613f4ea..3305bbb 100644 --- a/src/openvg/qpixmapfilter_vg.cpp +++ b/src/openvg/qpixmapfilter_vg.cpp @@ -123,8 +123,7 @@ void QVGPixmapConvolutionFilter::draw } QVGPixmapColorizeFilter::QVGPixmapColorizeFilter() - : QPixmapColorizeFilter(), - firstTime(true) + : QPixmapColorizeFilter() { } @@ -136,7 +135,7 @@ void QVGPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const { if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { // The pixmap data is not an instance of QVGPixmapData, so fall - // back to the default convolution filter implementation. + // back to the default colorize filter implementation. QPixmapColorizeFilter::draw(painter, dest, src, srcRect); return; } @@ -154,50 +153,45 @@ void QVGPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const if (dstImage == VG_INVALID_HANDLE) return; - // Recompute the color matrix if the color has changed. + // Determine the weights for the matrix from the color and strength. QColor c = color(); - if (c != prevColor || firstTime) { - prevColor = c; - - // Determine the weights for the matrix from the color. - VGfloat weights[3]; - VGfloat invweights[3]; - VGfloat alpha = c.alphaF(); - weights[0] = c.redF() * alpha; - weights[1] = c.greenF() * alpha; - weights[2] = c.blueF() * alpha; - invweights[0] = 1.0f - weights[0]; - invweights[1] = 1.0f - weights[1]; - invweights[2] = 1.0f - weights[2]; - - // Grayscale weights. - static const VGfloat redGray = 11.0f / 32.0f; - static const VGfloat greenGray = 16.0f / 32.0f; - static const VGfloat blueGray = 1.0f - (redGray + greenGray); - - matrix[0][0] = redGray * invweights[0]; - matrix[0][1] = redGray * invweights[1]; - matrix[0][2] = redGray * invweights[2]; - matrix[0][3] = 0.0f; - matrix[1][0] = greenGray * invweights[0]; - matrix[1][1] = greenGray * invweights[1]; - matrix[1][2] = greenGray * invweights[2]; - matrix[1][3] = 0.0f; - matrix[2][0] = blueGray * invweights[0]; - matrix[2][1] = blueGray * invweights[1]; - matrix[2][2] = blueGray * invweights[2]; - matrix[2][3] = 0.0f; - matrix[3][0] = 0.0f; - matrix[3][1] = 0.0f; - matrix[3][2] = 0.0f; - matrix[3][3] = 1.0f; - matrix[4][0] = weights[0]; - matrix[4][1] = weights[1]; - matrix[4][2] = weights[2]; - matrix[4][3] = 0.0f; - } - - firstTime = false; + VGfloat strength = this->strength(); + VGfloat weights[3]; + VGfloat invweights[3]; + VGfloat alpha = c.alphaF(); + weights[0] = c.redF() * alpha; + weights[1] = c.greenF() * alpha; + weights[2] = c.blueF() * alpha; + invweights[0] = (1.0f - weights[0]) * strength; + invweights[1] = (1.0f - weights[1]) * strength; + invweights[2] = (1.0f - weights[2]) * strength; + + // Grayscale weights. + static const VGfloat redGray = 11.0f / 32.0f; + static const VGfloat greenGray = 16.0f / 32.0f; + static const VGfloat blueGray = 1.0f - (redGray + greenGray); + + VGfloat matrix[5][4]; + matrix[0][0] = redGray * invweights[0] + (1.0f - strength); + matrix[0][1] = redGray * invweights[1]; + matrix[0][2] = redGray * invweights[2]; + matrix[0][3] = 0.0f; + matrix[1][0] = greenGray * invweights[0]; + matrix[1][1] = greenGray * invweights[1] + (1.0f - strength); + matrix[1][2] = greenGray * invweights[2]; + matrix[1][3] = 0.0f; + matrix[2][0] = blueGray * invweights[0]; + matrix[2][1] = blueGray * invweights[1]; + matrix[2][2] = blueGray * invweights[2] + (1.0f - strength); + matrix[2][3] = 0.0f; + matrix[3][0] = 0.0f; + matrix[3][1] = 0.0f; + matrix[3][2] = 0.0f; + matrix[3][3] = 1.0f; + matrix[4][0] = weights[0] * strength; + matrix[4][1] = weights[1] * strength; + matrix[4][2] = weights[2] * strength; + matrix[4][3] = 0.0f; vgColorMatrix(dstImage, srcImage, matrix[0]); diff --git a/src/openvg/qpixmapfilter_vg_p.h b/src/openvg/qpixmapfilter_vg_p.h index 58111ec..f79b6c2 100644 --- a/src/openvg/qpixmapfilter_vg_p.h +++ b/src/openvg/qpixmapfilter_vg_p.h @@ -79,11 +79,6 @@ public: ~QVGPixmapColorizeFilter(); void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const; - -private: - mutable VGfloat matrix[5][4]; - mutable QColor prevColor; - mutable bool firstTime; }; class Q_OPENVG_EXPORT QVGPixmapDropShadowFilter : public QPixmapDropShadowFilter |