summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MCReconBlock.c
blob: 7b3faeeb4973cd08ce0d1e6d2d07cf6591064454 (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
/**
 * 
 * File Name:  omxVCM4P2_MCReconBlock.c
 * OpenMAX DL: v1.0.2
 * Revision:   9641
 * Date:       Thursday, February 7, 2008
 * 
 * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
 * 
 * 
 * Description:
 * MPEG4 motion compensation prediction for an 8x8 block using 
 * interpolation
 * 
 */
 
#include "omxtypes.h"
#include "armOMX.h"
#include "omxVC.h"

#include "armCOMM.h"

/**
 * Function: armVCM4P2_HalfPelVer
 *
 * Description:
 * Performs half pel motion compensation for an 8x8 block using vertical 
 * interpolation described in ISO/IEC 14496-2, subclause 7.6.2.
 *
 * Remarks:
 *
 * Parameters:
 * [in] pSrc        pointer to the block in the reference plane.
 * [in] srcStep     distance between the start of consecutive lines
 *                  in the reference plane, in bytes; must be a multiple
 *                  of 8.
 * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
 * [out] pDst       pointer to the linaer 8x8 destination buffer;
 *
 */
static OMXVoid armVCM4P2_HalfPelVer(
      const OMX_U8 *pSrc,
      OMX_INT srcStep, 
      OMX_U8 *pDst,
      OMX_INT rndVal)
{
  const OMX_U8 *pTempSrc1;
  const OMX_U8 *pTempSrc2;
  OMX_INT y, x;
  
  pTempSrc1 = pSrc;  
  pTempSrc2 = pSrc + srcStep;
  srcStep -= 8;
  for (y = 0; y < 8; y++)
  {
    for (x = 0; x < 8; x++)
    {
      *pDst++ = ((*pTempSrc1++ + *pTempSrc2++) + 1 - rndVal) >> 1;
    }
    pTempSrc1 += srcStep;
    pTempSrc2 += srcStep;
  }
}

/**
 * Function: armVCM4P2_HalfPelHor
 *
 * Description:
 * Performs half pel motion compensation for an 8x8 block using horizontal 
 * interpolation described in ISO/IEC 14496-2, subclause 7.6.2.
 *
 * Remarks:
 *
 * Parameters:
 * [in] pSrc        pointer to the block in the reference plane.
 * [in] srcStep     distance between the start of consecutive lines
 *                  in the reference plane, in bytes; must be a multiple
 *                  of 8.
 * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
 * [out] pDst       pointer to the linaer 8x8 destination buffer;
 *
 */
static OMXVoid armVCM4P2_HalfPelHor(
      const OMX_U8 *pSrc,
      OMX_INT srcStep, 
      OMX_U8 *pDst,
      OMX_INT rndVal)
{
  const OMX_U8 *pTempSrc1;
  const OMX_U8 *pTempSrc2;
  OMX_INT y, x;
  
  pTempSrc1 = pSrc;
  pTempSrc2 = pTempSrc1 + 1;

  srcStep -= 8;
  for (y=0; y<8; y++)
  {
    for (x=0; x<8; x++)
    {
      *pDst++ = ((*pTempSrc1++ + *pTempSrc2++) + 1 - rndVal) >> 1;
    }
    pTempSrc1 += srcStep;
    pTempSrc2 += srcStep;
  }
}


/**
 * Function: armVCM4P2_HalfPelVerHor
 *
 * Description:
 * Performs half pel motion compensation for an 8x8 block using both 
 * horizontal and vertical interpolation described in ISO/IEC 14496-2,
 * subclause 7.6.2.
 *
 * Remarks:
 *
 * Parameters:
 * [in] pSrc        pointer to the block in the reference plane.
 * [in] srcStep     distance between the start of consecutive lines
 *                  in the reference plane, in bytes; must be a multiple
 *                  of 8.
 * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
 * [out] pDst       pointer to the linaer 8x8 destination buffer;
 *
 */
static OMXVoid armVCM4P2_HalfPelVerHor(
      const OMX_U8 *pSrc,
      OMX_INT srcStep, 
      OMX_U8 *pDst,
      OMX_INT rndVal)
{
  const OMX_U8 *pTempSrc1;
  const OMX_U8 *pTempSrc2;
  const OMX_U8 *pTempSrc3;
  const OMX_U8 *pTempSrc4;
  OMX_INT y, x;

  pTempSrc1 = pSrc;
  pTempSrc2 = pSrc + srcStep;
  pTempSrc3 = pSrc + 1;
  pTempSrc4 = pSrc + srcStep + 1;

  srcStep -= 8;
  for (y=0; y<8; y++)
  {
    for (x=0; x<8; x++)
	{
	  *pDst++ = ((*pTempSrc1++ + *pTempSrc2++ + *pTempSrc3++ + *pTempSrc4++) + 
	                  2 - rndVal) >> 2;
	}
    pTempSrc1 += srcStep;
    pTempSrc2 += srcStep;
    pTempSrc3 += srcStep;
    pTempSrc4 += srcStep;
  }
}

/**
 * Function: armVCM4P2_MCReconBlock_NoRes
 *
 * Description:
 * Do motion compensation and copy the result to the current block.
 *
 * Remarks:
 *
 * Parameters:
 * [in] pSrc        pointer to the block in the reference plane.
 * [in] srcStep     distance between the start of consecutive lines
 *                  in the reference plane, in bytes; must be a multiple
 *                  of 8.
 * [in] dstStep     distance between the start of consecutive lines in the
 *                  destination plane, in bytes; must be a multiple of 8.
 * [in] predictType bilinear interpolation type, as defined in section 6.2.1.2.
 * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
 * [out] pDst       pointer to the destination buffer; must be 8-byte aligned.
 *                  If prediction residuals are added then output intensities
 *                  are clipped to the range [0,255].
 *
 */
static OMXVoid armVCM4P2_MCReconBlock_NoRes(
      const OMX_U8 *pSrc, 
      OMX_INT srcStep,
      OMX_U8 *pDst,
      OMX_INT dstStep)
{
    OMX_U8 x,y,count,index;
    
    /* Copying the ref 8x8 blk to the curr blk */
    for (y = 0, count = 0, index = 0; y < 8; y++,index += (srcStep -8), count += (dstStep - 8))
    {
        for (x = 0; x < 8; x++, count++,index++)
        {
            pDst[count] = pSrc[index];
        }       
    }
}

/**
 * Function: armVCM4P2_MCReconBlock_Res
 *
 * Description:
 * Reconstructs INTER block by summing the motion compensation results
 * and the results of the inverse transformation (prediction residuals).
 * Output intensities are clipped to the range [0,255].
 *
 * Remarks:
 *
 * Parameters:
 * [in] pSrc        pointer to the block in the reference plane.
 * [in] pSrcResidue pointer to a buffer containing the 16-bit prediction
 *                  residuals. If the pointer is NULL,then no prediction
 *                  is done, only motion compensation, i.e., the block is
 *                  moved with interpolation.
 * [in] dstStep     distance between the start of consecutive lines in the
 *                  destination plane, in bytes; must be a multiple of 8.
 * [out] pDst       pointer to the destination buffer; must be 8-byte aligned.
 *                  If prediction residuals are added then output intensities
 *                  are clipped to the range [0,255].
 *
 */
static OMXVoid armVCM4P2_MCReconBlock_Res(
      const OMX_U8 *pSrc, 
      const OMX_S16 *pSrcResidue,
      OMX_U8 *pDst,
      OMX_INT dstStep)
{
      
  OMX_U8 x,y;
  OMX_INT temp;
  
  for(y = 0; y < 8; y++)
  {
    for(x = 0; x < 8; x++)
    {
      temp = pSrc[x] + pSrcResidue[x];         
      pDst[x] = armClip(0,255,temp);
    }
    pDst += dstStep;
    pSrc += 8;
    pSrcResidue += 8;
  }
}

/**
 * Function:  omxVCM4P2_MCReconBlock   (6.2.5.5.1)
 *
 * Description:
 * Performs motion compensation prediction for an 8x8 block using 
 * interpolation described in [ISO14496-2], subclause 7.6.2. 
 *
 * Input Arguments:
 *   
 *   pSrc - pointer to the block in the reference plane. 
 *   srcStep - distance between the start of consecutive lines in the 
 *            reference plane, in bytes; must be a multiple of 8. 
 *   dstStep - distance between the start of consecutive lines in the 
 *            destination plane, in bytes; must be a multiple of 8. 
 *   pSrcResidue - pointer to a buffer containing the 16-bit prediction 
 *            residuals; must be 16-byte aligned. If the pointer is NULL, then 
 *            no prediction is done, only motion compensation, i.e., the block 
 *            is moved with interpolation. 
 *   predictType - bilinear interpolation type, as defined in section 
 *            6.2.1.2. 
 *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
 *
 * Output Arguments:
 *   
 *   pDst - pointer to the destination buffer; must be 8-byte aligned.  If 
 *            prediction residuals are added then output intensities are 
 *            clipped to the range [0,255]. 
 *
 * Return Value:
 *    
 *    OMX_Sts_NoErr - no error 
 *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
 *              conditions: 
 *    -    pDst is not 8-byte aligned. 
 *    -    pSrcResidue is not 16-byte aligned. 
 *    -    one or more of the following pointers is NULL: pSrc or pDst. 
 *    -    either srcStep or dstStep is not a multiple of 8. 
 *    -    invalid type specified for the parameter predictType. 
 *    -    the parameter rndVal is not equal either to 0 or 1. 
 *
 */
OMXResult omxVCM4P2_MCReconBlock(
		const OMX_U8 *pSrc,
		OMX_INT srcStep,
		const OMX_S16 *pSrcResidue,
		OMX_U8 *pDst, 
		OMX_INT dstStep,
		OMX_INT predictType,
		OMX_INT rndVal)
{
    /* Definitions and Initializations*/
    OMX_U8 pTempDst[64];
    
    /* Argument error checks */
    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
    armRetArgErrIf(!armIs16ByteAligned(pSrcResidue), OMX_Sts_BadArgErr);
    armRetArgErrIf(((dstStep % 8) || (srcStep % 8)), OMX_Sts_BadArgErr);
    armRetArgErrIf(((predictType != OMX_VC_INTEGER_PIXEL) &&
                    (predictType != OMX_VC_HALF_PIXEL_X) &&
                    (predictType != OMX_VC_HALF_PIXEL_Y) &&
                    (predictType != OMX_VC_HALF_PIXEL_XY)
                   ),OMX_Sts_BadArgErr); 
    armRetArgErrIf(((rndVal != 0) && (rndVal != 1)),OMX_Sts_BadArgErr);
    
    switch(predictType)
    {
        case OMX_VC_INTEGER_PIXEL:
                                   armVCM4P2_MCReconBlock_NoRes(pSrc,
                                                                    srcStep,
                                                                    &(pTempDst[0]),
                                                                    8);
                                   break;
        case OMX_VC_HALF_PIXEL_X:
                                   armVCM4P2_HalfPelHor(pSrc,
                                                            srcStep,
                                                            &(pTempDst[0]),
                                                            rndVal);
                                   break;
        case OMX_VC_HALF_PIXEL_Y:
                                   armVCM4P2_HalfPelVer(pSrc,
                                                            srcStep,
                                                            &(pTempDst[0]),
                                                            rndVal);
                                   break;
        case OMX_VC_HALF_PIXEL_XY:
                                   armVCM4P2_HalfPelVerHor(pSrc,
                                                            srcStep,
                                                            &(pTempDst[0]),
                                                            rndVal);
                                   break;
    }
    
    if(pSrcResidue == NULL)
    {
      armVCM4P2_MCReconBlock_NoRes(&(pTempDst[0]),
                                         8,
                                         pDst,
                                         dstStep);    
    }
    else
    {
      armVCM4P2_MCReconBlock_Res(&(pTempDst[0]),
                                          pSrcResidue,
                                          pDst,
                                          dstStep);    
    }
    
    return OMX_Sts_NoErr;
}