|
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 * Renderer Draw Item Interface. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include "h263dconfig.h" |
|
23 #include "rendri.h" |
|
24 #include "debug.h" |
|
25 |
|
26 |
|
27 /* |
|
28 * Preprocessor definitions |
|
29 */ |
|
30 |
|
31 |
|
32 #define renDriMalloc malloc |
|
33 #define renDriCalloc calloc |
|
34 #define renDriRealloc realloc |
|
35 #define renDriDealloc free |
|
36 |
|
37 #ifndef renAssert |
|
38 #ifndef assert |
|
39 #include <assert.h> |
|
40 #endif |
|
41 #define renAssert(exp) assert(exp) |
|
42 #endif |
|
43 |
|
44 |
|
45 /* |
|
46 * Local function prototypes |
|
47 */ |
|
48 |
|
49 |
|
50 /* |
|
51 * Global functions |
|
52 */ |
|
53 |
|
54 /* {{-output"renDriAlloc.txt"}} */ |
|
55 /* |
|
56 * renDriAlloc |
|
57 * |
|
58 * |
|
59 * Parameters: |
|
60 * width luminance image width in pixels |
|
61 * height luminance image height in pixels |
|
62 * |
|
63 * Function: |
|
64 * This function creates and initializes a new draw item. |
|
65 * |
|
66 * When passed to the renderer the following members of the draw item |
|
67 * must be explicitly set (i.e. these members are not set by this |
|
68 * function): |
|
69 * drawItem->param.dwFlags |
|
70 * drawItem->param.lTime |
|
71 * drawItem->extParam.flags |
|
72 * drawItem->extParam.rate |
|
73 * drawItem->extParam.scale |
|
74 * drawItem->extParam.numOfCodedMBs |
|
75 * drawItem->extParam.snapshotRect |
|
76 * drawItem->extParam.ckInfo |
|
77 * drawItem->retFrame |
|
78 * drawItem->retFrameParam |
|
79 * |
|
80 * Returns: |
|
81 * a pointer to the created |
|
82 * draw item if the function was successful |
|
83 * NULL indicating a general error |
|
84 * |
|
85 * |
|
86 */ |
|
87 |
|
88 renDrawItem_t * renDriAlloc(int width, int height, int fYuvNeeded) |
|
89 /* {{-output"renDriAlloc.txt"}} */ |
|
90 { |
|
91 renDrawItem_t *drawItem; |
|
92 renBitmapInfoHeader_t *bmi; |
|
93 void *data; |
|
94 |
|
95 /* Allocate draw item */ |
|
96 drawItem = (renDrawItem_t *) renDriMalloc(sizeof(renDrawItem_t)); |
|
97 if (drawItem == NULL) |
|
98 return NULL; |
|
99 memset(drawItem, 0, sizeof(renDrawItem_t)); |
|
100 |
|
101 /* Allocate bitmap info header */ |
|
102 bmi = (renBitmapInfoHeader_t *) renDriMalloc(sizeof(renBitmapInfoHeader_t)); |
|
103 if (bmi == NULL) { |
|
104 renDriDealloc(drawItem); |
|
105 return NULL; |
|
106 } |
|
107 |
|
108 /* Initialize bitmap info header */ |
|
109 bmi->biSize = sizeof(renBitmapInfoHeader_t); |
|
110 bmi->biWidth = width; |
|
111 bmi->biHeight = height; |
|
112 if ( fYuvNeeded ) |
|
113 { |
|
114 bmi->biSizeImage = (u_int32) width * (u_int32) height * 3 / 2; |
|
115 /* Allocate room for frame data */ |
|
116 data = renDriMalloc(bmi->biSizeImage); |
|
117 if (data == NULL) { |
|
118 renDriDealloc(bmi); |
|
119 renDriDealloc(drawItem); |
|
120 return NULL; |
|
121 } |
|
122 } |
|
123 else |
|
124 { |
|
125 bmi->biSizeImage = 0; |
|
126 data = NULL; |
|
127 } |
|
128 |
|
129 |
|
130 /* Initialize renDrawParam_t member of draw item */ |
|
131 /* dwFlags set by application */ |
|
132 drawItem->param.lpFormat = bmi; |
|
133 drawItem->param.lpData = data; |
|
134 drawItem->param.cbData = bmi->biSizeImage; |
|
135 /* lTime set by application */ |
|
136 |
|
137 drawItem->extParam.size = sizeof(renExtDrawParam_t); |
|
138 /* flags set by application */ |
|
139 /* rate set by application */ |
|
140 /* scale set by application */ |
|
141 drawItem->extParam.numOfMBs = (width / 16) * (height / 16); |
|
142 /* numOfCodedMBs set by application */ |
|
143 drawItem->extParam.fCodedMBs = (u_char *) renDriMalloc( |
|
144 drawItem->extParam.numOfMBs * sizeof(u_char)); |
|
145 if (drawItem->extParam.fCodedMBs == NULL) { |
|
146 renDriDealloc(data); |
|
147 renDriDealloc(bmi); |
|
148 renDriDealloc(drawItem); |
|
149 return NULL; |
|
150 } |
|
151 /* snapshotRect set by application */ |
|
152 /* ckInfo set by application */ |
|
153 |
|
154 /* retFrame and retFrameParam members of draw item are set by application */ |
|
155 |
|
156 return drawItem; |
|
157 } |
|
158 |
|
159 |
|
160 /* {{-output"renDriCopyParameters.txt"}} */ |
|
161 /* |
|
162 * renDriCopyParameters |
|
163 * |
|
164 * |
|
165 * Parameters: |
|
166 * dstDrawItem destination draw item |
|
167 * srcDrawItem source draw item |
|
168 * |
|
169 * Function: |
|
170 * This function copies the srcDrawItem structure to the dstDrawItem |
|
171 * structure. All other parameters are copied but the actual picture |
|
172 * contents. The function handles nested structures correctly. |
|
173 * No pointers are overwritten but rather the contents corresponding |
|
174 * to a pointer are copied from the source to the destionation structure. |
|
175 * |
|
176 * Returns: |
|
177 * Nothing |
|
178 * |
|
179 * |
|
180 */ |
|
181 |
|
182 void renDriCopyParameters( |
|
183 renDrawItem_t *dstDrawItem, |
|
184 const renDrawItem_t *srcDrawItem) |
|
185 /* {{-output"renDriCopyParameters.txt"}} */ |
|
186 { |
|
187 /* param */ |
|
188 { |
|
189 renDrawParam_t *dstDrawParam = &(dstDrawItem->param); |
|
190 const renDrawParam_t *srcDrawParam = &(srcDrawItem->param); |
|
191 |
|
192 /* dwFlags */ |
|
193 dstDrawParam->dwFlags = srcDrawParam->dwFlags; |
|
194 |
|
195 /* lpFormat */ |
|
196 { |
|
197 const renBitmapInfoHeader_t *srcBitmapInfoHeader = |
|
198 (renBitmapInfoHeader_t *) srcDrawParam->lpFormat; |
|
199 |
|
200 /* biSize indicates the size of the bitmap info header. |
|
201 Thus, copy biSize bytes from source to destination bitmap info |
|
202 header. |
|
203 Note: it is assumed that biSize (and the amount of allocated |
|
204 memory) is the same in both structures. */ |
|
205 MEMCPY( |
|
206 dstDrawParam->lpFormat, |
|
207 srcDrawParam->lpFormat, |
|
208 (TInt)srcBitmapInfoHeader->biSize); |
|
209 } |
|
210 |
|
211 /* lpData */ |
|
212 /* Not copied since contains a pointer to actual picture contents. |
|
213 Set to NULL for clarity. */ |
|
214 |
|
215 /* cbData */ |
|
216 dstDrawParam->cbData = srcDrawParam->cbData; |
|
217 |
|
218 /* lTime */ |
|
219 dstDrawParam->lTime = srcDrawParam->lTime; |
|
220 } |
|
221 |
|
222 /* extParam */ |
|
223 { |
|
224 renExtDrawParam_t *dstExtDrawParam = &(dstDrawItem->extParam); |
|
225 const renExtDrawParam_t *srcExtDrawParam = &(srcDrawItem->extParam); |
|
226 u_char *dstFCodedMBs = dstExtDrawParam->fCodedMBs; |
|
227 |
|
228 /* fCodedMBs is the only pointer in the structure. Thus, it is easier |
|
229 to temporally save the destionation fCodedMBs, then overwrite each |
|
230 member of the destination structure by corresponding member of |
|
231 the source structure and finally restore fCodedMBs in the destination |
|
232 structure. */ |
|
233 |
|
234 /* "size" member indicates the size of the structure. |
|
235 Thus, copy size bytes from source to destination structure. |
|
236 Note: it is assumed that size (and the amount of allocated |
|
237 memory) is the same in both structures. */ |
|
238 MEMCPY( |
|
239 (void *) dstExtDrawParam, |
|
240 (void *) srcExtDrawParam, |
|
241 (TInt)srcExtDrawParam->size); |
|
242 |
|
243 /* Restore destination fCodedMBs. */ |
|
244 dstExtDrawParam->fCodedMBs = dstFCodedMBs; |
|
245 |
|
246 /* Copy coded MBs array */ |
|
247 MEMCPY( |
|
248 (void *) dstFCodedMBs, |
|
249 (void *) srcExtDrawParam->fCodedMBs, |
|
250 (TInt)srcExtDrawParam->numOfMBs); |
|
251 } |
|
252 |
|
253 } |
|
254 |
|
255 /* {{-output"renDriCopyFrameData.txt"}} */ |
|
256 /* |
|
257 * renDriCopyFrameData |
|
258 * |
|
259 * Parameters: |
|
260 * dstDrawItem destination draw item |
|
261 * srcDrawItem source draw item |
|
262 * |
|
263 * Function: |
|
264 * This function copies the actual picture data contents from srcDrawItem |
|
265 * structure to the dstDrawItem structure. No pointers are overwritten |
|
266 * but rather the contents corresponding to a pointer are copied from |
|
267 * the source to the destination structure. |
|
268 * |
|
269 * Returns: |
|
270 * Nothing |
|
271 * |
|
272 */ |
|
273 |
|
274 void renDriCopyFrameData( |
|
275 renDrawItem_t *dstDrawItem, |
|
276 const renDrawItem_t *srcDrawItem) |
|
277 /* {{-output"renDriCopyFrameData.txt"}} */ |
|
278 { |
|
279 |
|
280 renDrawParam_t *dstDrawParam = &(dstDrawItem->param); |
|
281 const renDrawParam_t *srcDrawParam = &(srcDrawItem->param); |
|
282 const renBitmapInfoHeader_t *srcBitmapInfoHeader = |
|
283 (renBitmapInfoHeader_t *) srcDrawParam->lpFormat; |
|
284 |
|
285 /* biSizeImage indicates the size of the image data in bytes. |
|
286 Copy biSizeImage bytes from source to destination frame data. |
|
287 Note: it is assumed that size (and the amount of allocated |
|
288 memory) is the same in both structures. */ |
|
289 |
|
290 renAssert(((renBitmapInfoHeader_t *) dstDrawParam->lpFormat)->biSizeImage == srcBitmapInfoHeader->biSizeImage); |
|
291 |
|
292 MEMCPY(dstDrawParam->lpData, |
|
293 srcDrawParam->lpData, |
|
294 (TInt)srcBitmapInfoHeader->biSizeImage); |
|
295 |
|
296 } |
|
297 |
|
298 /* {{-output"renDriFree.txt"}} */ |
|
299 /* |
|
300 * renDriFree |
|
301 * |
|
302 * |
|
303 * Parameters: |
|
304 * drawItem a pointer to the draw item to free |
|
305 * |
|
306 * Function: |
|
307 * This function destroys the passed draw item. |
|
308 * |
|
309 * Returns: |
|
310 * Nothing. |
|
311 * |
|
312 * |
|
313 */ |
|
314 |
|
315 void renDriFree(renDrawItem_t *drawItem) |
|
316 /* {{-output"renDriFree.txt"}} */ |
|
317 { |
|
318 renDrawParam_t *param; |
|
319 renExtDrawParam_t *extParam; |
|
320 |
|
321 if (!drawItem) |
|
322 return; |
|
323 |
|
324 param = &drawItem->param; |
|
325 extParam = &drawItem->extParam; |
|
326 |
|
327 if (param) { |
|
328 if (param->lpFormat) |
|
329 renDriDealloc(param->lpFormat); |
|
330 if (param->lpData) |
|
331 renDriDealloc(param->lpData); |
|
332 } |
|
333 |
|
334 if (extParam) { |
|
335 if (extParam->fCodedMBs) |
|
336 renDriDealloc(extParam->fCodedMBs); |
|
337 } |
|
338 |
|
339 renDriDealloc(drawItem); |
|
340 } |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 /* {{-output"renDriYUV.txt"}} */ |
|
347 /* |
|
348 * renDriYUV |
|
349 * |
|
350 * |
|
351 * Parameters: |
|
352 * drawItem a pointer to a draw item |
|
353 * y, u, v top-left corners of the Y, U and V frames |
|
354 * corresponding to the passed draw item |
|
355 * width, height the dimensions of the luminance frame of |
|
356 * the passed draw item |
|
357 * |
|
358 * Function: |
|
359 * This function returns the Y, U and V pointers to the passed draw item |
|
360 * as well as the dimensions of the luminance frame of the draw item. |
|
361 * |
|
362 * Returns: |
|
363 * REN_OK if the function was successful |
|
364 * REN_ERROR indicating a general error |
|
365 * |
|
366 */ |
|
367 |
|
368 int renDriYUV(renDrawItem_t *drawItem, |
|
369 u_char **y, u_char **u, u_char **v, int *width, int *height) |
|
370 /* {{-output"renDriYUV.txt"}} */ |
|
371 { |
|
372 renBitmapInfoHeader_t *bmi; |
|
373 int32 ySize, uvSize; |
|
374 |
|
375 /* If invalid arguments */ |
|
376 if (!drawItem || !drawItem->param.lpFormat || |
|
377 !y || !u || !v || !width || !height) { |
|
378 /* Return error */ |
|
379 debPrintf("renGetYUVFromDrawParam: ERROR - null pointer.\n"); |
|
380 return REN_ERROR; |
|
381 } |
|
382 |
|
383 |
|
384 bmi = (renBitmapInfoHeader_t *) drawItem->param.lpFormat; |
|
385 |
|
386 *width = bmi->biWidth; |
|
387 *height = labs(bmi->biHeight); |
|
388 |
|
389 if ( drawItem->param.lpData == NULL ) |
|
390 { |
|
391 // no YUV buffer, parsing-only instance |
|
392 *y = NULL, |
|
393 *u = NULL; |
|
394 *v = NULL; |
|
395 |
|
396 return REN_OK; |
|
397 } |
|
398 |
|
399 ySize = (*width) * (*height) * sizeof(u_char); |
|
400 uvSize = ySize / 4; |
|
401 |
|
402 *y = (u_char *) drawItem->param.lpData; |
|
403 *u = *y + ySize; |
|
404 *v = *u + uvSize; |
|
405 |
|
406 return REN_OK; |
|
407 } |
|
408 |
|
409 // End of File |