46
|
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: NVG Decoder source file
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "TLVIconCreator.h"
|
|
19 |
#include "MVGImageBinder.h"
|
|
20 |
#include "NVGUtil.h"
|
|
21 |
#include "NVGIconData.h"
|
|
22 |
#include "NVGTLVIcon.h"
|
|
23 |
#include "nvg.h"
|
|
24 |
|
|
25 |
/*
|
|
26 |
* Length of each encoded OpenVG API in bytes. -1 if not pre known.
|
|
27 |
* The order here and in the enum TOpenVGAPI should be same.
|
|
28 |
*/
|
|
29 |
const TInt APICommandLength[] =
|
|
30 |
{
|
|
31 |
16, //EvgClear
|
|
32 |
4, //EvgSeti
|
|
33 |
6, //EvgSetf
|
|
34 |
-1, //EvgSetfv
|
|
35 |
8, //EvgSetParameteri
|
|
36 |
10, //EvgSetParameterf
|
|
37 |
-1, //EvgSetParameterfv
|
|
38 |
8, //EvgSetColor
|
|
39 |
5, //EvgSetPaint
|
|
40 |
36, //EvgLoadMatrix
|
|
41 |
36, //EvgMultMatrix
|
|
42 |
0, //EvgLoadIdentity
|
|
43 |
8, //EvgScale
|
|
44 |
4, //EvgRotate
|
|
45 |
8, //EvgTranslate
|
|
46 |
-1, //EvgAppendPathData
|
|
47 |
6, //EvgDrawPath
|
|
48 |
6, //EvgClearPath
|
|
49 |
20, //EvguRect
|
|
50 |
20, //EvguEllipse
|
|
51 |
28, //EvguRoundRect
|
|
52 |
20, //EvguLine
|
|
53 |
4, //EvgCreatePaint
|
|
54 |
29, //EvgCreatePath
|
|
55 |
0, //EvgGetPixels
|
|
56 |
4, //EvgDestroyImage
|
|
57 |
0, //EvgDestroyPaint
|
|
58 |
0, //EvgDestroyPath
|
|
59 |
-1, //EvgSetiv
|
|
60 |
17, //EvgCreateImage
|
|
61 |
4, //EvgDrawImage
|
|
62 |
20, //EvgClearImage
|
|
63 |
-1, //EvgImageSubData
|
|
64 |
0, //EvgPrepareToBindImage
|
|
65 |
4, //EvgBindImage
|
|
66 |
0, //EvgUnBindImage
|
|
67 |
0 //EvgFlush
|
|
68 |
};
|
|
69 |
|
|
70 |
CTLVIconCreator::CTLVIconCreator(TInt aWidth, TInt aHeight, CNVGTLVIcon * aNVGTLVIcon)
|
|
71 |
:
|
|
72 |
iNVGDataPtr((TUint8 *)&aWidth, 1)
|
|
73 |
{
|
|
74 |
vgapi[EvgSeti] = &DvgAddCommandL;
|
|
75 |
vgapi[EvgSetf] = &DvgAddCommandL;
|
|
76 |
vgapi[EvgSetParameteri] = &DvgAddCommandL;
|
|
77 |
vgapi[EvgSetParameterf] = &DvgAddCommandL;
|
|
78 |
vgapi[EvgSetParameterfv] = &DvgSetParameterfvL;
|
|
79 |
vgapi[EvgSetColor] = &DvgAddCommandL;
|
|
80 |
vgapi[EvgSetPaint] = &DvgAddCommandL;
|
|
81 |
vgapi[EvgLoadMatrix] = &DvgAddCommandL;
|
|
82 |
vgapi[EvgMultMatrix] = &DvgAddCommandL;
|
|
83 |
vgapi[EvgLoadIdentity] = &DvgAddCommandL;
|
|
84 |
vgapi[EvgScale] = &DvgAddCommandL;
|
|
85 |
vgapi[EvgTranslate] = &DvgAddCommandL;
|
|
86 |
vgapi[EvgAppendPathData] = &DvgAppendPathDataL;
|
|
87 |
vgapi[EvgDrawPath] = &DvgDrawPathL;
|
|
88 |
vgapi[EvgClearPath] = &DvgAddCommandL;
|
|
89 |
vgapi[EvguRect] = &DvguRectL;
|
|
90 |
vgapi[EvguEllipse] = &DvguEllipseL;
|
|
91 |
vgapi[EvguRoundRect] = &DvguRoundRectL;
|
|
92 |
vgapi[EvguLine] = &DvguLineL;
|
|
93 |
vgapi[EvgCreatePaint] = &DvgAddCommandL;
|
|
94 |
vgapi[EvgSetiv] = &DvgSetivL;
|
|
95 |
vgapi[EvgClear] = &DvgAddCommandL;
|
|
96 |
vgapi[EvgSetfv] = &DvgSetfvL;
|
|
97 |
vgapi[EvgRotate] = &DvgAddCommandL;
|
|
98 |
vgapi[EvgCreatePath] = &DvgCreatePathL;
|
|
99 |
vgapi[EvgCreateImage] = &DvgAddCommandL;
|
|
100 |
vgapi[EvgGetPixels] = &DvgGetPixelsL;
|
|
101 |
vgapi[EvgDrawImage] = &DvgAddCommandL;
|
|
102 |
vgapi[EvgClearImage] = &DvgAddCommandL;
|
|
103 |
vgapi[EvgImageSubData] = &DvgImageSubDataL;
|
|
104 |
vgapi[EvgDestroyImage] = &DvgAddCommandL;
|
|
105 |
vgapi[EvgDestroyPaint] = &DvgDestroyPaintL;
|
|
106 |
vgapi[EvgDestroyPath] = &DvgDestroyPathL;
|
|
107 |
|
|
108 |
vgapi[EvgPrepareToBindImage]= &DvgAddCommandL;
|
|
109 |
vgapi[EvgBindImage] = &DvgAddCommandL;
|
|
110 |
vgapi[EvgUnBindImage] = &DvgAddCommandL;
|
|
111 |
|
|
112 |
vgapi[EvgFlush] = &DvgAddCommandL;
|
|
113 |
|
|
114 |
iTargetWidth = aWidth;
|
|
115 |
iTargetHeight = aHeight;
|
|
116 |
iPrepareToBindImage = 0;
|
|
117 |
iNVGTLVIcon = aNVGTLVIcon;
|
|
118 |
iLastVGPath = 0;
|
|
119 |
}
|
|
120 |
|
|
121 |
CTLVIconCreator * CTLVIconCreator::NewL(const TDesC8& aBuf, TInt aWidth, TInt aHeight, CNVGTLVIcon * aNVGTLVIcon)
|
|
122 |
{
|
|
123 |
CTLVIconCreator* self = CTLVIconCreator::NewLC(aBuf,aWidth, aHeight, aNVGTLVIcon);
|
|
124 |
CleanupStack::Pop(self);
|
|
125 |
return self;
|
|
126 |
}
|
|
127 |
|
|
128 |
CTLVIconCreator * CTLVIconCreator::NewLC(const TDesC8& aBuf, TInt aWidth, TInt aHeight, CNVGTLVIcon * aNVGTLVIcon)
|
|
129 |
{
|
|
130 |
CTLVIconCreator* self = new (ELeave) CTLVIconCreator(aWidth, aHeight, aNVGTLVIcon);
|
|
131 |
CleanupStack::PushL(self);
|
|
132 |
self->ConstructL(aBuf);
|
|
133 |
return self;
|
|
134 |
}
|
|
135 |
|
|
136 |
void CTLVIconCreator::ConstructL(const TDesC8& aBuf)
|
|
137 |
{
|
|
138 |
vgGetMatrix(iUserMatrix);
|
|
139 |
|
|
140 |
iNVGIconData = CNVGIconData::NewL(aBuf);
|
|
141 |
iDataLength = aBuf.Length();
|
|
142 |
|
|
143 |
iCommandBuffer = (TUint8 *)aBuf.Ptr();
|
|
144 |
iNVGIconData->BeginRead();
|
|
145 |
iNVGIconData->ReadL(iNvgHeader, sizeof(iNvgHeader));
|
|
146 |
iNVGTLVIcon->AddCommandL(iNvgHeader, sizeof(iNvgHeader));
|
|
147 |
}
|
|
148 |
|
|
149 |
CTLVIconCreator::~CTLVIconCreator()
|
|
150 |
{
|
|
151 |
delete iNVGIconData;
|
|
152 |
}
|
|
153 |
|
|
154 |
void CTLVIconCreator::DvgAddCommandL(TInt aLength, TInt aPos)
|
|
155 |
{
|
|
156 |
iNVGTLVIcon->AddCommandL(iCurrentCommand, iCommandBuffer + aPos, aLength);
|
|
157 |
}
|
|
158 |
|
|
159 |
void CTLVIconCreator::DvgAddCommandL()
|
|
160 |
{
|
|
161 |
iNVGTLVIcon->AddCommandL(iCurrentCommand, iCommandBuffer + iNVGIconData->ReadPos(),
|
|
162 |
APICommandLength[iCurrentCommand]);
|
|
163 |
iNVGIconData->SkipL(APICommandLength[iCurrentCommand]);
|
|
164 |
}
|
|
165 |
|
|
166 |
void CTLVIconCreator::DvgSetParameterfvL()
|
|
167 |
{
|
|
168 |
TInt length = 0;
|
|
169 |
TInt cpos = iNVGIconData->ReadPos();
|
|
170 |
|
|
171 |
TUint32 pvalue = iNVGIconData->ReadInt32L();
|
|
172 |
iNVGIconData->ReadInt16L();
|
|
173 |
TUint32 countt = iNVGIconData->ReadInt32L();
|
|
174 |
length = length + sizeof(TUint32) + sizeof(TUint16) + sizeof(TUint32) + countt * sizeof(float);
|
|
175 |
|
|
176 |
iNVGIconData->SkipL(countt * sizeof(TReal32));
|
|
177 |
|
|
178 |
DvgAddCommandL(length, cpos);
|
|
179 |
}
|
|
180 |
|
|
181 |
void CTLVIconCreator::DvgSetivL()
|
|
182 |
{
|
|
183 |
TInt length = 0;
|
|
184 |
TInt cpos = iNVGIconData->ReadPos();
|
|
185 |
TUint16 type = iNVGIconData->ReadInt16L();
|
|
186 |
TUint16 count = iNVGIconData->ReadInt16L();
|
|
187 |
|
|
188 |
length = sizeof(TInt16) + sizeof(TInt16);
|
|
189 |
length += count * sizeof(TInt32);
|
|
190 |
|
|
191 |
iNVGIconData->SkipL(count * sizeof(TInt32));
|
|
192 |
|
|
193 |
DvgAddCommandL(length, cpos);
|
|
194 |
}
|
|
195 |
|
|
196 |
|
|
197 |
VGPath CTLVIconCreator::CreatePathL()
|
|
198 |
{
|
|
199 |
const float KScale = 1.0f / 65536.0f;
|
|
200 |
|
|
201 |
VGPath pathH = vgCreatePath( VG_PATH_FORMAT_STANDARD,
|
|
202 |
VG_PATH_DATATYPE_S_32, KScale, 0.0f, 0, 0,
|
|
203 |
VG_PATH_CAPABILITY_APPEND_TO );
|
|
204 |
if (pathH == VG_INVALID_HANDLE)
|
|
205 |
{
|
|
206 |
User::LeaveIfError(CNvgEngine::OpenVGErrorToSymbianError(vgGetError()));
|
|
207 |
}
|
|
208 |
|
|
209 |
return pathH;
|
|
210 |
}
|
|
211 |
|
|
212 |
void CTLVIconCreator::DvgAppendPathDataL()
|
|
213 |
{
|
|
214 |
TUint16 numSegments;
|
|
215 |
TUint16 coordinatecount;
|
|
216 |
VGubyte * pathSegments;
|
|
217 |
TFloatFixPt * pathData;
|
|
218 |
TFloatFixPt * coordhandle;
|
|
219 |
|
|
220 |
iNVGIconData->ReadInt32L();
|
|
221 |
numSegments = iNVGIconData->ReadInt16L();
|
|
222 |
|
|
223 |
pathSegments = new (ELeave) VGubyte[numSegments];
|
|
224 |
CleanupStack::PushL(TCleanupItem(CleanupArray, pathSegments));
|
|
225 |
|
|
226 |
for(int j=0; j < numSegments; j++)
|
|
227 |
{
|
|
228 |
pathSegments[j] = iNVGIconData->ReadInt8L();
|
|
229 |
}
|
|
230 |
|
|
231 |
coordinatecount = iNVGIconData->ReadInt16L();
|
|
232 |
pathData = new (ELeave) TFloatFixPt[coordinatecount];
|
|
233 |
CleanupStack::PushL(TCleanupItem(CleanupArray, pathData));
|
|
234 |
|
|
235 |
TInt lFloatFixVal = 0;
|
|
236 |
|
|
237 |
coordhandle = pathData;
|
|
238 |
for(int i = 0; i < coordinatecount; i++, coordhandle++)
|
|
239 |
{
|
|
240 |
lFloatFixVal = iNVGIconData->ReadInt32L();
|
|
241 |
coordhandle->copyfloatfix(lFloatFixVal);
|
|
242 |
}
|
|
243 |
|
|
244 |
iLastVGPath = CreatePathL();
|
|
245 |
vgAppendPathData(iLastVGPath, numSegments, pathSegments, pathData);
|
|
246 |
|
|
247 |
CleanupStack::PopAndDestroy(2);
|
|
248 |
}
|
|
249 |
|
|
250 |
void CTLVIconCreator::DvgDrawPathL()
|
|
251 |
{
|
|
252 |
iNVGIconData->ReadInt32L();
|
|
253 |
TUint16 value = iNVGIconData->ReadInt16L();
|
|
254 |
|
|
255 |
iNVGTLVIcon->AddDrawPathCommandL(iLastVGPath, (VGPaintMode)value);
|
|
256 |
}
|
|
257 |
|
|
258 |
void CTLVIconCreator::DvguRectL()
|
|
259 |
{
|
|
260 |
iNVGIconData->ReadInt32L();
|
|
261 |
|
|
262 |
TReal32 x = iNVGIconData->ReadReal32L();
|
|
263 |
TReal32 y = iNVGIconData->ReadReal32L();
|
|
264 |
|
|
265 |
TReal32 width = iNVGIconData->ReadReal32L();
|
|
266 |
TReal32 height = iNVGIconData->ReadReal32L();
|
|
267 |
|
|
268 |
iLastVGPath = CreatePathL();
|
|
269 |
vguRect(iLastVGPath, x, y, width, height);
|
|
270 |
}
|
|
271 |
|
|
272 |
void CTLVIconCreator::DvguEllipseL()
|
|
273 |
{
|
|
274 |
TReal32 cx;
|
|
275 |
TReal32 cy;
|
|
276 |
TReal32 width;
|
|
277 |
TReal32 height;
|
|
278 |
|
|
279 |
iNVGIconData->ReadInt32L();
|
|
280 |
|
|
281 |
cx = iNVGIconData->ReadReal32L();
|
|
282 |
cy = iNVGIconData->ReadReal32L();
|
|
283 |
|
|
284 |
width = iNVGIconData->ReadReal32L();
|
|
285 |
height = iNVGIconData->ReadReal32L();
|
|
286 |
|
|
287 |
iLastVGPath = CreatePathL();
|
|
288 |
vguEllipse(iLastVGPath, cx, cy, width, height);
|
|
289 |
}
|
|
290 |
|
|
291 |
void CTLVIconCreator::DvguRoundRectL()
|
|
292 |
{
|
|
293 |
TReal32 x;
|
|
294 |
TReal32 y;
|
|
295 |
TReal32 width;
|
|
296 |
TReal32 height;
|
|
297 |
TReal32 arcWidth;
|
|
298 |
TReal32 arcHeight;
|
|
299 |
|
|
300 |
iNVGIconData->ReadInt32L();
|
|
301 |
|
|
302 |
x = iNVGIconData->ReadReal32L();
|
|
303 |
y = iNVGIconData->ReadReal32L();
|
|
304 |
|
|
305 |
width = iNVGIconData->ReadReal32L();
|
|
306 |
height= iNVGIconData->ReadReal32L();
|
|
307 |
|
|
308 |
arcWidth = iNVGIconData->ReadReal32L();
|
|
309 |
arcHeight= iNVGIconData->ReadReal32L();
|
|
310 |
|
|
311 |
iLastVGPath = CreatePathL();
|
|
312 |
vguRoundRect(iLastVGPath, x, y, width, height, arcWidth, arcHeight);
|
|
313 |
}
|
|
314 |
|
|
315 |
void CTLVIconCreator::DvguLineL()
|
|
316 |
{
|
|
317 |
TReal32 x0;
|
|
318 |
TReal32 y0;
|
|
319 |
TReal32 x1;
|
|
320 |
TReal32 y1;
|
|
321 |
|
|
322 |
iNVGIconData->ReadInt32L();
|
|
323 |
|
|
324 |
x0 = iNVGIconData->ReadReal32L();
|
|
325 |
y0 = iNVGIconData->ReadReal32L();
|
|
326 |
|
|
327 |
x1 = iNVGIconData->ReadReal32L();
|
|
328 |
y1 = iNVGIconData->ReadReal32L();
|
|
329 |
|
|
330 |
iLastVGPath = CreatePathL();
|
|
331 |
vguLine(iLastVGPath, x0, y0, x1, y1);
|
|
332 |
}
|
|
333 |
|
|
334 |
void CTLVIconCreator::DvgSetfvL()
|
|
335 |
{
|
|
336 |
TUint16 count;
|
|
337 |
TInt length = 0;
|
|
338 |
TInt cpos = iNVGIconData->ReadPos();
|
|
339 |
|
|
340 |
iNVGIconData->ReadInt16L();
|
|
341 |
count = iNVGIconData->ReadInt16L();
|
|
342 |
|
|
343 |
iNVGIconData->SkipL(sizeof(TReal32) * count);
|
|
344 |
|
|
345 |
length = length + 2 * sizeof(TUint16) + count * sizeof(VGfloat);
|
|
346 |
|
|
347 |
DvgAddCommandL(length, cpos);
|
|
348 |
}
|
|
349 |
|
|
350 |
void CTLVIconCreator::DvgCreatePathL()
|
|
351 |
{
|
|
352 |
iNVGIconData->SkipL(APICommandLength[EvgCreatePath]);
|
|
353 |
}
|
|
354 |
|
|
355 |
void CTLVIconCreator::DvgImageSubDataL()
|
|
356 |
{
|
|
357 |
TInt cpos = iNVGIconData->ReadPos();
|
|
358 |
|
|
359 |
TInt encodedImageHandle = iNVGIconData->ReadInt32L();
|
|
360 |
TInt dataLength = 0;
|
|
361 |
|
|
362 |
iNVGIconData->ReadInt32L();
|
|
363 |
iNVGIconData->ReadInt32L();
|
|
364 |
iNVGIconData->ReadInt32L();
|
|
365 |
iNVGIconData->ReadInt32L();
|
|
366 |
iNVGIconData->ReadInt32L();
|
|
367 |
iNVGIconData->ReadInt32L();
|
|
368 |
dataLength = iNVGIconData->ReadInt32L();
|
|
369 |
iNVGIconData->SkipL(dataLength);
|
|
370 |
|
|
371 |
DvgAddCommandL(iNVGIconData->ReadPos() - cpos, cpos);
|
|
372 |
}
|
|
373 |
|
|
374 |
void CTLVIconCreator::DvgGetPixelsL()
|
|
375 |
{
|
|
376 |
}
|
|
377 |
|
|
378 |
void CTLVIconCreator::DvgDestroyPaintL()
|
|
379 |
{
|
|
380 |
}
|
|
381 |
|
|
382 |
void CTLVIconCreator::DvgDestroyPathL()
|
|
383 |
{
|
|
384 |
}
|
|
385 |
|
|
386 |
void CTLVIconCreator::DvgFlushL()
|
|
387 |
{
|
|
388 |
}
|
|
389 |
|
|
390 |
TInt CTLVIconCreator::ExecuteL(TInt aIndex)
|
|
391 |
{
|
|
392 |
iCurrentCommand = aIndex;
|
|
393 |
if (0 <= aIndex && aIndex < EvgFlush + 1)
|
|
394 |
{
|
|
395 |
(this->*(vgapi[aIndex]))();
|
|
396 |
}
|
|
397 |
else
|
|
398 |
{
|
|
399 |
return KErrCorrupt;
|
|
400 |
}
|
|
401 |
|
|
402 |
return KErrNone;
|
|
403 |
}
|
|
404 |
|
|
405 |
TInt CTLVIconCreator::ExecuteL()
|
|
406 |
{
|
|
407 |
TInt error = KErrNone;
|
|
408 |
|
|
409 |
while (!iNVGIconData->EOF())
|
|
410 |
{
|
|
411 |
error = ExecuteL(iNVGIconData->ReadInt8L());
|
|
412 |
if (error != KErrNone)
|
|
413 |
{
|
|
414 |
break;
|
|
415 |
}
|
|
416 |
}
|
|
417 |
|
|
418 |
return error;
|
|
419 |
}
|