Coverage Report

Created: 2025-08-26 06:38

/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
4.42k
{
118
119
4.42k
    WORD16 i2_r, i2_g, i2_b;
120
4.42k
    UWORD32 u4_r, u4_g, u4_b;
121
4.42k
    WORD16 i2_i, i2_j;
122
4.42k
    UWORD8 *pu1_y_src_nxt;
123
4.42k
    UWORD16 *pu2_rgb_dst_next_row;
124
125
4.42k
    UWORD8 *pu1_u_src, *pu1_v_src;
126
127
4.42k
    if(is_u_first)
128
4.42k
    {
129
4.42k
        pu1_u_src = (UWORD8 *)pu1_uv_src;
130
4.42k
        pu1_v_src = (UWORD8 *)pu1_uv_src + 1;
131
4.42k
    }
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
4.42k
    pu1_y_src_nxt = pu1_y_src + src_y_strd;
139
4.42k
    pu2_rgb_dst_next_row = pu2_rgb_dst + dst_strd;
140
141
175k
    for(i2_i = 0; i2_i < (ht >> 1); i2_i++)
142
170k
    {
143
26.9M
        for(i2_j = (wd >> 1); i2_j > 0; i2_j--)
144
26.7M
        {
145
26.7M
            i2_b = ((*pu1_u_src - 128) * COEFF4 >> 13);
146
26.7M
            i2_g = ((*pu1_u_src - 128) * COEFF2 + (*pu1_v_src - 128) * COEFF3)
147
26.7M
                            >> 13;
148
26.7M
            i2_r = ((*pu1_v_src - 128) * COEFF1) >> 13;
149
150
26.7M
            pu1_u_src += 2;
151
26.7M
            pu1_v_src += 2;
152
            /* pixel 0 */
153
            /* B */
154
26.7M
            u4_b = CLIP_U8(*pu1_y_src + i2_b);
155
26.7M
            u4_b >>= 3;
156
            /* G */
157
26.7M
            u4_g = CLIP_U8(*pu1_y_src + i2_g);
158
26.7M
            u4_g >>= 2;
159
            /* R */
160
26.7M
            u4_r = CLIP_U8(*pu1_y_src + i2_r);
161
26.7M
            u4_r >>= 3;
162
163
26.7M
            pu1_y_src++;
164
26.7M
            *pu2_rgb_dst++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
165
166
            /* pixel 1 */
167
            /* B */
168
26.7M
            u4_b = CLIP_U8(*pu1_y_src + i2_b);
169
26.7M
            u4_b >>= 3;
170
            /* G */
171
26.7M
            u4_g = CLIP_U8(*pu1_y_src + i2_g);
172
26.7M
            u4_g >>= 2;
173
            /* R */
174
26.7M
            u4_r = CLIP_U8(*pu1_y_src + i2_r);
175
26.7M
            u4_r >>= 3;
176
177
26.7M
            pu1_y_src++;
178
26.7M
            *pu2_rgb_dst++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
179
180
            /* pixel 2 */
181
            /* B */
182
26.7M
            u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b);
183
26.7M
            u4_b >>= 3;
184
            /* G */
185
26.7M
            u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g);
186
26.7M
            u4_g >>= 2;
187
            /* R */
188
26.7M
            u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r);
189
26.7M
            u4_r >>= 3;
190
191
26.7M
            pu1_y_src_nxt++;
192
26.7M
            *pu2_rgb_dst_next_row++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
193
194
            /* pixel 3 */
195
            /* B */
196
26.7M
            u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b);
197
26.7M
            u4_b >>= 3;
198
            /* G */
199
26.7M
            u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g);
200
26.7M
            u4_g >>= 2;
201
            /* R */
202
26.7M
            u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r);
203
26.7M
            u4_r >>= 3;
204
205
26.7M
            pu1_y_src_nxt++;
206
26.7M
            *pu2_rgb_dst_next_row++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
207
208
26.7M
        }
209
210
170k
        pu1_u_src = pu1_u_src + src_uv_strd - wd;
211
170k
        pu1_v_src = pu1_v_src + src_uv_strd - wd;
212
213
170k
        pu1_y_src = pu1_y_src + (src_y_strd << 1) - wd;
214
170k
        pu1_y_src_nxt = pu1_y_src_nxt + (src_y_strd << 1) - wd;
215
216
170k
        pu2_rgb_dst = pu2_rgb_dst_next_row - wd + dst_strd;
