1 /* |
1 /* |
2 * Copyright (c) 2010 Ixonos Plc. |
2 * Copyright (c) 2010 Ixonos Plc. |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the "Eclipse Public License v1.0" |
5 * under the terms of the "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - Initial contribution |
10 * Nokia Corporation - Initial contribution |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * Ixonos Plc |
13 * Ixonos Plc |
14 * |
14 * |
15 * Description: |
15 * Description: |
16 * Draw filter for Draw UI plugin. |
16 * Draw filter for Draw UI plugin. |
17 * |
17 * |
18 */ |
18 */ |
19 |
|
20 |
19 |
21 #include <fbs.h> |
20 #include <fbs.h> |
22 #include <bitdev.h> |
21 #include <bitdev.h> |
23 #include <e32math.h> |
22 #include <e32math.h> |
24 #include "cfilterdraw.h" |
23 #include "cfilterdraw.h" |
25 |
24 |
26 const TInt KDrawBitmapWidth(640); |
25 const TInt KDrawBitmapWidth(480); |
27 const TInt KDrawBitmapHeight(480); |
26 const TInt KDrawBitmapHeight(640); |
|
27 TUint32* CFilterDraw::iData = NULL; |
28 // --------------------------------------------------------------------------- |
28 // --------------------------------------------------------------------------- |
29 // Create |
29 // Create |
30 // --------------------------------------------------------------------------- |
30 // --------------------------------------------------------------------------- |
31 // |
31 // |
32 EXPORT_C TInt CFilterDraw::Create() |
32 EXPORT_C TInt CFilterDraw::Create() |
33 { |
33 { |
34 CFilterDraw* ptr = NULL; |
34 CFilterDraw* ptr = NULL; |
35 TRAP_IGNORE( ptr = NewL() ); |
35 TRAP_IGNORE( ptr = NewL() ); |
36 return (TInt)((MImageFilter*)ptr); |
36 return (TInt) ((MImageFilter*) ptr); |
37 } |
37 } |
38 |
38 |
39 // --------------------------------------------------------------------------- |
39 // --------------------------------------------------------------------------- |
40 // NewL |
40 // NewL |
41 // --------------------------------------------------------------------------- |
41 // --------------------------------------------------------------------------- |
42 // |
42 // |
43 CFilterDraw* CFilterDraw::NewL() |
43 CFilterDraw* CFilterDraw::NewL() |
44 { |
44 { |
45 return new( ELeave )CFilterDraw(); |
45 return new (ELeave) CFilterDraw(); |
46 } |
46 } |
47 |
47 |
48 // --------------------------------------------------------------------------- |
48 // --------------------------------------------------------------------------- |
49 // ~CFilterDraw |
49 // ~CFilterDraw |
50 // --------------------------------------------------------------------------- |
50 // --------------------------------------------------------------------------- |
51 // |
51 // |
52 CFilterDraw::~CFilterDraw() |
52 CFilterDraw::~CFilterDraw() |
53 { |
53 { |
|
54 if(iData) |
|
55 { |
54 delete[] iData; |
56 delete[] iData; |
|
57 iData = NULL; |
|
58 } |
55 iReadyToRender = EFalse; |
59 iReadyToRender = EFalse; |
56 // Close all paths |
60 // Close all paths |
57 for( TInt i(0); i<iPaths.Count(); i++ ) |
61 for (TInt i(0); i < iPaths.Count(); i++) |
58 { |
62 { |
59 iPaths[i].Close(); |
63 iPaths[i].Close(); |
60 } |
64 } |
61 iPaths.Close(); |
65 iPaths.Close(); |
|
66 |
|
67 for (TInt j(0); j < iUndoPaths.Count(); j++) |
|
68 { |
|
69 iUndoPaths[j].Close(); |
|
70 } |
|
71 iUndoPaths.Close(); |
|
72 |
|
73 if(iMask) |
|
74 { |
|
75 delete iMask; |
|
76 iMask =NULL; |
|
77 } |
|
78 if(iBitmap) |
|
79 { |
|
80 delete iBitmap; |
|
81 iBitmap =NULL; |
|
82 } |
62 } |
83 } |
63 |
84 |
64 // --------------------------------------------------------------------------- |
85 // --------------------------------------------------------------------------- |
65 // CFilterDraw |
86 // CFilterDraw |
66 // --------------------------------------------------------------------------- |
87 // --------------------------------------------------------------------------- |
67 // |
88 // |
68 CFilterDraw::CFilterDraw():iData(NULL), |
89 CFilterDraw::CFilterDraw() : |
69 iBitmapSize(KDrawBitmapWidth, KDrawBitmapHeight) |
90 iBitmapSize(KDrawBitmapWidth, KDrawBitmapHeight), iCanRedo( |
|
91 EFalse) |
70 { |
92 { |
71 } |
93 } |
72 |
94 |
73 // --------------------------------------------------------------------------- |
95 // --------------------------------------------------------------------------- |
74 // Rect |
96 // Rect |
95 // --------------------------------------------------------------------------- |
117 // --------------------------------------------------------------------------- |
96 // |
118 // |
97 TSize CFilterDraw::ViewPortSize() |
119 TSize CFilterDraw::ViewPortSize() |
98 { |
120 { |
99 ASSERT(iChild); |
121 ASSERT(iChild); |
100 return iChild->ViewPortSize(); |
122 return iChild->ViewPortSize(); |
101 } |
123 } |
102 |
124 |
103 // --------------------------------------------------------------------------- |
125 // --------------------------------------------------------------------------- |
104 // GetBlockL |
126 // GetBlockL |
105 // --------------------------------------------------------------------------- |
127 // --------------------------------------------------------------------------- |
106 // |
128 // |
107 TBlock* CFilterDraw::GetBlockL( const TRect& aRect ) |
129 TBlock* CFilterDraw::GetBlockL(const TRect& aRect) |
108 { |
130 { |
109 ASSERT(iChild); |
131 ASSERT(iChild); |
110 TBlock* pB = iChild->GetBlockL( aRect ); |
132 TBlock* pB = iChild->GetBlockL(aRect); |
111 if( !pB ) return NULL; |
133 if (!pB) |
112 TUint32* pD = pB->iData; |
134 return NULL; |
113 |
135 TUint32* pD = pB->iData; |
114 if( iData && iReadyToRender ) |
136 |
115 { |
137 if (iData && iReadyToRender) |
116 // Factor between real and viewed image |
138 { |
117 TReal realToViewedFactorWidth; |
139 // Factor between real and viewed image |
118 TReal realToViewedFactorHeight; |
140 TReal realToViewedFactorWidth; |
119 RealToViewedFactories(realToViewedFactorWidth, realToViewedFactorHeight); |
141 TReal realToViewedFactorHeight; |
120 const TInt width( iBitmapSize.iWidth ); // Data bitmap width |
142 RealToViewedFactories(realToViewedFactorWidth, realToViewedFactorHeight); |
121 |
143 const TInt width(iBitmapSize.iWidth); // Data bitmap width |
122 for( TInt y(pB->iRect.iTl.iY); y<pB->iRect.iBr.iY; ++y ) |
144 |
123 { |
145 for (TInt y(pB->iRect.iTl.iY); y < pB->iRect.iBr.iY; ++y) |
124 TInt realY(y / Scale() + 0.5); |
146 { |
125 TInt viewY(realY / realToViewedFactorHeight + 0.5); |
147 TInt realY(y / Scale() + 0.5); |
126 for( TInt x(pB->iRect.iTl.iX); x<pB->iRect.iBr.iX; ++x ) |
148 TInt viewY(realY / realToViewedFactorHeight + 0.5); |
127 { |
149 for (TInt x(pB->iRect.iTl.iX); x < pB->iRect.iBr.iX; ++x) |
128 TInt realX(x / Scale() + 0.5); |
150 { |
129 TInt viewX(realX / realToViewedFactorWidth + 0.5); |
151 TInt realX(x / Scale() + 0.5); |
130 |
152 TInt viewX(realX / realToViewedFactorWidth + 0.5); |
131 TUint32 color = iData[ width*viewY + viewX ]; |
153 |
132 if( (color & 0xff000000) ) |
154 if( viewY >= KDrawBitmapHeight) |
133 { |
155 { |
134 *pD = color; |
156 viewY--; |
135 } |
157 } |
136 |
158 if(iData[width * viewY + viewX]) |
137 *pD++; |
159 { |
138 } |
160 TUint32 color = iData[width * viewY + viewX]; |
139 } |
161 if ((color & 0xff000000)) |
140 } |
162 { |
141 return pB; |
163 *pD = color; |
|
164 } |
|
165 } |
|
166 *pD++; |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 return pB; |
142 } |
172 } |
143 |
173 |
144 // --------------------------------------------------------------------------- |
174 // --------------------------------------------------------------------------- |
145 // SetParent |
175 // SetParent |
146 // --------------------------------------------------------------------------- |
176 // --------------------------------------------------------------------------- |
147 // |
177 // |
148 void CFilterDraw::SetParent( MImageFilter* aParent ) |
178 void CFilterDraw::SetParent(MImageFilter* aParent) |
149 { |
179 { |
150 ASSERT(aParent); |
180 ASSERT(aParent); |
151 iParent = aParent; |
181 iParent = aParent; |
152 } |
182 } |
153 |
183 |
154 // --------------------------------------------------------------------------- |
184 // --------------------------------------------------------------------------- |
155 // SetChild |
185 // SetChild |
156 // --------------------------------------------------------------------------- |
186 // --------------------------------------------------------------------------- |
157 // |
187 // |
158 void CFilterDraw::SetChild( MImageFilter* aChild ) |
188 void CFilterDraw::SetChild(MImageFilter* aChild) |
159 { |
189 { |
160 ASSERT(aChild); |
190 ASSERT(aChild); |
161 iChild = aChild; |
191 iChild = aChild; |
162 } |
192 } |
163 |
193 |
164 // --------------------------------------------------------------------------- |
194 // --------------------------------------------------------------------------- |
165 // CmdL |
195 // CmdL |
166 // --------------------------------------------------------------------------- |
196 // --------------------------------------------------------------------------- |
167 // |
197 // |
168 TInt CFilterDraw::CmdL( const TDesC16& aCmd ) |
198 TInt CFilterDraw::CmdL(const TDesC16& aCmd) |
169 { |
199 { |
|
200 TInt bbb(0); |
|
201 bbb = iPaths.Count(); |
170 ASSERT(iChild); |
202 ASSERT(iChild); |
171 TLex lex (aCmd); |
203 TLex lex(aCmd); |
172 TPoint position(0,0); |
204 TPoint position(0, 0); |
173 // Factor between real and viewed image |
205 // Factor between real and viewed image |
174 TReal realToViewedFactorWidth; |
206 TReal realToViewedFactorWidth; |
175 TReal realToViewedFactorHeight; |
207 TReal realToViewedFactorHeight; |
176 RealToViewedFactories(realToViewedFactorWidth, realToViewedFactorHeight); |
208 RealToViewedFactories(realToViewedFactorWidth, realToViewedFactorHeight); |
177 |
209 |
178 // Handle parameters |
210 // Handle parameters |
179 while( !lex.Eos() ) |
211 while (!lex.Eos()) |
180 { |
212 { |
|
213 RDebug::RawPrint(aCmd); |
181 TPtrC token = lex.NextToken(); |
214 TPtrC token = lex.NextToken(); |
182 if( token.Compare( _L("x") ) == 0 ) |
215 TInt pathCount(0); |
183 { |
216 pathCount = iPaths.Count(); |
|
217 |
|
218 if (token.Compare(_L("x")) == 0) |
|
219 { |
|
220 iCanRedo = EFalse; |
|
221 for (TInt j(0); j < iUndoPaths.Count(); j++) |
|
222 { |
|
223 iUndoPaths[j].Close(); |
|
224 } |
|
225 iUndoPaths.Close(); |
184 iReadyToRender = EFalse; |
226 iReadyToRender = EFalse; |
185 TReal relscale = Scale(); |
227 TReal relscale = Scale(); |
186 TInt param = 0; |
228 TInt param = 0; |
187 lex.Inc (); |
229 lex.Inc(); |
188 lex.Val (param); |
230 lex.Val(param); |
189 // Coordinates on data bitmap |
231 // Coordinates on data bitmap |
190 position.iX = (TReal(param) / relscale) / realToViewedFactorWidth + 0.5; |
232 position.iX = (TReal(param) / relscale) / realToViewedFactorWidth + 0.5; |
191 } |
233 } |
192 else if( token.Compare( _L("y") ) == 0 ) |
234 else if (token.Compare(_L("y")) == 0) |
193 { |
235 { |
194 TReal relscale = Scale(); |
236 TReal relscale = Scale(); |
195 TInt param = 0; |
237 TInt param = 0; |
196 lex.Inc (); |
238 lex.Inc(); |
197 lex.Val (param); |
239 lex.Val(param); |
198 position.iY = (TReal(param) / relscale) / realToViewedFactorHeight + 0.5; |
240 position.iY = (TReal(param) / relscale) / realToViewedFactorHeight + 0.5; |
199 RDebug::Print(_L("CFilterDraw::CmdL x:%d y:%d Scale:%g Rw:%d Rh:%d Vpw:%d Vph:%d Rtvw:%g Rtvh:%g"), |
241 RDebug::Print( |
200 position.iX, |
242 _L("CFilterDraw::CmdL x:%d y:%d Scale:%g Rw:%d Rh:%d Vpw:%d Vph:%d Rtvw:%g Rtvh:%g"), |
201 position.iY, |
243 position.iX, position.iY, relscale, Rect().Size().iWidth, |
202 relscale, |
244 Rect().Size().iHeight, ViewPortSize().iWidth, |
203 Rect().Size().iWidth, |
245 ViewPortSize().iHeight, realToViewedFactorWidth, |
204 Rect().Size().iHeight, |
246 realToViewedFactorHeight); |
205 ViewPortSize().iWidth, |
247 |
206 ViewPortSize().iHeight, |
248 if (!iPaths.Count()) |
207 realToViewedFactorWidth, |
|
208 realToViewedFactorHeight); |
|
209 |
|
210 if(!iPaths.Count()) |
|
211 { |
249 { |
212 RDrawPath newPath; |
250 RDrawPath newPath; |
213 User::LeaveIfError( newPath.Append(position) ); |
251 User::LeaveIfError(newPath.Append(position)); |
214 User::LeaveIfError( iPaths.Append( newPath ) ); |
252 User::LeaveIfError(iPaths.Append(newPath)); |
215 } |
253 } |
216 else |
254 else |
217 { |
255 { |
218 ASSERT(iPaths.Count()); |
256 ASSERT(iPaths.Count()); |
219 RDrawPath& lastPath = iPaths[iPaths.Count()-1]; |
257 RDrawPath& lastPath = iPaths[iPaths.Count() - 1]; |
220 User::LeaveIfError( lastPath.Append(position) ); |
258 User::LeaveIfError(lastPath.Append(position)); |
221 } |
259 } |
222 } |
260 } |
223 else if( token.Compare( _L("color") ) == 0 ) |
261 else if (token.Compare(_L("color")) == 0) |
224 { |
262 { |
225 TUint32 color(0); |
263 TUint32 color(0); |
226 lex.Inc(); |
264 lex.Inc(); |
227 lex.Val( color, EDecimal ); |
265 lex.Val(color, EDecimal); |
228 TRgb rgb(color); |
266 TRgb rgb(color); |
229 TUint32 colorValue = |
267 TUint32 colorValue = (rgb.Red() << 16) + (rgb.Green() << 8) + rgb.Blue(); |
230 ( rgb.Red() << 16 ) + ( rgb.Green() << 8 ) + rgb.Blue(); |
268 ASSERT( iPaths.Count() ); |
231 ASSERT( iPaths.Count() ); |
269 RDrawPath& lastPath = iPaths[iPaths.Count() - 1]; |
232 RDrawPath& lastPath = iPaths[iPaths.Count()-1]; |
270 lastPath.SetColor(TRgb(colorValue)); |
233 lastPath.SetColor( TRgb(colorValue) ); |
271 } |
234 } |
272 else if (token.Compare(_L("size")) == 0) |
235 else if( token.Compare( _L("size") ) == 0 ) |
|
236 { |
273 { |
237 TInt size(0); |
274 TInt size(0); |
238 lex.Inc (); |
275 lex.Inc(); |
239 lex.Val(size); |
276 lex.Val(size); |
240 // Scale line size to match bitmap scale |
277 // Scale line size to match bitmap scale |
241 TInt sizew( (TReal(size) / realToViewedFactorWidth) + 0.5 ); |
278 TInt sizew( (TReal(size) / realToViewedFactorWidth) + 0.5 ); |
242 TInt sizeh( (TReal(size) / realToViewedFactorHeight) + 0.5 ); |
279 TInt sizeh( (TReal(size) / realToViewedFactorHeight) + 0.5 ); |
|
280 |
|
281 if (!sizew) |
|
282 { |
|
283 sizew++; |
|
284 } |
|
285 if (!sizeh) |
|
286 { |
|
287 sizeh++; |
|
288 } |
|
289 |
|
290 if (iPaths.Count()) |
|
291 { |
|
292 RDrawPath& lastPath = iPaths[iPaths.Count() - 1]; |
|
293 lastPath.SetSize(TSize(sizew, sizeh)); |
|
294 } |
|
295 } |
|
296 else if (token.Compare(_L("lastItem")) == 0) |
|
297 { |
|
298 ASSERT(iPaths.Count()); |
|
299 |
|
300 RDrawPath& lastPath = iPaths[iPaths.Count() - 1]; |
|
301 RDebug::Print( |
|
302 _L("CFilterDraw::CmdL lastItem count:%d size:%d r:%d g:%d b:%d"), |
|
303 iPaths.Count(), lastPath.Size().iHeight, |
|
304 lastPath.Color().Red(), lastPath.Color().Green(), |
|
305 lastPath.Color().Blue()); |
|
306 |
|
307 RDrawPath newPath; |
|
308 User::LeaveIfError(iPaths.Append(newPath)); |
|
309 } |
|
310 else if (token.Compare(_L("done")) == 0) |
|
311 { |
|
312 LoadFrameL(); |
|
313 iReadyToRender = ETrue; |
|
314 } |
|
315 //Undo functionality |
|
316 else if (token.Compare(_L("Undo")) == 0) |
|
317 { |
|
318 TInt count(0); |
|
319 count = iPaths.Count(); |
|
320 count = iUndoPaths.Count(); |
243 |
321 |
244 if( !sizew ) |
322 if (iPaths.Count() > 1) |
245 { |
323 { |
246 sizew++; |
324 TInt count = iPaths.Count(); |
247 } |
325 iUndoPaths.Append(iPaths[iPaths.Count() - 2]); |
248 if( !sizeh ) |
326 iPaths.Remove(iPaths.Count() - 2); |
249 { |
327 iCanRedo = ETrue; |
250 sizeh++; |
328 } |
251 } |
329 count = iPaths.Count(); |
252 |
330 count = iUndoPaths.Count(); |
253 if(iPaths.Count()) |
331 } |
254 { |
332 //Redo functionality |
255 RDrawPath& lastPath = iPaths[iPaths.Count()-1]; |
333 else if (token.Compare(_L("redone")) == 0) |
256 lastPath.SetSize( TSize(sizew, sizeh) ); |
334 { |
257 } |
335 TInt count(0); |
258 } |
336 count = iPaths.Count(); |
259 else if( token.Compare( _L("lastItem") ) == 0 ) |
337 count = iUndoPaths.Count(); |
260 { |
338 |
261 ASSERT(iPaths.Count()); |
339 if (iCanRedo) |
262 |
340 { |
263 RDrawPath& lastPath = iPaths[iPaths.Count()-1]; |
341 if (iUndoPaths.Count()) |
264 RDebug::Print(_L("CFilterDraw::CmdL lastItem count:%d size:%d r:%d g:%d b:%d"), |
342 { |
265 iPaths.Count(), lastPath.Size().iHeight, |
343 if (iPaths.Count() >= 1) |
266 lastPath.Color().Red(), |
344 { |
267 lastPath.Color().Green(), |
345 iPaths.Insert(iUndoPaths[iUndoPaths.Count() - 1],iPaths.Count() - 1); |
268 lastPath.Color().Blue() |
346 iUndoPaths.Remove(iUndoPaths.Count() - 1); |
269 ); |
347 } |
270 |
348 } |
271 RDrawPath newPath; |
349 } |
272 User::LeaveIfError( iPaths.Append( newPath ) ); |
350 count = iPaths.Count(); |
273 } |
351 count = iUndoPaths.Count(); |
274 else if( token.Compare( _L("done") ) == 0 ) |
352 } |
275 { |
353 } |
276 LoadFrameL(); |
354 return KErrNone; |
277 iReadyToRender = ETrue; |
|
278 } |
|
279 } |
|
280 |
|
281 return KErrNone; |
|
282 } |
355 } |
283 |
356 |
284 // --------------------------------------------------------------------------- |
357 // --------------------------------------------------------------------------- |
285 // Type |
358 // Type |
286 // --------------------------------------------------------------------------- |
359 // --------------------------------------------------------------------------- |
293 // --------------------------------------------------------------------------- |
366 // --------------------------------------------------------------------------- |
294 // LoadFrameL |
367 // LoadFrameL |
295 // --------------------------------------------------------------------------- |
368 // --------------------------------------------------------------------------- |
296 // |
369 // |
297 void CFilterDraw::LoadFrameL() |
370 void CFilterDraw::LoadFrameL() |
298 { |
371 { |
299 RDebug::Print(_L("CFilterDraw::LoadFrameL w:%d h:%d"), |
372 RDebug::Print(_L("CFilterDraw::LoadFrameL w:%d h:%d"), iBitmapSize.iWidth, |
300 iBitmapSize.iWidth, |
373 iBitmapSize.iHeight); |
301 iBitmapSize.iHeight); |
374 |
302 |
375 TInt xxx(0); |
303 // Create a bitmap big enough to hold the drawed lines |
376 xxx = iPaths.Count(); |
304 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap(); |
377 // Create a bitmap big enough to hold the drawed lines |
305 CleanupStack::PushL( bitmap ); |
378 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); |
306 User::LeaveIfError( bitmap->Create( iBitmapSize, EColor16MA ) ); |
379 CleanupStack::PushL(bitmap); |
307 |
380 User::LeaveIfError(bitmap->Create(iBitmapSize, EColor16MA)); |
|
381 |
308 // create mask |
382 // create mask |
309 CFbsBitmap* mask = new (ELeave) CFbsBitmap(); |
383 CFbsBitmap* mask = new (ELeave) CFbsBitmap(); |
310 CleanupStack::PushL( mask ); |
384 CleanupStack::PushL(mask); |
311 User::LeaveIfError( mask->Create(iBitmapSize,EColor16MA) ); |
385 User::LeaveIfError(mask->Create(iBitmapSize, EColor16MA)); |
312 |
386 |
313 CFbsBitmapDevice* maskDevice = CFbsBitmapDevice::NewL( mask ); |
387 CFbsBitmapDevice* maskDevice = CFbsBitmapDevice::NewL(mask); |
314 CleanupStack::PushL( maskDevice ); |
388 CleanupStack::PushL(maskDevice); |
315 |
389 |
316 CFbsBitGc * maskContext(NULL); |
390 CFbsBitGc * maskContext(NULL); |
317 User::LeaveIfError( maskDevice->CreateContext(maskContext) ); |
391 User::LeaveIfError(maskDevice->CreateContext(maskContext)); |
318 CleanupStack::PushL(maskContext); |
392 CleanupStack::PushL(maskContext); |
319 maskContext->SetPenStyle(CGraphicsContext::ESolidPen); |
393 maskContext->SetPenStyle(CGraphicsContext::ESolidPen); |
320 maskContext->SetBrushStyle(CGraphicsContext::ESolidBrush); |
394 maskContext->SetBrushStyle(CGraphicsContext::ESolidBrush); |
321 maskContext->SetBrushColor(KRgbBlack); |
395 maskContext->SetBrushColor(KRgbBlack); |
322 |
396 |
323 // Create bitmap device and context |
397 // Create bitmap device and context |
324 CFbsBitmapDevice * bitmapDevice = CFbsBitmapDevice::NewL (bitmap); |
398 CFbsBitmapDevice * bitmapDevice = CFbsBitmapDevice::NewL(bitmap); |
325 CleanupStack::PushL (bitmapDevice); |
399 CleanupStack::PushL(bitmapDevice); |
326 |
400 |
327 // Create bitmap graphics context |
401 // Create bitmap graphics context |
328 CFbsBitGc * bitmapContext(NULL); |
402 CFbsBitGc * bitmapContext(NULL); |
329 User::LeaveIfError (bitmapDevice->CreateContext (bitmapContext)); |
403 User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext)); |
330 CleanupStack::PushL (bitmapContext); |
404 CleanupStack::PushL(bitmapContext); |
331 |
405 |
332 TDisplayMode dmode = bitmap->DisplayMode(); |
406 TDisplayMode dmode = bitmap->DisplayMode(); |
333 |
407 |
334 for(TInt pathNumber(0); pathNumber<iPaths.Count(); pathNumber++) |
408 for (TInt pathNumber(0); pathNumber < iPaths.Count(); pathNumber++) |
335 { |
409 { |
336 RDrawPath path = iPaths[pathNumber]; |
410 RDrawPath path = iPaths[pathNumber]; |
337 bitmapContext->SetPenStyle (CGraphicsContext::ESolidPen); |
411 bitmapContext->SetPenStyle(CGraphicsContext::ESolidPen); |
338 bitmapContext->SetBrushStyle (CGraphicsContext::ESolidBrush); |
412 bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush); |
339 bitmapContext->SetPenColor(path.Color()); |
413 bitmapContext->SetPenColor(path.Color()); |
340 bitmapContext->SetPenSize(path.Size()); |
414 bitmapContext->SetPenSize(path.Size()); |
341 maskContext->SetPenSize(path.Size()); |
415 maskContext->SetPenSize(path.Size()); |
342 |
416 |
343 RDebug::Print(_L("CFilterDraw::LoadFrameL ps:%dx%d S:%g"), |
417 RDebug::Print(_L("CFilterDraw::LoadFrameL ps:%dx%d S:%g"), |
344 path.Size().iWidth, |
418 path.Size().iWidth, path.Size().iHeight, Scale()); |
345 path.Size().iHeight, |
419 |
346 Scale()); |
|
347 |
|
348 CArrayFix<TPoint>* pointArray = NULL; |
420 CArrayFix<TPoint>* pointArray = NULL; |
349 RDrawPath2PointArray(path, pointArray); |
421 RDrawPath2PointArray(path, pointArray); |
350 bitmapContext->DrawPolyLine( pointArray ); |
422 bitmapContext->DrawPolyLine(pointArray); |
351 maskContext->DrawPolyLine( pointArray ); |
423 maskContext->DrawPolyLine(pointArray); |
352 |
424 |
353 delete pointArray; |
425 delete pointArray; |
354 } |
426 } |
355 |
427 |
356 // Create memory buffer to hold rendered image data |
428 // Create memory buffer to hold rendered image data |
357 |
429 |
358 if( !iData ) |
430 if (!iData) |
359 { |
431 { |
360 iData = new (ELeave) TUint32 [iBitmapSize.iWidth * iBitmapSize.iHeight]; |
432 iData = new (ELeave) TUint32[iBitmapSize.iWidth * iBitmapSize.iHeight]; |
361 } |
433 Mem::FillZ(iData, iBitmapSize.iWidth * iBitmapSize.iHeight |
362 Mem::FillZ(iData, |
434 * sizeof(TUint32)); |
363 iBitmapSize.iWidth * iBitmapSize.iHeight * sizeof (TUint32)); |
435 } |
364 |
436 |
365 TBitmapUtil bm (bitmap); |
437 TBitmapUtil bm(bitmap); |
366 bm.Begin(TPoint(0,0)); |
438 bm.Begin(TPoint(0, 0)); |
367 TBitmapUtil maskbm (mask); |
439 TBitmapUtil maskbm(mask); |
368 maskbm.Begin(TPoint(0,0)); |
440 maskbm.Begin(TPoint(0, 0)); |
369 TRgb rgb(0); |
441 TRgb rgb(0); |
370 // Find drawed lines from bitmap |
442 |
371 for (TInt y(0); y < iBitmapSize.iHeight - 1; y++ ) |
443 // Find drawed lines from bitmap |
372 { |
444 for (TInt y(0); y < iBitmapSize.iHeight - 1; y++) |
373 for (TInt x(0); x < iBitmapSize.iWidth - 1; x++ ) |
445 { |
374 { |
446 for (TInt x(0); x < iBitmapSize.iWidth - 1; x++) |
375 // Check mask first |
447 { |
376 maskbm.SetPos(TPoint(x,y)); |
448 // Check mask first |
377 if( maskbm.GetPixel() == KRgbBlack.Internal() ) |
449 maskbm.SetPos(TPoint(x, y)); |
378 { |
450 if (maskbm.GetPixel() == KRgbBlack.Internal()) |
379 bm.SetPos(TPoint(x,y)); |
451 { |
380 rgb = bm.GetPixel(); |
452 bm.SetPos(TPoint(x, y)); |
381 iData[(iBitmapSize.iWidth*y)+x] = |
453 rgb = bm.GetPixel(); |
382 ( rgb.Red() << 16 ) + ( rgb.Green() << 8 ) + rgb.Blue() | |
454 iData[(iBitmapSize.iWidth * y) + x] = (rgb.Red() << 16) |
383 0xff000000; |
455 + (rgb.Green() << 8) + rgb.Blue() | 0xff000000; |
384 } |
456 } |
385 } |
457 } |
386 } |
458 } |
|
459 |
387 bm.End(); |
460 bm.End(); |
388 maskbm.End(); |
461 maskbm.End(); |
389 // bitmapContext, bitmapDevice, maskContext, maskDevice, mask, bitmap |
462 // bitmapContext, bitmapDevice, maskContext, maskDevice, mask, bitmap |
390 CleanupStack::PopAndDestroy(6, bitmap); |
463 CleanupStack::PopAndDestroy(6, bitmap); |
391 RDebug::Print(_L("CFilterDraw::LoadFrameL - end")); |
464 RDebug::Print(_L("CFilterDraw::LoadFrameL - end")); |
392 } |
465 } |
393 |
466 |
394 // --------------------------------------------------------------------------- |
467 // --------------------------------------------------------------------------- |
395 // RDrawPath2PointArray |
468 // RDrawPath2PointArray |
396 // --------------------------------------------------------------------------- |
469 // --------------------------------------------------------------------------- |
397 // |
470 // |
398 void CFilterDraw::RDrawPath2PointArray( |
471 void CFilterDraw::RDrawPath2PointArray(const RDrawPath& aPath, |
399 const RDrawPath& aPath, CArrayFix<TPoint>*& aArrayPtr) const |
472 CArrayFix<TPoint>*& aArrayPtr) const |
400 { |
473 { |
401 // if allocation fails just do nothing. +1 if count is zero |
474 // if allocation fails just do nothing. +1 if count is zero |
402 aArrayPtr = new CArrayFixFlat<TPoint> ( aPath.Count() + 1 ); |
475 aArrayPtr = new CArrayFixFlat<TPoint> (aPath.Count() + 1); |
403 if (aArrayPtr) |
476 if (aArrayPtr) |
404 { |
477 { |
405 for( TInt i(0); i<aPath.Count(); i++ ) |
478 for (TInt i(0); i < aPath.Count(); i++) |
406 { |
479 { |
407 TPoint item = aPath[i]; |
480 TPoint item = aPath[i]; |
408 TRAP_IGNORE( aArrayPtr->AppendL( item ) ); |
481 TRAP_IGNORE( aArrayPtr->AppendL( item ) ); |
409 } |
482 } |
410 } |
483 } |
411 } |
484 } |
412 |
485 |
413 // --------------------------------------------------------------------------- |
486 // --------------------------------------------------------------------------- |
414 // RealToViewedFactories |
487 // RealToViewedFactories |
415 // --------------------------------------------------------------------------- |
488 // --------------------------------------------------------------------------- |
416 // |
489 // |
417 void CFilterDraw::RealToViewedFactories(TReal& aWidth, TReal& aHeight) |
490 void CFilterDraw::RealToViewedFactories(TReal& aWidth, TReal& aHeight) |
418 { |
491 { |
419 // Factor between real and viewed image |
492 // Factor between real and viewed image |
420 aWidth = TReal(ViewPortSize().iWidth) / |
493 aWidth = TReal(ViewPortSize().iWidth) / TReal(iBitmapSize.iWidth); |
421 TReal(iBitmapSize.iWidth); |
494 aHeight = TReal(ViewPortSize().iHeight) / TReal(iBitmapSize.iHeight); |
422 aHeight = TReal(ViewPortSize().iHeight) / |
495 } |
423 TReal(iBitmapSize.iHeight); |
496 |
424 } |
|
425 |
|