uiacceltk/hitchcock/coretoolkit/src/HuiFxColorParameter.cpp
changeset 0 15bf7259bb7c
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 "HuiFxColorParameter.h"
       
    21 #include <gdi.h>
       
    22 
       
    23 template<>
       
    24 TUint32 RHuiFxColorTimeLine::ToFixedPoint(const TRgb& aValue)
       
    25     {
       
    26     return aValue.Internal();
       
    27     }
       
    28 
       
    29 template<>
       
    30 TRgb RHuiFxColorTimeLine::FromFixedPoint(const TUint32& aValue)
       
    31     {
       
    32     return TRgb(aValue);
       
    33     }
       
    34 
       
    35 template<>
       
    36 TUint32 RHuiFxColorTimeLine::Blend(const TUint32& aValue1, const TUint32& aValue2, TInt32 aAlpha)
       
    37     {
       
    38     TUint32 redBlue1    = (aValue1 & 0x00ff00ff);
       
    39     TUint32 alphaGreen1 = (aValue1 & 0xff00ff00) >> 8;
       
    40     TUint32 redBlue2    = (aValue2 & 0x00ff00ff);
       
    41     TUint32 alphaGreen2 = (aValue2 & 0xff00ff00) >> 8;
       
    42     
       
    43     TUint32 redBlueDelta    = redBlue2 - redBlue1; 
       
    44     TUint32 alphaGreenDelta = alphaGreen2 - alphaGreen1;
       
    45 
       
    46     aAlpha >>= 8;
       
    47     
       
    48     redBlueDelta    = (redBlueDelta * aAlpha) >> 8;
       
    49     alphaGreenDelta = (alphaGreenDelta * aAlpha) >> 8;
       
    50 
       
    51     redBlue1    += (redBlueDelta & 0xff00ff);
       
    52     alphaGreen1 += (alphaGreenDelta & 0xff00ff);
       
    53     
       
    54     return redBlue1 | (alphaGreen1 << 8);
       
    55     }
       
    56 
       
    57 template<>
       
    58 TUint32 RHuiFxColorTimeLine::WeightedSum4(const TUint32& aValue1, const TUint32& aValue2, const TUint32& aValue3, const TUint32& aValue4,
       
    59                                           TInt32 aWeight1, TInt32 aWeight2, TInt32 aWeight3, TInt32 aWeight4)
       
    60     {
       
    61     TUint32 a1 = ((aValue1 & 0xff000000) >> 24) * aWeight1;
       
    62     TUint32 a2 = ((aValue2 & 0xff000000) >> 24) * aWeight2;
       
    63     TUint32 a3 = ((aValue3 & 0xff000000) >> 24) * aWeight3;
       
    64     TUint32 a4 = ((aValue4 & 0xff000000) >> 24) * aWeight4;
       
    65     
       
    66     TUint32 r1 = ((aValue1 & 0x00ff0000) >> 16) * aWeight1;
       
    67     TUint32 r2 = ((aValue2 & 0x00ff0000) >> 16) * aWeight2;
       
    68     TUint32 r3 = ((aValue3 & 0x00ff0000) >> 16) * aWeight3;
       
    69     TUint32 r4 = ((aValue4 & 0x00ff0000) >> 16) * aWeight4;
       
    70 
       
    71     TUint32 g1 = ((aValue1 & 0x0000ff00) >> 8) * aWeight1;
       
    72     TUint32 g2 = ((aValue2 & 0x0000ff00) >> 8) * aWeight2;
       
    73     TUint32 g3 = ((aValue3 & 0x0000ff00) >> 8) * aWeight3;
       
    74     TUint32 g4 = ((aValue4 & 0x0000ff00) >> 8) * aWeight4;
       
    75     
       
    76     TUint32 b1 = (aValue1 & 0x000000ff) * aWeight1;
       
    77     TUint32 b2 = (aValue2 & 0x000000ff) * aWeight2;
       
    78     TUint32 b3 = (aValue3 & 0x000000ff) * aWeight3;
       
    79     TUint32 b4 = (aValue4 & 0x000000ff) * aWeight4;
       
    80     
       
    81     TUint32 a = ((a1 + a2 + a3 + a4) << 8)  & 0xff000000;
       
    82     TUint32 r = ((r1 + r2 + r3 + r4))       & 0x00ff0000;
       
    83     TUint32 g = ((g1 + g2 + g3 + g4) >> 8)  & 0x0000ff00;
       
    84     TUint32 b = ((b1 + b2 + b3 + b4) >> 16) & 0x000000ff;
       
    85     
       
    86     return (a | r | g | b);
       
    87     }