uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10BrightnessContrastFilter.cpp
changeset 0 15bf7259bb7c
child 24 f93c875b566e
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "HuiFxVg10BrightnessContrastFilter.h"
       
    21 #include "HuiFxConstants.h"
       
    22 
       
    23 CHuiFxVg10BrightnessContrastFilter* CHuiFxVg10BrightnessContrastFilter::NewL()
       
    24     {
       
    25     CHuiFxVg10BrightnessContrastFilter* e = new (ELeave) CHuiFxVg10BrightnessContrastFilter();
       
    26     CleanupStack::PushL(e);
       
    27     e->ConstructL();
       
    28     CleanupStack::Pop(e);
       
    29     return e;
       
    30     }
       
    31 
       
    32 void CHuiFxVg10BrightnessContrastFilter::ConstructL()
       
    33     {
       
    34     CHuiFxVg10ColorMatrixFilterBase::ConstructL();
       
    35     // neutral settings
       
    36     iBrightness = 0.0f;
       
    37     iContrast = 1.0f;
       
    38     RegisterParameterL(KLitBrightness, &iBrightness);
       
    39     RegisterParameterL(KLitContrast, &iContrast);
       
    40     }
       
    41 CHuiFxVg10BrightnessContrastFilter *CHuiFxVg10BrightnessContrastFilter::CloneL() const
       
    42     {
       
    43     CHuiFxVg10BrightnessContrastFilter *filter = new(ELeave) CHuiFxVg10BrightnessContrastFilter;
       
    44     filter->CHuiFxVg10ColorMatrixFilterBase::CopyFromL(this);
       
    45     filter->iBrightness = iBrightness;
       
    46     filter->iContrast = iContrast;
       
    47     filter->CopyParameterL(KLitBrightness, &filter->iBrightness, this);
       
    48     filter->CopyParameterL(KLitContrast, &filter->iContrast, this);    
       
    49     return filter;
       
    50     }
       
    51 
       
    52 void CHuiFxVg10BrightnessContrastFilter::UpdateColorMatrix(void)
       
    53     {
       
    54     // brightness [-1, 1]
       
    55     const VGfloat offset_br = clamp(iBrightness, -1.0f, 1.0f);
       
    56     const VGfloat scale_br = 1.0f - 0.5 * ((offset_br < 0.0f) ? -offset_br : offset_br);
       
    57     
       
    58     // contrast [0, N]
       
    59     const VGfloat scale_con = clamp(iContrast, 0.0f, 100.0f);
       
    60     const VGfloat offset_con = -0.5f * scale_con + 0.5f ;
       
    61     
       
    62     // combine the effects of brightness and contrast
       
    63     const VGfloat off = offset_br + offset_con;
       
    64     const VGfloat sc  = scale_br * scale_con;
       
    65 
       
    66     // take opacity into account
       
    67     const VGfloat opacity = clamp(iOpacity, 0.0f, 1.0f);
       
    68     const VGfloat oOff = off * opacity;
       
    69     const VGfloat oSc  = (sc * opacity) + (1.0f - opacity);
       
    70     
       
    71     iColorMatrix[0] = oSc;
       
    72     iColorMatrix[1] = 0.0f;
       
    73     iColorMatrix[2] = 0.0f;
       
    74     iColorMatrix[3] = 0.0f;
       
    75     iColorMatrix[4] = 0.0f;
       
    76     iColorMatrix[5] = oSc;
       
    77     iColorMatrix[6] = 0.0f;
       
    78     iColorMatrix[7] = 0.0f;
       
    79     iColorMatrix[8] = 0.0f;
       
    80     iColorMatrix[9] = 0.0f;
       
    81     iColorMatrix[10] = oSc;
       
    82     iColorMatrix[11] = 0.0f;
       
    83     iColorMatrix[12] = 0.0f;
       
    84     iColorMatrix[13] = 0.0f;
       
    85     iColorMatrix[14] = 0.0f;
       
    86     iColorMatrix[15] = 1.0f;
       
    87     iColorMatrix[16] = oOff;
       
    88     iColorMatrix[17] = oOff;
       
    89     iColorMatrix[18] = oOff;
       
    90     iColorMatrix[19] = 0.0f;
       
    91     }