summaryrefslogtreecommitdiff
path: root/common/impeg2_inter_pred.c
blob: 019fa5c7812e3192d74ef52c60baf3354e22f41d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
/**
*******************************************************************************
* @file
*  impeg2d_mcu.c
*
* @brief
*  Contains MC function definitions for MPEG2 decoder
*
* @author
*  Harish
*
* @par List of Functions:
* - impeg2_copy_mb()
* - impeg2_interpolate()
* - impeg2_mc_halfx_halfy_8x8()
* - impeg2_mc_halfx_fully_8x8()
* - impeg2_mc_fullx_halfy_8x8()
* - impeg2_mc_fullx_fully_8x8()
*
* @remarks
*  None
*
*******************************************************************************
*/

#include <stdio.h>
#include <string.h>
#include "iv_datatypedef.h"
#include "iv.h"
#include "impeg2_buf_mgr.h"
#include "impeg2_disp_mgr.h"
#include "impeg2_defs.h"
#include "impeg2_platform_macros.h"

#include "impeg2_inter_pred.h"
#include "impeg2_globals.h"
#include "impeg2_macros.h"
#include "impeg2_idct.h"

/*******************************************************************************
*  Function Name   : impeg2_copy_mb
*
*  Description     : copies 3 components to the frame from mc_buf
*
*  Arguments       :
*  src_buf         : Source Buffer
*  dst_buf         : Destination Buffer
*  src_offset_x    : X offset for source
*  src_offset_y    : Y offset for source
*  dst_offset_x    : X offset for destination
*  dst_offset_y    : Y offset for destination
*  src_wd          : Source Width
*  dst_wd          : destination Width
*  rows            : Number of rows
*  cols            : Number of columns
*
*  Values Returned : None
*******************************************************************************/
void impeg2_copy_mb(yuv_buf_t *ps_src_buf,
                    yuv_buf_t *ps_dst_buf,
                    UWORD32 u4_src_wd,
                    UWORD32 u4_dst_wd)
{
    UWORD8 *pu1_src;
    UWORD8 *pu1_dst;
    UWORD32 i;
    UWORD32 u4_rows = MB_SIZE;
    UWORD32 u4_cols = MB_SIZE;

    /*******************************************************/
    /* copy Y                                              */
    /*******************************************************/
    pu1_src = ps_src_buf->pu1_y;
    pu1_dst = ps_dst_buf->pu1_y;
    for(i = 0; i < u4_rows; i++)
    {
        memcpy(pu1_dst, pu1_src, u4_cols);
        pu1_src += u4_src_wd;
        pu1_dst += u4_dst_wd;
    }

    u4_src_wd >>= 1;
    u4_dst_wd >>= 1;
    u4_rows >>= 1;
    u4_cols >>= 1;

    /*******************************************************/
    /* copy U                                              */
    /*******************************************************/
    pu1_src = ps_src_buf->pu1_u;
    pu1_dst = ps_dst_buf->pu1_u;
    for(i = 0; i < u4_rows; i++)
    {
        memcpy(pu1_dst, pu1_src, u4_cols);

        pu1_src += u4_src_wd;
        pu1_dst += u4_dst_wd;
    }
    /*******************************************************/
    /* copy V                                              */
    /*******************************************************/
    pu1_src = ps_src_buf->pu1_v;
    pu1_dst = ps_dst_buf->pu1_v;
    for(i = 0; i < u4_rows; i++)
    {
        memcpy(pu1_dst, pu1_src, u4_cols);

        pu1_src += u4_src_wd;
        pu1_dst += u4_dst_wd;
    }

}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : impeg2_interpolate                                       */
/*                                                                           */
/*  Description   : averages the contents of buf_src1 and buf_src2 and stores*/
/*                  result in buf_dst                                        */
/*                                                                           */
/*  Inputs        : buf_src1 -  First Source                                 */
/*                  buf_src2 -  Second Source                                */
/*                                                                           */
/*  Globals       : None                                                     */
/*                                                                           */
/*  Processing    : Avg the values from two sources and store the result in  */
/*                  destination buffer                                       */
/*                                                                           */
/*  Outputs       : buf_dst  -  Avg of contents of buf_src1 and buf_src2     */
/*                                                                           */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Issues        : Assumes that all 3 buffers are of same size              */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes                              */
/*         14 09 2005   Harish M        First Version                        */
/*         15 09 2010   Venkat          Added stride                         */
/*                                                                           */
/*****************************************************************************/
void impeg2_interpolate(yuv_buf_t *ps_buf_src1,
                        yuv_buf_t *ps_buf_src2,
                        yuv_buf_t *ps_buf_dst,
                        UWORD32 u4_stride)
{

    UWORD32 i,j;
    UWORD8 *pu1_src1,*pu1_src2,*pu1_dst;
    pu1_src1 = ps_buf_src1->pu1_y;
    pu1_src2 = ps_buf_src2->pu1_y;
    pu1_dst  = ps_buf_dst->pu1_y;
    for(i = MB_SIZE; i > 0; i--)
    {
        for(j = MB_SIZE; j > 0; j--)
        {
            *pu1_dst++ = ((*pu1_src1++) + (*pu1_src2++) + 1) >> 1;
        }

        pu1_dst += u4_stride - MB_SIZE;

    }

    u4_stride >>= 1;

    pu1_src1 = ps_buf_src1->pu1_u;
    pu1_src2 = ps_buf_src2->pu1_u;
    pu1_dst  = ps_buf_dst->pu1_u;
    for(i = MB_CHROMA_SIZE; i > 0 ; i--)
    {
        for(j = MB_CHROMA_SIZE; j > 0; j--)
        {
            *pu1_dst++ = ((*pu1_src1++) + (*pu1_src2++) + 1) >> 1;
        }

        pu1_dst += u4_stride - MB_CHROMA_SIZE;
    }

    pu1_src1 = ps_buf_src1->pu1_v;
    pu1_src2 = ps_buf_src2->pu1_v;
    pu1_dst  = ps_buf_dst->pu1_v;
    for(i = MB_CHROMA_SIZE; i > 0 ; i--)
    {
        for(j = MB_CHROMA_SIZE; j > 0; j--)
        {
            *pu1_dst++ = ((*pu1_src1++) + (*pu1_src2++) + 1) >> 1;
        }

        pu1_dst += u4_stride - MB_CHROMA_SIZE;
    }

}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : impeg2_mc_halfx_halfy_8x8()                                 */
/*                                                                           */
/*  Description   : Gets the buffer from (0.5,0.5) to (8.5,8.5)              */
/*                  and the above block of size 8 x 8 will be placed as a    */
/*                  block from the current position of out_buf               */
/*                                                                           */
/*  Inputs        : ref - Reference frame from which the block will be       */
/*                        block will be extracted.                           */
/*                  ref_wid - WIdth of reference frame                       */
/*                  out_wid - WIdth of the output frame                      */
/*                  blk_width  - width of the block                          */
/*                  blk_width  - height of the block                         */
/*                                                                           */
/*  Globals       : None                                                     */
/*                                                                           */
/*  Processing    : Point to the (0,0),(1,0),(0,1),(1,1) position in         */
/*                  the ref frame.Interpolate these four values to get the   */
/*                  value at(0.5,0.5).Repeat this to get an 8 x 8 block      */
/*                  using 9 x 9 block from reference frame                   */
/*                                                                           */
/*  Outputs       : out -  Output containing the extracted block             */
/*                                                                           */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Issues        : None                                                     */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes                              */
/*         05 09 2005   Harish M        First Version                        */
/*                                                                           */
/*****************************************************************************/
void impeg2_mc_halfx_halfy_8x8(UWORD8 *pu1_out,
                            UWORD8 *pu1_ref,
                            UWORD32 u4_ref_wid,
                            UWORD32 u4_out_wid)
{
    UWORD8 *pu1_ref_p0,*pu1_ref_p1,*pu1_ref_p2,*pu1_ref_p3;
    UWORD32 i,j;
    /* P0-P3 are the pixels in the reference frame and Q is the value being */
    /* estimated                                                            */
    /*
       P0 P1
         Q
       P2 P3
    */

    pu1_ref_p0 = pu1_ref;
    pu1_ref_p1 = pu1_ref + 1;
    pu1_ref_p2 = pu1_ref + u4_ref_wid;
    pu1_ref_p3 = pu1_ref + u4_ref_wid + 1;

    for(i = 0; i < BLK_SIZE; i++)
    {
        for(j = 0; j < BLK_SIZE; j++)
        {
            *pu1_out++ =   (( (*pu1_ref_p0++ )
                        + (*pu1_ref_p1++ )
                        + (*pu1_ref_p2++ )
                        + (*pu1_ref_p3++ ) + 2 ) >> 2);
        }
        pu1_ref_p0 += u4_ref_wid - BLK_SIZE;
        pu1_ref_p1 += u4_ref_wid - BLK_SIZE;
        pu1_ref_p2 += u4_ref_wid - BLK_SIZE;
        pu1_ref_p3 += u4_ref_wid - BLK_SIZE;

        pu1_out    += u4_out_wid - BLK_SIZE;
    }
    return;
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : impeg2_mc_halfx_fully_8x8()                                 */
/*                                                                           */
/*  Description   : Gets the buffer from (0.5,0) to (8.5,8)                  */
/*                  and the above block of size 8 x 8 will be placed as a    */
/*                  block from the current position of out_buf               */
/*                                                                           */
/*  Inputs        : ref - Reference frame from which the block will be       */
/*                        block will be extracted.                           */
/*                  ref_wid - WIdth of reference frame                       */
/*                  out_wid - WIdth of the output frame                      */
/*                  blk_width  - width of the block                          */
/*                  blk_width  - height of the block                         */
/*                                                                           */
/*  Globals       : None                                                     */
/*                                                                           */
/*  Processing    : Point to the (0,0) and (1,0) position in the ref frame   */
/*                  Interpolate these two values to get the value at(0.5,0)  */
/*                  Repeat this to get an 8 x 8 block using 9 x 8 block from */
/*                  reference frame                                          */
/*                                                                           */
/*  Outputs       : out -  Output containing the extracted block             */
/*                                                                           */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Issues        : None                                                     */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes                              */
/*         05 09 2005   Harish M        First Version                        */
/*                                                                           */
/*****************************************************************************/
void impeg2_mc_halfx_fully_8x8(UWORD8 *pu1_out,
                            UWORD8 *pu1_ref,
                            UWORD32 u4_ref_wid,
                            UWORD32 u4_out_wid)
{
    UWORD8 *pu1_ref_p0, *pu1_ref_p1;
    UWORD32 i,j;

    /* P0-P3 are the pixels in the reference frame and Q is the value being */
    /* estimated                                                            */
    /*
       P0 Q P1
    */

    pu1_ref_p0 = pu1_ref;
    pu1_ref_p1 = pu1_ref + 1;

    for(i = 0; i < BLK_SIZE; i++)
    {
        for(j = 0; j < BLK_SIZE; j++)
        {
            *pu1_out++ =   ((( *pu1_ref_p0++ )
                        + (*pu1_ref_p1++) + 1 ) >> 1);
        }
        pu1_ref_p0 += u4_ref_wid - BLK_SIZE;
        pu1_ref_p1 += u4_ref_wid - BLK_SIZE;

        pu1_out    += u4_out_wid - BLK_SIZE;
    }
    return;
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : impeg2_mc_fullx_halfy_8x8()                                 */
/*                                                                           */
/*  Description   : Gets the buffer from (0,0.5) to (8,8.5)                  */
/*                  and the above block of size 8 x 8 will be placed as a    */
/*                  block from the current position of out_buf               */
/*                                                                           */
/*  Inputs        : ref - Reference frame from which the block will be       */
/*                        block will be extracted.                           */
/*                  ref_wid - WIdth of reference frame                       */
/*                  out_wid - WIdth of the output frame                      */
/*                  blk_width  - width of the block                          */
/*                  blk_width  - height of the block                         */
/*                                                                           */
/*  Globals       : None                                                     */
/*                                                                           */
/*  Processing    : Point to the (0,0) and (0,1)   position in the ref frame */
/*                  Interpolate these two values to get the value at(0,0.5)  */
/*                  Repeat this to get an 8 x 8 block using 8 x 9 block from */
/*                  reference frame                                          */
/*                                                                           */
/*  Outputs       : out -  Output containing the extracted block             */
/*                                                                           */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Issues        : None                                                     */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes                              */
/*         05 09 2005   Harish M        First Version                        */
/*                                                                           */
/*****************************************************************************/
void impeg2_mc_fullx_halfy_8x8(UWORD8 *pu1_out,
                            UWORD8 *pu1_ref,
                            UWORD32 u4_ref_wid,
                            UWORD32 u4_out_wid)
{

    UWORD8 *pu1_ref_p0, *pu1_ref_p1;
    UWORD32 i,j;
    /* P0-P3 are the pixels in the reference frame and Q is the value being */
    /* estimated                                                            */
    /*
       P0
        x
       P1
    */
    pu1_ref_p0 = pu1_ref;
    pu1_ref_p1 = pu1_ref + u4_ref_wid;

    for(i = 0; i < BLK_SIZE; i++)
    {
        for(j = 0; j < BLK_SIZE; j++)
        {
            *pu1_out++ =   ((( *pu1_ref_p0++)
                        + (*pu1_ref_p1++) + 1 ) >> 1);
        }
        pu1_ref_p0 += u4_ref_wid - BLK_SIZE;
        pu1_ref_p1 += u4_ref_wid - BLK_SIZE;

        pu1_out    += u4_out_wid - BLK_SIZE;
    }

    return;
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : impeg2_mc_fullx_fully_8x8()                                 */
/*                                                                           */
/*  Description   : Gets the buffer from (x,y) to (x+8,y+8)                  */
/*                  and the above block of size 8 x 8 will be placed as a    */
/*                  block from the current position of out_buf               */
/*                                                                           */
/*  Inputs        : ref - Reference frame from which the block will be       */
/*                        block will be extracted.                           */
/*                  ref_wid - WIdth of reference frame                       */
/*                  out_wid - WIdth of the output frame                      */
/*                  blk_width  - width of the block                          */
/*                  blk_width  - height of the block                         */
/*                                                                           */
/*  Globals       : None                                                     */
/*                                                                           */
/*  Processing    : Point to the (0,0) position in the ref frame             */
/*                  Get an 8 x 8 block from reference frame                  */
/*                                                                           */
/*  Outputs       : out -  Output containing the extracted block             */
/*                                                                           */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Issues        : None                                                     */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes                              */
/*         05 09 2005   Harish M        First Version                        */
/*                                                                           */
/*****************************************************************************/
void impeg2_mc_fullx_fully_8x8(UWORD8 *pu1_out,
                            UWORD8 *pu1_ref,
                            UWORD32 u4_ref_wid,
                            UWORD32 u4_out_wid)
{

    UWORD32 i;

    for(i = 0; i < BLK_SIZE; i++)
    {
        memcpy(pu1_out, pu1_ref, BLK_SIZE);
        pu1_ref += u4_ref_wid;
        pu1_out += u4_out_wid;
    }
    return;
}