|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "CFilterSepia.h" |
|
21 |
|
22 // Sepia in RGB |
|
23 const TInt rs = 112; |
|
24 const TInt gs = 66; |
|
25 const TInt bs = 20; |
|
26 |
|
27 // Helper variables |
|
28 const TInt kr = 45808 * rs - 38446 * gs - 7362 * bs + 32768; |
|
29 const TInt kg = - 19496 * rs + 26952 * gs - 3750 * bs + 32768; |
|
30 const TInt kb = - 19608 * rs - 38184 * gs + 57792* bs + 32768; |
|
31 |
|
32 EXPORT_C TInt CFilterSepia::Create() |
|
33 { |
|
34 CFilterSepia* ptr = NULL; |
|
35 TRAPD( error, ptr = NewL(); ); |
|
36 if( error != KErrNone ) |
|
37 { |
|
38 ptr = NULL; |
|
39 } |
|
40 return (TInt)((MImageFilter*)ptr); |
|
41 } |
|
42 |
|
43 |
|
44 |
|
45 CFilterSepia* CFilterSepia::NewL() |
|
46 { |
|
47 CFilterSepia* self = new( ELeave )CFilterSepia(); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop( self ); |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 |
|
56 CFilterSepia::~CFilterSepia() |
|
57 { |
|
58 } |
|
59 |
|
60 |
|
61 |
|
62 CFilterSepia::CFilterSepia() |
|
63 { |
|
64 |
|
65 } |
|
66 |
|
67 |
|
68 |
|
69 void CFilterSepia::ConstructL() |
|
70 { |
|
71 |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 TRect CFilterSepia::Rect() |
|
77 { |
|
78 return iChild->Rect(); |
|
79 } |
|
80 |
|
81 TReal CFilterSepia::Scale() |
|
82 { |
|
83 return iChild->Scale(); |
|
84 } |
|
85 |
|
86 TSize CFilterSepia::ViewPortSize() |
|
87 { |
|
88 return iChild->ViewPortSize(); |
|
89 } |
|
90 |
|
91 |
|
92 TBlock * CFilterSepia::GetBlockL ( const TRect & aRect ) |
|
93 { |
|
94 TBlock * pB = iChild->GetBlockL (aRect); |
|
95 if (!pB) return NULL; |
|
96 TUint32 * pD = pB->iData; |
|
97 |
|
98 for (TInt i = 0; i < pB->iDataLength; ++i) |
|
99 { |
|
100 TUint32 c = *pD; |
|
101 |
|
102 // Get RGB values |
|
103 TInt b = c & 0xFF; |
|
104 c >>= 8; |
|
105 TInt g = c & 0xFF; |
|
106 c >>= 8; |
|
107 TInt r = c & 0xFF; |
|
108 |
|
109 |
|
110 TInt alpha = 19668 * r + 38442 * g + 7450 * b; |
|
111 r = (alpha + kr) >> 16; |
|
112 if (r < 0) |
|
113 { |
|
114 r = 0; |
|
115 } |
|
116 else if (r > 255) |
|
117 { |
|
118 r = 255; |
|
119 } |
|
120 g = (alpha + kg) >> 16; |
|
121 if (g < 0) |
|
122 { |
|
123 g = 0; |
|
124 } |
|
125 else if (g > 255) |
|
126 { |
|
127 g = 255; |
|
128 } |
|
129 b = (alpha + kb) >> 16; |
|
130 if (b < 0) |
|
131 { |
|
132 b = 0; |
|
133 } |
|
134 else if (b > 255) |
|
135 { |
|
136 b = 255; |
|
137 } |
|
138 |
|
139 *pD++ = b | (g << 8) | (r << 16); |
|
140 } |
|
141 |
|
142 return pB; |
|
143 } |
|
144 |
|
145 |
|
146 void CFilterSepia::SetParent( MImageFilter* aParent ) |
|
147 { |
|
148 iParent = aParent; |
|
149 } |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 void CFilterSepia::SetChild( MImageFilter* aChild ) |
|
155 { |
|
156 iChild = aChild; |
|
157 } |
|
158 |
|
159 |
|
160 |
|
161 TInt CFilterSepia::CmdL( const TDesC16& /*aCmd*/ ) |
|
162 { |
|
163 return 0; |
|
164 } |
|
165 |
|
166 |
|
167 |
|
168 const char* CFilterSepia::Type() |
|
169 { |
|
170 return "sepia"; |
|
171 } |
|
172 |
|
173 |
|
174 #if !defined(EKA2) |
|
175 GLDEF_C TInt E32Dll( TDllReason ) |
|
176 { |
|
177 return KErrNone; |
|
178 } |
|
179 #endif |