src/hbcore/ovgeffects/hbvgbceffect.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    61 }
    61 }
    62 
    62 
    63 void HbVgBcEffect::setBrightness(qreal brightness)
    63 void HbVgBcEffect::setBrightness(qreal brightness)
    64 {
    64 {
    65     Q_D(HbVgBcEffect);
    65     Q_D(HbVgBcEffect);
    66     if (d->brightness == brightness)
    66     if (d->brightness == brightness) {
    67         return;
    67         return;
       
    68     }
    68     d->brightness = brightness;
    69     d->brightness = brightness;
    69     updateEffect();
    70     updateEffect();
    70     emit brightnessChanged(brightness);
    71     emit brightnessChanged(brightness);
    71 }
    72 }
    72 
    73 
    77 }
    78 }
    78 
    79 
    79 void HbVgBcEffect::setContrast(qreal contrast)
    80 void HbVgBcEffect::setContrast(qreal contrast)
    80 {
    81 {
    81     Q_D(HbVgBcEffect);
    82     Q_D(HbVgBcEffect);
    82     if (d->contrast == contrast)
    83     if (d->contrast == contrast) {
    83         return;
    84         return;
       
    85     }
    84     d->contrast = contrast;
    86     d->contrast = contrast;
    85     updateEffect();
    87     updateEffect();
    86     emit contrastChanged(contrast);
    88     emit contrastChanged(contrast);
    87 }
    89 }
    88 
    90 
    90 {
    92 {
    91     return rect;
    93     return rect;
    92 }
    94 }
    93 
    95 
    94 void HbVgBcEffect::performEffect(QPainter *painter,
    96 void HbVgBcEffect::performEffect(QPainter *painter,
    95                                    const QPointF &offset,
    97                                  const QPointF &offset,
    96                                    const QVariant &vgImage,
    98                                  const QVariant &vgImage,
    97                                    const QSize &vgImageSize)
    99                                  const QSize &vgImageSize)
    98 {
   100 {
    99 #ifdef HB_EFFECTS_OPENVG
   101 #ifdef HB_EFFECTS_OPENVG
   100     QPixmap cachedPm = cached(vgImageSize);
   102     QPixmap cachedPm = cached(vgImageSize);
   101     if (!cachedPm.isNull()) {
   103     if (!cachedPm.isNull()) {
   102         painter->drawPixmap(offset, cachedPm);
   104         painter->drawPixmap(offset, cachedPm);
   110     if (opacity > HBVG_EPSILON) {
   112     if (opacity > HBVG_EPSILON) {
   111         if (d->paramsChanged) {
   113         if (d->paramsChanged) {
   112             // brightness [-1, 1]
   114             // brightness [-1, 1]
   113             const VGfloat offset_br = clamp(d->brightness, -1.0f, 1.0f);
   115             const VGfloat offset_br = clamp(d->brightness, -1.0f, 1.0f);
   114             const VGfloat scale_br = 1.0f - 0.5f * ((offset_br < 0.0f) ? -offset_br : offset_br);
   116             const VGfloat scale_br = 1.0f - 0.5f * ((offset_br < 0.0f) ? -offset_br : offset_br);
   115     
   117 
   116             // contrast [0, N]
   118             // contrast [0, N]
   117             const VGfloat scale_con = clamp(d->contrast, 0.0f, 100.0f);
   119             const VGfloat scale_con = clamp(d->contrast, 0.0f, 100.0f);
   118             const VGfloat offset_con = -0.5f * scale_con + 0.5f ;
   120             const VGfloat offset_con = -0.5f * scale_con + 0.5f ;
   119     
   121 
   120             // combine the effects of brightness and contrast
   122             // combine the effects of brightness and contrast
   121             const VGfloat off = offset_br + offset_con;
   123             const VGfloat off = offset_br + offset_con;
   122             const VGfloat sc  = scale_br * scale_con;
   124             const VGfloat sc  = scale_br * scale_con;
   123 
   125 
   124             // take opacity into account
   126             // take opacity into account
   125             const VGfloat o = (VGfloat) opacity;
   127             const VGfloat o = (VGfloat) opacity;
   126             const VGfloat oOff = off * o;
   128             const VGfloat oOff = off * o;
   127             const VGfloat oSc  = (sc * o) + (1.0f - o);
   129             const VGfloat oSc  = (sc * o) + (1.0f - o);
   128     
   130 
   129             d->colorMatrix[0] = oSc;
   131             d->colorMatrix[0] = oSc;
   130             d->colorMatrix[1] = 0.0f;
   132             d->colorMatrix[1] = 0.0f;
   131             d->colorMatrix[2] = 0.0f;
   133             d->colorMatrix[2] = 0.0f;
   132             d->colorMatrix[3] = 0.0f;
   134             d->colorMatrix[3] = 0.0f;
   133             d->colorMatrix[4] = 0.0f;
   135             d->colorMatrix[4] = 0.0f;