summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.c
blob: ce5eeff76e7a05c811c7d9359f3c60b7c1a9a9a2 (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
/*
 * Copyright (C) 2009 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.
 */

/*------------------------------------------------------------------------------

    Table of contents

     1. Include headers
     2. External compiler flags
     3. Module defines
     4. Local function prototypes
     5. Functions
          h264bsdInitMbNeighbours
          h264bsdGetNeighbourMb
          h264bsdNeighbour4x4BlockA
          h264bsdNeighbour4x4BlockB
          h264bsdNeighbour4x4BlockC
          h264bsdNeighbour4x4BlockD

------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    1. Include headers
------------------------------------------------------------------------------*/

#include "h264bsd_neighbour.h"
#include "h264bsd_util.h"

/*------------------------------------------------------------------------------
    2. External compiler flags
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
    3. Module defines
------------------------------------------------------------------------------*/

/* Following four tables indicate neighbours of each block of a macroblock.
 * First 16 values are for luma blocks, next 4 values for Cb and last 4
 * values for Cr. Elements of the table indicate to which macroblock the
 * neighbour block belongs and the index of the neighbour block in question.
 * Indexing of the blocks goes as follows
 *
 *          Y             Cb       Cr
 *      0  1  4  5      16 17    20 21
 *      2  3  6  7      18 19    22 23
 *      8  9 12 13
 *     10 11 14 15
 */

/* left neighbour for each block */
static const neighbour_t N_A_4x4B[24] = {
    {MB_A,5},    {MB_CURR,0}, {MB_A,7},    {MB_CURR,2},
    {MB_CURR,1}, {MB_CURR,4}, {MB_CURR,3}, {MB_CURR,6},
    {MB_A,13},   {MB_CURR,8}, {MB_A,15},   {MB_CURR,10},
    {MB_CURR,9}, {MB_CURR,12},{MB_CURR,11},{MB_CURR,14},
    {MB_A,17},   {MB_CURR,16},{MB_A,19},   {MB_CURR,18},
    {MB_A,21},   {MB_CURR,20},{MB_A,23},   {MB_CURR,22} };

/* above neighbour for each block */
static const neighbour_t N_B_4x4B[24] = {
    {MB_B,10},   {MB_B,11},   {MB_CURR,0}, {MB_CURR,1},
    {MB_B,14},   {MB_B,15},   {MB_CURR,4}, {MB_CURR,5},
    {MB_CURR,2}, {MB_CURR,3}, {MB_CURR,8}, {MB_CURR,9},
    {MB_CURR,6}, {MB_CURR,7}, {MB_CURR,12},{MB_CURR,13},
    {MB_B,18},   {MB_B,19},   {MB_CURR,16},{MB_CURR,17},
    {MB_B,22},   {MB_B,23},   {MB_CURR,20},{MB_CURR,21} };

/* above-right neighbour for each block */
static const neighbour_t N_C_4x4B[24] = {
    {MB_B,11},   {MB_B,14},   {MB_CURR,1}, {MB_NA,4},
    {MB_B,15},   {MB_C,10},   {MB_CURR,5}, {MB_NA,0},
    {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_NA,12},
    {MB_CURR,7}, {MB_NA,2},   {MB_CURR,13},{MB_NA,8},
    {MB_B,19},   {MB_C,18},   {MB_CURR,17},{MB_NA,16},
    {MB_B,23},   {MB_C,22},   {MB_CURR,21},{MB_NA,20} };

/* above-left neighbour for each block */
static const neighbour_t N_D_4x4B[24] = {
    {MB_D,15},   {MB_B,10},   {MB_A,5},    {MB_CURR,0},
    {MB_B,11},   {MB_B,14},   {MB_CURR,1}, {MB_CURR,4},
    {MB_A,7},    {MB_CURR,2}, {MB_A,13},   {MB_CURR,8},
    {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_CURR,12},
    {MB_D,19},   {MB_B,18},   {MB_A,17},   {MB_CURR,16},
    {MB_D,23},   {MB_B,22},   {MB_A,21},   {MB_CURR,20} };

/*------------------------------------------------------------------------------
    4. Local function prototypes
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------

    Function: h264bsdInitMbNeighbours

        Functional description:
            Initialize macroblock neighbours. Function sets neighbour
            macroblock pointers in macroblock structures to point to
            macroblocks on the left, above, above-right and above-left.
            Pointers are set NULL if the neighbour does not fit into the
            picture.

        Inputs:
            picWidth        width of the picture in macroblocks
            picSizeInMbs    no need to clarify

        Outputs:
            pMbStorage      neighbour pointers of each mbStorage structure
                            stored here

        Returns:
            none

------------------------------------------------------------------------------*/

void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth,
    u32 picSizeInMbs)
{

/* Variables */

    u32 i, row, col;

/* Code */

    ASSERT(pMbStorage);
    ASSERT(picWidth);
    ASSERT(picWidth <= picSizeInMbs);
    ASSERT(((picSizeInMbs / picWidth) * picWidth) == picSizeInMbs);

    row = col = 0;

    for (i = 0; i < picSizeInMbs; i++)
    {

        if (col)
            pMbStorage[i].mbA = pMbStorage + i - 1;
        else
            pMbStorage[i].mbA = NULL;

        if (row)
            pMbStorage[i].mbB = pMbStorage + i - picWidth;
        else
            pMbStorage[i].mbB = NULL;

        if (row && (col < picWidth - 1))
            pMbStorage[i].mbC = pMbStorage + i - (picWidth - 1);
        else
            pMbStorage[i].mbC = NULL;

        if (row && col)
            pMbStorage[i].mbD = pMbStorage + i - (picWidth + 1);
        else
            pMbStorage[i].mbD = NULL;

        col++;
        if (col == picWidth)
        {
            col = 0;
            row++;
        }
    }

}

