summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/m4v_h263/dec/src/pp_semaphore_luma.cpp
blob: b3a1ebddb14a8a3986a40a35dd9492f906cc6580 (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
/* ------------------------------------------------------------------
 * Copyright (C) 1998-2009 PacketVideo
 *
 * 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.
 * -------------------------------------------------------------------
 */
/*
------------------------------------------------------------------------------
 INPUT AND OUTPUT DEFINITIONS

 Inputs:
    xpred = x-axis coordinate of the MB used for prediction (int)
    ypred = y-axis coordinate of the MB used for prediction (int)
    pp_dec_y = pointer to the post processing semaphore for current
           luminance frame (uint8)
    pstprcTypPrv = pointer the previous frame's post processing type
                   (uint8)
    ll = pointer to the buffer (int)
    mv_loc = flag indicating location of the motion compensated
         (x,y) position with respect to the luminance MB (int);
         0 -> inside MB, 1 -> outside MB
    dx = horizontal component of the motion vector (int)
    dy = vertical component of the motion vector (int)
    mvwidth = number of blocks per row (int)
    width = luminance VOP width in pixels (int)
    height = luminance VOP height in pixels (int)

 Local Stores/Buffers/Pointers Needed:
    None

 Global Stores/Buffers/Pointers Needed:
    None

 Outputs:
    msk_deblock = flag that indicates whether deblocking is to be
              performed (msk_deblock = 0) or not (msk_deblock =
              1) (uint8)

 Pointers and Buffers Modified:
    pp_dec_y contents are the updated semapohore propagation data

 Local Stores Modified:
    None

 Global Stores Modified:
    None

------------------------------------------------------------------------------
 FUNCTION DESCRIPTION

 This functions performs post processing semaphore propagation processing
 after luminance prediction.

*/


/*----------------------------------------------------------------------------
; INCLUDES
----------------------------------------------------------------------------*/
#include    "mp4dec_api.h"
#include    "mp4def.h"

/*----------------------------------------------------------------------------
; MACROS
; Define module specific macros here
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; DEFINES
; Include all pre-processor statements here. Include conditional
; compile variables also.
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL FUNCTION DEFINITIONS
; Function Prototype declaration
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
; Variable declaration - defined here and used outside this module
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; EXTERNAL FUNCTION REFERENCES
; Declare functions defined elsewhere and referenced in this module
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
; Declare variables used in this module but defined elsewhere
----------------------------------------------------------------------------*/
#ifdef PV_POSTPROC_ON
#ifdef __cplusplus
extern "C"
{
#endif
    /*----------------------------------------------------------------------------
    ; FUNCTION CODE
    ----------------------------------------------------------------------------*/
    uint8 pp_semaphore_luma(
        int xpred,      /* i */
        int ypred,      /* i */
        uint8   *pp_dec_y,  /* i/o */
        uint8   *pstprcTypPrv,  /* i */
        int *ll,        /* i */
        int *mv_loc,    /* i/o */
        int dx,     /* i */
        int dy,     /* i */
        int mvwidth,    /* i */
        int width,      /* i */
        int height      /* i */
    )
    {
        /*----------------------------------------------------------------------------
        ; Define all local variables
        ----------------------------------------------------------------------------*/
        int kk, mmvy, mmvx, nmvx, nmvy;
        uint8   *pp_prev1, *pp_prev2, *pp_prev3, *pp_prev4;
        uint8   msk_deblock = 0;        /*  11/3/00 */

        /*----------------------------------------------------------------------------
        ; Function body here
        ----------------------------------------------------------------------------*/
        /* Interframe Processing - 1 MV per MB */

        /* check whether the MV points outside the frame */
        if (xpred >= 0 && xpred <= ((width << 1) - (2*MB_SIZE)) && ypred >= 0 &&
                ypred <= ((height << 1) - (2*MB_SIZE)))
        {   /*****************************/
            /* (x,y) is inside the frame */
            /*****************************/

            /*  10/24/2000 post_processing semaphore */
            /* generation */

            /*  10/23/2000 no boundary checking*/
            *mv_loc = 0;

            /* Calculate block x coordinate. Divide by 16 is for  */
            /* converting half-pixel resolution to block          */
            mmvx = xpred >> 4;

            /* Calculate block y coordinate. Divide by 16 is for */
            /* converting half-pixel resolution to block         */
            mmvy = ypred >> 4;

            /* Find post processing semaphore location for block */
            /* used for prediction, i.e.,                */
            /* pp_prev1 = &pstprcTypPrv[mmvy*mvwidth][mmvx]      */
            pp_prev1 = pstprcTypPrv + mmvx + mmvy * mvwidth;

            /* Check if MV is a multiple of 16 */
            if ((dx&0xF) != 0)
            {   /* dx is not a multiple of 16 */

                /* pp_prev2 is the block to the right of */
                /* pp_prev1 block            */
                pp_prev2 = pp_prev1 + 1;

                if ((dy&0xF) != 0)
                {   /* dy is not a multiple of 16 */

                    /* pp_prev3 is the block below */
                    /* pp_prev1 block          */
                    pp_prev3 = pp_prev1 + mvwidth;
                }
                else
                {   /* dy is a multiple of 16 */

                    pp_prev3 = pp_prev1;
                }

                /* pp_prev4 is the block to the right of */
                /* pp_prev3 block.           */
                pp_prev4 = pp_prev3 + 1;
            }
            else
            {   /* dx is a multiple of 16 */

                pp_prev2 = pp_prev1;

                if ((dy&0xF) != 0)
                {   /* dy is not a multiple of 16 */

                    /* pp_prev3 is the block below */
                    /* pp_prev1 block.         */
                    pp_prev3 = pp_prev1 + mvwidth;
                }
                else
                {   /* dy is a multiple of 16 */

                    pp_prev3 = pp_prev1;
                    msk_deblock = 0x3;
                }

                pp_prev4 = pp_prev3;
            }

            /* Perform post processing semaphore propagation for each */
            /* of the 4 blocks in a MB.               */
            for (kk = 0; kk < 4; kk++)
            {
                /* Deringing semaphore propagation */
                if ((*(pp_dec_y) & 4) == 0)
                {
                    *(pp_dec_y) |= ((*(pp_prev1) | *(pp_prev2) |
                                     *(pp_prev3) | *(pp_prev4)) & 0x4);
                }
                /* Deblocking semaphore propagation */
                /*  11/3/00, change the propagation for deblocking */
                if (msk_deblock == 0)
                {
                    *(pp_dec_y) = 0;
                }

                pp_dec_y += ll[kk];
                pp_prev1 += ll[kk];
                pp_prev2 += ll[kk];
                pp_prev3 += ll[kk];
                pp_prev4 += ll[kk];
            }

        }
        else
        {   /******************************/
            /* (x,y) is outside the frame */
            /******************************/

            /*  10/24/2000 post_processing semaphore */
            /* generation */

            /*  10/23/2000 boundary checking*/
            *mv_loc = 1;

            /* Perform post processing semaphore propagation for each */
            /* of the 4 blocks in a MB.               */
            for (kk = 0; kk < 4; kk++)
            {
                /* Calculate block x coordinate and round (?).  */
                /* Divide by 16 is for converting half-pixel    */
                /* resolution to block.             */
                mmvx = (xpred + ((kk & 1) << 3)) >> 4;
                nmvx = mmvx;

                /* Calculate block y coordinate and round (?).  */
                /* Divide by 16 is for converting half-pixel    */
                /* resolution to block.             */
                mmvy = (ypred + ((kk & 2) << 2)) >> 4;
                nmvy = mmvy;

                /* Perform boundary checking */
                if (nmvx < 0)
                {
                    nmvx = 0;
                }
                else if (nmvx > mvwidth - 1)
                {
                    nmvx = mvwidth - 1;
                }

                if (nmvy < 0)
                {
                    nmvy = 0;
                }
                else if (nmvy > (height >> 3) - 1)
                {
                    nmvy = (height >> 3) - 1;
                }

                /* Find post processing semaphore location for block */
                /* used for prediction, i.e.,                */
                /* pp_prev1 = &pstprcTypPrv[nmvy*mvwidth][nmvx]      */
                pp_prev1 = pstprcTypPrv + nmvx + nmvy * mvwidth;

                /* Check if x component of MV is a multiple of 16    */
                /* and check if block x coordinate is out of bounds  */
                if (((dx&0xF) != 0) && (mmvx + 1 < mvwidth - 1))
                {   /* dx is not a multiple of 16 and the block */
                    /* x coordinate is within the bounds        */

                    /* pp_prev2 is the block to the right of */
                    /* pp_prev1 block            */
                    pp_prev2 = pp_prev1 + 1;

                    /* Check if y component of MV is a multiple */
                    /* of 16 and check if block y coordinate is */
                    /* out of bounds                */
                    if (((dy&0xF) != 0) && (mmvy + 1 < (height >> 3) - 1))
                    {   /* dy is not a multiple of 16 and */
                        /* the block y coordinate is      */
                        /* within the bounds              */

                        /* pp_prev3 is the block below */
                        /* pp_prev1 block          */
                        pp_prev3 = pp_prev1 + mvwidth;

                        /* all prediction are from different blocks */
                        msk_deblock = 0x3;
                    }
                    else
                    {   /* dy is a multiple of 16 or the block */
                        /* y coordinate is out of bounds       */

                        pp_prev3 = pp_prev1;
                    }

                    /* pp_prev4 is the block to the right of */
                    /* pp_prev3 block.           */
                    pp_prev4 = pp_prev3 + 1;
                }
                else
                {   /* dx is a multiple of 16 or the block x */
                    /* coordinate is out of bounds           */

                    pp_prev2 = pp_prev1;

                    /* Check if y component of MV is a multiple */
                    /* of 16 and check if block y coordinate is */
                    /* out of bounds                */
                    if (((dy&0xF) != 0) && (mmvy + 1 < (height >> 3) - 1))
                    {   /* dy is not a multiple of 16 and */
                        /* the block y coordinate is      */
                        /* within the bounds              */

                        /* pp_prev3 is the block below */
                        /* pp_prev1 block.         */
                        pp_prev3 = pp_prev1 + mvwidth;
                    }
                    else
                    {   /* dy is a multiple of 16 or the block */
                        /* y coordinate is out of bounds       */

                        pp_prev3 = pp_prev1;
                    }

                    pp_prev4 = pp_prev3;
                }

                /* Deringing semaphore propagation */
                if ((*(pp_dec_y)&4) == 0)
                {
                    *(pp_dec_y) |= ((*(pp_prev1) |
                                     *(pp_prev2) | *(pp_prev3) |
                                     *(pp_prev4)) & 0x4);
                }
                /* Deblocking semaphore propagation */
                /*  11/3/00, change the propaga= */
                /* tion for deblocking */
                if (msk_deblock == 0)
                {
                    *(pp_dec_y) = 0;
                }

                pp_dec_y += ll[kk];
            }
        }

        /*----------------------------------------------------------------------------
        ; Return nothing or data or data pointer
        ----------------------------------------------------------------------------*/
        return (msk_deblock);
    }
#ifdef __cplusplus
}
#endif
#endif