10c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2009 The Android Open Source Project
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License");
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License.
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *      http://www.apache.org/licenses/LICENSE-2.0
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software
110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS,
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and
140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
180c1bc742181ded4930842b46e9507372f0b1b963James Dong
190c1bc742181ded4930842b46e9507372f0b1b963James Dong    Table of contents
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong     1. Include headers
220c1bc742181ded4930842b46e9507372f0b1b963James Dong     2. External compiler flags
230c1bc742181ded4930842b46e9507372f0b1b963James Dong     3. Module defines
240c1bc742181ded4930842b46e9507372f0b1b963James Dong     4. Local function prototypes
250c1bc742181ded4930842b46e9507372f0b1b963James Dong     5. Functions
260c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdFilterPicture
270c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterVerLumaEdge
280c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterHorLumaEdge
290c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterHorLuma
300c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterVerChromaEdge
310c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterHorChromaEdge
320c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterHorChroma
330c1bc742181ded4930842b46e9507372f0b1b963James Dong          InnerBoundaryStrength
340c1bc742181ded4930842b46e9507372f0b1b963James Dong          EdgeBoundaryStrength
350c1bc742181ded4930842b46e9507372f0b1b963James Dong          GetBoundaryStrengths
360c1bc742181ded4930842b46e9507372f0b1b963James Dong          IsSliceBoundaryOnLeft
370c1bc742181ded4930842b46e9507372f0b1b963James Dong          IsSliceBoundaryOnTop
380c1bc742181ded4930842b46e9507372f0b1b963James Dong          GetMbFilteringFlags
390c1bc742181ded4930842b46e9507372f0b1b963James Dong          GetLumaEdgeThresholds
400c1bc742181ded4930842b46e9507372f0b1b963James Dong          GetChromaEdgeThresholds
410c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterLuma
420c1bc742181ded4930842b46e9507372f0b1b963James Dong          FilterChroma
430c1bc742181ded4930842b46e9507372f0b1b963James Dong
440c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
450c1bc742181ded4930842b46e9507372f0b1b963James Dong
460c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
470c1bc742181ded4930842b46e9507372f0b1b963James Dong    1. Include headers
480c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
490c1bc742181ded4930842b46e9507372f0b1b963James Dong
500c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "basetype.h"
510c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h"
520c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_macroblock_layer.h"
530c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_deblocking.h"
540c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_dpb.h"
550c1bc742181ded4930842b46e9507372f0b1b963James Dong
560c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL
570c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
580c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
590c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
600c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
610c1bc742181ded4930842b46e9507372f0b1b963James Dong
620c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
630c1bc742181ded4930842b46e9507372f0b1b963James Dong    2. External compiler flags
640c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
650c1bc742181ded4930842b46e9507372f0b1b963James Dong
660c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
670c1bc742181ded4930842b46e9507372f0b1b963James Dong    3. Module defines
680c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
690c1bc742181ded4930842b46e9507372f0b1b963James Dong
700c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Switch off the following Lint messages for this file:
710c1bc742181ded4930842b46e9507372f0b1b963James Dong * Info 701: Shift left of signed quantity (int)
720c1bc742181ded4930842b46e9507372f0b1b963James Dong * Info 702: Shift right of signed quantity (int)
730c1bc742181ded4930842b46e9507372f0b1b963James Dong */
740c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint -e701 -e702 */
750c1bc742181ded4930842b46e9507372f0b1b963James Dong
760c1bc742181ded4930842b46e9507372f0b1b963James Dong/* array of alpha values, from the standard */
770c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u8 alphas[52] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,5,6,7,8,9,10,
780c1bc742181ded4930842b46e9507372f0b1b963James Dong    12,13,15,17,20,22,25,28,32,36,40,45,50,56,63,71,80,90,101,113,127,144,162,
790c1bc742181ded4930842b46e9507372f0b1b963James Dong    182,203,226,255,255};
800c1bc742181ded4930842b46e9507372f0b1b963James Dong
810c1bc742181ded4930842b46e9507372f0b1b963James Dong/* array of beta values, from the standard */
820c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u8 betas[52] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,3,3,3,3,4,4,
830c1bc742181ded4930842b46e9507372f0b1b963James Dong    4,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18};
840c1bc742181ded4930842b46e9507372f0b1b963James Dong
850c1bc742181ded4930842b46e9507372f0b1b963James Dong
860c1bc742181ded4930842b46e9507372f0b1b963James Dong
870c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
880c1bc742181ded4930842b46e9507372f0b1b963James Dong/* array of tc0 values, from the standard, each triplet corresponds to a
890c1bc742181ded4930842b46e9507372f0b1b963James Dong * column in the table. Indexing goes as tc0[indexA][bS-1] */
900c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u8 tc0[52][3] = {
910c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
920c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
930c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0,0,0},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,1,1},{0,1,1},{1,1,1},
940c1bc742181ded4930842b46e9507372f0b1b963James Dong    {1,1,1},{1,1,1},{1,1,1},{1,1,2},{1,1,2},{1,1,2},{1,1,2},{1,2,3},
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    {1,2,3},{2,2,3},{2,2,4},{2,3,4},{2,3,4},{3,3,5},{3,4,6},{3,4,6},
960c1bc742181ded4930842b46e9507372f0b1b963James Dong    {4,5,7},{4,5,8},{4,6,9},{5,7,10},{6,8,11},{6,8,13},{7,10,14},{8,11,16},
970c1bc742181ded4930842b46e9507372f0b1b963James Dong    {9,12,18},{10,13,20},{11,15,23},{13,17,25}
980c1bc742181ded4930842b46e9507372f0b1b963James Dong};
990c1bc742181ded4930842b46e9507372f0b1b963James Dong#else
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong/* array of tc0 values, from the standard, each triplet corresponds to a
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong * column in the table. Indexing goes as tc0[indexA][bS] */
1020c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u8 tc0[52][5] = {
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 1, 0},
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 0, 0, 1, 0}, {0, 0, 1, 1, 0}, {0, 0, 1, 1, 0}, {0, 1, 1, 1, 0},
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 2, 0},
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 1, 1, 2, 0}, {0, 1, 1, 2, 0}, {0, 1, 1, 2, 0}, {0, 1, 2, 3, 0},
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 1, 2, 3, 0}, {0, 2, 2, 3, 0}, {0, 2, 2, 4, 0}, {0, 2, 3, 4, 0},
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 2, 3, 4, 0}, {0, 3, 3, 5, 0}, {0, 3, 4, 6, 0}, {0, 3, 4, 6, 0},
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 4, 5, 7, 0}, {0, 4, 5, 8, 0}, {0, 4, 6, 9, 0}, {0, 5, 7, 10, 0},
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 6, 8, 11, 0}, {0, 6, 8, 13, 0}, {0, 7, 10, 14, 0},
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 8, 11, 16, 0}, {0, 9, 12, 18, 0}, {0, 10, 13, 20, 0},
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 11, 15, 23, 0}, {0, 13, 17, 25, 0}
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong};
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong/* mapping of raster scan block index to 4x4 block index */
1230c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u32 mb4x4Index[16] =
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong
1260c1bc742181ded4930842b46e9507372f0b1b963James Dongtypedef struct {
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *tc0;
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 alpha;
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 beta;
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong} edgeThreshold_t;
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong
1320c1bc742181ded4930842b46e9507372f0b1b963James Dongtypedef struct {
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 top;
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 left;
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong} bS_t;
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong
1370c1bc742181ded4930842b46e9507372f0b1b963James Dongenum { TOP = 0, LEFT = 1, INNER = 2 };
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong#define FILTER_LEFT_EDGE    0x04
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong#define FILTER_TOP_EDGE     0x02
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong#define FILTER_INNER_EDGE   0x01
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong/* clipping table defined in intra_prediction.c */
1460c1bc742181ded4930842b46e9507372f0b1b963James Dongextern const u8 h264bsdClip[];
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong    4. Local function prototypes
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong
1520c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 InnerBoundaryStrength(mbStorage_t *mb1, u32 i1, u32 i2);
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
1550c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 EdgeBoundaryStrength(mbStorage_t *mb1, mbStorage_t *mb2,
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i1, u32 i2);
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong#else
1580c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 InnerBoundaryStrength2(mbStorage_t *mb1, u32 i1, u32 i2);
1590c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 EdgeBoundaryStrengthLeft(mbStorage_t *mb1, mbStorage_t *mb2);
1600c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 EdgeBoundaryStrengthTop(mbStorage_t *mb1, mbStorage_t *mb2);
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong
1630c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 IsSliceBoundaryOnLeft(mbStorage_t *mb);
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong
1650c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 IsSliceBoundaryOnTop(mbStorage_t *mb);
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong
1670c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 GetMbFilteringFlags(mbStorage_t *mb);
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong
1710c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 GetBoundaryStrengths(mbStorage_t *mb, bS_t *bs, u32 flags);
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong
1730c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterLuma(u8 *data, bS_t *bS, edgeThreshold_t *thresholds,
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 imageWidth);
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong
1760c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterChroma(u8 *cb, u8 *cr, bS_t *bS, edgeThreshold_t *thresholds,
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 imageWidth);
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong
1790c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterVerLumaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 imageWidth);
1810c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterHorLumaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong        i32 imageWidth);
1830c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterHorLuma( u8 *data, u32 bS, edgeThreshold_t *thresholds,
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong        i32 imageWidth);
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong
1860c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterVerChromaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 imageWidth);
1880c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterHorChromaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 imageWidth);
1900c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FilterHorChroma( u8 *data, u32 bS, edgeThreshold_t *thresholds,
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 imageWidth);
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong
1930c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void GetLumaEdgeThresholds(
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong  mbStorage_t *mb,
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 filteringFlags);
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong
1980c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void GetChromaEdgeThresholds(
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong  mbStorage_t *mb,
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 filteringFlags,
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 chromaQpIndexOffset);
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong
2060c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 GetBoundaryStrengths(mbStorage_t *mb, u8 (*bs)[16], u32 flags);
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong
2080c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void GetLumaEdgeThresholds(
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *mb,
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*alpha)[2],
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*beta)[2],
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*threshold)[16],
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*bs)[16],
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 filteringFlags );
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong
2160c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void GetChromaEdgeThresholds(
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *mb,
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*alpha)[2],
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*beta)[2],
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*threshold)[8],
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*bs)[16],
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 filteringFlags,
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 chromaQpIndexOffset);
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IsSliceBoundaryOnLeft
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to determine if there is a slice boundary on the left side
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong            of a macroblock.
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2360c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 IsSliceBoundaryOnLeft(mbStorage_t *mb)
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb && mb->mbA);
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (mb->sliceId != mb->mbA->sliceId)
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_TRUE);
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_FALSE);
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IsSliceBoundaryOnTop
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to determine if there is a slice boundary above the
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong            current macroblock.
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2610c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 IsSliceBoundaryOnTop(mbStorage_t *mb)
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb && mb->mbB);
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (mb->sliceId != mb->mbB->sliceId)
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_TRUE);
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_FALSE);
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetMbFilteringFlags
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to determine which edges of a macroblock has to be
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong          filtered. Output is a bit-wise OR of FILTER_LEFT_EDGE,
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong          FILTER_TOP_EDGE and FILTER_INNER_EDGE, depending on which edges
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong          shall be filtered.
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2880c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 GetMbFilteringFlags(mbStorage_t *mb)
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 flags = 0;
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* nothing will be filtered if disableDeblockingFilterIdc == 1 */
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (mb->disableDeblockingFilterIdc != 1)
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3020c1bc742181ded4930842b46e9507372f0b1b963James Dong        flags |= FILTER_INNER_EDGE;
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* filterLeftMbEdgeFlag, left mb is MB_A */
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (mb->mbA &&
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong            ((mb->disableDeblockingFilterIdc != 2) ||
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong             !IsSliceBoundaryOnLeft(mb)))
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong            flags |= FILTER_LEFT_EDGE;
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* filterTopMbEdgeFlag */
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (mb->mbB &&
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong            ((mb->disableDeblockingFilterIdc != 2) ||
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong             !IsSliceBoundaryOnTop(mb)))
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong            flags |= FILTER_TOP_EDGE;
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(flags);
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: InnerBoundaryStrength
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strength value bs for an inner
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong            edge of a macroblock. Macroblock type is checked before this is
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong            called -> no intra mb condition here.
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3310c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 InnerBoundaryStrength(mbStorage_t *mb1, u32 ind1, u32 ind2)
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2;
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 mv1, mv2, mv3, mv4;
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp1 = mb1->totalCoeff[ind1];
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp2 = mb1->totalCoeff[ind2];
3380c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv1 = mb1->mv[ind1].hor;
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv2 = mb1->mv[ind2].hor;
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv3 = mb1->mv[ind1].ver;
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv4 = mb1->mv[ind2].ver;
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp1 || tmp2)
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 2;
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ( (ABS(mv1 - mv2) >= 4) || (ABS(mv3 - mv4) >= 4) ||
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong              (mb1->refAddr[ind1 >> 2] != mb1->refAddr[ind2 >> 2]) )
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 1;
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 0;
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: InnerBoundaryStrength2
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong
3600c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strength value bs for an inner
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong            edge of a macroblock. The function is the same as
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong            InnerBoundaryStrength but without checking totalCoeff.
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3660c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 InnerBoundaryStrength2(mbStorage_t *mb1, u32 ind1, u32 ind2)
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4;
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp1 = mb1->mv[ind1].hor;
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp2 = mb1->mv[ind2].hor;
3720c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp3 = mb1->mv[ind1].ver;
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp4 = mb1->mv[ind2].ver;
3740c1bc742181ded4930842b46e9507372f0b1b963James Dong
3750c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( (ABS(tmp1 - tmp2) >= 4) || (ABS(tmp3 - tmp4) >= 4) ||
3760c1bc742181ded4930842b46e9507372f0b1b963James Dong         (mb1->refAddr[ind1 >> 2] != mb1->refAddr[ind2 >> 2]))
3770c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3780c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 1;
3790c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3800c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
3810c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 0;
3820c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3830c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
3840c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
3850c1bc742181ded4930842b46e9507372f0b1b963James Dong
3860c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: EdgeBoundaryStrength
3870c1bc742181ded4930842b46e9507372f0b1b963James Dong
3880c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
3890c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strength value bs for left- or
3900c1bc742181ded4930842b46e9507372f0b1b963James Dong            top-most edge of a macroblock. Macroblock types are checked
3910c1bc742181ded4930842b46e9507372f0b1b963James Dong            before this is called -> no intra mb conditions here.
3920c1bc742181ded4930842b46e9507372f0b1b963James Dong
3930c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3940c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 EdgeBoundaryStrength(mbStorage_t *mb1, mbStorage_t *mb2,
3950c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 ind1, u32 ind2)
3960c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3970c1bc742181ded4930842b46e9507372f0b1b963James Dong
3980c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (mb1->totalCoeff[ind1] || mb2->totalCoeff[ind2])
3990c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4000c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 2;
4010c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4020c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((mb1->refAddr[ind1 >> 2] != mb2->refAddr[ind2 >> 2]) ||
4030c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[ind1].hor - mb2->mv[ind2].hor) >= 4) ||
4040c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[ind1].ver - mb2->mv[ind2].ver) >= 4))
4050c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4060c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 1;
4070c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4080c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
4090c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 0;
4100c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4110c1bc742181ded4930842b46e9507372f0b1b963James Dong
4120c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */
4130c1bc742181ded4930842b46e9507372f0b1b963James Dong
4140c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4150c1bc742181ded4930842b46e9507372f0b1b963James Dong
4160c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: EdgeBoundaryStrengthTop
4170c1bc742181ded4930842b46e9507372f0b1b963James Dong
4180c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4190c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strength value bs for
4200c1bc742181ded4930842b46e9507372f0b1b963James Dong            top-most edge of a macroblock. Macroblock types are checked
4210c1bc742181ded4930842b46e9507372f0b1b963James Dong            before this is called -> no intra mb conditions here.
4220c1bc742181ded4930842b46e9507372f0b1b963James Dong
4230c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4240c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 EdgeBoundaryStrengthTop(mbStorage_t *mb1, mbStorage_t *mb2)
4250c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4260c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 topBs = 0;
4270c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp1, tmp2, tmp3, tmp4;
4280c1bc742181ded4930842b46e9507372f0b1b963James Dong
4290c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp1 = mb1->totalCoeff[0];
4300c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp2 = mb2->totalCoeff[10];
4310c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp3 = mb1->totalCoeff[1];
4320c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp4 = mb2->totalCoeff[11];
4330c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp1 || tmp2)
4340c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4350c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs = 2<<0;
4360c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4370c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[0].hor - mb2->mv[10].hor) >= 4) ||
4380c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[0].ver - mb2->mv[10].ver) >= 4) ||
4390c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[0] != mb2->refAddr[10 >> 2]))
4400c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4410c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs = 1<<0;
4420c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4430c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp1 = mb1->totalCoeff[4];
4440c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp2 = mb2->totalCoeff[14];
4450c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp3 || tmp4)
4460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4470c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs += 2<<8;
4480c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4490c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[1].hor - mb2->mv[11].hor) >= 4) ||
4500c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[1].ver - mb2->mv[11].ver) >= 4) ||
4510c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[0] != mb2->refAddr[11 >> 2]))
4520c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4530c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs += 1<<8;
4540c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4550c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp3 = mb1->totalCoeff[5];
4560c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp4 = mb2->totalCoeff[15];
4570c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp1 || tmp2)
4580c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4590c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs += 2<<16;
4600c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4610c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[4].hor - mb2->mv[14].hor) >= 4) ||
4620c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[4].ver - mb2->mv[14].ver) >= 4) ||
4630c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[4 >> 2] != mb2->refAddr[14 >> 2]))
4640c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4650c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs += 1<<16;
4660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4670c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp3 || tmp4)
4680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4690c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs += 2<<24;
4700c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4710c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[5].hor - mb2->mv[15].hor) >= 4) ||
4720c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[5].ver - mb2->mv[15].ver) >= 4) ||
4730c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[5 >> 2] != mb2->refAddr[15 >> 2]))
4740c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4750c1bc742181ded4930842b46e9507372f0b1b963James Dong        topBs += 1<<24;
4760c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4770c1bc742181ded4930842b46e9507372f0b1b963James Dong
4780c1bc742181ded4930842b46e9507372f0b1b963James Dong    return topBs;
4790c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4800c1bc742181ded4930842b46e9507372f0b1b963James Dong
4810c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4820c1bc742181ded4930842b46e9507372f0b1b963James Dong
4830c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: EdgeBoundaryStrengthLeft
4840c1bc742181ded4930842b46e9507372f0b1b963James Dong
4850c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4860c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strength value bs for left-
4870c1bc742181ded4930842b46e9507372f0b1b963James Dong            edge of a macroblock. Macroblock types are checked
4880c1bc742181ded4930842b46e9507372f0b1b963James Dong            before this is called -> no intra mb conditions here.
4890c1bc742181ded4930842b46e9507372f0b1b963James Dong
4900c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4910c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 EdgeBoundaryStrengthLeft(mbStorage_t *mb1, mbStorage_t *mb2)
4920c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4930c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 leftBs = 0;
4940c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp1, tmp2, tmp3, tmp4;
4950c1bc742181ded4930842b46e9507372f0b1b963James Dong
4960c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp1 = mb1->totalCoeff[0];
4970c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp2 = mb2->totalCoeff[5];
4980c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp3 = mb1->totalCoeff[2];
4990c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp4 = mb2->totalCoeff[7];
5000c1bc742181ded4930842b46e9507372f0b1b963James Dong
5010c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp1 || tmp2)
5020c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5030c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs = 2<<0;
5040c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5050c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[0].hor - mb2->mv[5].hor) >= 4) ||
5060c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[0].ver - mb2->mv[5].ver) >= 4) ||
5070c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[0] != mb2->refAddr[5 >> 2]))
5080c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5090c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs = 1<<0;
5100c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5110c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp1 = mb1->totalCoeff[8];
5120c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp2 = mb2->totalCoeff[13];
5130c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp3 || tmp4)
5140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5150c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs += 2<<8;
5160c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5170c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[2].hor - mb2->mv[7].hor) >= 4) ||
5180c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[2].ver - mb2->mv[7].ver) >= 4) ||
5190c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[0] != mb2->refAddr[7 >> 2]))
5200c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5210c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs += 1<<8;
5220c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5230c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp3 = mb1->totalCoeff[10];
5240c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp4 = mb2->totalCoeff[15];
5250c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp1 || tmp2)
5260c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5270c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs += 2<<16;
5280c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5290c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[8].hor - mb2->mv[13].hor) >= 4) ||
5300c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[8].ver - mb2->mv[13].ver) >= 4) ||
5310c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[8 >> 2] != mb2->refAddr[13 >> 2]))
5320c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5330c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs += 1<<16;
5340c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5350c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp3 || tmp4)
5360c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5370c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs += 2<<24;
5380c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5390c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ((ABS(mb1->mv[10].hor - mb2->mv[15].hor) >= 4) ||
5400c1bc742181ded4930842b46e9507372f0b1b963James Dong             (ABS(mb1->mv[10].ver - mb2->mv[15].ver) >= 4) ||
5410c1bc742181ded4930842b46e9507372f0b1b963James Dong             (mb1->refAddr[10 >> 2] != mb2->refAddr[15 >> 2]))
5420c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5430c1bc742181ded4930842b46e9507372f0b1b963James Dong        leftBs += 1<<24;
5440c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5450c1bc742181ded4930842b46e9507372f0b1b963James Dong
5460c1bc742181ded4930842b46e9507372f0b1b963James Dong    return leftBs;
5470c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5480c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
5490c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
5500c1bc742181ded4930842b46e9507372f0b1b963James Dong
5510c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdFilterPicture
5520c1bc742181ded4930842b46e9507372f0b1b963James Dong
5530c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
5540c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform deblocking filtering for a picture. Filter does not copy
5550c1bc742181ded4930842b46e9507372f0b1b963James Dong          the original picture anywhere but filtering is performed directly
5560c1bc742181ded4930842b46e9507372f0b1b963James Dong          on the original image. Parameters controlling the filtering process
5570c1bc742181ded4930842b46e9507372f0b1b963James Dong          are computed based on information in macroblock structures of the
5580c1bc742181ded4930842b46e9507372f0b1b963James Dong          filtered macroblock, macroblock above and macroblock on the left of
5590c1bc742181ded4930842b46e9507372f0b1b963James Dong          the filtered one.
5600c1bc742181ded4930842b46e9507372f0b1b963James Dong
5610c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
5620c1bc742181ded4930842b46e9507372f0b1b963James Dong          image         pointer to image to be filtered
5630c1bc742181ded4930842b46e9507372f0b1b963James Dong          mb            pointer to macroblock data structure of the top-left
5640c1bc742181ded4930842b46e9507372f0b1b963James Dong                        macroblock of the picture
5650c1bc742181ded4930842b46e9507372f0b1b963James Dong
5660c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
5670c1bc742181ded4930842b46e9507372f0b1b963James Dong          image         filtered image stored here
5680c1bc742181ded4930842b46e9507372f0b1b963James Dong
5690c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
5700c1bc742181ded4930842b46e9507372f0b1b963James Dong          none
5710c1bc742181ded4930842b46e9507372f0b1b963James Dong
5720c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
5730c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
5740c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdFilterPicture(
5750c1bc742181ded4930842b46e9507372f0b1b963James Dong  image_t *image,
5760c1bc742181ded4930842b46e9507372f0b1b963James Dong  mbStorage_t *mb)
5770c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5780c1bc742181ded4930842b46e9507372f0b1b963James Dong
5790c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
5800c1bc742181ded4930842b46e9507372f0b1b963James Dong
5810c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 flags;
5820c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 picSizeInMbs, mbRow, mbCol;
5830c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 picWidthInMbs;
5840c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *data;
5850c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *pMb;
5860c1bc742181ded4930842b46e9507372f0b1b963James Dong    bS_t bS[16];
5870c1bc742181ded4930842b46e9507372f0b1b963James Dong    edgeThreshold_t thresholds[3];
5880c1bc742181ded4930842b46e9507372f0b1b963James Dong
5890c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
5900c1bc742181ded4930842b46e9507372f0b1b963James Dong
5910c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image);
5920c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
5930c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image->data);
5940c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image->width);
5950c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image->height);
5960c1bc742181ded4930842b46e9507372f0b1b963James Dong
5970c1bc742181ded4930842b46e9507372f0b1b963James Dong    picWidthInMbs = image->width;
5980c1bc742181ded4930842b46e9507372f0b1b963James Dong    data = image->data;
5990c1bc742181ded4930842b46e9507372f0b1b963James Dong    picSizeInMbs = picWidthInMbs * image->height;
6000c1bc742181ded4930842b46e9507372f0b1b963James Dong
6010c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb = mb;
6020c1bc742181ded4930842b46e9507372f0b1b963James Dong
6030c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (mbRow = 0, mbCol = 0; mbRow < image->height; pMb++)
6040c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6050c1bc742181ded4930842b46e9507372f0b1b963James Dong        flags = GetMbFilteringFlags(pMb);
6060c1bc742181ded4930842b46e9507372f0b1b963James Dong
6070c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (flags)
6080c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6090c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* GetBoundaryStrengths function returns non-zero value if any of
6100c1bc742181ded4930842b46e9507372f0b1b963James Dong             * the bS values for the macroblock being processed was non-zero */
6110c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (GetBoundaryStrengths(pMb, bS, flags))
6120c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
6130c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* luma */
6140c1bc742181ded4930842b46e9507372f0b1b963James Dong                GetLumaEdgeThresholds(thresholds, pMb, flags);
6150c1bc742181ded4930842b46e9507372f0b1b963James Dong                data = image->data + mbRow * picWidthInMbs * 256 + mbCol * 16;
6160c1bc742181ded4930842b46e9507372f0b1b963James Dong
6170c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterLuma((u8*)data, bS, thresholds, picWidthInMbs*16);
6180c1bc742181ded4930842b46e9507372f0b1b963James Dong
6190c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* chroma */
6200c1bc742181ded4930842b46e9507372f0b1b963James Dong                GetChromaEdgeThresholds(thresholds, pMb, flags,
6210c1bc742181ded4930842b46e9507372f0b1b963James Dong                    pMb->chromaQpIndexOffset);
6220c1bc742181ded4930842b46e9507372f0b1b963James Dong                data = image->data + picSizeInMbs * 256 +
6230c1bc742181ded4930842b46e9507372f0b1b963James Dong                    mbRow * picWidthInMbs * 64 + mbCol * 8;
6240c1bc742181ded4930842b46e9507372f0b1b963James Dong
6250c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterChroma((u8*)data, data + 64*picSizeInMbs, bS,
6260c1bc742181ded4930842b46e9507372f0b1b963James Dong                        thresholds, picWidthInMbs*8);
6270c1bc742181ded4930842b46e9507372f0b1b963James Dong
6280c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
6290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
6300c1bc742181ded4930842b46e9507372f0b1b963James Dong
6310c1bc742181ded4930842b46e9507372f0b1b963James Dong        mbCol++;
6320c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (mbCol == picWidthInMbs)
6330c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6340c1bc742181ded4930842b46e9507372f0b1b963James Dong            mbCol = 0;
6350c1bc742181ded4930842b46e9507372f0b1b963James Dong            mbRow++;
6360c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
6370c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6380c1bc742181ded4930842b46e9507372f0b1b963James Dong
6390c1bc742181ded4930842b46e9507372f0b1b963James Dong}
6400c1bc742181ded4930842b46e9507372f0b1b963James Dong
6410c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
6420c1bc742181ded4930842b46e9507372f0b1b963James Dong
6430c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterVerLumaEdge
6440c1bc742181ded4930842b46e9507372f0b1b963James Dong
6450c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
6460c1bc742181ded4930842b46e9507372f0b1b963James Dong            Filter one vertical 4-pixel luma edge.
6470c1bc742181ded4930842b46e9507372f0b1b963James Dong
6480c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
6490c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterVerLumaEdge(
6500c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
6510c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 bS,
6520c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
6530c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 imageWidth)
6540c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6550c1bc742181ded4930842b46e9507372f0b1b963James Dong
6560c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
6570c1bc742181ded4930842b46e9507372f0b1b963James Dong
6580c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 delta, tc, tmp;
6590c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
6600c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 p0, q0, p1, q1, p2, q2;
6610c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmpFlag;
6620c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
6630c1bc742181ded4930842b46e9507372f0b1b963James Dong
6640c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
6650c1bc742181ded4930842b46e9507372f0b1b963James Dong
6660c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
6670c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS && bS <= 4);
6680c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
6690c1bc742181ded4930842b46e9507372f0b1b963James Dong
6700c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (bS < 4)
6710c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6720c1bc742181ded4930842b46e9507372f0b1b963James Dong        tc = thresholds->tc0[bS-1];
6730c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = tc;
6740c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 4; i; i--, data += imageWidth)
6750c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6760c1bc742181ded4930842b46e9507372f0b1b963James Dong            p1 = data[-2]; p0 = data[-1];
6770c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = data[0]; q1 = data[1];
6780c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
6790c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
6800c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
6810c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
6820c1bc742181ded4930842b46e9507372f0b1b963James Dong                p2 = data[-3];
6830c1bc742181ded4930842b46e9507372f0b1b963James Dong                q2 = data[2];
6840c1bc742181ded4930842b46e9507372f0b1b963James Dong
6850c1bc742181ded4930842b46e9507372f0b1b963James Dong                if ((unsigned)ABS(p2-p0) < thresholds->beta)
6860c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
6870c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-2] = (u8)(p1 + CLIP3(-tc,tc,
6880c1bc742181ded4930842b46e9507372f0b1b963James Dong                        (p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1));
6890c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp++;
6900c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
6910c1bc742181ded4930842b46e9507372f0b1b963James Dong
6920c1bc742181ded4930842b46e9507372f0b1b963James Dong                if ((unsigned)ABS(q2-q0) < thresholds->beta)
6930c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
6940c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[1] = (u8)(q1 + CLIP3(-tc,tc,
6950c1bc742181ded4930842b46e9507372f0b1b963James Dong                        (q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1));
6960c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp++;
6970c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
6980c1bc742181ded4930842b46e9507372f0b1b963James Dong
6990c1bc742181ded4930842b46e9507372f0b1b963James Dong                delta = CLIP3(-tmp, tmp, ((((q0 - p0) << 2) +
7000c1bc742181ded4930842b46e9507372f0b1b963James Dong                          (p1 - q1) + 4) >> 3));
7010c1bc742181ded4930842b46e9507372f0b1b963James Dong
7020c1bc742181ded4930842b46e9507372f0b1b963James Dong                p0 = clp[p0 + delta];
7030c1bc742181ded4930842b46e9507372f0b1b963James Dong                q0 = clp[q0 - delta];
7040c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp = tc;
7050c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[-1] = p0;
7060c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[ 0] = q0;
7070c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
7080c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7090c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7100c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
7110c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7120c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 4; i; i--, data += imageWidth)
7130c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7140c1bc742181ded4930842b46e9507372f0b1b963James Dong            p1 = data[-2]; p0 = data[-1];
7150c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = data[0]; q1 = data[1];
7160c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
7170c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
7180c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
7190c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
7200c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmpFlag =
7210c1bc742181ded4930842b46e9507372f0b1b963James Dong                    ((unsigned)ABS(p0-q0) < ((thresholds->alpha >> 2) +2)) ?
7220c1bc742181ded4930842b46e9507372f0b1b963James Dong                        HANTRO_TRUE : HANTRO_FALSE;
7230c1bc742181ded4930842b46e9507372f0b1b963James Dong
7240c1bc742181ded4930842b46e9507372f0b1b963James Dong                p2 = data[-3];
7250c1bc742181ded4930842b46e9507372f0b1b963James Dong                q2 = data[2];
7260c1bc742181ded4930842b46e9507372f0b1b963James Dong
7270c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (tmpFlag && (unsigned)ABS(p2-p0) < thresholds->beta)
7280c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
7290c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp = p1 + p0 + q0;
7300c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-1] = (u8)((p2 + 2 * tmp + q1 + 4) >> 3);
7310c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-2] = (u8)((p2 + tmp + 2) >> 2);
7320c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-3] = (u8)((2 * data[-4] + 3 * p2 + tmp + 4) >> 3);
7330c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
7340c1bc742181ded4930842b46e9507372f0b1b963James Dong                else
7350c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-1] = (2 * p1 + p0 + q1 + 2) >> 2;
7360c1bc742181ded4930842b46e9507372f0b1b963James Dong
7370c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (tmpFlag && (unsigned)ABS(q2-q0) < thresholds->beta)
7380c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
7390c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp = p0 + q0 + q1;
7400c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[0] = (u8)((p1 + 2 * tmp + q2 + 4) >> 3);
7410c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[1] = (u8)((tmp + q2 + 2) >> 2);
7420c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[2] = (u8)((2 * data[3] + 3 * q2 + tmp + 4) >> 3);
7430c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
7440c1bc742181ded4930842b46e9507372f0b1b963James Dong                else
7450c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[0] = (u8)((2 * q1 + q0 + p1 + 2) >> 2);
7460c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
7470c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7480c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7490c1bc742181ded4930842b46e9507372f0b1b963James Dong
7500c1bc742181ded4930842b46e9507372f0b1b963James Dong}
7510c1bc742181ded4930842b46e9507372f0b1b963James Dong
7520c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
7530c1bc742181ded4930842b46e9507372f0b1b963James Dong
7540c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterHorLumaEdge
7550c1bc742181ded4930842b46e9507372f0b1b963James Dong
7560c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
7570c1bc742181ded4930842b46e9507372f0b1b963James Dong            Filter one horizontal 4-pixel luma edge
7580c1bc742181ded4930842b46e9507372f0b1b963James Dong
7590c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
7600c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterHorLumaEdge(
7610c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
7620c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 bS,
7630c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
7640c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 imageWidth)
7650c1bc742181ded4930842b46e9507372f0b1b963James Dong{
7660c1bc742181ded4930842b46e9507372f0b1b963James Dong
7670c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
7680c1bc742181ded4930842b46e9507372f0b1b963James Dong
7690c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 delta, tc, tmp;
7700c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
7710c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 p0, q0, p1, q1, p2, q2;
7720c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
7730c1bc742181ded4930842b46e9507372f0b1b963James Dong
7740c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
7750c1bc742181ded4930842b46e9507372f0b1b963James Dong
7760c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
7770c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS < 4);
7780c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
7790c1bc742181ded4930842b46e9507372f0b1b963James Dong
7800c1bc742181ded4930842b46e9507372f0b1b963James Dong    tc = thresholds->tc0[bS-1];
7810c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = tc;
7820c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 4; i; i--, data++)
7830c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7840c1bc742181ded4930842b46e9507372f0b1b963James Dong        p1 = data[-imageWidth*2]; p0 = data[-imageWidth];
7850c1bc742181ded4930842b46e9507372f0b1b963James Dong        q0 = data[0]; q1 = data[imageWidth];
7860c1bc742181ded4930842b46e9507372f0b1b963James Dong        if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
7870c1bc742181ded4930842b46e9507372f0b1b963James Dong             ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
7880c1bc742181ded4930842b46e9507372f0b1b963James Dong             ((unsigned)ABS(q1-q0) < thresholds->beta) )
7890c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7900c1bc742181ded4930842b46e9507372f0b1b963James Dong            p2 = data[-imageWidth*3];
7910c1bc742181ded4930842b46e9507372f0b1b963James Dong
7920c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ((unsigned)ABS(p2-p0) < thresholds->beta)
7930c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
7940c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[-imageWidth*2] = (u8)(p1 + CLIP3(-tc,tc,
7950c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1));
7960c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp++;
7970c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
7980c1bc742181ded4930842b46e9507372f0b1b963James Dong
7990c1bc742181ded4930842b46e9507372f0b1b963James Dong            q2 = data[imageWidth*2];
8000c1bc742181ded4930842b46e9507372f0b1b963James Dong
8010c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ((unsigned)ABS(q2-q0) < thresholds->beta)
8020c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
8030c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[imageWidth] = (u8)(q1 + CLIP3(-tc,tc,
8040c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1));
8050c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp++;
8060c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
8070c1bc742181ded4930842b46e9507372f0b1b963James Dong
8080c1bc742181ded4930842b46e9507372f0b1b963James Dong            delta = CLIP3(-tmp, tmp, ((((q0 - p0) << 2) +
8090c1bc742181ded4930842b46e9507372f0b1b963James Dong                      (p1 - q1) + 4) >> 3));
8100c1bc742181ded4930842b46e9507372f0b1b963James Dong
8110c1bc742181ded4930842b46e9507372f0b1b963James Dong            p0 = clp[p0 + delta];
8120c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = clp[q0 - delta];
8130c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = tc;
8140c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[-imageWidth] = p0;
8150c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[  0] = q0;
8160c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8170c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8180c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8190c1bc742181ded4930842b46e9507372f0b1b963James Dong
8200c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
8210c1bc742181ded4930842b46e9507372f0b1b963James Dong
8220c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterHorLuma
8230c1bc742181ded4930842b46e9507372f0b1b963James Dong
8240c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
8250c1bc742181ded4930842b46e9507372f0b1b963James Dong            Filter all four successive horizontal 4-pixel luma edges. This can
8260c1bc742181ded4930842b46e9507372f0b1b963James Dong            be done when bS is equal to all four edges.
8270c1bc742181ded4930842b46e9507372f0b1b963James Dong
8280c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
8290c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterHorLuma(
8300c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
8310c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 bS,
8320c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
8330c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 imageWidth)
8340c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8350c1bc742181ded4930842b46e9507372f0b1b963James Dong
8360c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
8370c1bc742181ded4930842b46e9507372f0b1b963James Dong
8380c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 delta, tc, tmp;
8390c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
8400c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 p0, q0, p1, q1, p2, q2;
8410c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmpFlag;
8420c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
8430c1bc742181ded4930842b46e9507372f0b1b963James Dong
8440c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
8450c1bc742181ded4930842b46e9507372f0b1b963James Dong
8460c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
8470c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS <= 4);
8480c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
8490c1bc742181ded4930842b46e9507372f0b1b963James Dong
8500c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (bS < 4)
8510c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8520c1bc742181ded4930842b46e9507372f0b1b963James Dong        tc = thresholds->tc0[bS-1];
8530c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = tc;
8540c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 16; i; i--, data++)
8550c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
8560c1bc742181ded4930842b46e9507372f0b1b963James Dong            p1 = data[-imageWidth*2]; p0 = data[-imageWidth];
8570c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = data[0]; q1 = data[imageWidth];
8580c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
8590c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
8600c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
8610c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
8620c1bc742181ded4930842b46e9507372f0b1b963James Dong                p2 = data[-imageWidth*3];
8630c1bc742181ded4930842b46e9507372f0b1b963James Dong
8640c1bc742181ded4930842b46e9507372f0b1b963James Dong                if ((unsigned)ABS(p2-p0) < thresholds->beta)
8650c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
8660c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-imageWidth*2] = (u8)(p1 + CLIP3(-tc,tc,
8670c1bc742181ded4930842b46e9507372f0b1b963James Dong                        (p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1));
8680c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp++;
8690c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
8700c1bc742181ded4930842b46e9507372f0b1b963James Dong
8710c1bc742181ded4930842b46e9507372f0b1b963James Dong                q2 = data[imageWidth*2];
8720c1bc742181ded4930842b46e9507372f0b1b963James Dong
8730c1bc742181ded4930842b46e9507372f0b1b963James Dong                if ((unsigned)ABS(q2-q0) < thresholds->beta)
8740c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
8750c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[imageWidth] = (u8)(q1 + CLIP3(-tc,tc,
8760c1bc742181ded4930842b46e9507372f0b1b963James Dong                        (q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1));
8770c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp++;
8780c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
8790c1bc742181ded4930842b46e9507372f0b1b963James Dong
8800c1bc742181ded4930842b46e9507372f0b1b963James Dong                delta = CLIP3(-tmp, tmp, ((((q0 - p0) << 2) +
8810c1bc742181ded4930842b46e9507372f0b1b963James Dong                          (p1 - q1) + 4) >> 3));
8820c1bc742181ded4930842b46e9507372f0b1b963James Dong
8830c1bc742181ded4930842b46e9507372f0b1b963James Dong                p0 = clp[p0 + delta];
8840c1bc742181ded4930842b46e9507372f0b1b963James Dong                q0 = clp[q0 - delta];
8850c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp = tc;
8860c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[-imageWidth] = p0;
8870c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[  0] = q0;
8880c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
8890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8900c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8910c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
8920c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8930c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 16; i; i--, data++)
8940c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
8950c1bc742181ded4930842b46e9507372f0b1b963James Dong            p1 = data[-imageWidth*2]; p0 = data[-imageWidth];
8960c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = data[0]; q1 = data[imageWidth];
8970c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
8980c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
8990c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
9000c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
9010c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmpFlag = ((unsigned)ABS(p0-q0) < ((thresholds->alpha >> 2) +2))
9020c1bc742181ded4930842b46e9507372f0b1b963James Dong                            ? HANTRO_TRUE : HANTRO_FALSE;
9030c1bc742181ded4930842b46e9507372f0b1b963James Dong
9040c1bc742181ded4930842b46e9507372f0b1b963James Dong                p2 = data[-imageWidth*3];
9050c1bc742181ded4930842b46e9507372f0b1b963James Dong                q2 = data[imageWidth*2];
9060c1bc742181ded4930842b46e9507372f0b1b963James Dong
9070c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (tmpFlag && (unsigned)ABS(p2-p0) < thresholds->beta)
9080c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
9090c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp = p1 + p0 + q0;
9100c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-imageWidth] = (u8)((p2 + 2 * tmp + q1 + 4) >> 3);
9110c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-imageWidth*2] = (u8)((p2 + tmp + 2) >> 2);
9120c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-imageWidth*3] = (u8)((2 * data[-imageWidth*4] +
9130c1bc742181ded4930842b46e9507372f0b1b963James Dong                                           3 * p2 + tmp + 4) >> 3);
9140c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
9150c1bc742181ded4930842b46e9507372f0b1b963James Dong                else
9160c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-imageWidth] = (u8)((2 * p1 + p0 + q1 + 2) >> 2);
9170c1bc742181ded4930842b46e9507372f0b1b963James Dong
9180c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (tmpFlag && (unsigned)ABS(q2-q0) < thresholds->beta)
9190c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
9200c1bc742181ded4930842b46e9507372f0b1b963James Dong                    tmp = p0 + q0 + q1;
9210c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[ 0] = (u8)((p1 + 2 * tmp + q2 + 4) >> 3);
9220c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[imageWidth] = (u8)((tmp + q2 + 2) >> 2);
9230c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[imageWidth*2] = (u8)((2 * data[imageWidth*3] +
9240c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          3 * q2 + tmp + 4) >> 3);
9250c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
9260c1bc742181ded4930842b46e9507372f0b1b963James Dong                else
9270c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[0] = (2 * q1 + q0 + p1 + 2) >> 2;
9280c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
9290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
9300c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9310c1bc742181ded4930842b46e9507372f0b1b963James Dong
9320c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9330c1bc742181ded4930842b46e9507372f0b1b963James Dong
9340c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9350c1bc742181ded4930842b46e9507372f0b1b963James Dong
9360c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterVerChromaEdge
9370c1bc742181ded4930842b46e9507372f0b1b963James Dong
9380c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9390c1bc742181ded4930842b46e9507372f0b1b963James Dong            Filter one vertical 2-pixel chroma edge
9400c1bc742181ded4930842b46e9507372f0b1b963James Dong
9410c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
9420c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterVerChromaEdge(
9430c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
9440c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 bS,
9450c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
9460c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width)
9470c1bc742181ded4930842b46e9507372f0b1b963James Dong{
9480c1bc742181ded4930842b46e9507372f0b1b963James Dong
9490c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
9500c1bc742181ded4930842b46e9507372f0b1b963James Dong
9510c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 delta, tc;
9520c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 p0, q0, p1, q1;
9530c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
9540c1bc742181ded4930842b46e9507372f0b1b963James Dong
9550c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
9560c1bc742181ded4930842b46e9507372f0b1b963James Dong
9570c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
9580c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS <= 4);
9590c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
9600c1bc742181ded4930842b46e9507372f0b1b963James Dong
9610c1bc742181ded4930842b46e9507372f0b1b963James Dong    p1 = data[-2]; p0 = data[-1];
9620c1bc742181ded4930842b46e9507372f0b1b963James Dong    q0 = data[0]; q1 = data[1];
9630c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
9640c1bc742181ded4930842b46e9507372f0b1b963James Dong         ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
9650c1bc742181ded4930842b46e9507372f0b1b963James Dong         ((unsigned)ABS(q1-q0) < thresholds->beta) )
9660c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9670c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (bS < 4)
9680c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
9690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tc = thresholds->tc0[bS-1] + 1;
9700c1bc742181ded4930842b46e9507372f0b1b963James Dong            delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
9710c1bc742181ded4930842b46e9507372f0b1b963James Dong                      (p1 - q1) + 4) >> 3));
9720c1bc742181ded4930842b46e9507372f0b1b963James Dong            p0 = clp[p0 + delta];
9730c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = clp[q0 - delta];
9740c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[-1] = p0;
9750c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[ 0] = q0;
9760c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
9770c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
9780c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
9790c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[-1] = (2 * p1 + p0 + q1 + 2) >> 2;
9800c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[ 0] = (2 * q1 + q0 + p1 + 2) >> 2;
9810c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
9820c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9830c1bc742181ded4930842b46e9507372f0b1b963James Dong    data += width;
9840c1bc742181ded4930842b46e9507372f0b1b963James Dong    p1 = data[-2]; p0 = data[-1];
9850c1bc742181ded4930842b46e9507372f0b1b963James Dong    q0 = data[0]; q1 = data[1];
9860c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
9870c1bc742181ded4930842b46e9507372f0b1b963James Dong         ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
9880c1bc742181ded4930842b46e9507372f0b1b963James Dong         ((unsigned)ABS(q1-q0) < thresholds->beta) )
9890c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9900c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (bS < 4)
9910c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
9920c1bc742181ded4930842b46e9507372f0b1b963James Dong            tc = thresholds->tc0[bS-1] + 1;
9930c1bc742181ded4930842b46e9507372f0b1b963James Dong            delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
9940c1bc742181ded4930842b46e9507372f0b1b963James Dong                      (p1 - q1) + 4) >> 3));
9950c1bc742181ded4930842b46e9507372f0b1b963James Dong            p0 = clp[p0 + delta];
9960c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = clp[q0 - delta];
9970c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[-1] = p0;
9980c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[ 0] = q0;
9990c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
10000c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
10010c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10020c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[-1] = (2 * p1 + p0 + q1 + 2) >> 2;
10030c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[ 0] = (2 * q1 + q0 + p1 + 2) >> 2;
10040c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
10050c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10060c1bc742181ded4930842b46e9507372f0b1b963James Dong
10070c1bc742181ded4930842b46e9507372f0b1b963James Dong}
10080c1bc742181ded4930842b46e9507372f0b1b963James Dong
10090c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
10100c1bc742181ded4930842b46e9507372f0b1b963James Dong
10110c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterHorChromaEdge
10120c1bc742181ded4930842b46e9507372f0b1b963James Dong
10130c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
10140c1bc742181ded4930842b46e9507372f0b1b963James Dong            Filter one horizontal 2-pixel chroma edge
10150c1bc742181ded4930842b46e9507372f0b1b963James Dong
10160c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
10170c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterHorChromaEdge(
10180c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
10190c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 bS,
10200c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
10210c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 width)
10220c1bc742181ded4930842b46e9507372f0b1b963James Dong{
10230c1bc742181ded4930842b46e9507372f0b1b963James Dong
10240c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
10250c1bc742181ded4930842b46e9507372f0b1b963James Dong
10260c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 delta, tc;
10270c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
10280c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 p0, q0, p1, q1;
10290c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
10300c1bc742181ded4930842b46e9507372f0b1b963James Dong
10310c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
10320c1bc742181ded4930842b46e9507372f0b1b963James Dong
10330c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
10340c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS < 4);
10350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
10360c1bc742181ded4930842b46e9507372f0b1b963James Dong
10370c1bc742181ded4930842b46e9507372f0b1b963James Dong    tc = thresholds->tc0[bS-1] + 1;
10380c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 2; i; i--, data++)
10390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10400c1bc742181ded4930842b46e9507372f0b1b963James Dong        p1 = data[-width*2]; p0 = data[-width];
10410c1bc742181ded4930842b46e9507372f0b1b963James Dong        q0 = data[0]; q1 = data[width];
10420c1bc742181ded4930842b46e9507372f0b1b963James Dong        if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
10430c1bc742181ded4930842b46e9507372f0b1b963James Dong             ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
10440c1bc742181ded4930842b46e9507372f0b1b963James Dong             ((unsigned)ABS(q1-q0) < thresholds->beta) )
10450c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10460c1bc742181ded4930842b46e9507372f0b1b963James Dong            delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
10470c1bc742181ded4930842b46e9507372f0b1b963James Dong                      (p1 - q1) + 4) >> 3));
10480c1bc742181ded4930842b46e9507372f0b1b963James Dong            p0 = clp[p0 + delta];
10490c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = clp[q0 - delta];
10500c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[-width] = p0;
10510c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[  0] = q0;
10520c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
10530c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10540c1bc742181ded4930842b46e9507372f0b1b963James Dong}
10550c1bc742181ded4930842b46e9507372f0b1b963James Dong
10560c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
10570c1bc742181ded4930842b46e9507372f0b1b963James Dong
10580c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterHorChroma
10590c1bc742181ded4930842b46e9507372f0b1b963James Dong
10600c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
10610c1bc742181ded4930842b46e9507372f0b1b963James Dong            Filter all four successive horizontal 2-pixel chroma edges. This
10620c1bc742181ded4930842b46e9507372f0b1b963James Dong            can be done if bS is equal for all four edges.
10630c1bc742181ded4930842b46e9507372f0b1b963James Dong
10640c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
10650c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterHorChroma(
10660c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
10670c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 bS,
10680c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
10690c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 width)
10700c1bc742181ded4930842b46e9507372f0b1b963James Dong{
10710c1bc742181ded4930842b46e9507372f0b1b963James Dong
10720c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
10730c1bc742181ded4930842b46e9507372f0b1b963James Dong
10740c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 delta, tc;
10750c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
10760c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 p0, q0, p1, q1;
10770c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
10780c1bc742181ded4930842b46e9507372f0b1b963James Dong
10790c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
10800c1bc742181ded4930842b46e9507372f0b1b963James Dong
10810c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
10820c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS <= 4);
10830c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
10840c1bc742181ded4930842b46e9507372f0b1b963James Dong
10850c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (bS < 4)
10860c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10870c1bc742181ded4930842b46e9507372f0b1b963James Dong        tc = thresholds->tc0[bS-1] + 1;
10880c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 8; i; i--, data++)
10890c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10900c1bc742181ded4930842b46e9507372f0b1b963James Dong            p1 = data[-width*2]; p0 = data[-width];
10910c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = data[0]; q1 = data[width];
10920c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
10930c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
10940c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
10950c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
10960c1bc742181ded4930842b46e9507372f0b1b963James Dong                delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
10970c1bc742181ded4930842b46e9507372f0b1b963James Dong                          (p1 - q1) + 4) >> 3));
10980c1bc742181ded4930842b46e9507372f0b1b963James Dong                p0 = clp[p0 + delta];
10990c1bc742181ded4930842b46e9507372f0b1b963James Dong                q0 = clp[q0 - delta];
11000c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[-width] = p0;
11010c1bc742181ded4930842b46e9507372f0b1b963James Dong                data[  0] = q0;
11020c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
11030c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11040c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11050c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
11060c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11070c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 8; i; i--, data++)
11080c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11090c1bc742181ded4930842b46e9507372f0b1b963James Dong            p1 = data[-width*2]; p0 = data[-width];
11100c1bc742181ded4930842b46e9507372f0b1b963James Dong            q0 = data[0]; q1 = data[width];
11110c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
11120c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
11130c1bc742181ded4930842b46e9507372f0b1b963James Dong                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
11140c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
11150c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[-width] = (2 * p1 + p0 + q1 + 2) >> 2;
11160c1bc742181ded4930842b46e9507372f0b1b963James Dong                    data[  0] = (2 * q1 + q0 + p1 + 2) >> 2;
11170c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
11180c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11190c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11200c1bc742181ded4930842b46e9507372f0b1b963James Dong
11210c1bc742181ded4930842b46e9507372f0b1b963James Dong}
11220c1bc742181ded4930842b46e9507372f0b1b963James Dong
11230c1bc742181ded4930842b46e9507372f0b1b963James Dong
11240c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
11250c1bc742181ded4930842b46e9507372f0b1b963James Dong
11260c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetBoundaryStrengths
11270c1bc742181ded4930842b46e9507372f0b1b963James Dong
11280c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
11290c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strengths for all edges of a
11300c1bc742181ded4930842b46e9507372f0b1b963James Dong            macroblock. Function returns HANTRO_TRUE if any of the bS values for
11310c1bc742181ded4930842b46e9507372f0b1b963James Dong            the macroblock had non-zero value, HANTRO_FALSE otherwise.
11320c1bc742181ded4930842b46e9507372f0b1b963James Dong
11330c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
11340c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 GetBoundaryStrengths(mbStorage_t *mb, bS_t *bS, u32 flags)
11350c1bc742181ded4930842b46e9507372f0b1b963James Dong{
11360c1bc742181ded4930842b46e9507372f0b1b963James Dong
11370c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
11380c1bc742181ded4930842b46e9507372f0b1b963James Dong
11390c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* this flag is set HANTRO_TRUE as soon as any boundary strength value is
11400c1bc742181ded4930842b46e9507372f0b1b963James Dong     * non-zero */
11410c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 nonZeroBs = HANTRO_FALSE;
11420c1bc742181ded4930842b46e9507372f0b1b963James Dong
11430c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
11440c1bc742181ded4930842b46e9507372f0b1b963James Dong
11450c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
11460c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS);
11470c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(flags);
11480c1bc742181ded4930842b46e9507372f0b1b963James Dong
11490c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* top edges */
11500c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (flags & FILTER_TOP_EDGE)
11510c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11520c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (IS_INTRA_MB(*mb) || IS_INTRA_MB(*mb->mbB))
11530c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11540c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0].top = bS[1].top = bS[2].top = bS[3].top = 4;
11550c1bc742181ded4930842b46e9507372f0b1b963James Dong            nonZeroBs = HANTRO_TRUE;
11560c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11570c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
11580c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11590c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0].top = EdgeBoundaryStrength(mb, mb->mbB, 0, 10);
11600c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1].top = EdgeBoundaryStrength(mb, mb->mbB, 1, 11);
11610c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[2].top = EdgeBoundaryStrength(mb, mb->mbB, 4, 14);
11620c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[3].top = EdgeBoundaryStrength(mb, mb->mbB, 5, 15);
11630c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (bS[0].top || bS[1].top || bS[2].top || bS[3].top)
11640c1bc742181ded4930842b46e9507372f0b1b963James Dong                nonZeroBs = HANTRO_TRUE;
11650c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11670c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
11680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11690c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[0].top = bS[1].top = bS[2].top = bS[3].top = 0;
11700c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11710c1bc742181ded4930842b46e9507372f0b1b963James Dong
11720c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* left edges */
11730c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (flags & FILTER_LEFT_EDGE)
11740c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11750c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (IS_INTRA_MB(*mb) || IS_INTRA_MB(*mb->mbA))
11760c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11770c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0].left = bS[4].left = bS[8].left = bS[12].left = 4;
11780c1bc742181ded4930842b46e9507372f0b1b963James Dong            nonZeroBs = HANTRO_TRUE;
11790c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11800c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
11810c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11820c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0].left = EdgeBoundaryStrength(mb, mb->mbA, 0, 5);
11830c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[4].left = EdgeBoundaryStrength(mb, mb->mbA, 2, 7);
11840c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[8].left = EdgeBoundaryStrength(mb, mb->mbA, 8, 13);
11850c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[12].left = EdgeBoundaryStrength(mb, mb->mbA, 10, 15);
11860c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!nonZeroBs &&
11870c1bc742181ded4930842b46e9507372f0b1b963James Dong                (bS[0].left || bS[4].left || bS[8].left || bS[12].left))
11880c1bc742181ded4930842b46e9507372f0b1b963James Dong                nonZeroBs = HANTRO_TRUE;
11890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11900c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11910c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
11920c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11930c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[0].left = bS[4].left = bS[8].left = bS[12].left = 0;
11940c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11950c1bc742181ded4930842b46e9507372f0b1b963James Dong
11960c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* inner edges */
11970c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (IS_INTRA_MB(*mb))
11980c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11990c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[4].top  = bS[5].top  = bS[6].top  = bS[7].top  =
12000c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[8].top  = bS[9].top  = bS[10].top = bS[11].top =
12010c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[12].top = bS[13].top = bS[14].top = bS[15].top = 3;
12020c1bc742181ded4930842b46e9507372f0b1b963James Dong
12030c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[1].left  = bS[2].left  = bS[3].left  =
12040c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[5].left  = bS[6].left  = bS[7].left  =
12050c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[9].left  = bS[10].left = bS[11].left =
12060c1bc742181ded4930842b46e9507372f0b1b963James Dong        bS[13].left = bS[14].left = bS[15].left = 3;
12070c1bc742181ded4930842b46e9507372f0b1b963James Dong        nonZeroBs = HANTRO_TRUE;
12080c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12090c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
12100c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12110c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 16x16 inter mb -> ref addresses or motion vectors cannot differ,
12120c1bc742181ded4930842b46e9507372f0b1b963James Dong         * only check if either of the blocks contain coefficients */
12130c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (h264bsdNumMbPart(mb->mbType) == 1)
12140c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
12150c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[4].top = mb->totalCoeff[2] || mb->totalCoeff[0] ? 2 : 0;
12160c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].top = mb->totalCoeff[3] || mb->totalCoeff[1] ? 2 : 0;
12170c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].top = mb->totalCoeff[6] || mb->totalCoeff[4] ? 2 : 0;
12180c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].top = mb->totalCoeff[7] || mb->totalCoeff[5] ? 2 : 0;
12190c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[8].top = mb->totalCoeff[8] || mb->totalCoeff[2] ? 2 : 0;
12200c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].top = mb->totalCoeff[9] || mb->totalCoeff[3] ? 2 : 0;
12210c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].top = mb->totalCoeff[12] || mb->totalCoeff[6] ? 2 : 0;
12220c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].top = mb->totalCoeff[13] || mb->totalCoeff[7] ? 2 : 0;
12230c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[12].top = mb->totalCoeff[10] || mb->totalCoeff[8] ? 2 : 0;
12240c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].top = mb->totalCoeff[11] || mb->totalCoeff[9] ? 2 : 0;
12250c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].top = mb->totalCoeff[14] || mb->totalCoeff[12] ? 2 : 0;
12260c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].top = mb->totalCoeff[15] || mb->totalCoeff[13] ? 2 : 0;
12270c1bc742181ded4930842b46e9507372f0b1b963James Dong
12280c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1].left = mb->totalCoeff[1] || mb->totalCoeff[0] ? 2 : 0;
12290c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[2].left = mb->totalCoeff[4] || mb->totalCoeff[1] ? 2 : 0;
12300c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[3].left = mb->totalCoeff[5] || mb->totalCoeff[4] ? 2 : 0;
12310c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].left = mb->totalCoeff[3] || mb->totalCoeff[2] ? 2 : 0;
12320c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].left = mb->totalCoeff[6] || mb->totalCoeff[3] ? 2 : 0;
12330c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].left = mb->totalCoeff[7] || mb->totalCoeff[6] ? 2 : 0;
12340c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].left = mb->totalCoeff[9] || mb->totalCoeff[8] ? 2 : 0;
12350c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].left = mb->totalCoeff[12] || mb->totalCoeff[9] ? 2 : 0;
12360c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].left = mb->totalCoeff[13] || mb->totalCoeff[12] ? 2 : 0;
12370c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].left = mb->totalCoeff[11] || mb->totalCoeff[10] ? 2 : 0;
12380c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].left = mb->totalCoeff[14] || mb->totalCoeff[11] ? 2 : 0;
12390c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].left = mb->totalCoeff[15] || mb->totalCoeff[14] ? 2 : 0;
12400c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
12410c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 16x8 inter mb -> ref addresses and motion vectors can be different
12420c1bc742181ded4930842b46e9507372f0b1b963James Dong         * only for the middle horizontal edge, for the other top edges it is
12430c1bc742181ded4930842b46e9507372f0b1b963James Dong         * enough to check whether the blocks contain coefficients or not. The
12440c1bc742181ded4930842b46e9507372f0b1b963James Dong         * same applies to all internal left edges. */
12450c1bc742181ded4930842b46e9507372f0b1b963James Dong        else if (mb->mbType == P_L0_L0_16x8)
12460c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
12470c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[4].top = mb->totalCoeff[2] || mb->totalCoeff[0] ? 2 : 0;
12480c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].top = mb->totalCoeff[3] || mb->totalCoeff[1] ? 2 : 0;
12490c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].top = mb->totalCoeff[6] || mb->totalCoeff[4] ? 2 : 0;
12500c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].top = mb->totalCoeff[7] || mb->totalCoeff[5] ? 2 : 0;
12510c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[12].top = mb->totalCoeff[10] || mb->totalCoeff[8] ? 2 : 0;
12520c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].top = mb->totalCoeff[11] || mb->totalCoeff[9] ? 2 : 0;
12530c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].top = mb->totalCoeff[14] || mb->totalCoeff[12] ? 2 : 0;
12540c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].top = mb->totalCoeff[15] || mb->totalCoeff[13] ? 2 : 0;
12550c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[8].top = InnerBoundaryStrength(mb, 8, 2);
12560c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].top = InnerBoundaryStrength(mb, 9, 3);
12570c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].top = InnerBoundaryStrength(mb, 12, 6);
12580c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].top = InnerBoundaryStrength(mb, 13, 7);
12590c1bc742181ded4930842b46e9507372f0b1b963James Dong
12600c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1].left = mb->totalCoeff[1] || mb->totalCoeff[0] ? 2 : 0;
12610c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[2].left = mb->totalCoeff[4] || mb->totalCoeff[1] ? 2 : 0;
12620c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[3].left = mb->totalCoeff[5] || mb->totalCoeff[4] ? 2 : 0;
12630c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].left = mb->totalCoeff[3] || mb->totalCoeff[2] ? 2 : 0;
12640c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].left = mb->totalCoeff[6] || mb->totalCoeff[3] ? 2 : 0;
12650c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].left = mb->totalCoeff[7] || mb->totalCoeff[6] ? 2 : 0;
12660c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].left = mb->totalCoeff[9] || mb->totalCoeff[8] ? 2 : 0;
12670c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].left = mb->totalCoeff[12] || mb->totalCoeff[9] ? 2 : 0;
12680c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].left = mb->totalCoeff[13] || mb->totalCoeff[12] ? 2 : 0;
12690c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].left = mb->totalCoeff[11] || mb->totalCoeff[10] ? 2 : 0;
12700c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].left = mb->totalCoeff[14] || mb->totalCoeff[11] ? 2 : 0;
12710c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].left = mb->totalCoeff[15] || mb->totalCoeff[14] ? 2 : 0;
12720c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
12730c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 8x16 inter mb -> ref addresses and motion vectors can be different
12740c1bc742181ded4930842b46e9507372f0b1b963James Dong         * only for the middle vertical edge, for the other left edges it is
12750c1bc742181ded4930842b46e9507372f0b1b963James Dong         * enough to check whether the blocks contain coefficients or not. The
12760c1bc742181ded4930842b46e9507372f0b1b963James Dong         * same applies to all internal top edges. */
12770c1bc742181ded4930842b46e9507372f0b1b963James Dong        else if (mb->mbType == P_L0_L0_8x16)
12780c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
12790c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[4].top = mb->totalCoeff[2] || mb->totalCoeff[0] ? 2 : 0;
12800c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].top = mb->totalCoeff[3] || mb->totalCoeff[1] ? 2 : 0;
12810c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].top = mb->totalCoeff[6] || mb->totalCoeff[4] ? 2 : 0;
12820c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].top = mb->totalCoeff[7] || mb->totalCoeff[5] ? 2 : 0;
12830c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[8].top = mb->totalCoeff[8] || mb->totalCoeff[2] ? 2 : 0;
12840c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].top = mb->totalCoeff[9] || mb->totalCoeff[3] ? 2 : 0;
12850c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].top = mb->totalCoeff[12] || mb->totalCoeff[6] ? 2 : 0;
12860c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].top = mb->totalCoeff[13] || mb->totalCoeff[7] ? 2 : 0;
12870c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[12].top = mb->totalCoeff[10] || mb->totalCoeff[8] ? 2 : 0;
12880c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].top = mb->totalCoeff[11] || mb->totalCoeff[9] ? 2 : 0;
12890c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].top = mb->totalCoeff[14] || mb->totalCoeff[12] ? 2 : 0;
12900c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].top = mb->totalCoeff[15] || mb->totalCoeff[13] ? 2 : 0;
12910c1bc742181ded4930842b46e9507372f0b1b963James Dong
12920c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1].left = mb->totalCoeff[1] || mb->totalCoeff[0] ? 2 : 0;
12930c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[3].left = mb->totalCoeff[5] || mb->totalCoeff[4] ? 2 : 0;
12940c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].left = mb->totalCoeff[3] || mb->totalCoeff[2] ? 2 : 0;
12950c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].left = mb->totalCoeff[7] || mb->totalCoeff[6] ? 2 : 0;
12960c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].left = mb->totalCoeff[9] || mb->totalCoeff[8] ? 2 : 0;
12970c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].left = mb->totalCoeff[13] || mb->totalCoeff[12] ? 2 : 0;
12980c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].left = mb->totalCoeff[11] || mb->totalCoeff[10] ? 2 : 0;
12990c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].left = mb->totalCoeff[15] || mb->totalCoeff[14] ? 2 : 0;
13000c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[2].left = InnerBoundaryStrength(mb, 4, 1);
13010c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].left = InnerBoundaryStrength(mb, 6, 3);
13020c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].left = InnerBoundaryStrength(mb, 12, 9);
13030c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].left = InnerBoundaryStrength(mb, 14, 11);
13040c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
13050c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
13060c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
13070c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[4].top =
13080c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[4], mb4x4Index[0]);
13090c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].top =
13100c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[5], mb4x4Index[1]);
13110c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].top =
13120c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[6], mb4x4Index[2]);
13130c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].top =
13140c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[7], mb4x4Index[3]);
13150c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[8].top =
13160c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[8], mb4x4Index[4]);
13170c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].top =
13180c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[9], mb4x4Index[5]);
13190c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].top =
13200c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[10], mb4x4Index[6]);
13210c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].top =
13220c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[11], mb4x4Index[7]);
13230c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[12].top =
13240c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[12], mb4x4Index[8]);
13250c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].top =
13260c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[13], mb4x4Index[9]);
13270c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].top =
13280c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[14], mb4x4Index[10]);
13290c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].top =
13300c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[15], mb4x4Index[11]);
13310c1bc742181ded4930842b46e9507372f0b1b963James Dong
13320c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1].left =
13330c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[1], mb4x4Index[0]);
13340c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[2].left =
13350c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[2], mb4x4Index[1]);
13360c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[3].left =
13370c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[3], mb4x4Index[2]);
13380c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[5].left =
13390c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[5], mb4x4Index[4]);
13400c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[6].left =
13410c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[6], mb4x4Index[5]);
13420c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[7].left =
13430c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[7], mb4x4Index[6]);
13440c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[9].left =
13450c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[9], mb4x4Index[8]);
13460c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[10].left =
13470c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[10], mb4x4Index[9]);
13480c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[11].left =
13490c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[11], mb4x4Index[10]);
13500c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[13].left =
13510c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[13], mb4x4Index[12]);
13520c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[14].left =
13530c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[14], mb4x4Index[13]);
13540c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[15].left =
13550c1bc742181ded4930842b46e9507372f0b1b963James Dong                InnerBoundaryStrength(mb, mb4x4Index[15], mb4x4Index[14]);
13560c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
13570c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (!nonZeroBs &&
13580c1bc742181ded4930842b46e9507372f0b1b963James Dong            (bS[4].top || bS[5].top || bS[6].top || bS[7].top ||
13590c1bc742181ded4930842b46e9507372f0b1b963James Dong             bS[8].top || bS[9].top || bS[10].top || bS[11].top ||
13600c1bc742181ded4930842b46e9507372f0b1b963James Dong             bS[12].top || bS[13].top || bS[14].top || bS[15].top ||
13610c1bc742181ded4930842b46e9507372f0b1b963James Dong             bS[1].left || bS[2].left || bS[3].left ||
13620c1bc742181ded4930842b46e9507372f0b1b963James Dong             bS[5].left || bS[6].left || bS[7].left ||
13630c1bc742181ded4930842b46e9507372f0b1b963James Dong             bS[9].left || bS[10].left || bS[11].left ||
13640c1bc742181ded4930842b46e9507372f0b1b963James Dong             bS[13].left || bS[14].left || bS[15].left))
13650c1bc742181ded4930842b46e9507372f0b1b963James Dong            nonZeroBs = HANTRO_TRUE;
13660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
13670c1bc742181ded4930842b46e9507372f0b1b963James Dong
13680c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(nonZeroBs);
13690c1bc742181ded4930842b46e9507372f0b1b963James Dong
13700c1bc742181ded4930842b46e9507372f0b1b963James Dong}
13710c1bc742181ded4930842b46e9507372f0b1b963James Dong
13720c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
13730c1bc742181ded4930842b46e9507372f0b1b963James Dong
13740c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetLumaEdgeThresholds
13750c1bc742181ded4930842b46e9507372f0b1b963James Dong
13760c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
13770c1bc742181ded4930842b46e9507372f0b1b963James Dong            Compute alpha, beta and tc0 thresholds for inner, left and top
13780c1bc742181ded4930842b46e9507372f0b1b963James Dong            luma edges of a macroblock.
13790c1bc742181ded4930842b46e9507372f0b1b963James Dong
13800c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
13810c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid GetLumaEdgeThresholds(
13820c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
13830c1bc742181ded4930842b46e9507372f0b1b963James Dong  mbStorage_t *mb,
13840c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 filteringFlags)
13850c1bc742181ded4930842b46e9507372f0b1b963James Dong{
13860c1bc742181ded4930842b46e9507372f0b1b963James Dong
13870c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
13880c1bc742181ded4930842b46e9507372f0b1b963James Dong
13890c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 indexA, indexB;
13900c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 qpAv, qp, qpTmp;
13910c1bc742181ded4930842b46e9507372f0b1b963James Dong
13920c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
13930c1bc742181ded4930842b46e9507372f0b1b963James Dong
13940c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
13950c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
13960c1bc742181ded4930842b46e9507372f0b1b963James Dong
13970c1bc742181ded4930842b46e9507372f0b1b963James Dong    qp = mb->qpY;
13980c1bc742181ded4930842b46e9507372f0b1b963James Dong
13990c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
14000c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
14010c1bc742181ded4930842b46e9507372f0b1b963James Dong
14020c1bc742181ded4930842b46e9507372f0b1b963James Dong    thresholds[INNER].alpha = alphas[indexA];
14030c1bc742181ded4930842b46e9507372f0b1b963James Dong    thresholds[INNER].beta = betas[indexB];
14040c1bc742181ded4930842b46e9507372f0b1b963James Dong    thresholds[INNER].tc0 = tc0[indexA];
14050c1bc742181ded4930842b46e9507372f0b1b963James Dong
14060c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_TOP_EDGE)
14070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14080c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbB->qpY;
14090c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != qp)
14100c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
14110c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
14120c1bc742181ded4930842b46e9507372f0b1b963James Dong
14130c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
14140c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
14150c1bc742181ded4930842b46e9507372f0b1b963James Dong
14160c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].alpha = alphas[indexA];
14170c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].beta = betas[indexB];
14180c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].tc0 = tc0[indexA];
14190c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
14200c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
14210c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
14220c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].alpha = thresholds[INNER].alpha;
14230c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].beta = thresholds[INNER].beta;
14240c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].tc0 = thresholds[INNER].tc0;
14250c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
14260c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14270c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_LEFT_EDGE)
14280c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14290c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbA->qpY;
14300c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != qp)
14310c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
14320c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
14330c1bc742181ded4930842b46e9507372f0b1b963James Dong
14340c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
14350c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
14360c1bc742181ded4930842b46e9507372f0b1b963James Dong
14370c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].alpha = alphas[indexA];
14380c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].beta = betas[indexB];
14390c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].tc0 = tc0[indexA];
14400c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
14410c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
14420c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
14430c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].alpha = thresholds[INNER].alpha;
14440c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].beta = thresholds[INNER].beta;
14450c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].tc0 = thresholds[INNER].tc0;
14460c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
14470c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14480c1bc742181ded4930842b46e9507372f0b1b963James Dong
14490c1bc742181ded4930842b46e9507372f0b1b963James Dong}
14500c1bc742181ded4930842b46e9507372f0b1b963James Dong
14510c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
14520c1bc742181ded4930842b46e9507372f0b1b963James Dong
14530c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetChromaEdgeThresholds
14540c1bc742181ded4930842b46e9507372f0b1b963James Dong
14550c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
14560c1bc742181ded4930842b46e9507372f0b1b963James Dong            Compute alpha, beta and tc0 thresholds for inner, left and top
14570c1bc742181ded4930842b46e9507372f0b1b963James Dong            chroma edges of a macroblock.
14580c1bc742181ded4930842b46e9507372f0b1b963James Dong
14590c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
14600c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid GetChromaEdgeThresholds(
14610c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
14620c1bc742181ded4930842b46e9507372f0b1b963James Dong  mbStorage_t *mb,
14630c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 filteringFlags,
14640c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 chromaQpIndexOffset)
14650c1bc742181ded4930842b46e9507372f0b1b963James Dong{
14660c1bc742181ded4930842b46e9507372f0b1b963James Dong
14670c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
14680c1bc742181ded4930842b46e9507372f0b1b963James Dong
14690c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 indexA, indexB;
14700c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 qpAv, qp, qpTmp;
14710c1bc742181ded4930842b46e9507372f0b1b963James Dong
14720c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
14730c1bc742181ded4930842b46e9507372f0b1b963James Dong
14740c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
14750c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
14760c1bc742181ded4930842b46e9507372f0b1b963James Dong
14770c1bc742181ded4930842b46e9507372f0b1b963James Dong    qp = mb->qpY;
14780c1bc742181ded4930842b46e9507372f0b1b963James Dong    qp = h264bsdQpC[CLIP3(0, 51, (i32)qp + chromaQpIndexOffset)];
14790c1bc742181ded4930842b46e9507372f0b1b963James Dong
14800c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
14810c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
14820c1bc742181ded4930842b46e9507372f0b1b963James Dong
14830c1bc742181ded4930842b46e9507372f0b1b963James Dong    thresholds[INNER].alpha = alphas[indexA];
14840c1bc742181ded4930842b46e9507372f0b1b963James Dong    thresholds[INNER].beta = betas[indexB];
14850c1bc742181ded4930842b46e9507372f0b1b963James Dong    thresholds[INNER].tc0 = tc0[indexA];
14860c1bc742181ded4930842b46e9507372f0b1b963James Dong
14870c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_TOP_EDGE)
14880c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14890c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbB->qpY;
14900c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != mb->qpY)
14910c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
14920c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
14930c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
14940c1bc742181ded4930842b46e9507372f0b1b963James Dong
14950c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
14960c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
14970c1bc742181ded4930842b46e9507372f0b1b963James Dong
14980c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].alpha = alphas[indexA];
14990c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].beta = betas[indexB];
15000c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].tc0 = tc0[indexA];
15010c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
15020c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
15030c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
15040c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].alpha = thresholds[INNER].alpha;
15050c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].beta = thresholds[INNER].beta;
15060c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[TOP].tc0 = thresholds[INNER].tc0;
15070c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
15080c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15090c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_LEFT_EDGE)
15100c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15110c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbA->qpY;
15120c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != mb->qpY)
15130c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
15140c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
15150c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
15160c1bc742181ded4930842b46e9507372f0b1b963James Dong
15170c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
15180c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
15190c1bc742181ded4930842b46e9507372f0b1b963James Dong
15200c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].alpha = alphas[indexA];
15210c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].beta = betas[indexB];
15220c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].tc0 = tc0[indexA];
15230c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
15240c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
15250c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
15260c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].alpha = thresholds[INNER].alpha;
15270c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].beta = thresholds[INNER].beta;
15280c1bc742181ded4930842b46e9507372f0b1b963James Dong            thresholds[LEFT].tc0 = thresholds[INNER].tc0;
15290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
15300c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15310c1bc742181ded4930842b46e9507372f0b1b963James Dong
15320c1bc742181ded4930842b46e9507372f0b1b963James Dong}
15330c1bc742181ded4930842b46e9507372f0b1b963James Dong
15340c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
15350c1bc742181ded4930842b46e9507372f0b1b963James Dong
15360c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterLuma
15370c1bc742181ded4930842b46e9507372f0b1b963James Dong
15380c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
15390c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to filter all luma edges of a macroblock
15400c1bc742181ded4930842b46e9507372f0b1b963James Dong
15410c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
15420c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterLuma(
15430c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
15440c1bc742181ded4930842b46e9507372f0b1b963James Dong  bS_t *bS,
15450c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
15460c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width)
15470c1bc742181ded4930842b46e9507372f0b1b963James Dong{
15480c1bc742181ded4930842b46e9507372f0b1b963James Dong
15490c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
15500c1bc742181ded4930842b46e9507372f0b1b963James Dong
15510c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 vblock;
15520c1bc742181ded4930842b46e9507372f0b1b963James Dong    bS_t *tmp;
15530c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptr;
15540c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 offset;
15550c1bc742181ded4930842b46e9507372f0b1b963James Dong
15560c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
15570c1bc742181ded4930842b46e9507372f0b1b963James Dong
15580c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
15590c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS);
15600c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
15610c1bc742181ded4930842b46e9507372f0b1b963James Dong
15620c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptr = data;
15630c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = bS;
15640c1bc742181ded4930842b46e9507372f0b1b963James Dong
15650c1bc742181ded4930842b46e9507372f0b1b963James Dong    offset  = TOP;
15660c1bc742181ded4930842b46e9507372f0b1b963James Dong
15670c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* loop block rows, perform filtering for all vertical edges of the block
15680c1bc742181ded4930842b46e9507372f0b1b963James Dong     * row first, then filter each horizontal edge of the row */
15690c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (vblock = 4; vblock--;)
15700c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15710c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* only perform filtering if bS is non-zero, first of the four
15720c1bc742181ded4930842b46e9507372f0b1b963James Dong         * FilterVerLumaEdge handles the left edge of the macroblock, others
15730c1bc742181ded4930842b46e9507372f0b1b963James Dong         * filter inner edges */
15740c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[0].left)
15750c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerLumaEdge(ptr, tmp[0].left, thresholds + LEFT, width);
15760c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[1].left)
15770c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerLumaEdge(ptr+4, tmp[1].left, thresholds + INNER, width);
15780c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[2].left)
15790c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerLumaEdge(ptr+8, tmp[2].left, thresholds + INNER, width);
15800c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[3].left)
15810c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerLumaEdge(ptr+12, tmp[3].left, thresholds + INNER, width);
15820c1bc742181ded4930842b46e9507372f0b1b963James Dong
15830c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* if bS is equal for all horizontal edges of the row -> perform
15840c1bc742181ded4930842b46e9507372f0b1b963James Dong         * filtering with FilterHorLuma, otherwise use FilterHorLumaEdge for
15850c1bc742181ded4930842b46e9507372f0b1b963James Dong         * each edge separately. offset variable indicates top macroblock edge
15860c1bc742181ded4930842b46e9507372f0b1b963James Dong         * on the first loop round, inner edge for the other rounds */
15870c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[0].top == tmp[1].top && tmp[1].top == tmp[2].top &&
15880c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp[2].top == tmp[3].top)
15890c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
15900c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(tmp[0].top)
15910c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorLuma(ptr, tmp[0].top, thresholds + offset, (i32)width);
15920c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
15930c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
15940c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
15950c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(tmp[0].top)
15960c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorLumaEdge(ptr, tmp[0].top, thresholds+offset,
15970c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
15980c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(tmp[1].top)
15990c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorLumaEdge(ptr+4, tmp[1].top, thresholds+offset,
16000c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
16010c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(tmp[2].top)
16020c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorLumaEdge(ptr+8, tmp[2].top, thresholds+offset,
16030c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
16040c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(tmp[3].top)
16050c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorLumaEdge(ptr+12, tmp[3].top, thresholds+offset,
16060c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
16070c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16080c1bc742181ded4930842b46e9507372f0b1b963James Dong
16090c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* four pixel rows ahead, i.e. next row of 4x4-blocks */
16100c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptr += width*4;
16110c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += 4;
16120c1bc742181ded4930842b46e9507372f0b1b963James Dong        offset = INNER;
16130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
16140c1bc742181ded4930842b46e9507372f0b1b963James Dong}
16150c1bc742181ded4930842b46e9507372f0b1b963James Dong
16160c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
16170c1bc742181ded4930842b46e9507372f0b1b963James Dong
16180c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FilterChroma
16190c1bc742181ded4930842b46e9507372f0b1b963James Dong
16200c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
16210c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to filter all chroma edges of a macroblock
16220c1bc742181ded4930842b46e9507372f0b1b963James Dong
16230c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
16240c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid FilterChroma(
16250c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *dataCb,
16260c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *dataCr,
16270c1bc742181ded4930842b46e9507372f0b1b963James Dong  bS_t *bS,
16280c1bc742181ded4930842b46e9507372f0b1b963James Dong  edgeThreshold_t *thresholds,
16290c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width)
16300c1bc742181ded4930842b46e9507372f0b1b963James Dong{
16310c1bc742181ded4930842b46e9507372f0b1b963James Dong
16320c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
16330c1bc742181ded4930842b46e9507372f0b1b963James Dong
16340c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 vblock;
16350c1bc742181ded4930842b46e9507372f0b1b963James Dong    bS_t *tmp;
16360c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 offset;
16370c1bc742181ded4930842b46e9507372f0b1b963James Dong
16380c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
16390c1bc742181ded4930842b46e9507372f0b1b963James Dong
16400c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(dataCb);
16410c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(dataCr);
16420c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS);
16430c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(thresholds);
16440c1bc742181ded4930842b46e9507372f0b1b963James Dong
16450c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = bS;
16460c1bc742181ded4930842b46e9507372f0b1b963James Dong    offset = TOP;
16470c1bc742181ded4930842b46e9507372f0b1b963James Dong
16480c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* loop block rows, perform filtering for all vertical edges of the block
16490c1bc742181ded4930842b46e9507372f0b1b963James Dong     * row first, then filter each horizontal edge of the row */
16500c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (vblock = 0; vblock < 2; vblock++)
16510c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
16520c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* only perform filtering if bS is non-zero, first two of the four
16530c1bc742181ded4930842b46e9507372f0b1b963James Dong         * FilterVerChromaEdge calls handle the left edge of the macroblock,
16540c1bc742181ded4930842b46e9507372f0b1b963James Dong         * others filter the inner edge. Note that as chroma uses bS values
16550c1bc742181ded4930842b46e9507372f0b1b963James Dong         * determined for luma edges, each bS is used only for 2 pixels of
16560c1bc742181ded4930842b46e9507372f0b1b963James Dong         * a 4-pixel edge */
16570c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[0].left)
16580c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
16590c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCb, tmp[0].left, thresholds + LEFT, width);
16600c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCr, tmp[0].left, thresholds + LEFT, width);
16610c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16620c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[4].left)
16630c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
16640c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCb+2*width, tmp[4].left, thresholds + LEFT,
16650c1bc742181ded4930842b46e9507372f0b1b963James Dong                width);
16660c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCr+2*width, tmp[4].left, thresholds + LEFT,
16670c1bc742181ded4930842b46e9507372f0b1b963James Dong                width);
16680c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16690c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[2].left)
16700c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
16710c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCb+4, tmp[2].left, thresholds + INNER,
16720c1bc742181ded4930842b46e9507372f0b1b963James Dong                width);
16730c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCr+4, tmp[2].left, thresholds + INNER,
16740c1bc742181ded4930842b46e9507372f0b1b963James Dong                width);
16750c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16760c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[6].left)
16770c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
16780c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCb+2*width+4, tmp[6].left,
16790c1bc742181ded4930842b46e9507372f0b1b963James Dong                thresholds + INNER, width);
16800c1bc742181ded4930842b46e9507372f0b1b963James Dong            FilterVerChromaEdge(dataCr+2*width+4, tmp[6].left,
16810c1bc742181ded4930842b46e9507372f0b1b963James Dong                thresholds + INNER, width);
16820c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16830c1bc742181ded4930842b46e9507372f0b1b963James Dong
16840c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* if bS is equal for all horizontal edges of the row -> perform
16850c1bc742181ded4930842b46e9507372f0b1b963James Dong         * filtering with FilterHorChroma, otherwise use FilterHorChromaEdge
16860c1bc742181ded4930842b46e9507372f0b1b963James Dong         * for each edge separately. offset variable indicates top macroblock
16870c1bc742181ded4930842b46e9507372f0b1b963James Dong         * edge on the first loop round, inner edge for the second */
16880c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp[0].top == tmp[1].top && tmp[1].top == tmp[2].top &&
16890c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp[2].top == tmp[3].top)
16900c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
16910c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(tmp[0].top)
16920c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
16930c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChroma(dataCb, tmp[0].top, thresholds+offset,
16940c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
16950c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChroma(dataCr, tmp[0].top, thresholds+offset,
16960c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
16970c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
16980c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16990c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
17000c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
17010c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (tmp[0].top)
17020c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
17030c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCb, tmp[0].top, thresholds+offset,
17040c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17050c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCr, tmp[0].top, thresholds+offset,
17060c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17070c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
17080c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (tmp[1].top)
17090c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
17100c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCb+2, tmp[1].top, thresholds+offset,
17110c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17120c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCr+2, tmp[1].top, thresholds+offset,
17130c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17140c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
17150c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (tmp[2].top)
17160c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
17170c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCb+4, tmp[2].top, thresholds+offset,
17180c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17190c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCr+4, tmp[2].top, thresholds+offset,
17200c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17210c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
17220c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (tmp[3].top)
17230c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
17240c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCb+6, tmp[3].top, thresholds+offset,
17250c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17260c1bc742181ded4930842b46e9507372f0b1b963James Dong                FilterHorChromaEdge(dataCr+6, tmp[3].top, thresholds+offset,
17270c1bc742181ded4930842b46e9507372f0b1b963James Dong                    (i32)width);
17280c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
17290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
17300c1bc742181ded4930842b46e9507372f0b1b963James Dong
17310c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += 8;
17320c1bc742181ded4930842b46e9507372f0b1b963James Dong        dataCb += width*4;
17330c1bc742181ded4930842b46e9507372f0b1b963James Dong        dataCr += width*4;
17340c1bc742181ded4930842b46e9507372f0b1b963James Dong        offset = INNER;
17350c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
17360c1bc742181ded4930842b46e9507372f0b1b963James Dong}
17370c1bc742181ded4930842b46e9507372f0b1b963James Dong
17380c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */
17390c1bc742181ded4930842b46e9507372f0b1b963James Dong
17400c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
17410c1bc742181ded4930842b46e9507372f0b1b963James Dong
17420c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdFilterPicture
17430c1bc742181ded4930842b46e9507372f0b1b963James Dong
17440c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
17450c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform deblocking filtering for a picture. Filter does not copy
17460c1bc742181ded4930842b46e9507372f0b1b963James Dong          the original picture anywhere but filtering is performed directly
17470c1bc742181ded4930842b46e9507372f0b1b963James Dong          on the original image. Parameters controlling the filtering process
17480c1bc742181ded4930842b46e9507372f0b1b963James Dong          are computed based on information in macroblock structures of the
17490c1bc742181ded4930842b46e9507372f0b1b963James Dong          filtered macroblock, macroblock above and macroblock on the left of
17500c1bc742181ded4930842b46e9507372f0b1b963James Dong          the filtered one.
17510c1bc742181ded4930842b46e9507372f0b1b963James Dong
17520c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
17530c1bc742181ded4930842b46e9507372f0b1b963James Dong          image         pointer to image to be filtered
17540c1bc742181ded4930842b46e9507372f0b1b963James Dong          mb            pointer to macroblock data structure of the top-left
17550c1bc742181ded4930842b46e9507372f0b1b963James Dong                        macroblock of the picture
17560c1bc742181ded4930842b46e9507372f0b1b963James Dong
17570c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
17580c1bc742181ded4930842b46e9507372f0b1b963James Dong          image         filtered image stored here
17590c1bc742181ded4930842b46e9507372f0b1b963James Dong
17600c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
17610c1bc742181ded4930842b46e9507372f0b1b963James Dong          none
17620c1bc742181ded4930842b46e9507372f0b1b963James Dong
17630c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
17640c1bc742181ded4930842b46e9507372f0b1b963James Dong
17650c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint --e{550} Symbol not accessed */
17660c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdFilterPicture(
17670c1bc742181ded4930842b46e9507372f0b1b963James Dong  image_t *image,
17680c1bc742181ded4930842b46e9507372f0b1b963James Dong  mbStorage_t *mb)
17690c1bc742181ded4930842b46e9507372f0b1b963James Dong{
17700c1bc742181ded4930842b46e9507372f0b1b963James Dong
17710c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
17720c1bc742181ded4930842b46e9507372f0b1b963James Dong
17730c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 flags;
17740c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 picSizeInMbs, mbRow, mbCol;
17750c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 picWidthInMbs;
17760c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *data;
17770c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *pMb;
17780c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 bS[2][16];
17790c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 thresholdLuma[2][16];
17800c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 thresholdChroma[2][8];
17810c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 alpha[2][2];
17820c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 beta[2][2];
17830c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXResult res;
17840c1bc742181ded4930842b46e9507372f0b1b963James Dong
17850c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
17860c1bc742181ded4930842b46e9507372f0b1b963James Dong
17870c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image);
17880c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
17890c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image->data);
17900c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image->width);
17910c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image->height);
17920c1bc742181ded4930842b46e9507372f0b1b963James Dong
17930c1bc742181ded4930842b46e9507372f0b1b963James Dong    picWidthInMbs = image->width;
17940c1bc742181ded4930842b46e9507372f0b1b963James Dong    data = image->data;
17950c1bc742181ded4930842b46e9507372f0b1b963James Dong    picSizeInMbs = picWidthInMbs * image->height;
17960c1bc742181ded4930842b46e9507372f0b1b963James Dong
17970c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb = mb;
17980c1bc742181ded4930842b46e9507372f0b1b963James Dong
17990c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (mbRow = 0, mbCol = 0; mbRow < image->height; pMb++)
18000c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
18010c1bc742181ded4930842b46e9507372f0b1b963James Dong        flags = GetMbFilteringFlags(pMb);
18020c1bc742181ded4930842b46e9507372f0b1b963James Dong
18030c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (flags)
18040c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
18050c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* GetBoundaryStrengths function returns non-zero value if any of
18060c1bc742181ded4930842b46e9507372f0b1b963James Dong             * the bS values for the macroblock being processed was non-zero */
18070c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (GetBoundaryStrengths(pMb, bS, flags))
18080c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
18090c1bc742181ded4930842b46e9507372f0b1b963James Dong
18100c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* Luma */
18110c1bc742181ded4930842b46e9507372f0b1b963James Dong                GetLumaEdgeThresholds(pMb,alpha,beta,thresholdLuma,bS,flags);
18120c1bc742181ded4930842b46e9507372f0b1b963James Dong                data = image->data + mbRow * picWidthInMbs * 256 + mbCol * 16;
18130c1bc742181ded4930842b46e9507372f0b1b963James Dong
18140c1bc742181ded4930842b46e9507372f0b1b963James Dong                res = omxVCM4P10_FilterDeblockingLuma_VerEdge_I( data,
18150c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (OMX_S32)(picWidthInMbs*16),
18160c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)alpha,
18170c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)beta,
18180c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)thresholdLuma,
18190c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)bS );
18200c1bc742181ded4930842b46e9507372f0b1b963James Dong
18210c1bc742181ded4930842b46e9507372f0b1b963James Dong                res = omxVCM4P10_FilterDeblockingLuma_HorEdge_I( data,
18220c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (OMX_S32)(picWidthInMbs*16),
18230c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)alpha+2,
18240c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)beta+2,
18250c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)thresholdLuma+16,
18260c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (const OMX_U8*)bS+16 );
18270c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* Cb */
18280c1bc742181ded4930842b46e9507372f0b1b963James Dong                GetChromaEdgeThresholds(pMb, alpha, beta, thresholdChroma,
18290c1bc742181ded4930842b46e9507372f0b1b963James Dong                                        bS, flags, pMb->chromaQpIndexOffset);
18300c1bc742181ded4930842b46e9507372f0b1b963James Dong                data = image->data + picSizeInMbs * 256 +
18310c1bc742181ded4930842b46e9507372f0b1b963James Dong                    mbRow * picWidthInMbs * 64 + mbCol * 8;
18320c1bc742181ded4930842b46e9507372f0b1b963James Dong
18330c1bc742181ded4930842b46e9507372f0b1b963James Dong                res = omxVCM4P10_FilterDeblockingChroma_VerEdge_I( data,
18340c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (OMX_S32)(picWidthInMbs*8),
18350c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)alpha,
18360c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)beta,
18370c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)thresholdChroma,
18380c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)bS );
18390c1bc742181ded4930842b46e9507372f0b1b963James Dong                res = omxVCM4P10_FilterDeblockingChroma_HorEdge_I( data,
18400c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (OMX_S32)(picWidthInMbs*8),
18410c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)alpha+2,
18420c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)beta+2,
18430c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)thresholdChroma+8,
18440c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)bS+16 );
18450c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* Cr */
18460c1bc742181ded4930842b46e9507372f0b1b963James Dong                data += (picSizeInMbs * 64);
18470c1bc742181ded4930842b46e9507372f0b1b963James Dong                res = omxVCM4P10_FilterDeblockingChroma_VerEdge_I( data,
18480c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (OMX_S32)(picWidthInMbs*8),
18490c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)alpha,
18500c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)beta,
18510c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)thresholdChroma,
18520c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)bS );
18530c1bc742181ded4930842b46e9507372f0b1b963James Dong                res = omxVCM4P10_FilterDeblockingChroma_HorEdge_I( data,
18540c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (OMX_S32)(picWidthInMbs*8),
18550c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)alpha+2,
18560c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)beta+2,
18570c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)thresholdChroma+8,
18580c1bc742181ded4930842b46e9507372f0b1b963James Dong                                              (const OMX_U8*)bS+16 );
18590c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
18600c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
18610c1bc742181ded4930842b46e9507372f0b1b963James Dong
18620c1bc742181ded4930842b46e9507372f0b1b963James Dong        mbCol++;
18630c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (mbCol == picWidthInMbs)
18640c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
18650c1bc742181ded4930842b46e9507372f0b1b963James Dong            mbCol = 0;
18660c1bc742181ded4930842b46e9507372f0b1b963James Dong            mbRow++;
18670c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
18680c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
18690c1bc742181ded4930842b46e9507372f0b1b963James Dong
18700c1bc742181ded4930842b46e9507372f0b1b963James Dong}
18710c1bc742181ded4930842b46e9507372f0b1b963James Dong
18720c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
18730c1bc742181ded4930842b46e9507372f0b1b963James Dong
18740c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetBoundaryStrengths
18750c1bc742181ded4930842b46e9507372f0b1b963James Dong
18760c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
18770c1bc742181ded4930842b46e9507372f0b1b963James Dong            Function to calculate boundary strengths for all edges of a
18780c1bc742181ded4930842b46e9507372f0b1b963James Dong            macroblock. Function returns HANTRO_TRUE if any of the bS values for
18790c1bc742181ded4930842b46e9507372f0b1b963James Dong            the macroblock had non-zero value, HANTRO_FALSE otherwise.
18800c1bc742181ded4930842b46e9507372f0b1b963James Dong
18810c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
18820c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 GetBoundaryStrengths(mbStorage_t *mb, u8 (*bS)[16], u32 flags)
18830c1bc742181ded4930842b46e9507372f0b1b963James Dong{
18840c1bc742181ded4930842b46e9507372f0b1b963James Dong
18850c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
18860c1bc742181ded4930842b46e9507372f0b1b963James Dong
18870c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* this flag is set HANTRO_TRUE as soon as any boundary strength value is
18880c1bc742181ded4930842b46e9507372f0b1b963James Dong     * non-zero */
18890c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 nonZeroBs = HANTRO_FALSE;
18900c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 *pTmp;
18910c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp1, tmp2, isIntraMb;
18920c1bc742181ded4930842b46e9507372f0b1b963James Dong
18930c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
18940c1bc742181ded4930842b46e9507372f0b1b963James Dong
18950c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
18960c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bS);
18970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(flags);
18980c1bc742181ded4930842b46e9507372f0b1b963James Dong
18990c1bc742181ded4930842b46e9507372f0b1b963James Dong    isIntraMb = IS_INTRA_MB(*mb);
19000c1bc742181ded4930842b46e9507372f0b1b963James Dong
19010c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* top edges */
19020c1bc742181ded4930842b46e9507372f0b1b963James Dong    pTmp = (u32*)&bS[1][0];
19030c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (flags & FILTER_TOP_EDGE)
19040c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19050c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (isIntraMb || IS_INTRA_MB(*mb->mbB))
19060c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19070c1bc742181ded4930842b46e9507372f0b1b963James Dong            *pTmp = 0x04040404;
19080c1bc742181ded4930842b46e9507372f0b1b963James Dong            nonZeroBs = HANTRO_TRUE;
19090c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19100c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
19110c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19120c1bc742181ded4930842b46e9507372f0b1b963James Dong            *pTmp = EdgeBoundaryStrengthTop(mb, mb->mbB);
19130c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (*pTmp)
19140c1bc742181ded4930842b46e9507372f0b1b963James Dong                nonZeroBs = HANTRO_TRUE;
19150c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19160c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19170c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
19180c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19190c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp = 0;
19200c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19210c1bc742181ded4930842b46e9507372f0b1b963James Dong
19220c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* left edges */
19230c1bc742181ded4930842b46e9507372f0b1b963James Dong    pTmp = (u32*)&bS[0][0];
19240c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (flags & FILTER_LEFT_EDGE)
19250c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19260c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (isIntraMb || IS_INTRA_MB(*mb->mbA))
19270c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19280c1bc742181ded4930842b46e9507372f0b1b963James Dong            /*bS[0][0] = bS[0][1] = bS[0][2] = bS[0][3] = 4;*/
19290c1bc742181ded4930842b46e9507372f0b1b963James Dong            *pTmp = 0x04040404;
19300c1bc742181ded4930842b46e9507372f0b1b963James Dong            nonZeroBs = HANTRO_TRUE;
19310c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19320c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
19330c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19340c1bc742181ded4930842b46e9507372f0b1b963James Dong            *pTmp = EdgeBoundaryStrengthLeft(mb, mb->mbA);
19350c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!nonZeroBs && *pTmp)
19360c1bc742181ded4930842b46e9507372f0b1b963James Dong                nonZeroBs = HANTRO_TRUE;
19370c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19380c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19390c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
19400c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19410c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp = 0;
19420c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19430c1bc742181ded4930842b46e9507372f0b1b963James Dong
19440c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* inner edges */
19450c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (isIntraMb)
19460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19470c1bc742181ded4930842b46e9507372f0b1b963James Dong        pTmp++;
19480c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp++ = 0x03030303;
19490c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp++ = 0x03030303;
19500c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp++ = 0x03030303;
19510c1bc742181ded4930842b46e9507372f0b1b963James Dong        pTmp++;
19520c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp++ = 0x03030303;
19530c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp++ = 0x03030303;
19540c1bc742181ded4930842b46e9507372f0b1b963James Dong        *pTmp = 0x03030303;
19550c1bc742181ded4930842b46e9507372f0b1b963James Dong
19560c1bc742181ded4930842b46e9507372f0b1b963James Dong        nonZeroBs = HANTRO_TRUE;
19570c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19580c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
19590c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19600c1bc742181ded4930842b46e9507372f0b1b963James Dong        pTmp = (u32*)mb->totalCoeff;
19610c1bc742181ded4930842b46e9507372f0b1b963James Dong
19620c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 16x16 inter mb -> ref addresses or motion vectors cannot differ,
19630c1bc742181ded4930842b46e9507372f0b1b963James Dong         * only check if either of the blocks contain coefficients */
19640c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (h264bsdNumMbPart(mb->mbType) == 1)
19650c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
19670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = *pTmp++;
19680c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][4]  = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [2]  || [0] */
19690c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][5]  = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [3]  || [1] */
19700c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][4]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [1]  || [0] */
19710c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][5]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [3]  || [2] */
19720c1bc742181ded4930842b46e9507372f0b1b963James Dong
19730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
19740c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][6]  = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [6]  || [4] */
19750c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][7]  = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [7]  || [5] */
19760c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][12] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [5]  || [4] */
19770c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][13] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [7]  || [6] */
19780c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = *pTmp;
19790c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [10] || [8] */
19800c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [11] || [9] */
19810c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [9]  || [8] */
19820c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [11] || [10] */
19830c1bc742181ded4930842b46e9507372f0b1b963James Dong
19840c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][14] = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [14] || [12] */
19850c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][15] = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [15] || [13] */
19860c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][14] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [13] || [12] */
19870c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][15] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [15] || [14] */
19880c1bc742181ded4930842b46e9507372f0b1b963James Dong
19890c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
19900c1bc742181ded4930842b46e9507372f0b1b963James Dong            u32 tmp3, tmp4;
19910c1bc742181ded4930842b46e9507372f0b1b963James Dong
19920c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[8];
19930c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[2];
19940c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[9];
19950c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[3];
19960c1bc742181ded4930842b46e9507372f0b1b963James Dong
19970c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][8] = tmp1 || tmp2 ? 2 : 0;
19980c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[12];
19990c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[6];
20000c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][9] = tmp3 || tmp4 ? 2 : 0;
20010c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[13];
20020c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[7];
20030c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][10] = tmp1 || tmp2 ? 2 : 0;
20040c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[4];
20050c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[1];
20060c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][11] = tmp3 || tmp4 ? 2 : 0;
20070c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[6];
20080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[3];
20090c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][8] = tmp1 || tmp2 ? 2 : 0;
20100c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[12];
20110c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[9];
20120c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][9] = tmp3 || tmp4 ? 2 : 0;
20130c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[14];
20140c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[11];
20150c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][10] = tmp1 || tmp2 ? 2 : 0;
20160c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][11] = tmp3 || tmp4 ? 2 : 0;
20170c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
20180c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
20190c1bc742181ded4930842b46e9507372f0b1b963James Dong
20200c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 16x8 inter mb -> ref addresses and motion vectors can be different
20210c1bc742181ded4930842b46e9507372f0b1b963James Dong         * only for the middle horizontal edge, for the other top edges it is
20220c1bc742181ded4930842b46e9507372f0b1b963James Dong         * enough to check whether the blocks contain coefficients or not. The
20230c1bc742181ded4930842b46e9507372f0b1b963James Dong         * same applies to all internal left edges. */
20240c1bc742181ded4930842b46e9507372f0b1b963James Dong        else if (mb->mbType == P_L0_L0_16x8)
20250c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
20260c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
20270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = *pTmp++;
20280c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][4]  = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [2]  || [0] */
20290c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][5]  = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [3]  || [1] */
20300c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][4]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [1]  || [0] */
20310c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][5]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [3]  || [2] */
20320c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
20330c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][6]  = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [6]  || [4] */
20340c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][7]  = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [7]  || [5] */
20350c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][12] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [5]  || [4] */
20360c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][13] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [7]  || [6] */
20370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = *pTmp;
20380c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [10] || [8] */
20390c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [11] || [9] */
20400c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [9]  || [8] */
20410c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [11] || [10] */
20420c1bc742181ded4930842b46e9507372f0b1b963James Dong
20430c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][14] = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [14] || [12] */
20440c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][15] = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [15] || [13] */
20450c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][14] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [13] || [12] */
20460c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][15] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [15] || [14] */
20470c1bc742181ded4930842b46e9507372f0b1b963James Dong
20480c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][8] = (u8)InnerBoundaryStrength(mb, 8, 2);
20490c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][9] = (u8)InnerBoundaryStrength(mb, 9, 3);
20500c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][10] = (u8)InnerBoundaryStrength(mb, 12, 6);
20510c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][11] = (u8)InnerBoundaryStrength(mb, 13, 7);
20520c1bc742181ded4930842b46e9507372f0b1b963James Dong
20530c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
20540c1bc742181ded4930842b46e9507372f0b1b963James Dong            u32 tmp3, tmp4;
20550c1bc742181ded4930842b46e9507372f0b1b963James Dong
20560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[4];
20570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[1];
20580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[6];
20590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[3];
20600c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][8] = tmp1 || tmp2 ? 2 : 0;
20610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[12];
20620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[9];
20630c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][9] = tmp3 || tmp4 ? 2 : 0;
20640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[14];
20650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[11];
20660c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][10] = tmp1 || tmp2 ? 2 : 0;
20670c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][11] = tmp3 || tmp4 ? 2 : 0;
20680c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
20690c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
20700c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 8x16 inter mb -> ref addresses and motion vectors can be different
20710c1bc742181ded4930842b46e9507372f0b1b963James Dong         * only for the middle vertical edge, for the other left edges it is
20720c1bc742181ded4930842b46e9507372f0b1b963James Dong         * enough to check whether the blocks contain coefficients or not. The
20730c1bc742181ded4930842b46e9507372f0b1b963James Dong         * same applies to all internal top edges. */
20740c1bc742181ded4930842b46e9507372f0b1b963James Dong        else if (mb->mbType == P_L0_L0_8x16)
20750c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
20760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
20770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = *pTmp++;
20780c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][4]  = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [2]  || [0] */
20790c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][5]  = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [3]  || [1] */
20800c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][4]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [1]  || [0] */
20810c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][5]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [3]  || [2] */
20820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
20830c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][6]  = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [6]  || [4] */
20840c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][7]  = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [7]  || [5] */
20850c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][12] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [5]  || [4] */
20860c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][13] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [7]  || [6] */
20870c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = *pTmp;
20880c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [10] || [8] */
20890c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [11] || [9] */
20900c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [9]  || [8] */
20910c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [11] || [10] */
20920c1bc742181ded4930842b46e9507372f0b1b963James Dong
20930c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][14] = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [14] || [12] */
20940c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][15] = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [15] || [13] */
20950c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][14] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [13] || [12] */
20960c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][15] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [15] || [14] */
20970c1bc742181ded4930842b46e9507372f0b1b963James Dong
20980c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][8] = (u8)InnerBoundaryStrength(mb, 4, 1);
20990c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][9] = (u8)InnerBoundaryStrength(mb, 6, 3);
21000c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][10] = (u8)InnerBoundaryStrength(mb, 12, 9);
21010c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][11] = (u8)InnerBoundaryStrength(mb, 14, 11);
21020c1bc742181ded4930842b46e9507372f0b1b963James Dong
21030c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
21040c1bc742181ded4930842b46e9507372f0b1b963James Dong            u32 tmp3, tmp4;
21050c1bc742181ded4930842b46e9507372f0b1b963James Dong
21060c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[8];
21070c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[2];
21080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[9];
21090c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[3];
21100c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][8] = tmp1 || tmp2 ? 2 : 0;
21110c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb->totalCoeff[12];
21120c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb->totalCoeff[6];
21130c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][9] = tmp3 || tmp4 ? 2 : 0;
21140c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = mb->totalCoeff[13];
21150c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = mb->totalCoeff[7];
21160c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][10] = tmp1 || tmp2 ? 2 : 0;
21170c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][11] = tmp3 || tmp4 ? 2 : 0;
21180c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
21190c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
21200c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
21210c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
21220c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
21230c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][4] = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 2, 0);
21240c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][5] = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 3, 1);
21250c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][4] = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 1, 0);
21260c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][5] = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 3, 2);
21270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
21280c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][6]  = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 6, 4);
21290c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][7]  = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 7, 5);
21300c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][12] = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 5, 4);
21310c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][13] = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 7, 6);
21320c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp++;
21330c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 10, 8);
21340c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 11, 9);
21350c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 9, 8);
21360c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 11, 10);
21370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *pTmp;
21380c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][14] = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 14, 12);
21390c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][15] = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 15, 13);
21400c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][14] = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 13, 12);
21410c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][15] = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 15, 14);
21420c1bc742181ded4930842b46e9507372f0b1b963James Dong
21430c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][8] = (u8)InnerBoundaryStrength(mb, 8, 2);
21440c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][9] = (u8)InnerBoundaryStrength(mb, 9, 3);
21450c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][10] = (u8)InnerBoundaryStrength(mb, 12, 6);
21460c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[1][11] = (u8)InnerBoundaryStrength(mb, 13, 7);
21470c1bc742181ded4930842b46e9507372f0b1b963James Dong
21480c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][8] = (u8)InnerBoundaryStrength(mb, 4, 1);
21490c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][9] = (u8)InnerBoundaryStrength(mb, 6, 3);
21500c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][10] = (u8)InnerBoundaryStrength(mb, 12, 9);
21510c1bc742181ded4930842b46e9507372f0b1b963James Dong            bS[0][11] = (u8)InnerBoundaryStrength(mb, 14, 11);
21520c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
21530c1bc742181ded4930842b46e9507372f0b1b963James Dong        pTmp = (u32*)&bS[0][0];
21540c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (!nonZeroBs && (pTmp[1] || pTmp[2] || pTmp[3] ||
21550c1bc742181ded4930842b46e9507372f0b1b963James Dong                           pTmp[5] || pTmp[6] || pTmp[7]) )
21560c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
21570c1bc742181ded4930842b46e9507372f0b1b963James Dong            nonZeroBs = HANTRO_TRUE;
21580c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
21590c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
21600c1bc742181ded4930842b46e9507372f0b1b963James Dong
21610c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(nonZeroBs);
21620c1bc742181ded4930842b46e9507372f0b1b963James Dong
21630c1bc742181ded4930842b46e9507372f0b1b963James Dong}
21640c1bc742181ded4930842b46e9507372f0b1b963James Dong
21650c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
21660c1bc742181ded4930842b46e9507372f0b1b963James Dong
21670c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetLumaEdgeThresholds
21680c1bc742181ded4930842b46e9507372f0b1b963James Dong
21690c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
21700c1bc742181ded4930842b46e9507372f0b1b963James Dong            Compute alpha, beta and tc0 thresholds for inner, left and top
21710c1bc742181ded4930842b46e9507372f0b1b963James Dong            luma edges of a macroblock.
21720c1bc742181ded4930842b46e9507372f0b1b963James Dong
21730c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
21740c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid GetLumaEdgeThresholds(
21750c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *mb,
21760c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*alpha)[2],
21770c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*beta)[2],
21780c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*threshold)[16],
21790c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*bs)[16],
21800c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 filteringFlags )
21810c1bc742181ded4930842b46e9507372f0b1b963James Dong{
21820c1bc742181ded4930842b46e9507372f0b1b963James Dong
21830c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
21840c1bc742181ded4930842b46e9507372f0b1b963James Dong
21850c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 indexA, indexB;
21860c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 qpAv, qp, qpTmp;
21870c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
21880c1bc742181ded4930842b46e9507372f0b1b963James Dong
21890c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
21900c1bc742181ded4930842b46e9507372f0b1b963James Dong
21910c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(threshold);
21920c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bs);
21930c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(beta);
21940c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(alpha);
21950c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
21960c1bc742181ded4930842b46e9507372f0b1b963James Dong
21970c1bc742181ded4930842b46e9507372f0b1b963James Dong    qp = mb->qpY;
21980c1bc742181ded4930842b46e9507372f0b1b963James Dong
21990c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
22000c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
22010c1bc742181ded4930842b46e9507372f0b1b963James Dong
22020c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Internal edge values */
22030c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[0][1] = alphas[indexA];
22040c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[1][1] = alphas[indexA];
22050c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[1][0] = alphas[indexA];
22060c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[0][0] = alphas[indexA];
22070c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[0][1] = betas[indexB];
22080c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[1][1] = betas[indexB];
22090c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[1][0] = betas[indexB];
22100c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[0][0] = betas[indexB];
22110c1bc742181ded4930842b46e9507372f0b1b963James Dong
22120c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* vertical scan order */
22130c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 2; i++)
22140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
22150c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 t1, t2;
22160c1bc742181ded4930842b46e9507372f0b1b963James Dong
22170c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][0];
22180c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][1];
22190c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][0]  = (t1) ? tc0[indexA][t1] : 0;
22200c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][2];
22210c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][1]  = (t2) ? tc0[indexA][t2] : 0;
22220c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][3];
22230c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][2]  = (t1) ? tc0[indexA][t1] : 0;
22240c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][4];
22250c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][3]  = (t2) ? tc0[indexA][t2] : 0;
22260c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][5];
22270c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][4]  = (t1) ? tc0[indexA][t1] : 0;
22280c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][6];
22290c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][5]  = (t2) ? tc0[indexA][t2] : 0;
22300c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][7];
22310c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][6]  = (t1) ? tc0[indexA][t1] : 0;
22320c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][8];
22330c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][7]  = (t2) ? tc0[indexA][t2] : 0;
22340c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][9];
22350c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][8]  = (t1) ? tc0[indexA][t1] : 0;
22360c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][10];
22370c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][9]  = (t2) ? tc0[indexA][t2] : 0;
22380c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][11];
22390c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][10] = (t1) ? tc0[indexA][t1] : 0;
22400c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][12];
22410c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][11] = (t2) ? tc0[indexA][t2] : 0;
22420c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][13];
22430c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][12] = (t1) ? tc0[indexA][t1] : 0;
22440c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][14];
22450c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][13] = (t2) ? tc0[indexA][t2] : 0;
22460c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][15];
22470c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][14] = (t1) ? tc0[indexA][t1] : 0;
22480c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][15] = (t2) ? tc0[indexA][t2] : 0;
22490c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
22500c1bc742181ded4930842b46e9507372f0b1b963James Dong
22510c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_TOP_EDGE)
22520c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
22530c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbB->qpY;
22540c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != qp)
22550c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
22560c1bc742181ded4930842b46e9507372f0b1b963James Dong            u32 t1, t2, t3, t4;
22570c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
22580c1bc742181ded4930842b46e9507372f0b1b963James Dong
22590c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
22600c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
22610c1bc742181ded4930842b46e9507372f0b1b963James Dong
22620c1bc742181ded4930842b46e9507372f0b1b963James Dong            alpha[1][0] = alphas[indexA];
22630c1bc742181ded4930842b46e9507372f0b1b963James Dong            beta[1][0] = betas[indexB];
22640c1bc742181ded4930842b46e9507372f0b1b963James Dong            t1 = bs[1][0];
22650c1bc742181ded4930842b46e9507372f0b1b963James Dong            t2 = bs[1][1];
22660c1bc742181ded4930842b46e9507372f0b1b963James Dong            t3 = bs[1][2];
22670c1bc742181ded4930842b46e9507372f0b1b963James Dong            t4 = bs[1][3];
22680c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][0] = (t1 && (t1 < 4)) ? tc0[indexA][t1] : 0;
22690c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][1] = (t2 && (t2 < 4)) ? tc0[indexA][t2] : 0;
22700c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][2] = (t3 && (t3 < 4)) ? tc0[indexA][t3] : 0;
22710c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][3] = (t4 && (t4 < 4)) ? tc0[indexA][t4] : 0;
22720c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
22730c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
22740c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_LEFT_EDGE)
22750c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
22760c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbA->qpY;
22770c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != qp)
22780c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
22790c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
22800c1bc742181ded4930842b46e9507372f0b1b963James Dong
22810c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
22820c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
22830c1bc742181ded4930842b46e9507372f0b1b963James Dong
22840c1bc742181ded4930842b46e9507372f0b1b963James Dong            alpha[0][0] = alphas[indexA];
22850c1bc742181ded4930842b46e9507372f0b1b963James Dong            beta[0][0] = betas[indexB];
22860c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][0] = (bs[0][0] && (bs[0][0] < 4)) ? tc0[indexA][bs[0][0]] : 0;
22870c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][1] = (bs[0][1] && (bs[0][1] < 4)) ? tc0[indexA][bs[0][1]] : 0;
22880c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][2] = (bs[0][2] && (bs[0][2] < 4)) ? tc0[indexA][bs[0][2]] : 0;
22890c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][3] = (bs[0][3] && (bs[0][3] < 4)) ? tc0[indexA][bs[0][3]] : 0;
22900c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
22910c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
22920c1bc742181ded4930842b46e9507372f0b1b963James Dong
22930c1bc742181ded4930842b46e9507372f0b1b963James Dong}
22940c1bc742181ded4930842b46e9507372f0b1b963James Dong
22950c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
22960c1bc742181ded4930842b46e9507372f0b1b963James Dong
22970c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetChromaEdgeThresholds
22980c1bc742181ded4930842b46e9507372f0b1b963James Dong
22990c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
23000c1bc742181ded4930842b46e9507372f0b1b963James Dong            Compute alpha, beta and tc0 thresholds for inner, left and top
23010c1bc742181ded4930842b46e9507372f0b1b963James Dong            chroma edges of a macroblock.
23020c1bc742181ded4930842b46e9507372f0b1b963James Dong
23030c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
23040c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid GetChromaEdgeThresholds(
23050c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *mb,
23060c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*alpha)[2],
23070c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*beta)[2],
23080c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*threshold)[8],
23090c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 (*bs)[16],
23100c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 filteringFlags,
23110c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 chromaQpIndexOffset)
23120c1bc742181ded4930842b46e9507372f0b1b963James Dong{
23130c1bc742181ded4930842b46e9507372f0b1b963James Dong
23140c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
23150c1bc742181ded4930842b46e9507372f0b1b963James Dong
23160c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 indexA, indexB;
23170c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 qpAv, qp, qpTmp;
23180c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
23190c1bc742181ded4930842b46e9507372f0b1b963James Dong
23200c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
23210c1bc742181ded4930842b46e9507372f0b1b963James Dong
23220c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(threshold);
23230c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(bs);
23240c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(beta);
23250c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(alpha);
23260c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
23270c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
23280c1bc742181ded4930842b46e9507372f0b1b963James Dong
23290c1bc742181ded4930842b46e9507372f0b1b963James Dong    qp = mb->qpY;
23300c1bc742181ded4930842b46e9507372f0b1b963James Dong    qp = h264bsdQpC[CLIP3(0, 51, (i32)qp + chromaQpIndexOffset)];
23310c1bc742181ded4930842b46e9507372f0b1b963James Dong
23320c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
23330c1bc742181ded4930842b46e9507372f0b1b963James Dong    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
23340c1bc742181ded4930842b46e9507372f0b1b963James Dong
23350c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[0][1] = alphas[indexA];
23360c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[1][1] = alphas[indexA];
23370c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[1][0] = alphas[indexA];
23380c1bc742181ded4930842b46e9507372f0b1b963James Dong    alpha[0][0] = alphas[indexA];
23390c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[0][1] = betas[indexB];
23400c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[1][1] = betas[indexB];
23410c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[1][0] = betas[indexB];
23420c1bc742181ded4930842b46e9507372f0b1b963James Dong    beta[0][0] = betas[indexB];
23430c1bc742181ded4930842b46e9507372f0b1b963James Dong
23440c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 2; i++)
23450c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
23460c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 t1, t2;
23470c1bc742181ded4930842b46e9507372f0b1b963James Dong
23480c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][0];
23490c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][1];
23500c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][0]  = (t1) ? tc0[indexA][t1] : 0;
23510c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][2];
23520c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][1]  = (t2) ? tc0[indexA][t2] : 0;
23530c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][3];
23540c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][2]  = (t1) ? tc0[indexA][t1] : 0;
23550c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][8];
23560c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][3]  = (t2) ? tc0[indexA][t2] : 0;
23570c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][9];
23580c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][4]  = (t1) ? tc0[indexA][t1] : 0;
23590c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = bs[i][10];
23600c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][5]  = (t2) ? tc0[indexA][t2] : 0;
23610c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = bs[i][11];
23620c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][6]  = (t1) ? tc0[indexA][t1] : 0;
23630c1bc742181ded4930842b46e9507372f0b1b963James Dong        threshold[i][7]  = (t2) ? tc0[indexA][t2] : 0;
23640c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
23650c1bc742181ded4930842b46e9507372f0b1b963James Dong
23660c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_TOP_EDGE)
23670c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
23680c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbB->qpY;
23690c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != mb->qpY)
23700c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
23710c1bc742181ded4930842b46e9507372f0b1b963James Dong            u32 t1, t2, t3, t4;
23720c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
23730c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
23740c1bc742181ded4930842b46e9507372f0b1b963James Dong
23750c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
23760c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
23770c1bc742181ded4930842b46e9507372f0b1b963James Dong
23780c1bc742181ded4930842b46e9507372f0b1b963James Dong            alpha[1][0] = alphas[indexA];
23790c1bc742181ded4930842b46e9507372f0b1b963James Dong            beta[1][0] = betas[indexB];
23800c1bc742181ded4930842b46e9507372f0b1b963James Dong
23810c1bc742181ded4930842b46e9507372f0b1b963James Dong            t1 = bs[1][0];
23820c1bc742181ded4930842b46e9507372f0b1b963James Dong            t2 = bs[1][1];
23830c1bc742181ded4930842b46e9507372f0b1b963James Dong            t3 = bs[1][2];
23840c1bc742181ded4930842b46e9507372f0b1b963James Dong            t4 = bs[1][3];
23850c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][0] = (t1) ? tc0[indexA][t1] : 0;
23860c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][1] = (t2) ? tc0[indexA][t2] : 0;
23870c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][2] = (t3) ? tc0[indexA][t3] : 0;
23880c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[1][3] = (t4) ? tc0[indexA][t4] : 0;
23890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
23900c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
23910c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (filteringFlags & FILTER_LEFT_EDGE)
23920c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
23930c1bc742181ded4930842b46e9507372f0b1b963James Dong        qpTmp = mb->mbA->qpY;
23940c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (qpTmp != mb->qpY)
23950c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
23960c1bc742181ded4930842b46e9507372f0b1b963James Dong
23970c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
23980c1bc742181ded4930842b46e9507372f0b1b963James Dong            qpAv = (qp + qpTmp + 1) >> 1;
23990c1bc742181ded4930842b46e9507372f0b1b963James Dong
24000c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
24010c1bc742181ded4930842b46e9507372f0b1b963James Dong            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
24020c1bc742181ded4930842b46e9507372f0b1b963James Dong
24030c1bc742181ded4930842b46e9507372f0b1b963James Dong            alpha[0][0] = alphas[indexA];
24040c1bc742181ded4930842b46e9507372f0b1b963James Dong            beta[0][0] = betas[indexB];
24050c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][0] = (bs[0][0]) ? tc0[indexA][bs[0][0]] : 0;
24060c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][1] = (bs[0][1]) ? tc0[indexA][bs[0][1]] : 0;
24070c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][2] = (bs[0][2]) ? tc0[indexA][bs[0][2]] : 0;
24080c1bc742181ded4930842b46e9507372f0b1b963James Dong            threshold[0][3] = (bs[0][3]) ? tc0[indexA][bs[0][3]] : 0;
24090c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
24100c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
24110c1bc742181ded4930842b46e9507372f0b1b963James Dong
24120c1bc742181ded4930842b46e9507372f0b1b963James Dong}
24130c1bc742181ded4930842b46e9507372f0b1b963James Dong
24140c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
24150c1bc742181ded4930842b46e9507372f0b1b963James Dong
24160c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint +e701 +e702 */
24170c1bc742181ded4930842b46e9507372f0b1b963James Dong
2418