/*------------------------------------------------------------------------------

    Function: h264bsdGetNeighbourMb

        Functional description:
            Get pointer to neighbour macroblock.

        Inputs:
            pMb         pointer to macroblock structure of the macroblock
                        whose neighbour is wanted
            neighbour   indicates which neighbour is wanted

        Outputs:
            none

        Returns:
            pointer to neighbour macroblock
            NULL if not available

------------------------------------------------------------------------------*/

mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour)
{

/* Variables */


/* Code */

    ASSERT((neighbour <= MB_CURR) || (neighbour == MB_NA));

    if (neighbour == MB_A)
        return(pMb->mbA);
    else if (neighbour == MB_B)
        return(pMb->mbB);
    else if (neighbour == MB_C)
        return(pMb->mbC);
    else if (neighbour == MB_D)
        return(pMb->mbD);
    else if (neighbour == MB_CURR)
        return(pMb);
    else
        return(NULL);

}

/*------------------------------------------------------------------------------

    Function: h264bsdNeighbour4x4BlockA

        Functional description:
            Get left neighbour of the block. Function returns pointer to
            the table defined in the beginning of the file.

        Inputs:
            blockIndex  indicates the block whose neighbours are wanted

        Outputs:

        Returns:
            pointer to neighbour structure

------------------------------------------------------------------------------*/

const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex)
{

/* Variables */

/* Code */

    ASSERT(blockIndex < 24);

    return(N_A_4x4B+blockIndex);

}

/*------------------------------------------------------------------------------

    Function: h264bsdNeighbour4x4BlockB

        Functional description:
            Get above neighbour of the block. Function returns pointer to
            the table defined in the beginning of the file.

        Inputs:
            blockIndex  indicates the block whose neighbours are wanted

        Outputs:

        Returns:
            pointer to neighbour structure

------------------------------------------------------------------------------*/

const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex)
{

/* Variables */

/* Code */

    ASSERT(blockIndex < 24);

    return(N_B_4x4B+blockIndex);

}

/*------------------------------------------------------------------------------

    Function: h264bsdNeighbour4x4BlockC

        Functional description:
            Get above-right  neighbour of the block. Function returns pointer
            to the table defined in the beginning of the file.

        Inputs:
            blockIndex  indicates the block whose neighbours are wanted

        Outputs:

        Returns:
            pointer to neighbour structure

------------------------------------------------------------------------------*/

const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex)
{

/* Variables */

/* Code */

    ASSERT(blockIndex < 24);

    return(N_C_4x4B+blockIndex);

}

/*------------------------------------------------------------------------------

    Function: h264bsdNeighbour4x4BlockD

        Functional description:
            Get above-left neighbour of the block. Function returns pointer to
            the table defined in the beginning of the file.

        Inputs:
            blockIndex  indicates the block whose neighbours are wanted

        Outputs:

        Returns:
            pointer to neighbour structure

------------------------------------------------------------------------------*/

const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex)
{

/* Variables */

/* Code */

    ASSERT(blockIndex < 24);

    return(N_D_4x4B+blockIndex);

}

/*------------------------------------------------------------------------------

    Function: h264bsdIsNeighbourAvailable

        Functional description:
            Check if neighbour macroblock is available. Neighbour macroblock
            is considered available if it is within the picture and belongs
            to the same slice as the current macroblock.

        Inputs:
            pMb         pointer to the current macroblock
            pNeighbour  pointer to the neighbour macroblock

        Outputs:
            none

        Returns:
            TRUE    neighbour is available
            FALSE   neighbour is not available

------------------------------------------------------------------------------*/

u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour)
{

/* Variables */

/* Code */

    if ( (pNeighbour == NULL) || (pMb->sliceId != pNeighbour->sliceId) )
        return(HANTRO_FALSE);
    else
        return(HANTRO_TRUE);

}