217
170k
        pu2_rgb_dst_next_row = pu2_rgb_dst_next_row + (dst_strd << 1) - wd;
218
170k
    }
219
220
4.42k
}
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
35.6k
{
384
35.6k
    UWORD8 *pu1_src, *pu1_dst;
385
35.6k
    WORD32 num_rows, num_cols, src_strd, dst_strd;
386
35.6k
    WORD32 i;
387
388
    /* copy luma */
389
35.6k
    pu1_src = (UWORD8 *)pu1_y_src;
390
35.6k
    pu1_dst = (UWORD8 *)pu1_y_dst;
391
392
35.6k
    num_rows = ht;
393
35.6k
    num_cols = wd;
394
395
35.6k
    src_strd = src_y_strd;
396
35.6k
    dst_strd = dst_y_strd;
397
398
2.15M
    for(i = 0; i < num_rows; i++)
399
2.12M
    {
400
2.12M
        memcpy(pu1_dst, pu1_src, num_cols);
401
2.12M
        pu1_dst += dst_strd;
402
2.12M
        pu1_src += src_strd;
403
2.12M
    }
404
405
    /* copy U and V */
406
35.6k
    pu1_src = (UWORD8 *)pu1_uv_src;
407
35.6k
    pu1_dst = (UWORD8 *)pu1_uv_dst;
408
409
35.6k
    num_rows = ht >> 1;
410
35.6k
    num_cols = wd;
411
412
35.6k
    src_strd = src_uv_strd;
413
35.6k
    dst_strd = dst_uv_strd;
414
415
1.09M
    for(i = 0; i < num_rows; i++)
416
1.06M
    {
417
1.06M
        memcpy(pu1_dst, pu1_src, num_cols);
418
1.06M
        pu1_dst += dst_strd;
419
1.06M
        pu1_src += src_strd;
420
1.06M
    }
421
35.6k
    return;
422
35.6k
}
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
11.7k
{
481
11.7k
    UWORD8 *pu1_src, *pu1_dst;
482
11.7k
    WORD32 num_rows, num_cols, src_strd, dst_strd;
483
11.7k
    WORD32 i;
484
485
    /* copy luma */
486
11.7k
    pu1_src = (UWORD8 *)pu1_y_src;
487
11.7k
    pu1_dst = (UWORD8 *)pu1_y_dst;
488
489
11.7k
    num_rows = ht;
490
11.7k
    num_cols = wd;
491
492
11.7k
    src_strd = src_y_strd;
493
11.7k
    dst_strd = dst_y_strd;
494
495
1.76M
    for(i = 0; i < num_rows; i++)
496
1.75M
    {
497
1.75M
        memcpy(pu1_dst, pu1_src, num_cols);
498
1.75M
        pu1_dst += dst_strd;
499
1.75M
        pu1_src += src_strd;
500
1.75M
    }
501
502
    /* copy U and V */
503
11.7k
    pu1_src = (UWORD8 *)pu1_uv_src;
504
11.7k
    pu1_dst = (UWORD8 *)pu1_uv_dst;
505
506
11.7k
    num_rows = ht >> 1;
507
11.7k
    num_cols = wd;
508
509
11.7k
    src_strd = src_uv_strd;
510
11.7k
    dst_strd = dst_uv_strd;
511
512
889k
    for(i = 0; i < num_rows; i++)
513
877k
    {
514
877k
        WORD32 j;
515
88.4M
        for(j = 0; j < num_cols; j += 2)
516
87.5M
        {
517
87.5M
            pu1_dst[j + 0] = pu1_src[j + 1];
518
87.5M
            pu1_dst[j + 1] = pu1_src[j + 0];
519
87.5M
        }
520
877k
        pu1_dst += dst_strd;
521
877k
        pu1_src += src_strd;
522
877k
    }
523
11.7k
    return;
524
11.7k
}
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
153k
{
592
153k
    UWORD8 *pu1_src, *pu1_dst;
593
153k
    UWORD8 *pu1_u_src, *pu1_v_src;
594
153k
    WORD32 num_rows, num_cols, src_strd, dst_strd;
595
153k
    WORD32 i, j;
596
597
153k
    if(0 == disable_luma_copy)
598
153k
    {
599
        /* copy luma */
600
153k
        pu1_src = (UWORD8 *)pu1_y_src;
601
153k
        pu1_dst = (UWORD8 *)pu1_y_dst;
602
603
153k
        num_rows = ht;
604
153k
        num_cols = wd;
605
606
153k
        src_strd = src_y_strd;
607
153k
        dst_strd = dst_y_strd;
608
609
6.31M
        for(i = 0; i < num_rows; i++)
610
6.16M
        {
611
6.16M
            memcpy(pu1_dst, pu1_src, num_cols);
612
6.16M
            pu1_dst += dst_strd;
613
6.16M
            pu1_src += src_strd;
614
6.16M
        }
615
153k
    }
616
    /* de-interleave U and V and copy to destination */
617
153k
    if(is_u_first)
618
153k
    {
619
153k
        pu1_u_src = (UWORD8 *)pu1_uv_src;
620
153k
        pu1_v_src = (UWORD8 *)pu1_uv_src + 1;
621
153k
    }
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
153k
    num_rows = ht >> 1;
629
153k
    num_cols = wd >> 1;
630
631
153k
    src_strd = src_uv_strd;
632
153k
    dst_strd = dst_uv_strd;
633
634
3.23M
    for(i = 0; i < num_rows; i++)
635
3.08M
    {
636
335M
        for(j = 0; j < num_cols; j++)
637
332M
        {
638
332M
            pu1_u_dst[j] = pu1_u_src[j * 2];
639
332M
            pu1_v_dst[j] = pu1_v_src[j * 2];
640
332M
        }
641
642
3.08M
        pu1_u_dst += dst_strd;
643
3.08M
        pu1_v_dst += dst_strd;
644
3.08M
        pu1_u_src += src_strd;
645
3.08M
        pu1_v_src += src_strd;
646
3.08M
    }
647
153k
    return;
648
153k
}
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
172k
{
673
172k
    UWORD32 convert_uv_only = 0;
674
172k
    iv_yuv_buf_t *ps_op_frm;
675
172k
    UWORD8 *pu1_y_src, *pu1_uv_src;
676
172k
    UWORD32 start_uv = u4_start_y >> 1;
677
678
172k
    if(1 == pv_disp_op->u4_error_code)
679
1
        return;
680
681
172k
    ps_op_frm = &(ps_dec->s_disp_frame_info);
682
683
    /* Requires u4_start_y and u4_num_rows_y to be even */
684
172k
    if(u4_start_y & 1)
685
0
    {
686
0
        return;
687
0
    }
688
689
172k
    if((1 == ps_dec->u4_share_disp_buf) &&
690
172k
       (pv_disp_op->e_output_format == IV_YUV_420SP_UV))
691
0
    {
692
0
        return;
693
0
    }
694
695
172k
    pu1_y_src = (UWORD8 *)ps_op_frm->pv_y_buf;
696
172k
    pu1_y_src += u4_start_y * ps_op_frm->u4_y_strd,
697
698
172k
    pu1_uv_src = (UWORD8 *)ps_op_frm->pv_u_buf;
699
172k
    pu1_uv_src += start_uv * ps_op_frm->u4_u_strd;
700
701
172k
    if(pv_disp_op->e_output_format == IV_YUV_420P)
702
79.9k
    {
703
79.9k
        UWORD8 *pu1_y_dst, *pu1_u_dst, *pu1_v_dst;
704
79.9k
        IV_COLOR_FORMAT_T e_output_format = pv_disp_op->e_output_format;
705
706
79.9k
        if(0 == ps_dec->u4_share_disp_buf)
707
79.9k
        {
708
79.9k
            convert_uv_only = 0;
709
79.9k
        }
710
0
        else
711
0
        {
712
0
            convert_uv_only = 1;
713
0
        }
714
715
79.9k
        pu1_y_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf;
716
79.9k
        pu1_y_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd;
717
718
79.9k
        pu1_u_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_u_buf;
719
79.9k
        pu1_u_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_u_strd;
720
721
79.9k
        pu1_v_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_v_buf;
722
79.9k
        pu1_v_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_v_strd;
723
724
79.9k
        ih264d_fmt_conv_420sp_to_420p(pu1_y_src,
725
79.9k
                                      pu1_uv_src,
726
79.9k
                                      pu1_y_dst,
727
79.9k
                                      pu1_u_dst,
728
79.9k
                                      pu1_v_dst,
729
79.9k
                                      ps_op_frm->u4_y_wd,
730
79.9k
                                      u4_num_rows_y,
731
79.9k
                                      ps_op_frm->u4_y_strd,
732
79.9k
                                      ps_op_frm->u4_u_strd,
733
79.9k
                                      pv_disp_op->s_disp_frm_buf.u4_y_strd,
734
79.9k
                                      pv_disp_op->s_disp_frm_buf.u4_u_strd,
735
79.9k
                                      1,
736
79.9k
                                      convert_uv_only);
737
738
79.9k
    }
739
92.5k
    else if((pv_disp_op->e_output_format == IV_YUV_420SP_UV) ||
740
92.5k
            (pv_disp_op->e_output_format == IV_YUV_420SP_VU))
741
47.4k
    {
742
47.4k
        UWORD8* pu1_y_dst, *pu1_uv_dst;
743
744
47.4k
        pu1_y_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf;
745
47.4k
        pu1_y_dst +=  u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd;
746
747
47.4k
        pu1_uv_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_u_buf;
748
47.4k
        pu1_uv_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_u_strd;
749
750
47.4k
        if(pv_disp_op->e_output_format == IV_YUV_420SP_UV)
751
35.6k
        {
752
35.6k
            ih264d_fmt_conv_420sp_to_420sp(pu1_y_src,
753
35.6k
                                           pu1_uv_src,
754
35.6k
                                           pu1_y_dst,
755
35.6k
                                           pu1_uv_dst,
756
35.6k
                                           ps_op_frm->u4_y_wd,
757
35.6k
                                           u4_num_rows_y,
758
35.6k
                                           ps_op_frm->u4_y_strd,
759
35.6k
                                           ps_op_frm->u4_u_strd,
760
35.6k
                                           pv_disp_op->s_disp_frm_buf.u4_y_strd,
761
35.6k
                                           pv_disp_op->s_disp_frm_buf.u4_u_strd);
762
35.6k
        }
763
11.7k
        else
764
11.7k
        {
765
11.7k
            ih264d_fmt_conv_420sp_to_420sp_swap_uv(pu1_y_src,
766
11.7k
                                                   pu1_uv_src,
767
11.7k
                                                   pu1_y_dst,
768
11.7k
                                                   pu1_uv_dst,
769
11.7k
                                                   ps_op_frm->u4_y_wd,
770
11.7k
                                                   u4_num_rows_y,
771
11.7k
                                                   ps_op_frm->u4_y_strd,
772
11.7k
                                                   ps_op_frm->u4_u_strd,
773
11.7k
                                                   pv_disp_op->s_disp_frm_buf.u4_y_strd,
774
11.7k
                                                   pv_disp_op->s_disp_frm_buf.u4_u_strd);
775
11.7k
        }
776
47.4k
    }
777
45.0k
    else if(pv_disp_op->e_output_format == IV_RGB_565)
778
4.42k
    {
779
4.42k
        UWORD16 *pu2_rgb_dst;
780
781
4.42k
        pu2_rgb_dst = (UWORD16 *)pv_disp_op->s_disp_frm_buf.pv_y_buf;
782
4.42k
        pu2_rgb_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd;
783
784
4.42k
        ih264d_fmt_conv_420sp_to_rgb565(pu1_y_src,
785
4.42k
                                        pu1_uv_src,
786
4.42k
                                        pu2_rgb_dst,
787
4.42k
                                        ps_op_frm->u4_y_wd,
788
4.42k
                                        u4_num_rows_y,
789
4.42k
                                        ps_op_frm->u4_y_strd,
790
4.42k
                                        ps_op_frm->u4_u_strd,
791
4.42k
                                        pv_disp_op->s_disp_frm_buf.u4_y_strd,
792
4.42k
                                        1);
793
4.42k
    }
794
795
172k
    if((u4_start_y + u4_num_rows_y) >= ps_dec->s_disp_frame_info.u4_y_ht)
796
29.5k
    {
797
798
29.5k
        INSERT_LOGO(pv_disp_op->s_disp_frm_buf.pv_y_buf,
799
29.5k
                        pv_disp_op->s_disp_frm_buf.pv_u_buf,
800
29.5k
                        pv_disp_op->s_disp_frm_buf.pv_v_buf,
801
29.5k
                        pv_disp_op->s_disp_frm_buf.u4_y_strd,
802
29.5k
                        ps_dec->u2_disp_width,
803
29.5k
                        ps_dec->u2_disp_height,
804
29.5k
                        pv_disp_op->e_output_format,
805
29.5k
                        ps_op_frm->u4_y_wd,
806
29.5k
                        ps_op_frm->u4_y_ht);
807
29.5k
    }
808
809
172k
    return;
810
172k
}