|
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 "HuiFxVg10ColorizeFilter.h" |
|
21 #include "HuiFxConstants.h" |
|
22 |
|
23 CHuiFxVg10ColorizeFilter* CHuiFxVg10ColorizeFilter::NewL() |
|
24 { |
|
25 CHuiFxVg10ColorizeFilter* e = new (ELeave) CHuiFxVg10ColorizeFilter(); |
|
26 CleanupStack::PushL(e); |
|
27 e->ConstructL(); |
|
28 CleanupStack::Pop(e); |
|
29 return e; |
|
30 } |
|
31 |
|
32 void CHuiFxVg10ColorizeFilter::ConstructL() |
|
33 { |
|
34 CHuiFxVg10ColorMatrixFilterBase::ConstructL(); |
|
35 iColor = TRgb(0xffffffff); |
|
36 RegisterParameterL(KLitColor, &iColor); |
|
37 } |
|
38 CHuiFxVg10ColorizeFilter *CHuiFxVg10ColorizeFilter::CloneL() const |
|
39 { |
|
40 CHuiFxVg10ColorizeFilter *filter = new(ELeave)CHuiFxVg10ColorizeFilter; |
|
41 filter->CHuiFxVg10ColorMatrixFilterBase::CopyFromL(this); |
|
42 filter->iColor = iColor; |
|
43 filter->CopyParameterL(KLitColor, &filter->iColor, this); |
|
44 return filter; |
|
45 } |
|
46 |
|
47 void CHuiFxVg10ColorizeFilter::UpdateColorMatrix(void) |
|
48 { |
|
49 const VGfloat o = clamp(iOpacity, 0.0f, 1.0f); |
|
50 const VGfloat ao = 1 - o; |
|
51 const VGfloat Rw = 0.3086f; |
|
52 const VGfloat Gw = 0.6094f; |
|
53 const VGfloat Bw = 0.0820f; |
|
54 const VGfloat R = (o / 255.0f) * (VGfloat)iColor.Red(); |
|
55 const VGfloat G = (o / 255.0f) * (VGfloat)iColor.Green(); |
|
56 const VGfloat B = (o / 255.0f) * (VGfloat)iColor.Blue(); |
|
57 |
|
58 // this matrix is ((I * (1 - opacity)) + (I * opacity) * RGBMatrix * desaturateMatrix)T |
|
59 // i.e. pixel is first converted to luminance, then multiplied by RGB, multiplied by opacity and finally the diagonal |
|
60 // compensated with 1 - opacity. |
|
61 // Precalculating abovementioned matrices to single matrix saves over a magnitude of multiplications and |
|
62 // almost two magnitudes of additions. Also less memory is used and no unnecessary copying is involved. |
|
63 iColorMatrix[0] = R*Rw + ao; |
|
64 iColorMatrix[1] = G*Rw; |
|
65 iColorMatrix[2] = B*Rw; |
|
66 iColorMatrix[3] = 0.0f; |
|
67 iColorMatrix[4] = R*Gw; |
|
68 iColorMatrix[5] = G*Gw + ao; |
|
69 iColorMatrix[6] = B*Gw; |
|
70 iColorMatrix[7] = 0.0f; |
|
71 iColorMatrix[8] = R*Bw; |
|
72 iColorMatrix[9] = G*Bw; |
|
73 iColorMatrix[10] = B*Bw + ao; |
|
74 iColorMatrix[11] = 0.0f; |
|
75 iColorMatrix[12] = 0.0f; |
|
76 iColorMatrix[13] = 0.0f; |
|
77 iColorMatrix[14] = 0.0f; |
|
78 iColorMatrix[15] = 1.0f; |
|
79 iColorMatrix[16] = 0.0f; |
|
80 iColorMatrix[17] = 0.0f; |
|
81 iColorMatrix[18] = 0.0f; |
|
82 iColorMatrix[19] = 0.0f; |
|
83 } |