|
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 "CFilterBuffer.h" |
|
21 |
|
22 EXPORT_C TInt CFilterBuffer::Create() |
|
23 { |
|
24 CFilterBuffer* ptr = NULL; |
|
25 TRAPD( error, ptr = NewL(); ); |
|
26 if( error != KErrNone ) |
|
27 { |
|
28 ptr = NULL; |
|
29 } |
|
30 return (TInt)((MImageFilter*)ptr); |
|
31 } |
|
32 |
|
33 |
|
34 |
|
35 CFilterBuffer* CFilterBuffer::NewL() |
|
36 { |
|
37 CFilterBuffer* self = new( ELeave )CFilterBuffer(); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 |
|
45 |
|
46 CFilterBuffer::~CFilterBuffer() |
|
47 { |
|
48 delete iBuffer; |
|
49 } |
|
50 |
|
51 |
|
52 |
|
53 CFilterBuffer::CFilterBuffer() |
|
54 { |
|
55 |
|
56 } |
|
57 |
|
58 |
|
59 |
|
60 void CFilterBuffer::ConstructL() |
|
61 { |
|
62 |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 TRect CFilterBuffer::Rect() |
|
68 { |
|
69 return iRect; |
|
70 } |
|
71 |
|
72 TReal CFilterBuffer::Scale() |
|
73 { |
|
74 return iChild->Scale(); |
|
75 } |
|
76 |
|
77 TSize CFilterBuffer::ViewPortSize() |
|
78 { |
|
79 return iChild->ViewPortSize(); |
|
80 } |
|
81 |
|
82 |
|
83 TBlock * CFilterBuffer::GetBlockL ( const TRect & aRect ) |
|
84 { |
|
85 |
|
86 if ( !aRect.Intersects(iRect) ) |
|
87 { |
|
88 return NULL; |
|
89 } |
|
90 |
|
91 TRect rect = aRect; |
|
92 rect.Intersection(iRect); |
|
93 |
|
94 TBlock * pB = new (ELeave) TBlock (rect); |
|
95 |
|
96 TUint32 * pS = iBuffer + rect.iTl.iY * iSize.iWidth + rect.iTl.iX; |
|
97 TUint32 * pD = pB->iData; |
|
98 |
|
99 for (TInt i = rect.iTl.iY; i < rect.iBr.iY; ++i) |
|
100 { |
|
101 Mem::Copy(pD, pS, pB->iWidth * sizeof(TUint32)); |
|
102 pD += pB->iWidth; |
|
103 pS += iSize.iWidth; |
|
104 } |
|
105 return pB; |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 void CFilterBuffer::SetParent( MImageFilter* aParent ) |
|
111 { |
|
112 iParent = aParent; |
|
113 } |
|
114 |
|
115 |
|
116 |
|
117 void CFilterBuffer::SetChild( MImageFilter* aChild ) |
|
118 { |
|
119 iChild = aChild; |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 TInt CFilterBuffer::CmdL( const TDesC16& aCmd ) |
|
125 { |
|
126 |
|
127 TSize oldSize = iSize; |
|
128 |
|
129 TInt rv = 0; |
|
130 |
|
131 TLex lex (aCmd); |
|
132 |
|
133 while ( !lex.Eos() ) |
|
134 { |
|
135 TPtrC token = lex.NextToken(); |
|
136 |
|
137 if( token.Compare( _L("width") ) == 0 ) |
|
138 { |
|
139 lex.Inc(); |
|
140 lex.Val( iSize.iWidth ); |
|
141 } |
|
142 else if( token.Compare( _L("height") ) == 0 ) |
|
143 { |
|
144 lex.Inc(); |
|
145 lex.Val( iSize.iHeight ); |
|
146 } |
|
147 else if( token.Compare( _L("getbitmap") ) == 0 ) |
|
148 { |
|
149 |
|
150 Mem::FillZ(iBuffer, iSize.iWidth * iSize.iHeight * sizeof(TUint32)); |
|
151 |
|
152 TPoint tl (0,0); |
|
153 TPoint br (16,16); |
|
154 |
|
155 while ( tl.iY < iRect.iBr.iY ) |
|
156 { |
|
157 |
|
158 tl.iX = 0; |
|
159 br.iX = 16; |
|
160 |
|
161 while ( tl.iX < iRect.iBr.iX ) |
|
162 { |
|
163 if (br.iX >= iSize.iWidth) br.iX = iSize.iWidth; |
|
164 if (br.iY >= iSize.iHeight) br.iY = iSize.iHeight; |
|
165 |
|
166 TBlock * pB = iChild->GetBlockL(TRect (tl,br) ); |
|
167 |
|
168 if (pB) |
|
169 { |
|
170 TUint32 * ps = pB->iData; |
|
171 TUint32 * pd = iBuffer + tl.iY * iSize.iWidth + tl.iX; |
|
172 |
|
173 for (TInt i = 0; i < pB->iHeight; ++i ) |
|
174 { |
|
175 Mem::Copy (pd, ps, pB->iWidth * sizeof (TUint32)); |
|
176 ps += pB->iWidth; |
|
177 pd += iSize.iWidth; |
|
178 } |
|
179 delete pB; |
|
180 pB = NULL; |
|
181 } |
|
182 else |
|
183 { |
|
184 TUint32 * pd = iBuffer + tl.iY * iSize.iWidth + tl.iX; |
|
185 TInt datalength = (br.iX - tl.iX) * sizeof (TUint32); |
|
186 for (TInt i = tl.iY; i < br.iY; ++i ) |
|
187 { |
|
188 Mem::FillZ (pd, datalength); |
|
189 pd += iSize.iWidth; |
|
190 } |
|
191 } |
|
192 |
|
193 tl.iX += 16; |
|
194 br.iX += 16; |
|
195 } |
|
196 |
|
197 tl.iY += 16; |
|
198 br.iY += 16; |
|
199 |
|
200 } |
|
201 /* |
|
202 CFbsBitmap * bitmap = new (ELeave) CFbsBitmap; |
|
203 CleanupStack::PushL(bitmap); |
|
204 User::LeaveIfError(bitmap->Create(iSize, EColor16M)); |
|
205 TBitmapUtil bm (bitmap); |
|
206 bm.Begin(TPoint(0,0)); |
|
207 TUint8 * pDOS = (TUint8 *)bitmap->DataAddress(); |
|
208 TUint32 * pS = iBuffer; |
|
209 TInt ws = CFbsBitmap::ScanLineLength(iSize.iWidth, EColor16M); |
|
210 for (TInt i = 0; i < iSize.iHeight; ++i) |
|
211 { |
|
212 TUint8 * pD = pDOS; |
|
213 pDOS += ws; |
|
214 for (TInt j = 0; j < iSize.iWidth; ++j) |
|
215 { |
|
216 TUint32 c = *pS++; |
|
217 *pD++ = c & 0xFF; |
|
218 c >>= 8; |
|
219 *pD++ = c & 0xFF; |
|
220 c >>= 8; |
|
221 *pD++ = c & 0xFF; |
|
222 } |
|
223 } |
|
224 bm.End(); |
|
225 TFileName filename; |
|
226 filename.Copy (_L("c:\\data\\images\\test_")); |
|
227 filename.AppendNum((TInt)iBuffer); |
|
228 filename.Append(_L(".mbm")); |
|
229 bitmap->Save(filename); |
|
230 |
|
231 CleanupStack::PopAndDestroy(); // bitmap |
|
232 */ |
|
233 |
|
234 rv = (TInt)iBuffer; |
|
235 } |
|
236 |
|
237 if( iSize != oldSize ) |
|
238 { |
|
239 if( iSize.iWidth > 0 && iSize.iHeight > 0 ) |
|
240 { |
|
241 delete[] iBuffer; |
|
242 iBuffer = NULL; |
|
243 iBuffer = new (ELeave) TUint32 [iSize.iWidth * iSize.iHeight]; |
|
244 } |
|
245 oldSize = iSize; |
|
246 iRect.iTl.iX = 0; |
|
247 iRect.iTl.iY = 0; |
|
248 iRect.iBr.iX = iSize.iWidth; |
|
249 iRect.iBr.iY = iSize.iHeight; |
|
250 } |
|
251 |
|
252 |
|
253 } |
|
254 |
|
255 return rv; |
|
256 |
|
257 } |
|
258 |
|
259 |
|
260 |
|
261 const char* CFilterBuffer::Type() |
|
262 { |
|
263 return "buffer"; |
|
264 } |
|
265 |
|
266 |
|
267 #if !defined(EKA2) |
|
268 GLDEF_C TInt E32Dll( TDllReason ) |
|
269 { |
|
270 return KErrNone; |
|
271 } |
|
272 #endif |