src/hbcore/ovgeffects/hbvgblureffect.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
child 21 4633027730f5
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    61 }
    61 }
    62 
    62 
    63 void HbVgBlurEffect::setRadius(const QPointF &radius)
    63 void HbVgBlurEffect::setRadius(const QPointF &radius)
    64 {
    64 {
    65     Q_D(HbVgBlurEffect);
    65     Q_D(HbVgBlurEffect);
    66     if (d->radius == radius)
    66     if (d->radius == radius) {
    67         return;
    67         return;
       
    68     }
    68     d->radius = radius;
    69     d->radius = radius;
    69     updateEffectBoundingRect();
    70     updateEffectBoundingRect();
    70     emit radiusChanged(radius);
    71     emit radiusChanged(radius);
    71 }
    72 }
    72 
    73 
    73 QRectF HbVgBlurEffect::boundingRectFor(const QRectF &rect) const
    74 QRectF HbVgBlurEffect::boundingRectFor(const QRectF &rect) const
    74 {
    75 {
    75     Q_D(const HbVgBlurEffect);
    76     Q_D(const HbVgBlurEffect);
    76     QSizeF mappedRadius = d->mapSize(QSizeF(d->radius.x(), d->radius.y())); 
    77     QSizeF mappedRadius = d->mapSize(QSizeF(d->radius.x(), d->radius.y()));
    77     qreal deltaX = mappedRadius.width(); 
    78     qreal deltaX = mappedRadius.width();
    78     qreal deltaY = mappedRadius.height(); 
    79     qreal deltaY = mappedRadius.height();
    79     return rect.adjusted(-deltaX, -deltaY, deltaX, deltaY);
    80     return rect.adjusted(-deltaX, -deltaY, deltaX, deltaY);
    80 }
    81 }
    81 
    82 
    82 #ifdef HB_EFFECTS_OPENVG
    83 #ifdef HB_EFFECTS_OPENVG
    83 // identity mapping of colour components (i.e. 0->0, 1->1, ..., 255->255)
    84 // identity mapping of colour components (i.e. 0->0, 1->1, ..., 255->255)
   103 
   104 
   104 QPixmap HbVgBlurEffect::makeBlur(const QVariant &vgImage, const QSize &vgImageSize)
   105 QPixmap HbVgBlurEffect::makeBlur(const QVariant &vgImage, const QSize &vgImageSize)
   105 {
   106 {
   106 #ifdef HB_EFFECTS_OPENVG
   107 #ifdef HB_EFFECTS_OPENVG
   107     QPixmap cachedPm = cached(vgImageSize);
   108     QPixmap cachedPm = cached(vgImageSize);
   108     if (!cachedPm.isNull())
   109     if (!cachedPm.isNull()) {
   109         return cachedPm;
   110         return cachedPm;
       
   111     }
   110 
   112 
   111     Q_D(HbVgBlurEffect);
   113     Q_D(HbVgBlurEffect);
   112     VGImage srcImage = vgImage.value<VGImage>();
   114     VGImage srcImage = vgImage.value<VGImage>();
   113     VGImage dstImage = d->ensurePixmap(&d->dstPixmap, vgImageSize);
   115     VGImage dstImage = d->ensurePixmap(&d->dstPixmap, vgImageSize);
   114     QSizeF mappedRadius = d->mapSize(QSizeF(d->radius.x(), d->radius.y()));
   116     QSizeF mappedRadius = d->mapSize(QSizeF(d->radius.x(), d->radius.y()));
   117     const VGfloat opacity = (VGfloat) clamp(d->opacity, 0.0f, 1.0f);
   119     const VGfloat opacity = (VGfloat) clamp(d->opacity, 0.0f, 1.0f);
   118     if (opacity < 1.0f - HBVG_EPSILON) {
   120     if (opacity < 1.0f - HBVG_EPSILON) {
   119         VGImage tmpImage = d->ensurePixmap(&d->tmpPixmap, vgImageSize);
   121         VGImage tmpImage = d->ensurePixmap(&d->tmpPixmap, vgImageSize);
   120         vgGaussianBlur(tmpImage, srcImage, blurX, blurY, VG_TILE_PAD);
   122         vgGaussianBlur(tmpImage, srcImage, blurX, blurY, VG_TILE_PAD);
   121         if (d->paramsChanged) {
   123         if (d->paramsChanged) {
   122             for (int i = 0; i < 256; ++i)
   124             for (int i = 0; i < 256; ++i) {
   123                 d->alphaLUT[i] = (VGubyte) (i * opacity);
   125                 d->alphaLUT[i] = (VGubyte)(i * opacity);
       
   126             }
   124         }
   127         }
   125         vgLookup(dstImage, tmpImage,
   128         vgLookup(dstImage, tmpImage,
   126                  identityLUT, identityLUT, identityLUT, d->alphaLUT,
   129                  identityLUT, identityLUT, identityLUT, d->alphaLUT,
   127                  VG_TRUE, VG_FALSE);
   130                  VG_TRUE, VG_FALSE);
   128     } else {
   131     } else {
   129         vgGaussianBlur(dstImage, srcImage, blurX, blurY, VG_TILE_PAD);   
   132         vgGaussianBlur(dstImage, srcImage, blurX, blurY, VG_TILE_PAD);
   130     }
   133     }
   131 
   134 
   132     tryCache(d->dstPixmap);
   135     tryCache(d->dstPixmap);
   133     return d->dstPixmap;
   136     return d->dstPixmap;
   134 #else
   137 #else