pp_semaphore_luma.cpp revision 3306cfee3bf38ab207a0504e49c2d492bb73ffbf
1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/*
19------------------------------------------------------------------------------
20 INPUT AND OUTPUT DEFINITIONS
21
22 Inputs:
23    xpred = x-axis coordinate of the MB used for prediction (int)
24    ypred = y-axis coordinate of the MB used for prediction (int)
25    pp_dec_y = pointer to the post processing semaphore for current
26           luminance frame (uint8)
27    pstprcTypPrv = pointer the previous frame's post processing type
28                   (uint8)
29    ll = pointer to the buffer (int)
30    mv_loc = flag indicating location of the motion compensated
31         (x,y) position with respect to the luminance MB (int);
32         0 -> inside MB, 1 -> outside MB
33    dx = horizontal component of the motion vector (int)
34    dy = vertical component of the motion vector (int)
35    mvwidth = number of blocks per row (int)
36    width = luminance VOP width in pixels (int)
37    height = luminance VOP height in pixels (int)
38
39 Local Stores/Buffers/Pointers Needed:
40    None
41
42 Global Stores/Buffers/Pointers Needed:
43    None
44
45 Outputs:
46    msk_deblock = flag that indicates whether deblocking is to be
47              performed (msk_deblock = 0) or not (msk_deblock =
48              1) (uint8)
49
50 Pointers and Buffers Modified:
51    pp_dec_y contents are the updated semapohore propagation data
52
53 Local Stores Modified:
54    None
55
56 Global Stores Modified:
57    None
58
59------------------------------------------------------------------------------
60 FUNCTION DESCRIPTION
61
62 This functions performs post processing semaphore propagation processing
63 after luminance prediction.
64
65*/
66
67
68/*----------------------------------------------------------------------------
69; INCLUDES
70----------------------------------------------------------------------------*/
71#include    "mp4dec_api.h"
72#include    "mp4def.h"
73
74/*----------------------------------------------------------------------------
75; MACROS
76; Define module specific macros here
77----------------------------------------------------------------------------*/
78
79/*----------------------------------------------------------------------------
80; DEFINES
81; Include all pre-processor statements here. Include conditional
82; compile variables also.
83----------------------------------------------------------------------------*/
84
85/*----------------------------------------------------------------------------
86; LOCAL FUNCTION DEFINITIONS
87; Function Prototype declaration
88----------------------------------------------------------------------------*/
89
90/*----------------------------------------------------------------------------
91; LOCAL STORE/BUFFER/POINTER DEFINITIONS
92; Variable declaration - defined here and used outside this module
93----------------------------------------------------------------------------*/
94
95/*----------------------------------------------------------------------------
96; EXTERNAL FUNCTION REFERENCES
97; Declare functions defined elsewhere and referenced in this module
98----------------------------------------------------------------------------*/
99
100/*----------------------------------------------------------------------------
101; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
102; Declare variables used in this module but defined elsewhere
103----------------------------------------------------------------------------*/
104#ifdef PV_POSTPROC_ON
105#ifdef __cplusplus
106extern "C"
107{
108#endif
109    /*----------------------------------------------------------------------------
110    ; FUNCTION CODE
111    ----------------------------------------------------------------------------*/
112    uint8 pp_semaphore_luma(
113        int xpred,      /* i */
114        int ypred,      /* i */
115        uint8   *pp_dec_y,  /* i/o */
116        uint8   *pstprcTypPrv,  /* i */
117        int *ll,        /* i */
118        int *mv_loc,    /* i/o */
119        int dx,     /* i */
120        int dy,     /* i */
121        int mvwidth,    /* i */
122        int width,      /* i */
123        int height      /* i */
124    )
125    {
126        /*----------------------------------------------------------------------------
127        ; Define all local variables
128        ----------------------------------------------------------------------------*/
129        int kk, mmvy, mmvx, nmvx, nmvy;
130        uint8   *pp_prev1, *pp_prev2, *pp_prev3, *pp_prev4;
131        uint8   msk_deblock = 0;        /*  11/3/00 */
132
133        /*----------------------------------------------------------------------------
134        ; Function body here
135        ----------------------------------------------------------------------------*/
136        /* Interframe Processing - 1 MV per MB */
137
138        /* check whether the MV points outside the frame */
139        if (xpred >= 0 && xpred <= ((width << 1) - (2*MB_SIZE)) && ypred >= 0 &&
140                ypred <= ((height << 1) - (2*MB_SIZE)))
141        {   /*****************************/
142            /* (x,y) is inside the frame */
143            /*****************************/
144
145            /*  10/24/2000 post_processing semaphore */
146            /* generation */
147
148            /*  10/23/2000 no boundary checking*/
149            *mv_loc = 0;
150
151            /* Calculate block x coordinate. Divide by 16 is for  */
152            /* converting half-pixel resolution to block          */
153            mmvx = xpred >> 4;
154
155            /* Calculate block y coordinate. Divide by 16 is for */
156            /* converting half-pixel resolution to block         */
157            mmvy = ypred >> 4;
158
159            /* Find post processing semaphore location for block */
160            /* used for prediction, i.e.,                */
161            /* pp_prev1 = &pstprcTypPrv[mmvy*mvwidth][mmvx]      */
162            pp_prev1 = pstprcTypPrv + mmvx + mmvy * mvwidth;
163
164            /* Check if MV is a multiple of 16 */
165            if ((dx&0xF) != 0)
166            {   /* dx is not a multiple of 16 */
167
168                /* pp_prev2 is the block to the right of */
169                /* pp_prev1 block            */
170                pp_prev2 = pp_prev1 + 1;
171
172                if ((dy&0xF) != 0)
173                {   /* dy is not a multiple of 16 */
174
175                    /* pp_prev3 is the block below */
176                    /* pp_prev1 block          */
177                    pp_prev3 = pp_prev1 + mvwidth;
178                }
179                else
180                {   /* dy is a multiple of 16 */
181
182                    pp_prev3 = pp_prev1;
183                }
184
185                /* pp_prev4 is the block to the right of */
186                /* pp_prev3 block.           */
187                pp_prev4 = pp_prev3 + 1;
188            }
189            else
190            {   /* dx is a multiple of 16 */
191
192                pp_prev2 = pp_prev1;
193
194                if ((dy&0xF) != 0)
195                {   /* dy is not a multiple of 16 */
196
197                    /* pp_prev3 is the block below */
198                    /* pp_prev1 block.         */
199                    pp_prev3 = pp_prev1 + mvwidth;
200                }
201                else
202                {   /* dy is a multiple of 16 */
203
204                    pp_prev3 = pp_prev1;
205                    msk_deblock = 0x3;
206                }
207
208                pp_prev4 = pp_prev3;
209            }
210
211            /* Perform post processing semaphore propagation for each */
212            /* of the 4 blocks in a MB.               */
213            for (kk = 0; kk < 4; kk++)
214            {
215                /* Deringing semaphore propagation */
216                if ((*(pp_dec_y) & 4) == 0)
217                {
218                    *(pp_dec_y) |= ((*(pp_prev1) | *(pp_prev2) |
219                                     *(pp_prev3) | *(pp_prev4)) & 0x4);
220                }
221                /* Deblocking semaphore propagation */
222                /*  11/3/00, change the propagation for deblocking */
223                if (msk_deblock == 0)
224                {
225                    *(pp_dec_y) = 0;
226                }
227
228                pp_dec_y += ll[kk];
229                pp_prev1 += ll[kk];
230                pp_prev2 += ll[kk];
231                pp_prev3 += ll[kk];
232                pp_prev4 += ll[kk];
233            }
234
235        }
236        else
237        {   /******************************/
238            /* (x,y) is outside the frame */
239            /******************************/
240
241            /*  10/24/2000 post_processing semaphore */
242            /* generation */
243
244            /*  10/23/2000 boundary checking*/
245            *mv_loc = 1;
246
247            /* Perform post processing semaphore propagation for each */
248            /* of the 4 blocks in a MB.               */
249            for (kk = 0; kk < 4; kk++)
250            {
251                /* Calculate block x coordinate and round (?).  */
252                /* Divide by 16 is for converting half-pixel    */
253                /* resolution to block.             */
254                mmvx = (xpred + ((kk & 1) << 3)) >> 4;
255                nmvx = mmvx;
256
257                /* Calculate block y coordinate and round (?).  */
258                /* Divide by 16 is for converting half-pixel    */
259                /* resolution to block.             */
260                mmvy = (ypred + ((kk & 2) << 2)) >> 4;
261                nmvy = mmvy;
262
263                /* Perform boundary checking */
264                if (nmvx < 0)
265                {
266                    nmvx = 0;
267                }
268                else if (nmvx > mvwidth - 1)
269                {
270                    nmvx = mvwidth - 1;
271                }
272
273                if (nmvy < 0)
274                {
275                    nmvy = 0;
276                }
277                else if (nmvy > (height >> 3) - 1)
278                {
279                    nmvy = (height >> 3) - 1;
280                }
281
282                /* Find post processing semaphore location for block */
283                /* used for prediction, i.e.,                */
284                /* pp_prev1 = &pstprcTypPrv[nmvy*mvwidth][nmvx]      */
285                pp_prev1 = pstprcTypPrv + nmvx + nmvy * mvwidth;
286
287                /* Check if x component of MV is a multiple of 16    */
288                /* and check if block x coordinate is out of bounds  */
289                if (((dx&0xF) != 0) && (mmvx + 1 < mvwidth - 1))
290                {   /* dx is not a multiple of 16 and the block */
291                    /* x coordinate is within the bounds        */
292
293                    /* pp_prev2 is the block to the right of */
294                    /* pp_prev1 block            */
295                    pp_prev2 = pp_prev1 + 1;
296
297                    /* Check if y component of MV is a multiple */
298                    /* of 16 and check if block y coordinate is */
299                    /* out of bounds                */
300                    if (((dy&0xF) != 0) && (mmvy + 1 < (height >> 3) - 1))
301                    {   /* dy is not a multiple of 16 and */
302                        /* the block y coordinate is      */
303                        /* within the bounds              */
304
305                        /* pp_prev3 is the block below */
306                        /* pp_prev1 block          */
307                        pp_prev3 = pp_prev1 + mvwidth;
308
309                        /* all prediction are from different blocks */
310                        msk_deblock = 0x3;
311                    }
312                    else
313                    {   /* dy is a multiple of 16 or the block */
314                        /* y coordinate is out of bounds       */
315
316                        pp_prev3 = pp_prev1;
317                    }
318
319                    /* pp_prev4 is the block to the right of */
320                    /* pp_prev3 block.           */
321                    pp_prev4 = pp_prev3 + 1;
322                }
323                else
324                {   /* dx is a multiple of 16 or the block x */
325                    /* coordinate is out of bounds           */
326
327                    pp_prev2 = pp_prev1;
328
329                    /* Check if y component of MV is a multiple */
330                    /* of 16 and check if block y coordinate is */
331                    /* out of bounds                */
332                    if (((dy&0xF) != 0) && (mmvy + 1 < (height >> 3) - 1))
333                    {   /* dy is not a multiple of 16 and */
334                        /* the block y coordinate is      */
335                        /* within the bounds              */
336
337                        /* pp_prev3 is the block below */
338                        /* pp_prev1 block.         */
339                        pp_prev3 = pp_prev1 + mvwidth;
340                    }
341                    else
342                    {   /* dy is a multiple of 16 or the block */
343                        /* y coordinate is out of bounds       */
344
345                        pp_prev3 = pp_prev1;
346                    }
347
348                    pp_prev4 = pp_prev3;
349                }
350
351                /* Deringing semaphore propagation */
352                if ((*(pp_dec_y)&4) == 0)
353                {
354                    *(pp_dec_y) |= ((*(pp_prev1) |
355                                     *(pp_prev2) | *(pp_prev3) |
356                                     *(pp_prev4)) & 0x4);
357                }
358                /* Deblocking semaphore propagation */
359                /*  11/3/00, change the propaga= */
360                /* tion for deblocking */
361                if (msk_deblock == 0)
362                {
363                    *(pp_dec_y) = 0;
364                }
365
366                pp_dec_y += ll[kk];
367            }
368        }
369
370        /*----------------------------------------------------------------------------
371        ; Return nothing or data or data pointer
372        ----------------------------------------------------------------------------*/
373        return (msk_deblock);
374    }
375#ifdef __cplusplus
376}
377#endif
378#endif
379