/src/libavc/decoder/ih264d_format_conv.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2015 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /*****************************************************************************/ |
21 | | /* */ |
22 | | /* File Name : ih264d_format_conv.c */ |
23 | | /* */ |
24 | | /* Description : Contains functions needed to convert the images in */ |
25 | | /* different color spaces to yuv 422i color space */ |
26 | | /* */ |
27 | | /* */ |
28 | | /* Issues / Problems : None */ |
29 | | /* */ |
30 | | /* Revision History : */ |
31 | | /* */ |
32 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
33 | | /* 28 08 2007 Naveen Kumar T Draft */ |
34 | | /* */ |
35 | | /*****************************************************************************/ |
36 | | /*****************************************************************************/ |
37 | | /* File Includes */ |
38 | | /*****************************************************************************/ |
39 | | |
40 | | /* System include files */ |
41 | | #include <string.h> |
42 | | /* User include files */ |
43 | | #include "ih264_typedefs.h" |
44 | | #include "iv.h" |
45 | | #include "ih264_macros.h" |
46 | | #include "ih264_platform_macros.h" |
47 | | #include "ih264d_structs.h" |
48 | | #include "ih264d_format_conv.h" |
49 | | #include "ih264d_defs.h" |
50 | | |
51 | | |
52 | | |
53 | | #ifdef LOGO_EN |
54 | | #include "ih264d_ittiam_logo.h" |
55 | | #define INSERT_LOGO(pu1_buf_y,pu1_buf_u,pu1_buf_v, u4_stride, u4_x_pos, u4_y_pos, u4_yuv_fmt, u4_disp_wd, u4_disp_ht) \ |
56 | | ih264d_insert_logo(pu1_buf_y,pu1_buf_u,pu1_buf_v, u4_stride,\ |
57 | | u4_x_pos, u4_y_pos, u4_yuv_fmt, u4_disp_wd, u4_disp_ht) |
58 | | #else |
59 | | #define INSERT_LOGO(pu1_buf_y,pu1_buf_u,pu1_buf_v, u4_stride, u4_x_pos, u4_y_pos, u4_yuv_fmt, u4_disp_wd, u4_disp_ht) |
60 | | #endif |
61 | | |
62 | | /** |
63 | | ******************************************************************************* |
64 | | * |
65 | | * @brief Function used from copying a 420SP buffer |
66 | | * |
67 | | * @par Description |
68 | | * Function used from copying a 420SP buffer |
69 | | * |
70 | | * @param[in] pu1_y_src |
71 | | * Input Y pointer |
72 | | * |
73 | | * @param[in] pu1_uv_src |
74 | | * Input UV pointer (UV is interleaved either in UV or VU format) |
75 | | * |
76 | | * @param[in] pu1_y_dst |
77 | | * Output Y pointer |
78 | | * |
79 | | * @param[in] pu1_uv_dst |
80 | | * Output UV pointer (UV is interleaved in the same format as that of input) |
81 | | * |
82 | | * @param[in] wd |
83 | | * Width |
84 | | * |
85 | | * @param[in] ht |
86 | | * Height |
87 | | * |
88 | | * @param[in] src_y_strd |
89 | | * Input Y Stride |
90 | | * |
91 | | * @param[in] src_uv_strd |
92 | | * Input UV stride |
93 | | * |
94 | | * @param[in] dst_y_strd |
95 | | * Output Y stride |
96 | | * |
97 | | * @param[in] dst_uv_strd |
98 | | * Output UV stride |
99 | | * |
100 | | * @returns None |
101 | | * |
102 | | * @remarks In case there is a need to perform partial frame copy then |
103 | | * by passion appropriate source and destination pointers and appropriate |
104 | | * values for wd and ht it can be done |
105 | | * |
106 | | ******************************************************************************* |
107 | | */ |
108 | | void ih264d_fmt_conv_420sp_to_rgb565(UWORD8 *pu1_y_src, |
109 | | UWORD8 *pu1_uv_src, |
110 | | UWORD16 *pu2_rgb_dst, |
111 | | WORD32 wd, |
112 | | WORD32 ht, |
113 | | WORD32 src_y_strd, |
114 | | WORD32 src_uv_strd, |
115 | | WORD32 dst_strd, |
116 | | WORD32 is_u_first) |
117 | 15.4k | { |
118 | | |
119 | 15.4k | WORD16 i2_r, i2_g, i2_b; |
120 | 15.4k | UWORD32 u4_r, u4_g, u4_b; |
121 | 15.4k | WORD16 i2_i, i2_j; |
122 | 15.4k | UWORD8 *pu1_y_src_nxt; |
123 | 15.4k | UWORD16 *pu2_rgb_dst_next_row; |
124 | | |
125 | 15.4k | UWORD8 *pu1_u_src, *pu1_v_src; |
126 | | |
127 | 15.4k | if(is_u_first) |
128 | 15.4k | { |
129 | 15.4k | pu1_u_src = (UWORD8 *)pu1_uv_src; |
130 | 15.4k | pu1_v_src = (UWORD8 *)pu1_uv_src + 1; |
131 | 15.4k | } |
132 | 0 | else |
133 | 0 | { |
134 | 0 | pu1_u_src = (UWORD8 *)pu1_uv_src + 1; |
135 | 0 | pu1_v_src = (UWORD8 *)pu1_uv_src; |
136 | 0 | } |
137 | | |
138 | 15.4k | pu1_y_src_nxt = pu1_y_src + src_y_strd; |
139 | 15.4k | pu2_rgb_dst_next_row = pu2_rgb_dst + dst_strd; |
140 | | |
141 | 871k | for(i2_i = 0; i2_i < (ht >> 1); i2_i++) |
142 | 855k | { |
143 | 123M | for(i2_j = (wd >> 1); i2_j > 0; i2_j--) |
144 | 122M | { |
145 | 122M | i2_b = ((*pu1_u_src - 128) * COEFF4 >> 13); |
146 | 122M | i2_g = ((*pu1_u_src - 128) * COEFF2 + (*pu1_v_src - 128) * COEFF3) |
147 | 122M | >> 13; |
148 | 122M | i2_r = ((*pu1_v_src - 128) * COEFF1) >> 13; |
149 | | |
150 | 122M | pu1_u_src += 2; |
151 | 122M | pu1_v_src += 2; |
152 | | /* pixel 0 */ |
153 | | /* B */ |
154 | 122M | u4_b = CLIP_U8(*pu1_y_src + i2_b); |
155 | 122M | u4_b >>= 3; |
156 | | /* G */ |
157 | 122M | u4_g = CLIP_U8(*pu1_y_src + i2_g); |
158 | 122M | u4_g >>= 2; |
159 | | /* R */ |
160 | 122M | u4_r = CLIP_U8(*pu1_y_src + i2_r); |
161 | 122M | u4_r >>= 3; |
162 | | |
163 | 122M | pu1_y_src++; |
164 | 122M | *pu2_rgb_dst++ = ((u4_r << 11) | (u4_g << 5) | u4_b); |
165 | | |
166 | | /* pixel 1 */ |
167 | | /* B */ |
168 | 122M | u4_b = CLIP_U8(*pu1_y_src + i2_b); |
169 | 122M | u4_b >>= 3; |
170 | | /* G */ |
171 | 122M | u4_g = CLIP_U8(*pu1_y_src + i2_g); |
172 | 122M | u4_g >>= 2; |
173 | | /* R */ |
174 | 122M | u4_r = CLIP_U8(*pu1_y_src + i2_r); |
175 | 122M | u4_r >>= 3; |
176 | | |
177 | 122M | pu1_y_src++; |
178 | 122M | *pu2_rgb_dst++ = ((u4_r << 11) | (u4_g << 5) | u4_b); |
179 | | |
180 | | /* pixel 2 */ |
181 | | /* B */ |
182 | 122M | u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b); |
183 | 122M | u4_b >>= 3; |
184 | | /* G */ |
185 | 122M | u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g); |
186 | 122M | u4_g >>= 2; |
187 | | /* R */ |
188 | 122M | u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r); |
189 | 122M | u4_r >>= 3; |
190 | | |
191 | 122M | pu1_y_src_nxt++; |
192 | 122M | *pu2_rgb_dst_next_row++ = ((u4_r << 11) | (u4_g << 5) | u4_b); |
193 | | |
194 | | /* pixel 3 */ |
195 | | /* B */ |
196 | 122M | u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b); |
197 | 122M | u4_b >>= 3; |
198 | | /* G */ |
199 | 122M | u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g); |
200 | 122M | u4_g >>= 2; |
201 | | /* R */ |
202 | 122M | u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r); |
203 | 122M | u4_r >>= 3; |
204 | | |
205 | 122M | pu1_y_src_nxt++; |
206 | 122M | *pu2_rgb_dst_next_row++ = ((u4_r << 11) | (u4_g << 5) | u4_b); |
207 | | |
208 | 122M | } |
209 | | |
210 | 855k | pu1_u_src = pu1_u_src + src_uv_strd - wd; |
211 | 855k | pu1_v_src = pu1_v_src + src_uv_strd - wd; |
212 | | |
213 | 855k | pu1_y_src = pu1_y_src + (src_y_strd << 1) - wd; |
214 | 855k | pu1_y_src_nxt = pu1_y_src_nxt + (src_y_strd << 1) - wd; |
215 | | |
216 | 855k | pu2_rgb_dst = pu2_rgb_dst_next_row - wd + dst_strd; |
217 | 855k | pu2_rgb_dst_next_row = pu2_rgb_dst_next_row + (dst_strd << 1) - wd; |
218 | 855k | } |
219 | | |
220 | 15.4k | } |
221 | | |
222 | | void ih264d_fmt_conv_420sp_to_rgba8888(UWORD8 *pu1_y_src, |
223 | | UWORD8 *pu1_uv_src, |
224 | | UWORD32 *pu4_rgba_dst, |
225 | | WORD32 wd, |
226 | | WORD32 ht, |
227 | | WORD32 src_y_strd, |
228 | | WORD32 src_uv_strd, |
229 | | WORD32 dst_strd, |
230 | | WORD32 is_u_first) |
231 | 0 | { |
232 | |
|
233 | 0 | WORD16 i2_r, i2_g, i2_b; |
234 | 0 | UWORD32 u4_r, u4_g, u4_b; |
235 | 0 | WORD16 i2_i, i2_j; |
236 | 0 | UWORD8 *pu1_y_src_nxt; |
237 | 0 | UWORD32 *pu4_rgba_dst_next_row; |
238 | |
|
239 | 0 | UWORD8 *pu1_u_src, *pu1_v_src; |
240 | |
|
241 | 0 | if(is_u_first) |
242 | 0 | { |
243 | 0 | pu1_u_src = (UWORD8 *)pu1_uv_src; |
244 | 0 | pu1_v_src = (UWORD8 *)pu1_uv_src + 1; |
245 | 0 | } |
246 | 0 | else |
247 | 0 | { |
248 | 0 | pu1_u_src = (UWORD8 *)pu1_uv_src + 1; |
249 | 0 | pu1_v_src = (UWORD8 *)pu1_uv_src; |
250 | 0 | } |
251 | |
|
252 | 0 | pu1_y_src_nxt = pu1_y_src + src_y_strd; |
253 | 0 | pu4_rgba_dst_next_row = pu4_rgba_dst + dst_strd; |
254 | |
|
255 | 0 | for(i2_i = 0; i2_i < (ht >> 1); i2_i++) |
256 | 0 | { |
257 | 0 | for(i2_j = (wd >> 1); i2_j > 0; i2_j--) |
258 | 0 | { |
259 | 0 | i2_b = ((*pu1_u_src - 128) * COEFF4 >> 13); |
260 | 0 | i2_g = ((*pu1_u_src - 128) * COEFF2 + (*pu1_v_src - 128) * COEFF3) |
261 | 0 | >> 13; |
262 | 0 | i2_r = ((*pu1_v_src - 128) * COEFF1) >> 13; |
263 | |
|
264 | 0 | pu1_u_src += 2; |
265 | 0 | pu1_v_src += 2; |
266 | | /* pixel 0 */ |
267 | | /* B */ |
268 | 0 | u4_b = CLIP_U8(*pu1_y_src + i2_b); |
269 | | /* G */ |
270 | 0 | u4_g = CLIP_U8(*pu1_y_src + i2_g); |
271 | | /* R */ |
272 | 0 | u4_r = CLIP_U8(*pu1_y_src + i2_r); |
273 | |
|
274 | 0 | pu1_y_src++; |
275 | 0 | *pu4_rgba_dst++ = ((u4_r << 16) | (u4_g << 8) | (u4_b << 0)); |
276 | | |
277 | | /* pixel 1 */ |
278 | | /* B */ |
279 | 0 | u4_b = CLIP_U8(*pu1_y_src + i2_b); |
280 | | /* G */ |
281 | 0 | u4_g = CLIP_U8(*pu1_y_src + i2_g); |
282 | | /* R */ |
283 | 0 | u4_r = CLIP_U8(*pu1_y_src + i2_r); |
284 | |
|
285 | 0 | pu1_y_src++; |
286 | 0 | *pu4_rgba_dst++ = ((u4_r << 16) | (u4_g << 8) | (u4_b << 0)); |
287 | | |
288 | | /* pixel 2 */ |
289 | | /* B */ |
290 | 0 | u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b); |
291 | | /* G */ |
292 | 0 | u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g); |
293 | | /* R */ |
294 | 0 | u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r); |
295 | |
|
296 | 0 | pu1_y_src_nxt++; |
297 | 0 | *pu4_rgba_dst_next_row++ = |
298 | 0 | ((u4_r << 16) | (u4_g << 8) | (u4_b << 0)); |
299 | | |
300 | | /* pixel 3 */ |
301 | | /* B */ |
302 | 0 | u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b); |
303 | | /* G */ |
304 | 0 | u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g); |
305 | | /* R */ |
306 | 0 | u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r); |
307 | |
|
308 | 0 | pu1_y_src_nxt++; |
309 | 0 | *pu4_rgba_dst_next_row++ = |
310 | 0 | ((u4_r << 16) | (u4_g << 8) | (u4_b << 0)); |
311 | |
|
312 | 0 | } |
313 | |
|
314 | 0 | pu1_u_src = pu1_u_src + src_uv_strd - wd; |
315 | 0 | pu1_v_src = pu1_v_src + src_uv_strd - wd; |
316 | |
|
317 | 0 | pu1_y_src = pu1_y_src + (src_y_strd << 1) - wd; |
318 | 0 | pu1_y_src_nxt = pu1_y_src_nxt + (src_y_strd << 1) - wd; |
319 | |
|
320 | 0 | pu4_rgba_dst = pu4_rgba_dst_next_row - wd + dst_strd; |
321 | 0 | pu4_rgba_dst_next_row = pu4_rgba_dst_next_row + (dst_strd << 1) - wd; |
322 | 0 | } |
323 | |
|
324 | 0 | } |
325 | | |
326 | | /** |
327 | | ******************************************************************************* |
328 | | * |
329 | | * @brief Function used from copying a 420SP buffer |
330 | | * |
331 | | * @par Description |
332 | | * Function used from copying a 420SP buffer |
333 | | * |
334 | | * @param[in] pu1_y_src |
335 | | * Input Y pointer |
336 | | * |
337 | | * @param[in] pu1_uv_src |
338 | | * Input UV pointer (UV is interleaved either in UV or VU format) |
339 | | * |
340 | | * @param[in] pu1_y_dst |
341 | | * Output Y pointer |
342 | | * |
343 | | * @param[in] pu1_uv_dst |
344 | | * Output UV pointer (UV is interleaved in the same format as that of input) |
345 | | * |
346 | | * @param[in] wd |
347 | | * Width |
348 | | * |
349 | | * @param[in] ht |
350 | | * Height |
351 | | * |
352 | | * @param[in] src_y_strd |
353 | | * Input Y Stride |
354 | | * |
355 | | * @param[in] src_uv_strd |
356 | | * Input UV stride |
357 | | * |
358 | | * @param[in] dst_y_strd |
359 | | * Output Y stride |
360 | | * |
361 | | * @param[in] dst_uv_strd |
362 | | * Output UV stride |
363 | | * |
364 | | * @returns None |
365 | | * |
366 | | * @remarks In case there is a need to perform partial frame copy then |
367 | | * by passion appropriate source and destination pointers and appropriate |
368 | | * values for wd and ht it can be done |
369 | | * |
370 | | ******************************************************************************* |
371 | | */ |
372 | | |
373 | | void ih264d_fmt_conv_420sp_to_420sp(UWORD8 *pu1_y_src, |
374 | | UWORD8 *pu1_uv_src, |
375 | | UWORD8 *pu1_y_dst, |
376 | | UWORD8 *pu1_uv_dst, |
377 | | WORD32 wd, |
378 | | WORD32 ht, |
379 | | WORD32 src_y_strd, |
380 | | WORD32 src_uv_strd, |
381 | | WORD32 dst_y_strd, |
382 | | WORD32 dst_uv_strd) |
383 | 57.8k | { |
384 | 57.8k | UWORD8 *pu1_src, *pu1_dst; |
385 | 57.8k | WORD32 num_rows, num_cols, src_strd, dst_strd; |
386 | 57.8k | WORD32 i; |
387 | | |
388 | | /* copy luma */ |
389 | 57.8k | pu1_src = (UWORD8 *)pu1_y_src; |
390 | 57.8k | pu1_dst = (UWORD8 *)pu1_y_dst; |
391 | | |
392 | 57.8k | num_rows = ht; |
393 | 57.8k | num_cols = wd; |
394 | | |
395 | 57.8k | src_strd = src_y_strd; |
396 | 57.8k | dst_strd = dst_y_strd; |
397 | | |
398 | 3.02M | for(i = 0; i < num_rows; i++) |
399 | 2.96M | { |
400 | 2.96M | memcpy(pu1_dst, pu1_src, num_cols); |
401 | 2.96M | pu1_dst += dst_strd; |
402 | 2.96M | pu1_src += src_strd; |
403 | 2.96M | } |
404 | | |
405 | | /* copy U and V */ |
406 | 57.8k | pu1_src = (UWORD8 *)pu1_uv_src; |
407 | 57.8k | pu1_dst = (UWORD8 *)pu1_uv_dst; |
408 | | |
409 | 57.8k | num_rows = ht >> 1; |
410 | 57.8k | num_cols = wd; |
411 | | |
412 | 57.8k | src_strd = src_uv_strd; |
413 | 57.8k | dst_strd = dst_uv_strd; |
414 | | |
415 | 1.53M | for(i = 0; i < num_rows; i++) |
416 | 1.48M | { |
417 | 1.48M | memcpy(pu1_dst, pu1_src, num_cols); |
418 | 1.48M | pu1_dst += dst_strd; |
419 | 1.48M | pu1_src += src_strd; |
420 | 1.48M | } |
421 | 57.8k | return; |
422 | 57.8k | } |
423 | | |
424 | | /** |
425 | | ******************************************************************************* |
426 | | * |
427 | | * @brief Function used from copying a 420SP buffer |
428 | | * |
429 | | * @par Description |
430 | | * Function used from copying a 420SP buffer |
431 | | * |
432 | | * @param[in] pu1_y_src |
433 | | * Input Y pointer |
434 | | * |
435 | | * @param[in] pu1_uv_src |
436 | | * Input UV pointer (UV is interleaved either in UV or VU format) |
437 | | * |
438 | | * @param[in] pu1_y_dst |
439 | | * Output Y pointer |
440 | | * |
441 | | * @param[in] pu1_uv_dst |
442 | | * Output UV pointer (UV is interleaved in the same format as that of input) |
443 | | * |
444 | | * @param[in] wd |
445 | | * Width |
446 | | * |
447 | | * @param[in] ht |
448 | | * Height |
449 | | * |
450 | | * @param[in] src_y_strd |
451 | | * Input Y Stride |
452 | | * |
453 | | * @param[in] src_uv_strd |
454 | | * Input UV stride |
455 | | * |
456 | | * @param[in] dst_y_strd |
457 | | * Output Y stride |
458 | | * |
459 | | * @param[in] dst_uv_strd |
460 | | * Output UV stride |
461 | | * |
462 | | * @returns None |
463 | | * |
464 | | * @remarks In case there is a need to perform partial frame copy then |
465 | | * by passion appropriate source and destination pointers and appropriate |
466 | | * values for wd and ht it can be done |
467 | | * |
468 | | ******************************************************************************* |
469 | | */ |
470 | | void ih264d_fmt_conv_420sp_to_420sp_swap_uv(UWORD8 *pu1_y_src, |
471 | | UWORD8 *pu1_uv_src, |
472 | | UWORD8 *pu1_y_dst, |
473 | | UWORD8 *pu1_uv_dst, |
474 | | WORD32 wd, |
475 | | WORD32 ht, |
476 | | WORD32 src_y_strd, |
477 | | WORD32 src_uv_strd, |
478 | | WORD32 dst_y_strd, |
479 | | WORD32 dst_uv_strd) |
480 | 24.4k | { |
481 | 24.4k | UWORD8 *pu1_src, *pu1_dst; |
482 | 24.4k | WORD32 num_rows, num_cols, src_strd, dst_strd; |
483 | 24.4k | WORD32 i; |
484 | | |
485 | | /* copy luma */ |
486 | 24.4k | pu1_src = (UWORD8 *)pu1_y_src; |
487 | 24.4k | pu1_dst = (UWORD8 *)pu1_y_dst; |
488 | | |
489 | 24.4k | num_rows = ht; |
490 | 24.4k | num_cols = wd; |
491 | | |
492 | 24.4k | src_strd = src_y_strd; |
493 | 24.4k | dst_strd = dst_y_strd; |
494 | | |
495 | 2.16M | for(i = 0; i < num_rows; i++) |
496 | 2.14M | { |
497 | 2.14M | memcpy(pu1_dst, pu1_src, num_cols); |
498 | 2.14M | pu1_dst += dst_strd; |
499 | 2.14M | pu1_src += src_strd; |
500 | 2.14M | } |
501 | | |
502 | | /* copy U and V */ |
503 | 24.4k | pu1_src = (UWORD8 *)pu1_uv_src; |
504 | 24.4k | pu1_dst = (UWORD8 *)pu1_uv_dst; |
505 | | |
506 | 24.4k | num_rows = ht >> 1; |
507 | 24.4k | num_cols = wd; |
508 | | |
509 | 24.4k | src_strd = src_uv_strd; |
510 | 24.4k | dst_strd = dst_uv_strd; |
511 | | |
512 | 1.09M | for(i = 0; i < num_rows; i++) |
513 | 1.07M | { |
514 | 1.07M | WORD32 j; |
515 | 129M | for(j = 0; j < num_cols; j += 2) |
516 | 128M | { |
517 | 128M | pu1_dst[j + 0] = pu1_src[j + 1]; |
518 | 128M | pu1_dst[j + 1] = pu1_src[j + 0]; |
519 | 128M | } |
520 | 1.07M | pu1_dst += dst_strd; |
521 | 1.07M | pu1_src += src_strd; |
522 | 1.07M | } |
523 | 24.4k | return; |
524 | 24.4k | } |
525 | | /** |
526 | | ******************************************************************************* |
527 | | * |
528 | | * @brief Function used from copying a 420SP buffer |
529 | | * |
530 | | * @par Description |
531 | | * Function used from copying a 420SP buffer |
532 | | * |
533 | | * @param[in] pu1_y_src |
534 | | * Input Y pointer |
535 | | * |
536 | | * @param[in] pu1_uv_src |
537 | | * Input UV pointer (UV is interleaved either in UV or VU format) |
538 | | * |
539 | | * @param[in] pu1_y_dst |
540 | | * Output Y pointer |
541 | | * |
542 | | * @param[in] pu1_u_dst |
543 | | * Output U pointer |
544 | | * |
545 | | * @param[in] pu1_v_dst |
546 | | * Output V pointer |
547 | | * |
548 | | * @param[in] wd |
549 | | * Width |
550 | | * |
551 | | * @param[in] ht |
552 | | * Height |
553 | | * |
554 | | * @param[in] src_y_strd |
555 | | * Input Y Stride |
556 | | * |
557 | | * @param[in] src_uv_strd |
558 | | * Input UV stride |
559 | | * |
560 | | * @param[in] dst_y_strd |
561 | | * Output Y stride |
562 | | * |
563 | | * @param[in] dst_uv_strd |
564 | | * Output UV stride |
565 | | * |
566 | | * @param[in] is_u_first |
567 | | * Flag to indicate if U is the first byte in input chroma part |
568 | | * |
569 | | * @returns none |
570 | | * |
571 | | * @remarks In case there is a need to perform partial frame copy then |
572 | | * by passion appropriate source and destination pointers and appropriate |
573 | | * values for wd and ht it can be done |
574 | | * |
575 | | ******************************************************************************* |
576 | | */ |
577 | | |
578 | | void ih264d_fmt_conv_420sp_to_420p(UWORD8 *pu1_y_src, |
579 | | UWORD8 *pu1_uv_src, |
580 | | UWORD8 *pu1_y_dst, |
581 | | UWORD8 *pu1_u_dst, |
582 | | UWORD8 *pu1_v_dst, |
583 | | WORD32 wd, |
584 | | WORD32 ht, |
585 | | WORD32 src_y_strd, |
586 | | WORD32 src_uv_strd, |
587 | | WORD32 dst_y_strd, |
588 | | WORD32 dst_uv_strd, |
589 | | WORD32 is_u_first, |
590 | | WORD32 disable_luma_copy) |
591 | 187k | { |
592 | 187k | UWORD8 *pu1_src, *pu1_dst; |
593 | 187k | UWORD8 *pu1_u_src, *pu1_v_src; |
594 | 187k | WORD32 num_rows, num_cols, src_strd, dst_strd; |
595 | 187k | WORD32 i, j; |
596 | | |
597 | 187k | if(0 == disable_luma_copy) |
598 | 187k | { |
599 | | /* copy luma */ |
600 | 187k | pu1_src = (UWORD8 *)pu1_y_src; |
601 | 187k | pu1_dst = (UWORD8 *)pu1_y_dst; |
602 | | |
603 | 187k | num_rows = ht; |
604 | 187k | num_cols = wd; |
605 | | |
606 | 187k | src_strd = src_y_strd; |
607 | 187k | dst_strd = dst_y_strd; |
608 | | |
609 | 9.37M | for(i = 0; i < num_rows; i++) |
610 | 9.18M | { |
611 | 9.18M | memcpy(pu1_dst, pu1_src, num_cols); |
612 | 9.18M | pu1_dst += dst_strd; |
613 | 9.18M | pu1_src += src_strd; |
614 | 9.18M | } |
615 | 187k | } |
616 | | /* de-interleave U and V and copy to destination */ |
617 | 187k | if(is_u_first) |
618 | 187k | { |
619 | 187k | pu1_u_src = (UWORD8 *)pu1_uv_src; |
620 | 187k | pu1_v_src = (UWORD8 *)pu1_uv_src + 1; |
621 | 187k | } |
622 | 0 | else |
623 | 0 | { |
624 | 0 | pu1_u_src = (UWORD8 *)pu1_uv_src + 1; |
625 | 0 | pu1_v_src = (UWORD8 *)pu1_uv_src; |
626 | 0 | } |
627 | | |
628 | 187k | num_rows = ht >> 1; |
629 | 187k | num_cols = wd >> 1; |
630 | | |
631 | 187k | src_strd = src_uv_strd; |
632 | 187k | dst_strd = dst_uv_strd; |
633 | | |
634 | 4.77M | for(i = 0; i < num_rows; i++) |
635 | 4.59M | { |
636 | 546M | for(j = 0; j < num_cols; j++) |
637 | 542M | { |
638 | 542M | pu1_u_dst[j] = pu1_u_src[j * 2]; |
639 | 542M | pu1_v_dst[j] = pu1_v_src[j * 2]; |
640 | 542M | } |
641 | | |
642 | 4.59M | pu1_u_dst += dst_strd; |
643 | 4.59M | pu1_v_dst += dst_strd; |
644 | 4.59M | pu1_u_src += src_strd; |
645 | 4.59M | pu1_v_src += src_strd; |
646 | 4.59M | } |
647 | 187k | return; |
648 | 187k | } |
649 | | |
650 | | /*****************************************************************************/ |
651 | | /* Function Name : ih264d_format_convert */ |
652 | | /* */ |
653 | | /* Description : Implements format conversion/frame copy */ |
654 | | /* Inputs : ps_dec - Decoder parameters */ |
655 | | /* Globals : None */ |
656 | | /* Processing : Refer bumping process in the standard */ |
657 | | /* Outputs : Assigns display sequence number. */ |
658 | | /* Returns : None */ |
659 | | /* */ |
660 | | /* Issues : None */ |
661 | | /* */ |
662 | | /* Revision History: */ |
663 | | /* */ |
664 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
665 | | /* 27 04 2005 NS Draft */ |
666 | | /* */ |
667 | | /*****************************************************************************/ |
668 | | void ih264d_format_convert(dec_struct_t *ps_dec, |
669 | | ivd_get_display_frame_op_t *pv_disp_op, |
670 | | UWORD32 u4_start_y, |
671 | | UWORD32 u4_num_rows_y) |
672 | 357k | { |
673 | 357k | UWORD32 convert_uv_only = 0; |
674 | 357k | iv_yuv_buf_t *ps_op_frm; |
675 | 357k | UWORD8 *pu1_y_src, *pu1_uv_src; |
676 | 357k | UWORD32 start_uv = u4_start_y >> 1; |
677 | | |
678 | 357k | if(1 == pv_disp_op->u4_error_code) |
679 | 2 | return; |
680 | | |
681 | 357k | ps_op_frm = &(ps_dec->s_disp_frame_info); |
682 | | |
683 | | /* Requires u4_start_y and u4_num_rows_y to be even */ |
684 | 357k | if(u4_start_y & 1) |
685 | 0 | { |
686 | 0 | return; |
687 | 0 | } |
688 | | |
689 | 357k | if((1 == ps_dec->u4_share_disp_buf) && |
690 | 357k | (pv_disp_op->e_output_format == IV_YUV_420SP_UV)) |
691 | 0 | { |
692 | 0 | return; |
693 | 0 | } |
694 | | |
695 | 357k | pu1_y_src = (UWORD8 *)ps_op_frm->pv_y_buf; |
696 | 357k | pu1_y_src += u4_start_y * ps_op_frm->u4_y_strd, |
697 | | |
698 | 357k | pu1_uv_src = (UWORD8 *)ps_op_frm->pv_u_buf; |
699 | 357k | pu1_uv_src += start_uv * ps_op_frm->u4_u_strd; |
700 | | |
701 | 357k | if(pv_disp_op->e_output_format == IV_YUV_420P) |
702 | 117k | { |
703 | 117k | UWORD8 *pu1_y_dst, *pu1_u_dst, *pu1_v_dst; |
704 | 117k | IV_COLOR_FORMAT_T e_output_format = pv_disp_op->e_output_format; |
705 | | |
706 | 117k | if(0 == ps_dec->u4_share_disp_buf) |
707 | 117k | { |
708 | 117k | convert_uv_only = 0; |
709 | 117k | } |
710 | 0 | else |
711 | 0 | { |
712 | 0 | convert_uv_only = 1; |
713 | 0 | } |
714 | | |
715 | 117k | pu1_y_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf; |
716 | 117k | pu1_y_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd; |
717 | | |
718 | 117k | pu1_u_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_u_buf; |
719 | 117k | pu1_u_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_u_strd; |
720 | | |
721 | 117k | pu1_v_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_v_buf; |
722 | 117k | pu1_v_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_v_strd; |
723 | | |
724 | 117k | ih264d_fmt_conv_420sp_to_420p(pu1_y_src, |
725 | 117k | pu1_uv_src, |
726 | 117k | pu1_y_dst, |
727 | 117k | pu1_u_dst, |
728 | 117k | pu1_v_dst, |
729 | 117k | ps_op_frm->u4_y_wd, |
730 | 117k | u4_num_rows_y, |
731 | 117k | ps_op_frm->u4_y_strd, |
732 | 117k | ps_op_frm->u4_u_strd, |
733 | 117k | pv_disp_op->s_disp_frm_buf.u4_y_strd, |
734 | 117k | pv_disp_op->s_disp_frm_buf.u4_u_strd, |
735 | 117k | 1, |
736 | 117k | convert_uv_only); |
737 | | |
738 | 117k | } |
739 | 239k | else if((pv_disp_op->e_output_format == IV_YUV_420SP_UV) || |
740 | 239k | (pv_disp_op->e_output_format == IV_YUV_420SP_VU)) |
741 | 82.3k | { |
742 | 82.3k | UWORD8* pu1_y_dst, *pu1_uv_dst; |
743 | | |
744 | 82.3k | pu1_y_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf; |
745 | 82.3k | pu1_y_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd; |
746 | | |
747 | 82.3k | pu1_uv_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_u_buf; |
748 | 82.3k | pu1_uv_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_u_strd; |
749 | | |
750 | 82.3k | if(pv_disp_op->e_output_format == IV_YUV_420SP_UV) |
751 | 57.8k | { |
752 | 57.8k | ih264d_fmt_conv_420sp_to_420sp(pu1_y_src, |
753 | 57.8k | pu1_uv_src, |
754 | 57.8k | pu1_y_dst, |
755 | 57.8k | pu1_uv_dst, |
756 | 57.8k | ps_op_frm->u4_y_wd, |
757 | 57.8k | u4_num_rows_y, |
758 | 57.8k | ps_op_frm->u4_y_strd, |
759 | 57.8k | ps_op_frm->u4_u_strd, |
760 | 57.8k | pv_disp_op->s_disp_frm_buf.u4_y_strd, |
761 | 57.8k | pv_disp_op->s_disp_frm_buf.u4_u_strd); |
762 | 57.8k | } |
763 | 24.4k | else |
764 | 24.4k | { |
765 | 24.4k | ih264d_fmt_conv_420sp_to_420sp_swap_uv(pu1_y_src, |
766 | 24.4k | pu1_uv_src, |
767 | 24.4k | pu1_y_dst, |
768 | 24.4k | pu1_uv_dst, |
769 | 24.4k | ps_op_frm->u4_y_wd, |
770 | 24.4k | u4_num_rows_y, |
771 | 24.4k | ps_op_frm->u4_y_strd, |
772 | 24.4k | ps_op_frm->u4_u_strd, |
773 | 24.4k | pv_disp_op->s_disp_frm_buf.u4_y_strd, |
774 | 24.4k | pv_disp_op->s_disp_frm_buf.u4_u_strd); |
775 | 24.4k | } |
776 | 82.3k | } |
777 | 157k | else if(pv_disp_op->e_output_format == IV_RGB_565) |
778 | 15.4k | { |
779 | 15.4k | UWORD16 *pu2_rgb_dst; |
780 | | |
781 | 15.4k | pu2_rgb_dst = (UWORD16 *)pv_disp_op->s_disp_frm_buf.pv_y_buf; |
782 | 15.4k | pu2_rgb_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd; |
783 | | |
784 | 15.4k | ih264d_fmt_conv_420sp_to_rgb565(pu1_y_src, |
785 | 15.4k | pu1_uv_src, |
786 | 15.4k | pu2_rgb_dst, |
787 | 15.4k | ps_op_frm->u4_y_wd, |
788 | 15.4k | u4_num_rows_y, |
789 | 15.4k | ps_op_frm->u4_y_strd, |
790 | 15.4k | ps_op_frm->u4_u_strd, |
791 | 15.4k | pv_disp_op->s_disp_frm_buf.u4_y_strd, |
792 | 15.4k | 1); |
793 | 15.4k | } |
794 | | |
795 | 357k | if((u4_start_y + u4_num_rows_y) >= ps_dec->s_disp_frame_info.u4_y_ht) |
796 | 50.8k | { |
797 | | |
798 | 50.8k | INSERT_LOGO(pv_disp_op->s_disp_frm_buf.pv_y_buf, |
799 | 50.8k | pv_disp_op->s_disp_frm_buf.pv_u_buf, |
800 | 50.8k | pv_disp_op->s_disp_frm_buf.pv_v_buf, |
801 | 50.8k | pv_disp_op->s_disp_frm_buf.u4_y_strd, |
802 | 50.8k | ps_dec->u2_disp_width, |
803 | 50.8k | ps_dec->u2_disp_height, |
804 | 50.8k | pv_disp_op->e_output_format, |
805 | 50.8k | ps_op_frm->u4_y_wd, |
806 | 50.8k | ps_op_frm->u4_y_ht); |
807 | 50.8k | } |
808 | | |
809 | 357k | return; |
810 | 357k | } |