summaryrefslogtreecommitdiffstats
path: root/decoder/ih264d_compute_bs.c
blob: 4a6750a41c90670d20b4ee8c5aa5f5f54c7ebbe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

#include "ih264_typedefs.h"
#include "ih264_macros.h"
#include "ih264_platform_macros.h"
#include "ih264d_structs.h"
#include "ih264d_defs.h"
#include "ih264d_deblocking.h"
#include "string.h"
#include "ih264d_debug.h"
#include "ih264d_tables.h"

UWORD16 ih264d_update_csbp_8x8(UWORD16 u2_luma_csbp)
{
    UWORD16 u2_mod_csbp;

    u2_mod_csbp = u2_luma_csbp;

    if(u2_mod_csbp & 0x0033)
    {
        u2_mod_csbp |= 0x0033;
    }

    if(u2_mod_csbp & 0x00CC)
    {
        u2_mod_csbp |= 0x00CC;
    }

    if(u2_mod_csbp & 0x3300)
    {
        u2_mod_csbp |= 0x3300;
    }

    if(u2_mod_csbp & 0xCC00)
    {
        u2_mod_csbp |= 0xCC00;
    }

    return u2_mod_csbp;
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs2_horz_vert                                       */
/*                                                                           */
/*  Description   : This function fills boundray strength (=2) for all horz  */
/*                  and vert edges of current mb based on coded sub block    */
/*                  pattern of current, top and left mb                      */
/*  Inputs        :                                                          */
/*                  pu4_bs : Base pointer of  BS table which gets updated    */
/*                  u4_left_mb_csbp : left mb's coded sub block pattern      */
/*                  u4_top_mb_csbp : top mb's coded sub block pattern        */
/*                  u4_cur_mb_csbp : current mb's coded sub block pattern    */
/*                                                                           */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    :                                                          */
/*                                                                           */
/*              csbp for each 4x4 block in a mb is bit packet in reverse     */
/*              raster scan order for each mb as shown below:                */
/*              15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0.                       */
/*                                                                           */
/*              BS=2 for a 4x4 edge if any of adjacent blocks forming edge   */
/*              are coded. Keeping this in mind, bs=2 for all horz and vert  */
/*              edges can be derived using  a lookup table for each edge     */
/*              after "ORing" the csbp values as follows:                    */
/*              (C means current Mb, T means top mb and L means left mb)     */
/*                                                                           */
/*              All Horz edges:                                              */
/*              15C|14C|13C|12C|11C|10C|9C|8C|7C|6C|5C|4C|3C |2C |1C |0C     */
/*  (or with)   11C|10C| 9C| 8C| 7C|6C |5C|4C|3C|2C|1C|0C|15T|14T|13T|12T    */
/*              -----BS[3]-----|----BS[2]----|---BS[1]---|----BS[0]-----|    */
/*                                                                           */
/*              All Vert edges:                                              */
/*              15C|14C|13C|12C|11C|10C|9C| 8C|7C|6C|5C|4C|3C |2C |1C |0C    */
/*  (or with)   14C|13C|12C|15L|10C| 9C|8C|11L|6C|5C|4C|7L|2C |1C |0C |3L    */
/*              Do 4x4 transpose of resulting pattern to get vertBS[4]-BS[7] */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
#define CSBP_LEFT_BLOCK_MASK 0x1111
#define CSBP_RIGHT_BLOCK_MASK 0x8888

void ih264d_fill_bs2_horz_vert(UWORD32 *pu4_bs, /* Base pointer of BS table */
                               WORD32 u4_left_mb_csbp, /* csbp of left mb */
                               WORD32 u4_top_mb_csbp, /* csbp of top mb */
                               WORD32 u4_cur_mb_csbp, /* csbp of current mb */
                               const UWORD32 *pu4_packed_bs2, const UWORD16 *pu2_4x4_v2h_reorder)
{
    /*************************************************************************/
    /*u4_nbr_horz_csbp=11C|10C|9C|8C|7C|6C|5C|4C|3C|2C|1C|0C|15T|14T|13T|12T */
    /*************************************************************************/
    UWORD32 u4_nbr_horz_csbp = (u4_cur_mb_csbp << 4) | (u4_top_mb_csbp >> 12);
    UWORD32 u4_horz_bs2_dec = u4_cur_mb_csbp | u4_nbr_horz_csbp;

    /*************************************************************************/
    /*u4_left_mb_masked_csbp = 15L|0|0|0|11L|0|0|0|7L|0|0|0|3L|0|0|0         */
    /*************************************************************************/
    UWORD32 u4_left_mb_masked_csbp = u4_left_mb_csbp & CSBP_RIGHT_BLOCK_MASK;

    /*************************************************************************/
    /*u4_cur_mb_masked_csbp =14C|13C|12C|x|10C|9C|8C|x|6C|5C|4C|x|2C|1C|0C|x */
    /*************************************************************************/
    UWORD32 u4_cur_mb_masked_csbp = (u4_cur_mb_csbp << 1)
                    & (~CSBP_LEFT_BLOCK_MASK);

    /*************************************************************************/
    /*u4_nbr_vert_csbp=14C|13C|12C|15L|10C|9C|8C|11L|6C|5C|4C|7L|2C|1C|0C|3L */
    /*************************************************************************/
    UWORD32 u4_nbr_vert_csbp = (u4_cur_mb_masked_csbp)
                    | (u4_left_mb_masked_csbp >> 3);

    UWORD32 u4_vert_bs2_dec = u4_cur_mb_csbp | u4_nbr_vert_csbp;

    UWORD32 u4_reordered_vert_bs2_dec, u4_temp;

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    /*************************************************************************/
    /* Fill horz edges (0,1,2,3) boundary strengths 2 using look up table    */
    /*************************************************************************/
    pu4_bs[0] = pu4_packed_bs2[u4_horz_bs2_dec & 0xF];
    pu4_bs[1] = pu4_packed_bs2[(u4_horz_bs2_dec >> 4) & 0xF];
    pu4_bs[2] = pu4_packed_bs2[(u4_horz_bs2_dec >> 8) & 0xF];
    pu4_bs[3] = pu4_packed_bs2[(u4_horz_bs2_dec >> 12) & 0xF];

    /*************************************************************************/
    /* Do 4x4 tranpose of u4_vert_bs2_dec by using look up table for reorder */
    /*************************************************************************/
    u4_reordered_vert_bs2_dec = pu2_4x4_v2h_reorder[u4_vert_bs2_dec & 0xF];
    u4_temp = pu2_4x4_v2h_reorder[(u4_vert_bs2_dec >> 4) & 0xF];
    u4_reordered_vert_bs2_dec |= (u4_temp << 1);
    u4_temp = pu2_4x4_v2h_reorder[(u4_vert_bs2_dec >> 8) & 0xF];
    u4_reordered_vert_bs2_dec |= (u4_temp << 2);
    u4_temp = pu2_4x4_v2h_reorder[(u4_vert_bs2_dec >> 12) & 0xF];
    u4_reordered_vert_bs2_dec |= (u4_temp << 3);

    /*************************************************************************/
    /* Fill vert edges (4,5,6,7) boundary strengths 2 using look up table    */
    /*************************************************************************/
    pu4_bs[4] = pu4_packed_bs2[u4_reordered_vert_bs2_dec & 0xF];
    pu4_bs[5] = pu4_packed_bs2[(u4_reordered_vert_bs2_dec >> 4) & 0xF];
    pu4_bs[6] = pu4_packed_bs2[(u4_reordered_vert_bs2_dec >> 8) & 0xF];
    pu4_bs[7] = pu4_packed_bs2[(u4_reordered_vert_bs2_dec >> 12) & 0xF];
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs1_16x16mb_pslice                                  */
/*                                                                           */
/*  Description   : This function fills boundray strength (=1) for those     */
/*                  horz and vert mb edges of 16x16mb which are set to 0 by  */
/*                  ih264d_fill_bs2_horz_vert. This function is used for p slices   */
/*                                                                           */
/*  Inputs        : <What inputs does the function take?>                    */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
/*                  differs by more than 1 integer pel or if reference       */
/*                  pictures are different, Bs is set to 1.                  */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs1_16x16mb_pslice(mv_pred_t *ps_cur_mv_pred,
                                    mv_pred_t *ps_top_mv_pred,
                                    void **ppv_map_ref_idx_to_poc,
                                    UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
                                    mv_pred_t *ps_leftmost_mv_pred,
                                    neighbouradd_t *ps_left_addr,
                                    void **u4_pic_addrress, /* picture address for BS calc */
                                    WORD32 i4_ver_mvlimit)
{
    WORD16 i2_q_mv0, i2_q_mv1;
    WORD16 i2_p_mv0, i2_p_mv1;
    void *pv_cur_pic_addr0, *pv_cur_pic_addr1;
    void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;
    void **ppv_map_ref_idx_to_poc_l0; //,*ppv_map_ref_idx_to_poc_l1;
    UWORD32 i;
    UWORD32 u4_bs_horz = pu4_bs_table[0];
    UWORD32 u4_bs_vert = pu4_bs_table[4];

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;

    i2_q_mv0 = ps_cur_mv_pred->i2_mv[0];
    i2_q_mv1 = ps_cur_mv_pred->i2_mv[1];
    pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[ps_cur_mv_pred->i1_ref_frame[0]];
    pv_cur_pic_addr1 = 0;

    /*********************************/
    /* Computing Bs for the top edge */
    /*********************************/
    for(i = 0; i < 4; i++, ps_top_mv_pred++)
    {
        UWORD32 u4_idx = 24 - (i << 3);

        /*********************************/
        /* check if Bs is already set    */
        /*********************************/
        if(!((u4_bs_horz >> u4_idx) & 0xf))
        {
            /************************************************************/
            /* If Bs is not set, use left edge and current edge mvs and */
            /* reference pictures addresses to evaluate Bs==1           */
            /************************************************************/
            UWORD32 u4_bs_temp1;
            UWORD32 u4_bs;

            /*********************************************************/
            /* If any motion vector component differs by more than 1 */
            /* integer pel or if reference pictures are different Bs */
            /* is set to 1. Note that this condition shall be met for*/
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
            /*********************************************************/
            i2_p_mv0 = ps_top_mv_pred->i2_mv[0];
            i2_p_mv1 = ps_top_mv_pred->i2_mv[1];
            pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
            pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];

            u4_bs_temp1 = ((ABS((i2_p_mv0 - i2_q_mv0)) >= 4) ||
                           (ABS((i2_p_mv1 - i2_q_mv1)) >= i4_ver_mvlimit));

            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
                            || u4_bs_temp1);

            u4_bs_horz |= (u4_bs << u4_idx);
        }
    }
    pu4_bs_table[0] = u4_bs_horz;

    /***********************************/
    /* Computing Bs for the left edge  */
    /***********************************/
    for(i = 0; i < 4; i++, ps_leftmost_mv_pred += 4)
    {
        UWORD32 u4_idx = 24 - (i << 3);

        /*********************************/
        /* check if Bs is already set    */
        /*********************************/
        if(!((u4_bs_vert >> u4_idx) & 0xf))
        {
            /****************************************************/
            /* If Bs is not set, evalaute conditions for Bs=1   */
            /****************************************************/
            UWORD32 u4_bs_temp1;
            UWORD32 u4_bs;
            /*********************************************************/
            /* If any motion vector component differs by more than 1 */
            /* integer pel or if reference pictures are different Bs */
            /* is set to 1. Note that this condition shall be met for*/
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
            /*********************************************************/

            i2_p_mv0 = ps_leftmost_mv_pred->i2_mv[0];
            i2_p_mv1 = ps_leftmost_mv_pred->i2_mv[1];
            pv_nbr_pic_addr0 = ps_left_addr->u4_add[i & 2];
            pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (i & 2)];

            u4_bs_temp1 =
                            ((ABS((i2_p_mv0 - i2_q_mv0))
                                            >= 4)
                                            | (ABS((i2_p_mv1 - i2_q_mv1))
                                                            >= i4_ver_mvlimit));

            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
                            || u4_bs_temp1);

            u4_bs_vert |= (u4_bs << u4_idx);
        }
    }
    pu4_bs_table[4] = u4_bs_vert;

    return;
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs1_non16x16mb_pslice                               */
/*                                                                           */
/*  Description   : This function fills boundray strength (=1) for those     */
/*                  horz and vert edges of non16x16mb which are set to 0 by  */
/*                  ih264d_fill_bs2_horz_vert. This function is used for p slices   */
/*                                                                           */
/*  Inputs        : <What inputs does the function take?>                    */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
/*                  differs by more than 1 integer pel or if reference       */
/*                  pictures are different, Bs is set to 1.                  */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs1_non16x16mb_pslice(mv_pred_t *ps_cur_mv_pred,
                                       mv_pred_t *ps_top_mv_pred,
                                       void **ppv_map_ref_idx_to_poc,
                                       UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
                                       mv_pred_t *ps_leftmost_mv_pred,
                                       neighbouradd_t *ps_left_addr,
                                       void **u4_pic_addrress,
                                       WORD32 i4_ver_mvlimit)
{
    UWORD32 edge;
    void **ppv_map_ref_idx_to_poc_l0; //,*ppv_map_ref_idx_to_poc_l1;

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;


    for(edge = 0; edge < 4; edge++, ps_top_mv_pred = ps_cur_mv_pred - 4)
    {
        /*********************************************************************/
        /* Each iteration of this loop fills the four BS values of one HORIZ */
        /* edge and one BS value for each of the four VERT edges.            */
        /*********************************************************************/
        WORD32 i;
        UWORD32 u4_vert_idx = 24 - (edge << 3);
        UWORD32 u4_bs_horz = pu4_bs_table[edge];
        mv_pred_t *ps_left_mv_pred = ps_leftmost_mv_pred + (edge << 2);

        for(i = 0; i < 4; i++, ps_top_mv_pred++, ps_cur_mv_pred++)
        {
            WORD16 i2_cur_mv0, i2_cur_mv1;
            WORD8 i1_cur_ref0;
            void *pv_cur_pic_addr0, *pv_cur_pic_addr1 = 0;
            void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;

            /******************************************************/
            /* Each iteration of this inner loop computes a HORIZ */
            /* and a VERT BS value for a 4x4 block                */
            /******************************************************/
            UWORD32 u4_bs_vert = (pu4_bs_table[i + 4] >> u4_vert_idx) & 0xf;
            UWORD32 u4_horz_idx = 24 - (i << 3);

            /*****************************************************/
            /* check if vert Bs for this block is already set    */
            /*****************************************************/
            if(!u4_bs_vert)
            {
                WORD16 i2_left_mv0, i2_left_mv1;
                /************************************************************/
                /* If Bs is not set, use left edge and current edge mvs and */
                /* reference pictures addresses to evaluate Bs==1           */
                /************************************************************/
                i2_left_mv0 = ps_left_mv_pred->i2_mv[0];
                i2_left_mv1 = ps_left_mv_pred->i2_mv[1];

                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];

                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];

                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
                if(i)
                {
                    WORD8 i1_left_ref0 = ps_left_mv_pred->i1_ref_frame[0];
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_left_ref0];
                    pv_nbr_pic_addr1 = 0;
                }
                else
                {
                    pv_nbr_pic_addr0 = ps_left_addr->u4_add[edge & 2];
                    pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (edge & 2)];
                }

                {
                    UWORD32 u4_bs_temp1;
                    /*********************************************************/
                    /* If any motion vector component differs by more than 1 */
                    /* integer pel or if reference pictures are different Bs */
                    /* is set to 1. Note that this condition shall be met for*/
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
                    /*********************************************************/

                    u4_bs_temp1 =
                                    ((ABS((i2_left_mv0 - i2_cur_mv0))
                                                    >= 4)
                                                    | (ABS((i2_left_mv1
                                                                    - i2_cur_mv1))
                                                                    >= i4_ver_mvlimit));

                    u4_bs_vert = ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
                                    || (pv_nbr_pic_addr1 != pv_cur_pic_addr1)
                                    || u4_bs_temp1);

                    pu4_bs_table[i + 4] |= (u4_bs_vert << u4_vert_idx);
                }
            }

            /*****************************************************/
            /* check if horz Bs for this block is already set    */
            /*****************************************************/
            if(!((u4_bs_horz >> u4_horz_idx) & 0xf))
            {
                WORD16 i2_top_mv0, i2_top_mv1;
                /************************************************************/
                /* If Bs is not set, use top edge and current edge mvs and  */
                /* reference pictures addresses to evaluate Bs==1           */
                /************************************************************/
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];

                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];

                i2_top_mv0 = ps_top_mv_pred->i2_mv[0];
                i2_top_mv1 = ps_top_mv_pred->i2_mv[1];

                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
                if(edge)
                {
                    WORD8 i1_top_ref0 = ps_top_mv_pred->i1_ref_frame[0];
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_top_ref0];
                    pv_nbr_pic_addr1 = 0;
                }
                else
                {
                    pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
                    pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];
                }

                {
                    UWORD32 u4_bs_temp1;
                    UWORD32 u4_bs;
                    /*********************************************************/
                    /* If any motion vector component differs by more than 1 */
                    /* integer pel or if reference pictures are different Bs */
                    /* is set to 1. Note that this condition shall be met for*/
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
                    /*********************************************************/

                    u4_bs_temp1 =
                                    ((ABS((i2_top_mv0 - i2_cur_mv0))
                                                    >= 4)
                                                    | (ABS((i2_top_mv1
                                                                    - i2_cur_mv1))
                                                                    >= i4_ver_mvlimit));

                    u4_bs = ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
                                    || (pv_nbr_pic_addr1 != pv_cur_pic_addr1)
                                    || u4_bs_temp1);

                    u4_bs_horz |= (u4_bs << u4_horz_idx);
                }
            }

            ps_left_mv_pred = ps_cur_mv_pred;
        }

        pu4_bs_table[edge] = u4_bs_horz;
    }
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs1_16x16mb_bslice                                  */
/*                                                                           */
/*  Description   : This function fills boundray strength (=1) for those     */
/*                  horz and vert mb edges of 16x16mb which are set to 0 by  */
/*                  ih264d_fill_bs2_horz_vert. This function is used for b slices   */
/*                                                                           */
/*  Inputs        : <What inputs does the function take?>                    */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
/*                  differs by more than 1 integer pel or if reference       */
/*                  pictures are different, Bs is set to 1.                  */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs1_16x16mb_bslice(mv_pred_t *ps_cur_mv_pred,
                                    mv_pred_t *ps_top_mv_pred,
                                    void **ppv_map_ref_idx_to_poc,
                                    UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
                                    mv_pred_t *ps_leftmost_mv_pred,
                                    neighbouradd_t *ps_left_addr,
                                    void **u4_pic_addrress,
                                    WORD32 i4_ver_mvlimit)
{
    WORD16 i2_q_mv0, i2_q_mv1, i2_q_mv2, i2_q_mv3;
    WORD16 i2_p_mv0, i2_p_mv1, i2_p_mv2, i2_p_mv3;
    void *pv_cur_pic_addr0, *pv_cur_pic_addr1;
    void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;
    void **ppv_map_ref_idx_to_poc_l0, **ppv_map_ref_idx_to_poc_l1;
    UWORD32 i;
    UWORD32 u4_bs_horz = pu4_bs_table[0];
    UWORD32 u4_bs_vert = pu4_bs_table[4];

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
    ppv_map_ref_idx_to_poc_l1 = ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
    i2_q_mv0 = ps_cur_mv_pred->i2_mv[0];
    i2_q_mv1 = ps_cur_mv_pred->i2_mv[1];
    i2_q_mv2 = ps_cur_mv_pred->i2_mv[2];
    i2_q_mv3 = ps_cur_mv_pred->i2_mv[3];
    pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[ps_cur_mv_pred->i1_ref_frame[0]];
    pv_cur_pic_addr1 = ppv_map_ref_idx_to_poc_l1[ps_cur_mv_pred->i1_ref_frame[1]];

    /*********************************/
    /* Computing Bs for the top edge */
    /*********************************/
    for(i = 0; i < 4; i++, ps_top_mv_pred++)
    {
        UWORD32 u4_idx = 24 - (i << 3);

        /*********************************/
        /* check if Bs is already set    */
        /*********************************/
        if(!((u4_bs_horz >> u4_idx) & 0xf))
        {
            /************************************************************/
            /* If Bs is not set, use left edge and current edge mvs and */
            /* reference pictures addresses to evaluate Bs==1           */
            /************************************************************/
            UWORD32 u4_bs_temp1, u4_bs_temp2;
            UWORD32 u4_bs;

            /*********************************************************/
            /* If any motion vector component differs by more than 1 */
            /* integer pel or if reference pictures are different Bs */
            /* is set to 1. Note that this condition shall be met for*/
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
            /*********************************************************/
            i2_p_mv0 = ps_top_mv_pred->i2_mv[0];
            i2_p_mv1 = ps_top_mv_pred->i2_mv[1];
            i2_p_mv2 = ps_top_mv_pred->i2_mv[2];
            i2_p_mv3 = ps_top_mv_pred->i2_mv[3];
            pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
            pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];

            u4_bs_temp1 =
                            ((ABS((i2_p_mv0 - i2_q_mv0))
                                            >= 4)
                                            | (ABS((i2_p_mv1 - i2_q_mv1))
                                                            >= i4_ver_mvlimit)
                                            | (ABS((i2_p_mv2 - i2_q_mv2))
                                                            >= 4)
                                            | (ABS((i2_p_mv3 - i2_q_mv3))
                                                            >= i4_ver_mvlimit));

            u4_bs_temp2 =
                            ((ABS((i2_p_mv0 - i2_q_mv2))
                                            >= 4)
                                            | (ABS((i2_p_mv1 - i2_q_mv3))
                                                            >= i4_ver_mvlimit)
                                            | (ABS((i2_p_mv2 - i2_q_mv0))
                                                            >= 4)
                                            | (ABS((i2_p_mv3 - i2_q_mv1))
                                                            >= i4_ver_mvlimit));

            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
                            || u4_bs_temp1)
                            && ((pv_cur_pic_addr0 != pv_nbr_pic_addr1)
                                            || (pv_cur_pic_addr1
                                                            != pv_nbr_pic_addr0)
                                            || u4_bs_temp2);

            u4_bs_horz |= (u4_bs << u4_idx);
        }
    }
    pu4_bs_table[0] = u4_bs_horz;

    /***********************************/
    /* Computing Bs for the left edge  */
    /***********************************/
    for(i = 0; i < 4; i++, ps_leftmost_mv_pred += 4)
    {
        UWORD32 u4_idx = 24 - (i << 3);

        /*********************************/
        /* check if Bs is already set    */
        /*********************************/
        if(!((u4_bs_vert >> u4_idx) & 0xf))
        {
            /****************************************************/
            /* If Bs is not set, evalaute conditions for Bs=1   */
            /****************************************************/
            UWORD32 u4_bs_temp1, u4_bs_temp2;
            UWORD32 u4_bs;
            /*********************************************************/
            /* If any motion vector component differs by more than 1 */
            /* integer pel or if reference pictures are different Bs */
            /* is set to 1. Note that this condition shall be met for*/
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
            /*********************************************************/

            i2_p_mv0 = ps_leftmost_mv_pred->i2_mv[0];
            i2_p_mv1 = ps_leftmost_mv_pred->i2_mv[1];
            i2_p_mv2 = ps_leftmost_mv_pred->i2_mv[2];
            i2_p_mv3 = ps_leftmost_mv_pred->i2_mv[3];
            pv_nbr_pic_addr0 = ps_left_addr->u4_add[i & 2];
            pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (i & 2)];

            u4_bs_temp1 =
                            ((ABS((i2_p_mv0 - i2_q_mv0))
                                            >= 4)
                                            | (ABS((i2_p_mv1 - i2_q_mv1))
                                                            >= i4_ver_mvlimit)
                                            | (ABS((i2_p_mv2 - i2_q_mv2))
                                                            >= 4)
                                            | (ABS((i2_p_mv3 - i2_q_mv3))
                                                            >= i4_ver_mvlimit));

            u4_bs_temp2 =
                            ((ABS((i2_p_mv0 - i2_q_mv2))
                                            >= 4)
                                            | (ABS((i2_p_mv1 - i2_q_mv3))
                                                            >= i4_ver_mvlimit)
                                            | (ABS((i2_p_mv2 - i2_q_mv0))
                                                            >= 4)
                                            | (ABS((i2_p_mv3 - i2_q_mv1))
                                                            >= i4_ver_mvlimit));

            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
                            || u4_bs_temp1)
                            && ((pv_cur_pic_addr0 != pv_nbr_pic_addr1)
                                            || (pv_cur_pic_addr1
                                                            != pv_nbr_pic_addr0)
                                            || u4_bs_temp2);

            u4_bs_vert |= (u4_bs << u4_idx);
        }
    }
    pu4_bs_table[4] = u4_bs_vert;

    return;
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs1_non16x16mb_bslice                               */
/*                                                                           */
/*  Description   : This function fills boundray strength (=1) for those     */
/*                  horz and vert edges of non16x16mb which are set to 0 by  */
/*                  ih264d_fill_bs2_horz_vert. This function is used for b slices   */
/*                                                                           */
/*  Inputs        : <What inputs does the function take?>                    */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
/*                  differs by more than 1 integer pel or if reference       */
/*                  pictures are different, Bs is set to 1.                  */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs1_non16x16mb_bslice(mv_pred_t *ps_cur_mv_pred,
                                       mv_pred_t *ps_top_mv_pred,
                                       void **ppv_map_ref_idx_to_poc,
                                       UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
                                       mv_pred_t *ps_leftmost_mv_pred,
                                       neighbouradd_t *ps_left_addr,
                                       void **u4_pic_addrress,
                                       WORD32 i4_ver_mvlimit)
{
    UWORD32 edge;
    void **ppv_map_ref_idx_to_poc_l0, **ppv_map_ref_idx_to_poc_l1;
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
    ppv_map_ref_idx_to_poc_l1 = ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    for(edge = 0; edge < 4; edge++, ps_top_mv_pred = ps_cur_mv_pred - 4)
    {
        /*********************************************************************/
        /* Each iteration of this loop fills the four BS values of one HORIZ */
        /* edge and one BS value for each of the four VERT edges.            */
        /*********************************************************************/
        WORD32 i;
        UWORD32 u4_vert_idx = 24 - (edge << 3);
        UWORD32 u4_bs_horz = pu4_bs_table[edge];
        mv_pred_t *ps_left_mv_pred = ps_leftmost_mv_pred + (edge << 2);

        for(i = 0; i < 4; i++, ps_top_mv_pred++, ps_cur_mv_pred++)
        {
            WORD16 i2_cur_mv0, i2_cur_mv1, i16_curMv2, i16_curMv3;
            WORD8 i1_cur_ref0, i1_cur_ref1;
            void *pv_cur_pic_addr0, *pv_cur_pic_addr1;
            void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;

            /******************************************************/
            /* Each iteration of this inner loop computes a HORIZ */
            /* and a VERT BS value for a 4x4 block                */
            /******************************************************/
            UWORD32 u4_bs_vert = (pu4_bs_table[i + 4] >> u4_vert_idx) & 0xf;
            UWORD32 u4_horz_idx = 24 - (i << 3);

            /*****************************************************/
            /* check if vert Bs for this block is already set    */
            /*****************************************************/
            if(!u4_bs_vert)
            {
                WORD16 i2_left_mv0, i2_left_mv1, i2_left_mv2, i2_left_mv3;
                /************************************************************/
                /* If Bs is not set, use left edge and current edge mvs and */
                /* reference pictures addresses to evaluate Bs==1           */
                /************************************************************/
                i2_left_mv0 = ps_left_mv_pred->i2_mv[0];
                i2_left_mv1 = ps_left_mv_pred->i2_mv[1];
                i2_left_mv2 = ps_left_mv_pred->i2_mv[2];
                i2_left_mv3 = ps_left_mv_pred->i2_mv[3];

                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];
                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
                pv_cur_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];

                if(i)
                {
                    WORD8 i1_left_ref0, i1_left_ref1;
                    i1_left_ref0 = ps_left_mv_pred->i1_ref_frame[0];
                    i1_left_ref1 = ps_left_mv_pred->i1_ref_frame[1];
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_left_ref0];
                    pv_nbr_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_left_ref1];
                }
                else
                {
                    pv_nbr_pic_addr0 = ps_left_addr->u4_add[edge & 2];
                    pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (edge & 2)];
                }

                {
                    UWORD32 u4_bs_temp1, u4_bs_temp2;
                    /*********************************************************/
                    /* If any motion vector component differs by more than 1 */
                    /* integer pel or if reference pictures are different Bs */
                    /* is set to 1. Note that this condition shall be met for*/
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
                    /*********************************************************/

                    u4_bs_temp1 =
                                    ((ABS((i2_left_mv0 - i2_cur_mv0))
                                                    >= 4)
                                                    | (ABS((i2_left_mv1
                                                                    - i2_cur_mv1))
                                                                    >= i4_ver_mvlimit)
                                                    | (ABS((i2_left_mv2
                                                                    - i16_curMv2))
                                                                    >= 4)
                                                    | (ABS((i2_left_mv3
                                                                    - i16_curMv3))
                                                                    >= i4_ver_mvlimit));

                    u4_bs_temp2 =
                                    ((ABS((i2_left_mv0 - i16_curMv2))
                                                    >= 4)
                                                    | (ABS((i2_left_mv1
                                                                    - i16_curMv3))
                                                                    >= i4_ver_mvlimit)
                                                    | (ABS((i2_left_mv2
                                                                    - i2_cur_mv0))
                                                                    >= 4)
                                                    | (ABS((i2_left_mv3
                                                                    - i2_cur_mv1))
                                                                    >= i4_ver_mvlimit));

                    u4_bs_vert =
                                    ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
                                                    || (pv_nbr_pic_addr1
                                                                    != pv_cur_pic_addr1)
                                                    || u4_bs_temp1)
                                                    && ((pv_nbr_pic_addr0
                                                                    != pv_cur_pic_addr1)
                                                                    || (pv_nbr_pic_addr1
                                                                                    != pv_cur_pic_addr0)
                                                                    || u4_bs_temp2);

                    pu4_bs_table[i + 4] |= (u4_bs_vert << u4_vert_idx);
                }
            }

            /*****************************************************/
            /* check if horz Bs for this block is already set    */
            /*****************************************************/
            if(!((u4_bs_horz >> u4_horz_idx) & 0xf))
            {
                WORD16 i2_top_mv0, i2_top_mv1, i16_topMv2, i16_topMv3;
                /************************************************************/
                /* If Bs is not set, use top edge and current edge mvs and  */
                /* reference pictures addresses to evaluate Bs==1           */
                /************************************************************/
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];

                i2_top_mv0 = ps_top_mv_pred->i2_mv[0];
                i2_top_mv1 = ps_top_mv_pred->i2_mv[1];
                i16_topMv2 = ps_top_mv_pred->i2_mv[2];
                i16_topMv3 = ps_top_mv_pred->i2_mv[3];
                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
                pv_cur_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];
                if(edge)
                {
                    WORD8 i1_top_ref0, i1_top_ref1;
                    i1_top_ref0 = ps_top_mv_pred->i1_ref_frame[0];
                    i1_top_ref1 = ps_top_mv_pred->i1_ref_frame[1];
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_top_ref0];
                    pv_nbr_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_top_ref1];
                }
                else
                {
                    pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
                    pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];
                }

                {
                    UWORD32 u4_bs_temp1, u4_bs_temp2;
                    UWORD32 u4_bs;
                    /*********************************************************/
                    /* If any motion vector component differs by more than 1 */
                    /* integer pel or if reference pictures are different Bs */
                    /* is set to 1. Note that this condition shall be met for*/
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
                    /*********************************************************/

                    u4_bs_temp1 =
                                    ((ABS((i2_top_mv0 - i2_cur_mv0))
                                                    >= 4)
                                                    | (ABS((i2_top_mv1
                                                                    - i2_cur_mv1))
                                                                    >= i4_ver_mvlimit)
                                                    | (ABS((i16_topMv2
                                                                    - i16_curMv2))
                                                                    >= 4)
                                                    | (ABS((i16_topMv3
                                                                    - i16_curMv3))
                                                                    >= i4_ver_mvlimit));

                    u4_bs_temp2 =
                                    ((ABS((i2_top_mv0 - i16_curMv2))
                                                    >= 4)
                                                    | (ABS((i2_top_mv1
                                                                    - i16_curMv3))
                                                                    >= i4_ver_mvlimit)
                                                    | (ABS((i16_topMv2
                                                                    - i2_cur_mv0))
                                                                    >= 4)
                                                    | (ABS((i16_topMv3
                                                                    - i2_cur_mv1))
                                                                    >= i4_ver_mvlimit));

                    u4_bs =
                                    ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
                                                    || (pv_nbr_pic_addr1
                                                                    != pv_cur_pic_addr1)
                                                    || u4_bs_temp1)
                                                    && ((pv_nbr_pic_addr0
                                                                    != pv_cur_pic_addr1)
                                                                    || (pv_nbr_pic_addr1
                                                                                    != pv_cur_pic_addr0)
                                                                    || u4_bs_temp2);

                    u4_bs_horz |= (u4_bs << u4_horz_idx);
                }
            }

            ps_left_mv_pred = ps_cur_mv_pred;
        }

        pu4_bs_table[edge] = u4_bs_horz;
    }
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs_xtra_left_edge_cur_fld                           */
/*                                                                           */
/*  Description   : This function fills boundray strength (= 2 or 1) for     */
/*                  xtra left mb edge when cur mb is field and left mb is    */
/*                  frame.                                                   */
/*  Inputs        :                                                          */
/*                                                                           */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    :                                                          */
/*                                                                           */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs_xtra_left_edge_cur_fld(UWORD32 *pu4_bs, /* Base pointer of BS table */
                                           WORD32 u4_left_mb_t_csbp, /* left mbpair's top csbp   */
                                           WORD32 u4_left_mb_b_csbp, /* left mbpair's bottom csbp*/
                                           WORD32 u4_cur_mb_csbp, /* csbp of current mb */
                                           UWORD32 u4_cur_mb_top /* is top or bottom mb */

                                           )
{
    const UWORD32 *pu4_packed_bs = (const UWORD32 *)gau4_ih264d_packed_bs2;
    UWORD32 u4_cur, u4_left, u4_or;
    UNUSED(u4_cur_mb_top);

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    u4_left_mb_t_csbp = ((u4_left_mb_t_csbp & 0x0008) >> 3)
                    + ((u4_left_mb_t_csbp & 0x0080) >> 6)
                    + ((u4_left_mb_t_csbp & 0x0800) >> 9)
                    + ((u4_left_mb_t_csbp & 0x8000) >> 12);

    u4_left_mb_b_csbp = ((u4_left_mb_b_csbp & 0x0008) << 1)
                    + ((u4_left_mb_b_csbp & 0x0080) >> 2)
                    + ((u4_left_mb_b_csbp & 0x0800) >> 5)
                    + ((u4_left_mb_b_csbp & 0x8000) >> 8);

    /*********************************************************************/
    /* u4_cur = 0|0|0|0|0|0|0|0|12C|12C|8C|8C|4C|4C|0C|0C                */
    /*********************************************************************/
    u4_cur = (u4_cur_mb_csbp & 0x0001) + ((u4_cur_mb_csbp & 0x0001) << 1)
                    + ((u4_cur_mb_csbp & 0x0010) >> 2)
                    + ((u4_cur_mb_csbp & 0x0010) >> 1)
                    + ((u4_cur_mb_csbp & 0x0100) >> 4)
                    + ((u4_cur_mb_csbp & 0x0100) >> 3)
                    + ((u4_cur_mb_csbp & 0x1000) >> 6)
                    + ((u4_cur_mb_csbp & 0x1000) >> 5);

    /*********************************************************************/
    /* u4_left =0|0|0|0|0|0|0|0|15Lb|11Lb|7Lb|3Lb|15Lt|11Lt|7Lt|3Lt      */
    /*********************************************************************/
    u4_left = u4_left_mb_t_csbp + u4_left_mb_b_csbp;

    u4_or = (u4_cur | u4_left);
    /*********************************************************************/
    /* Fill vert edges (4,9) boundary strengths  using look up table     */
    /*********************************************************************/
    pu4_packed_bs += 16;
    pu4_bs[4] = pu4_packed_bs[u4_or & 0xF];
    pu4_bs[9] = pu4_packed_bs[(u4_or >> 4)];
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs_xtra_left_edge_cur_frm                           */
/*                                                                           */
/*  Description   : This function fills boundray strength (= 2 or 1) for     */
/*                  xtra left mb edge when cur mb is frame and left mb is    */
/*                  field.                                                   */
/*  Inputs        :                                                          */
/*                                                                           */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    :                                                          */
/*                                                                           */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs_xtra_left_edge_cur_frm(UWORD32 *pu4_bs, /* Base pointer of BS table */
                                           WORD32 u4_left_mb_t_csbp, /* left mbpair's top csbp   */
                                           WORD32 u4_left_mb_b_csbp, /* left mbpair's bottom csbp*/
                                           WORD32 u4_cur_mb_csbp, /* csbp of current mb */
                                           UWORD32 u4_cur_mb_bot /* is top or bottom mb */

                                           )
{
    const UWORD32 *pu4_packed_bs = (const UWORD32 *)gau4_ih264d_packed_bs2;
    UWORD32 u4_cur, u4_left, u4_or;
    UWORD32 u4_right_shift = (u4_cur_mb_bot << 3);

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    u4_left_mb_t_csbp >>= u4_right_shift;
    u4_left_mb_b_csbp >>= u4_right_shift;

    u4_left_mb_t_csbp = ((u4_left_mb_t_csbp & 0x08) >> 3)
                    + ((u4_left_mb_t_csbp & 0x08) >> 2)
                    + ((u4_left_mb_t_csbp & 0x80) >> 5)
                    + ((u4_left_mb_t_csbp & 0x80) >> 4);

    u4_left_mb_b_csbp = ((u4_left_mb_b_csbp & 0x08) << 1)
                    + ((u4_left_mb_b_csbp & 0x08) << 2)
                    + ((u4_left_mb_b_csbp & 0x80) >> 1)
                    + ((u4_left_mb_b_csbp & 0x80));

    u4_cur = ((u4_cur_mb_csbp & 0x0001)) + ((u4_cur_mb_csbp & 0x0010) >> 3)
                    + ((u4_cur_mb_csbp & 0x0100) >> 6)
                    + ((u4_cur_mb_csbp & 0x1000) >> 9);

    u4_cur += (u4_cur << 4);

    u4_left = u4_left_mb_t_csbp + u4_left_mb_b_csbp;

    u4_or = (u4_cur | u4_left);
    /*********************************************************************/
    /* Fill vert edges (4,9) boundary strengths  using look up table     */
    /*********************************************************************/
    pu4_packed_bs += 16;
    pu4_bs[4] = pu4_packed_bs[u4_or & 0xF];
    pu4_bs[9] = pu4_packed_bs[(u4_or >> 4)];
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_fill_bs_xtra_top_edge                                    */
/*                                                                           */
/*  Description   : This function fills boundray strength (= 2 or 1) for     */
/*                  xtra top mb edge when cur mb is top mb of frame mb pair  */
/*                  and top mbpair is field coded.                           */
/*  Inputs        :                                                          */
/*                                                                           */
/*  Globals       : <Does it use any global variables?>                      */
/*  Processing    :                                                          */
/*                                                                           */
/*                                                                           */
/*  Outputs       : <What does the function produce?>                        */
/*  Returns       : <What does the function return?>                         */
/*                                                                           */
/*  Issues        : <List any issues or problems with this function>         */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*         16 10 2008   Jay             Draft                                */
/*                                                                           */
/*****************************************************************************/
void ih264d_fill_bs_xtra_top_edge(UWORD32 *pu4_bs, /* Base pointer of BS table */
                                  WORD32 u4_topmb_t_csbp, /* top mbpair's top csbp   */
                                  WORD32 u4_topmb_b_csbp, /* top mbpair's bottom csbp*/
                                  WORD32 u4_cur_mb_csbp /* csbp of current mb */

                                  )
{
    const UWORD32 *pu4_packed_bs = (const UWORD32 *)gau4_ih264d_packed_bs2;
    UWORD32 u4_or;

    u4_cur_mb_csbp &= 0xf;
    u4_topmb_t_csbp >>= 12;
    u4_topmb_b_csbp >>= 12;

    u4_or = (u4_cur_mb_csbp | u4_topmb_t_csbp);
    /*********************************************************************/
    /* Fill vert edges (0,8) boundary strengths  using look up table     */
    /*********************************************************************/
    pu4_packed_bs += 16;
    pu4_bs[8] = pu4_packed_bs[u4_or];

    u4_or = (u4_cur_mb_csbp | u4_topmb_b_csbp);
    pu4_bs[0] = pu4_packed_bs[u4_or];
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_compute_bs_non_mbaff                                        */
/*                                                                           */
/*  Description   : This function computes the pointers of left,top & current*/
/*                : Nnz, MvPred & deblk_mb_t and supplies to FillBs function for*/
/*                : Boundary Strength Calculation                            */
/*  Inputs        : <What inputs does the function take?>                    */
/*  Processing    : This functions calls deblock MB in the MB increment order*/
/*                                                                           */
/*  Outputs       : Produces the Boundary Strength for Current Mb            */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*                      ITTIAM                                               */
/*****************************************************************************/

void ih264d_compute_bs_non_mbaff(dec_struct_t * ps_dec,
                                 dec_mb_info_t * ps_cur_mb_info,
                                 const UWORD16 u2_mbxn_mb)
{
    /* Mvpred and Nnz for top and Courrent */
    mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
    /* deblk_mb_t Params */
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
    deblkmb_neighbour_t *ps_deblk_top_mb;

    /* Reference Index to POC mapping*/
    void ** apv_map_ref_idx_to_poc;
    UWORD32 u4_leftmbtype;

    UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;

    /* Set of flags */
    UWORD32 u4_cur_mb_intra, u1_top_mb_typ, u4_cur_mb_fld;
    UWORD32 u1_cur_mb_type;
    UWORD32 * pu4_bs_table;

    /* Neighbour availability */
    /* Initialization */
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
    const UWORD32 u1_pingpong = u2_mbx & 0x01;

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;


    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + u2_mbxn_mb;
    ps_cur_mv_pred = ps_dec->ps_mv_cur + (u2_mbxn_mb << 4);

    apv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc + 1;
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
    u1_top_mb_typ = ps_deblk_top_mb->u1_mb_type;
    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;

    {
        UWORD8 mb_qp_temp;

        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;

        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;

    }

    /* if no deblocking required for current Mb then continue */
    /* Check next Mbs   in Mb group                           */
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
    {
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
        POC_LIST_L0_TO_L1_DIFF;
        {
            /* Store Parameter for Top MvPred refernce frame Address */

            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;

            /* Store Left addresses for Next Mb   */
            void ** ppv_left_mv_pred_addr =
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
            WORD8 * p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;


            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];

            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];

            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
            //}
            /* Storing the leftMbtype for next Mb */
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
        }

        return;
    }

    /* Flag for extra left Edge */
    ps_cur_mb_params->u1_single_call = 1;

    /* Update the Left deblk_mb_t and Left MvPred Parameters           */
    if(!u2_mbx)
    {
        u4_leftmbtype = 0;

        /* Initialize the ps_left_mv_pred with Junk but Valid Location */
        /* to avoid invalid memory access                           */
        /* this is read only pointer                                */
        ps_left_mv_pred = ps_dec->ps_mv_cur + 3;
    }
    else
    {
        u4_leftmbtype = ps_dec->deblk_left_mb[1].u1_mb_type;

        /* Come to Left Most Edge of the MB */
        ps_left_mv_pred = (u2_mbxn_mb) ?
                        ps_dec->ps_mv_cur + ((u2_mbxn_mb - 1) << 4) + 3 :
                        ps_dec->ps_mv_left + 3;
    }

    if(!u2_mby)
        u1_top_mb_typ = 0;

    /* MvPred Pointer Calculation */
    /* CHANGED CODE */
    ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 4) + 12;

    u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;
    u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
    /* Compute BS function */
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;

    u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
    u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
    u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
    /* Compute BS function */
    if(ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC)
    {
        if(ps_cur_mb_info->u1_tran_form8x8 == 1)
        {
            u2_cur_csbp = ih264d_update_csbp_8x8(
                            ps_cur_mb_info->ps_curmb->u2_luma_csbp);
        }

        if(ps_cur_mb_info->ps_left_mb->u1_tran_form8x8 == 1)
        {
            u2_left_csbp = ih264d_update_csbp_8x8(
                            ps_cur_mb_info->ps_left_mb->u2_luma_csbp);
        }

        if(ps_cur_mb_info->ps_top_mb->u1_tran_form8x8 == 1)
        {
            u2_top_csbp = ih264d_update_csbp_8x8(
                            ps_cur_mb_info->ps_top_mb->u2_luma_csbp);
        }
    }
    if(u4_cur_mb_intra)
    {

        pu4_bs_table[4] = 0x04040404;
        pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
        pu4_bs_table[1] = 0x03030303;
        pu4_bs_table[2] = 0x03030303;
        pu4_bs_table[3] = 0x03030303;
        pu4_bs_table[5] = 0x03030303;
        pu4_bs_table[6] = 0x03030303;
        pu4_bs_table[7] = 0x03030303;
    }
    else
    {
        UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
        UWORD32 u4_is_b = ps_dec->u1_B;

        ih264d_fill_bs2_horz_vert(
                        pu4_bs_table, u2_left_csbp, u2_top_csbp, u2_cur_csbp,
                        (const UWORD32 *)(gau4_ih264d_packed_bs2),
                        (const UWORD16 *)(gau2_ih264d_4x4_v2h_reorder));

        if(u4_leftmbtype & D_INTRA_MB)
            pu4_bs_table[4] = 0x04040404;

        if(u1_top_mb_typ & D_INTRA_MB)
            pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;

        ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
                        ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc,
                        pu4_bs_table, ps_left_mv_pred,
                        &(ps_dec->ps_left_mvpred_addr[u1_pingpong][1]),
                        ps_cur_mb_info->ps_top_mb->u4_pic_addrress,
                        (4 >> u4_cur_mb_fld));
    }

    {
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
        POC_LIST_L0_TO_L1_DIFF;
        {
            /* Store Parameter for Top MvPred refernce frame Address */

            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;

            /* Store Left addresses for Next Mb   */
            void ** ppv_left_mv_pred_addr =
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
            WORD8 * p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;

            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];

            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];

            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];

            /* Storing the leftMbtype for next Mb */
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;

        }
    }

    /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
    if(ps_cur_mb_info->u1_tran_form8x8)
    {
        pu4_bs_table[1] = 0;
        pu4_bs_table[3] = 0;
        pu4_bs_table[5] = 0;
        pu4_bs_table[7] = 0;
    }
}

/*****************************************************************************/
/*                                                                           */
/*  Function Name : ih264d_compute_bs_mbaff                                           */
/*                                                                           */
/*  Description   : This function computes the pointers of left,top & current*/
/*                : Nnz, MvPred & deblk_mb_t and supplies to FillBs function for*/
/*                : Boundary Strength Calculation                            */
/*  Inputs        : <What inputs does the function take?>                    */
/*  Processing    : This functions calls deblock MB in the MB increment order*/
/*                                                                           */
/*  Outputs       : Produces the Boundary Strength for Current Mb            */
/*  Returns       : None                                                     */
/*                                                                           */
/*  Revision History:                                                        */
/*                                                                           */
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
/*                      ITTIAM                                               */
/*****************************************************************************/

void ih264d_compute_bs_mbaff(dec_struct_t * ps_dec,
                             dec_mb_info_t * ps_cur_mb_info,
                             const UWORD16 u2_mbxn_mb)
{
    /* Mvpred and Nnz for top and Courrent */
    mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
    /* deblk_mb_t Params */
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
    neighbouradd_t * ps_left_ngbr;
    deblkmb_neighbour_t *ps_deblk_top_mb;
    /* Reference Index to POC mapping*/
    void ** apv_map_ref_idx_to_poc;

    UWORD32 u4_leftmbtype;


    UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;

    /* Set of flags */
    UWORD32 u4_cur_mb_intra, u4_cur_mb_fld, u4_top_mb_fld, u1_top_mb_typ, u4_left_mb_fld;
    UWORD32 u1_cur_mb_type;
    UWORD32 * pu4_bs_table;
    const UWORD32 u4_bot_mb = (1 - ps_cur_mb_info->u1_topmb);
    /* Initialization */
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
    /* Load From u1_pingpong and Store in !u1_pingpong */
    const UWORD32 u1_pingpong = u2_mbx & 0x01;

    PROFILE_DISABLE_BOUNDARY_STRENGTH()

    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + (u2_mbx << 1);


    /************************************************/
    /* Initialize the left Mb type                  */
    /* Left MvPred                                  */
    /************************************************/

    if(!u2_mbx)
    {
        /************************************************************/
        /* Initialize the ps_left_mv_pred with Junk but Valid Location */
        /* to avoid invalid memory access                       */
        /* this is read only pointer                                */
        /************************************************************/
        ps_left_mv_pred = ps_dec->ps_mv_cur + 16;
    }
    else
    {
        /* Come to Left Most Edge of the MB */
        ps_left_mv_pred = (u2_mbxn_mb) ?
                        ps_dec->ps_mv_cur + ((u2_mbxn_mb - 1) << 5) + 3 :
                        ps_dec->ps_mv_left + 3;

        ps_left_mv_pred += (u4_bot_mb << 4);
    }

    u4_leftmbtype = ps_dec->deblk_left_mb[u4_bot_mb].u1_mb_type;

    ps_left_ngbr = &(ps_dec->ps_left_mvpred_addr[u1_pingpong][u4_bot_mb]);

    /************************************************/
    /* Pointer Assignment for Current Mb Parameters */
    /* Pointer Assignment for Current MvPred        */
    /************************************************/
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + (u2_mbxn_mb << 1) + u4_bot_mb;
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;

    ps_cur_mv_pred = ps_dec->ps_mv_cur + (u2_mbxn_mb << 5);
    ps_cur_mv_pred += (u4_bot_mb << 4);

    /********************************************/
    /* Pointer Assignment for Top Mb Parameters */
    /* Pointer Assignment for Top MvPred and    */
    /* Pointer Assignment for Top Nnz           */
    /********************************************/

    /* CHANGED CODE */
    ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 5) + 12;

    u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
    u4_left_mb_fld = !!(ps_dec->deblk_left_mb[0].u1_mb_type & D_FLD_MB);

    if(u4_left_mb_fld != u4_cur_mb_fld)
    {
        /* Flag for extra left Edge */
        ps_cur_mb_params->u1_single_call = 0;

        if(u4_bot_mb)
        {
            ps_left_ngbr--;
            ps_left_mv_pred -= 16;
        }
    }
    else
        ps_cur_mb_params->u1_single_call = 1;

    apv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc + 1;
    if(u4_cur_mb_fld)
    {
        if(u4_bot_mb)
        {
            apv_map_ref_idx_to_poc += BOT_LIST_FLD_L0;
        }
        else
        {
            apv_map_ref_idx_to_poc += TOP_LIST_FLD_L0;
        }
    }

    /**********************************************************/
    /* if no deblocking required for current Mb then continue */
    /**********************************************************/
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
    {
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
        POC_LIST_L0_TO_L1_DIFF;

        {
            /* Store Parameter for Top MvPred refernce frame Address */

            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
            void ** ppv_left_mv_pred_addr =
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][u4_bot_mb].u4_add;
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
            WORD8 * p1_refLeft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refLeft0[0]];
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refLeft0[1]];
        }
        if(u4_bot_mb)
        {
            /* store The Left Mb Type*/
            ps_dec->deblk_left_mb[0].u1_mb_type =
                            (ps_cur_mb_params - 1)->u1_mb_type;
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;

        }
        ps_deblk_top_mb[u4_bot_mb].u1_mb_type = u1_cur_mb_type;
        return;
    }

    if(u2_mby)
    {
        u1_top_mb_typ = ps_deblk_top_mb[1].u1_mb_type;
        u4_top_mb_fld = !!(u1_top_mb_typ & D_FLD_MB);

        if(!u4_bot_mb)
        {
            if(u4_top_mb_fld & u4_cur_mb_fld)
                u1_top_mb_typ = ps_deblk_top_mb[0].u1_mb_type;
            else
            {
                ps_top_mv_pred += 16;
            }
        }
    }
    else
    {
        u4_top_mb_fld = u4_cur_mb_fld;
        u1_top_mb_typ = 0;
    }

    if(u4_bot_mb & !u4_cur_mb_fld)
    {
        u1_top_mb_typ = ps_deblk_top_mb[0].u1_mb_type;
        u4_top_mb_fld = u4_cur_mb_fld;
        ps_top_mv_pred = ps_cur_mv_pred - 4;
    }

    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
    u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;

    u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
    u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
    u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
    /* Compute BS function */
    if(ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC)
    {

        if(ps_cur_mb_info->u1_tran_form8x8 == 1)
        {
            u2_cur_csbp = ih264d_update_csbp_8x8(
                            ps_cur_mb_info->ps_curmb->u2_luma_csbp);
        }

        if(ps_cur_mb_info->ps_left_mb->u1_tran_form8x8 == 1)
        {
            u2_left_csbp = ih264d_update_csbp_8x8(
                            ps_cur_mb_info->ps_left_mb->u2_luma_csbp);
        }

        if(ps_cur_mb_info->ps_top_mb->u1_tran_form8x8 == 1)
        {
            u2_top_csbp = ih264d_update_csbp_8x8(
                            ps_cur_mb_info->ps_top_mb->u2_luma_csbp);
        }
    }
    if(u4_cur_mb_intra)
    {

        pu4_bs_table[4] = 0x04040404;
        if((0 == u4_cur_mb_fld) && (0 == u4_top_mb_fld))
        {
            pu4_bs_table[0] = 0x04040404;
        }
        else
        {
            pu4_bs_table[0] = 0x03030303;
        }

        pu4_bs_table[1] = 0x03030303;
        pu4_bs_table[2] = 0x03030303;
        pu4_bs_table[3] = 0x03030303;
        pu4_bs_table[5] = 0x03030303;
        pu4_bs_table[6] = 0x03030303;
        pu4_bs_table[7] = 0x03030303;

        /*********************************************************************/
        /* Fill Bs of xtra top and left edge unconditionally to avoid checks */
        /*********************************************************************/
        pu4_bs_table[8] = 0x03030303;
        pu4_bs_table[9] = 0x04040404;
    }
    else
    {
        UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
        UWORD32 u4_is_b = ps_dec->u1_B;

        ih264d_fill_bs2_horz_vert(
                        pu4_bs_table, u2_left_csbp, u2_top_csbp, u2_cur_csbp,
                        (const UWORD32 *)(gau4_ih264d_packed_bs2),
                        (const UWORD16 *)(gau2_ih264d_4x4_v2h_reorder));

        if(u4_leftmbtype & D_INTRA_MB)
            pu4_bs_table[4] = 0x04040404;

        if(u1_top_mb_typ & D_INTRA_MB)
            pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
        else if(u4_cur_mb_fld != u4_top_mb_fld)
        {
            /****************************************************/
            /* Setting BS for mixed mode edge=1 when (Bs!=2)    */
            /****************************************************/
            pu4_bs_table[0] = (pu4_bs_table[0] >> 1) + 0x01010101;
        }

        {
            /* Call to Compute Boundary Strength for Extra Left Edge */
            if(u2_mbx
                            && !(ps_cur_mb_params->u1_deblocking_mode
                                            & MB_DISABLE_LEFT_EDGE))
            {
                if(u4_cur_mb_fld != u4_left_mb_fld)
                {
                    UWORD32 u4_left_mb_t_csbp =
                                    ps_cur_mb_info->ps_left_mb[0].u2_luma_csbp;
                    UWORD32 u4_left_mb_b_csbp =
                                    ps_cur_mb_info->ps_left_mb[1].u2_luma_csbp;
                    if(1 == ps_cur_mb_info->ps_left_mb[0].u1_tran_form8x8)
                    {
                        u4_left_mb_t_csbp = (UWORD32)ih264d_update_csbp_8x8(
                                        (UWORD16)u4_left_mb_t_csbp);
                    }

                    if(1 == ps_cur_mb_info->ps_left_mb[1].u1_tran_form8x8)
                    {
                        u4_left_mb_b_csbp = (UWORD32)ih264d_update_csbp_8x8(
                                        (UWORD16)u4_left_mb_b_csbp);
                    }
                    ps_dec->pf_fill_bs_xtra_left_edge[u4_cur_mb_fld](
                                    pu4_bs_table, u4_left_mb_t_csbp,
                                    u4_left_mb_b_csbp, u2_cur_csbp, u4_bot_mb);

                    if(ps_dec->deblk_left_mb[0].u1_mb_type & D_INTRA_MB)
                        pu4_bs_table[4] = 0x04040404;

                    if(ps_dec->deblk_left_mb[1].u1_mb_type & D_INTRA_MB)
                        pu4_bs_table[9] = 0x04040404;

                }
            }
            /* Call to Compute Boundary Strength for Extra Top Edge */
            if(u2_mby
                            && !(ps_cur_mb_params->u1_deblocking_mode
                                            & MB_DISABLE_TOP_EDGE))
            {
                if((((!u4_bot_mb) & (!u4_cur_mb_fld)) && u4_top_mb_fld))
                {
                    UWORD32 u4_topmb_t_csbp =
                                    ps_cur_mb_info->ps_top_mb[-1].u2_luma_csbp;
                    UWORD32 u4_topmb_b_csbp =
                                    ps_cur_mb_info->ps_top_mb[0].u2_luma_csbp;
                    if(1 == ps_cur_mb_info->ps_top_mb[-1].u1_tran_form8x8)
                    {
                        u4_topmb_t_csbp = (UWORD32)ih264d_update_csbp_8x8(
                                        (UWORD16)u4_topmb_t_csbp);
                    }

                    if(1 == ps_cur_mb_info->ps_top_mb[0].u1_tran_form8x8)
                    {
                        u4_topmb_b_csbp = (UWORD32)ih264d_update_csbp_8x8(
                                        (UWORD16)u4_topmb_b_csbp);
                    }
                    ih264d_fill_bs_xtra_top_edge(pu4_bs_table, u4_topmb_t_csbp,
                                                 u4_topmb_b_csbp, u2_cur_csbp);

                    if(ps_deblk_top_mb[0].u1_mb_type & D_INTRA_MB)
                        pu4_bs_table[8] = 0x03030303;

                    if(ps_deblk_top_mb[1].u1_mb_type & D_INTRA_MB)
                        pu4_bs_table[0] = 0x03030303;
                }
            }
        }

        ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
                        ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc,
                        pu4_bs_table, ps_left_mv_pred, ps_left_ngbr,
                        ps_cur_mb_info->ps_top_mb->u4_pic_addrress,
                        (4 >> u4_cur_mb_fld));
    }

    {
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
        POC_LIST_L0_TO_L1_DIFF;

        {
            /* Store Parameter for Top MvPred refernce frame Address */
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
            void ** ppv_left_mv_pred_addr =
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][u4_bot_mb].u4_add;
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
            WORD8 * p1_refLeft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refLeft0[0]];
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refLeft0[1]];
        }
        if(u4_bot_mb)
        {
            /* store The Left Mb Type*/
            ps_dec->deblk_left_mb[0].u1_mb_type =
                            (ps_cur_mb_params - 1)->u1_mb_type;
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;

        }
        ps_deblk_top_mb[u4_bot_mb].u1_mb_type = u1_cur_mb_type;
    }
    /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
    if(ps_cur_mb_info->u1_tran_form8x8)
    {
        pu4_bs_table[1] = 0;
        pu4_bs_table[3] = 0;
        pu4_bs_table[5] = 0;
        pu4_bs_table[7] = 0;
    }

}



/*!
 **************************************************************************
 * \if Function name : ih264d_fill_bs_for_mb \endif
 *
 * \brief
 *    Determines the boundary strength (Bs), for the complete MB. Bs is
 *    determined for each block boundary between two neighbouring 4x4
 *    luma blocks, then packed in a UWORD32, first Bs placed in MSB and
 *    so on.  Such packed Bs values for all 8 edges are kept in an array.
 *
 * \return
 *    Returns the packed boundary strength(Bs)  MSB -> LSB Bs0|Bs1|Bs2|Bs3
 *
 **************************************************************************
 */

void ih264d_fill_bs_for_mb(deblk_mb_t * ps_cur_mb_params,
                           deblk_mb_t * ps_top_mb_params,
                           deblk_mb_t * ps_left_mb_params,
                           mv_pred_t *ps_cur_mv_pred,
                           mv_pred_t *ps_top_mv_pred,
                           UWORD8 *puc_cur_nnz,
                           UWORD8 *puc_top_nnz,
                           void **ppv_map_ref_idx_to_poc,
                           UWORD32 ui_mbAff,
                           UWORD32 ui_bs_table[], /* pointer to the BsTable array */
                           mv_pred_t *ps_leftmost_mv_pred,
                           neighbouradd_t *ps_left_addr,
                           neighbouradd_t *ps_top_add)
{
    UWORD32 u4_bs_horz = 0;
    UWORD8 edge, u1_top_intra = 0, u1_left_intra = 0;
    mv_pred_t *ps_left_mv_pred;
    WORD16 i2_cur_mv0, i2_cur_mv1, i16_curMv2, i16_curMv3;
    WORD16 i2_left_mv0, i2_left_mv1, i2_left_mv2, i2_left_mv3;
    WORD16 i2_top_mv0, i2_top_mv1, i16_topMv2, i16_topMv3;
    WORD8 i1_cur_ref0, i1_cur_ref1, i1_left_ref0, i1_left_ref1, i1_top_ref0, i1_top_ref1;
    UWORD8 uc_cur_nnz, uc_left_nnz, uc_top_nnz, u1_mb_type, uc_Bslice;
    void **ppv_map_ref_idx_to_poc_l0, **ppv_map_ref_idx_to_poc_l1;
    UWORD8 uc_temp;
    UWORD8 uc_cur_mb_fld, uc_top_mb_fld;
    UWORD32 c_mv_limit;

    u1_mb_type = ps_cur_mb_params->u1_mb_type;
    uc_Bslice = u1_mb_type & D_B_SLICE;
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
    ppv_map_ref_idx_to_poc_l1 = ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;

    ps_top_mb_params = ps_top_mb_params ? ps_top_mb_params : ps_cur_mb_params;
    u1_top_intra = ps_top_mb_params->u1_mb_type & D_INTRA_MB;
    u1_left_intra = ps_left_mb_params->u1_mb_type & D_INTRA_MB;

    ui_bs_table[4] = 0x04040404; //Default for INTRA MB Boundary edges.
    uc_cur_mb_fld = (ps_cur_mb_params->u1_mb_type & D_FLD_MB) >> 7;
    uc_top_mb_fld = (ps_top_mb_params->u1_mb_type & D_FLD_MB) >> 7;

    c_mv_limit = 4 >> uc_cur_mb_fld;
    if((0 == uc_cur_mb_fld) && (0 == uc_top_mb_fld))
    {
        ui_bs_table[0] = 0x04040404;
    }
    else
    {
        ui_bs_table[0] = 0x03030303;
    }

    for(edge = 0; edge < 4;
                    edge++, ps_top_mv_pred = ps_cur_mv_pred - 4, puc_top_nnz =
                                    puc_cur_nnz - 4)
    {
        //Each iteration of this loop fills the four BS values of one HORIZ edge and
        //one BS value for each of the four VERT edges.
        WORD8 i = 0;
        UWORD8 uc_bs_horiz, uc_bs_vert;
        UWORD32 ui_cnd;
        void *ui_ref_pic_addr[4];
        UWORD8 uc_mixed_mode_edge;

        uc_mixed_mode_edge = 0;

        uc_temp = (ui_mbAff << 4) + 13;

        uc_cur_nnz = *(puc_cur_nnz - uc_temp);
        ps_left_mv_pred = ps_leftmost_mv_pred + (edge << 2);

        for(i = 0; i < 4; i++, ps_top_mv_pred++, ps_cur_mv_pred++)
        {
            //Each iteration of this inner loop computes a HORIZ
            //and a VERT BS value for a 4x4 block

            uc_left_nnz = uc_cur_nnz;
            uc_cur_nnz = *puc_cur_nnz++;
            uc_top_nnz = *puc_top_nnz++;

            //VERT edge is assigned BS values first
            ui_cnd = !(uc_left_nnz || uc_cur_nnz);
            uc_bs_vert = 2;

            if(ui_cnd)
            {
                i2_left_mv0 = ps_left_mv_pred->i2_mv[0];
                i2_left_mv1 = ps_left_mv_pred->i2_mv[1];
                i2_left_mv2 = ps_left_mv_pred->i2_mv[2];
                i2_left_mv3 = ps_left_mv_pred->i2_mv[3];

                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];
                ui_ref_pic_addr[2] = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
                ui_ref_pic_addr[3] = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];

                if(i)
                {
                    i1_left_ref0 = ps_left_mv_pred->i1_ref_frame[0];
                    i1_left_ref1 = ps_left_mv_pred->i1_ref_frame[1];
                    ui_ref_pic_addr[0] = ppv_map_ref_idx_to_poc_l0[i1_left_ref0];
                    ui_ref_pic_addr[1] = ppv_map_ref_idx_to_poc_l1[i1_left_ref1];
                }
                else
                {
                    ui_ref_pic_addr[0] = ps_left_addr->u4_add[edge & 2];
                    ui_ref_pic_addr[1] = ps_left_addr->u4_add[1 + (edge & 2)];
                }
                if(!uc_Bslice)
                {
                    uc_bs_vert =
                                    (ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
                                                    | (ABS((i2_left_mv0
                                                                    - i2_cur_mv0))
                                                                    >= 4)
                                                    | (ABS((i2_left_mv1
                                                                    - i2_cur_mv1))
                                                                    >= (UWORD8)c_mv_limit);
                }
                else
                {
                    UWORD8 uc_bs_temp1, uc_bs_temp2;

                    uc_bs_vert = 1;

                    uc_bs_temp1 =
                                    ((ABS((i2_left_mv0 - i2_cur_mv0))
                                                    >= 4)
                                                    | (ABS((i2_left_mv1
                                                                    - i2_cur_mv1))
                                                                    >= (UWORD8)c_mv_limit)
                                                    | (ABS((i2_left_mv2
                                                                    - i16_curMv2))
                                                                    >= 4)
                                                    | (ABS((i2_left_mv3
                                                                    - i16_curMv3))
                                                                    >= (UWORD8)c_mv_limit));

                    uc_bs_temp2 =
                                    ((ABS((i2_left_mv0 - i16_curMv2))
                                                    >= 4)
                                                    | (ABS((i2_left_mv1
                                                                    - i16_curMv3))
                                                                    >= (UWORD8)c_mv_limit)
                                                    | (ABS((i2_left_mv2
                                                                    - i2_cur_mv0))
                                                                    >= 4)
                                                    | (ABS((i2_left_mv3
                                                                    - i2_cur_mv1))
                                                                    >= (UWORD8)c_mv_limit));

                    uc_bs_vert =
                                    (((ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
                                                    || (ui_ref_pic_addr[1]
                                                                    != ui_ref_pic_addr[3]))
                                                    || (uc_bs_temp1))
                                                    && (((ui_ref_pic_addr[0]
                                                                    != ui_ref_pic_addr[3])
                                                                    || (ui_ref_pic_addr[1]
                                                                                    != ui_ref_pic_addr[2]))
                                                                    || (uc_bs_temp2));

                }
            }
            //Fill the VERT BS, only if valid i.e.,
            //if it is a non-edge OR it is an edge, which is not yet filled
            uc_bs_vert = (!i && u1_left_intra) ? 4 : uc_bs_vert;
            ui_bs_table[i + 4] = (ui_bs_table[i + 4] << 8) | uc_bs_vert;

            //HORIZ edge is assigned BS values next
            ui_cnd = !(uc_top_nnz || uc_cur_nnz);
            uc_bs_horiz = 2;

            if(ui_cnd)
            {
                uc_mixed_mode_edge =
                                (0 == edge) ? (uc_top_mb_fld != uc_cur_mb_fld) : 0;
                ui_cnd = 1 - uc_mixed_mode_edge;
                uc_bs_horiz = uc_mixed_mode_edge;
            }

            if(ui_cnd)
            {
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];

                i2_top_mv0 = ps_top_mv_pred->i2_mv[0];
                i2_top_mv1 = ps_top_mv_pred->i2_mv[1];
                i16_topMv2 = ps_top_mv_pred->i2_mv[2];
                i16_topMv3 = ps_top_mv_pred->i2_mv[3];
                ui_ref_pic_addr[2] = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
                ui_ref_pic_addr[3] = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];
                if(edge)
                {
                    i1_top_ref0 = ps_top_mv_pred->i1_ref_frame[0];
                    i1_top_ref1 = ps_top_mv_pred->i1_ref_frame[1];
                    ui_ref_pic_addr[0] = ppv_map_ref_idx_to_poc_l0[i1_top_ref0];
                    ui_ref_pic_addr[1] = ppv_map_ref_idx_to_poc_l1[i1_top_ref1];
                }
                else
                {
                    ui_ref_pic_addr[0] = ps_top_add->u4_add[i & 2];
                    ui_ref_pic_addr[1] = ps_top_add->u4_add[1 + (i & 2)];
                }
                if(!uc_Bslice)
                {
                    uc_bs_horiz =
                                    (ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
                                                    | (ABS((i2_top_mv0
                                                                    - i2_cur_mv0))
                                                                    >= 4)
                                                    | (ABS((i2_top_mv1
                                                                    - i2_cur_mv1))
                                                                    >= (UWORD8)c_mv_limit);
                }
                else
                {
                    UWORD8 uc_bs_temp1, uc_bs_temp2;

                    uc_bs_horiz = 1;

                    uc_bs_temp1 =
                                    ((ABS((i2_top_mv0 - i2_cur_mv0))
                                                    >= 4)
                                                    | (ABS((i2_top_mv1
                                                                    - i2_cur_mv1))
                                                                    >= (UWORD8)c_mv_limit)
                                                    | (ABS((i16_topMv2
                                                                    - i16_curMv2))
                                                                    >= 4)
                                                    | (ABS((i16_topMv3
                                                                    - i16_curMv3))
                                                                    >= (UWORD8)c_mv_limit));

                    uc_bs_temp2 =
                                    ((ABS((i2_top_mv0 - i16_curMv2))
                                                    >= 4)
                                                    | (ABS((i2_top_mv1
                                                                    - i16_curMv3))
                                                                    >= (UWORD8)c_mv_limit)
                                                    | (ABS((i16_topMv2
                                                                    - i2_cur_mv0))
                                                                    >= 4)
                                                    | (ABS((i16_topMv3
                                                                    - i2_cur_mv1))
                                                                    >= (UWORD8)c_mv_limit));

                    uc_bs_horiz =
                                    (((ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
                                                    || (ui_ref_pic_addr[1]
                                                                    != ui_ref_pic_addr[3]))
                                                    || (uc_bs_temp1))
                                                    && (((ui_ref_pic_addr[0]
                                                                    != ui_ref_pic_addr[3])
                                                                    || (ui_ref_pic_addr[1]
                                                                                    != ui_ref_pic_addr[2]))
                                                                    || (uc_bs_temp2));

                }
            }
            ps_left_mv_pred = ps_cur_mv_pred;
            u4_bs_horz = (u4_bs_horz << 8) + uc_bs_horiz;
        }
        //Fill the HORIZ BS, only if valid i.e.,
        //if it is a non-edge OR it is an edge, which is not yet filled
        if(edge || (!edge && !u1_top_intra))
            ui_bs_table[edge] = u4_bs_horz;
    }
}

/*!
 **************************************************************************
 * \if Function name : ih264d_fill_bs_for_extra_left_edge \endif
 *
 * \brief
 *    Fills the boundary strength (Bs), for the top extra edge. ock
 *
 * \return
 *    Returns the packed boundary strength(Bs)  MSB -> LSB Bs0|Bs1|Bs2|Bs3
 *
 **************************************************************************
 */
void ih264d_fill_bs_for_extra_left_edge(deblk_mb_t *ps_cur_deblk_mb,
                                        deblk_mb_t *ps_leftDeblkMb,
                                        UWORD8* puc_cur_nnz,
                                        UWORD8 uc_botMb)
{
    /* Set the Flag in uc_deblocking_mode variable of current MB*/
    /* for mixed mode edge*/
    ps_cur_deblk_mb->u1_single_call = 0;

    if(ps_cur_deblk_mb->u1_mb_type & D_INTRA_MB)
    {
        ps_cur_deblk_mb->u4_bs_table[4] = 0x04040404;
        ps_cur_deblk_mb->u4_bs_table[9] = 0x04040404;
    }
    else if((ps_leftDeblkMb->u1_mb_type & D_INTRA_MB)
                    && ((ps_leftDeblkMb + 1)->u1_mb_type & D_INTRA_MB))
    {
        ps_cur_deblk_mb->u4_bs_table[4] = 0x04040404;
        ps_cur_deblk_mb->u4_bs_table[9] = 0x04040404;
    }
    else
    {
        /* Get strengths of left MB edge */
        UWORD32 u4_bs;
        UWORD8 uc_Bs;
        WORD32 i;
        UWORD32 ui_curMbFld;
        UWORD8 *puc_left_nnz;
        UWORD32 ui_bs_left_edge[2];

        ui_curMbFld = (ps_cur_deblk_mb->u1_mb_type & D_FLD_MB) >> 7;

        puc_left_nnz = puc_cur_nnz - 29;
        if((ui_curMbFld == 0) && uc_botMb)
        {
            puc_left_nnz -= 8;
        }
        else if(ui_curMbFld && uc_botMb)
        {
            puc_left_nnz -= 16;
        }

        if(ui_curMbFld)
        {
            if(ps_leftDeblkMb->u1_mb_type & D_INTRA_MB)
            {
                ui_bs_left_edge[0] = 0x04040404;
                puc_left_nnz += 16;
                puc_cur_nnz += 8;
            }
            else
            {
                u4_bs = 0;
                for(i = 4; i > 0; i--)
                {
                    uc_Bs = ((*puc_cur_nnz || *puc_left_nnz)) ? 2 : 1;
                    u4_bs = (u4_bs << 8) | uc_Bs;
                    puc_left_nnz += 4;
                    if(i & 0x01)
                        puc_cur_nnz += 4;
                }
                ui_bs_left_edge[0] = u4_bs;
            }

            if((ps_leftDeblkMb + 1)->u1_mb_type & D_INTRA_MB)
            {
                ui_bs_left_edge[1] = 0x04040404;
            }
            else
            {
                u4_bs = 0;
                for(i = 4; i > 0; i--)
                {
                    uc_Bs = ((*puc_cur_nnz || *puc_left_nnz)) ? 2 : 1;
                    u4_bs = (u4_bs << 8) | uc_Bs;
                    puc_left_nnz += 4;
                    if(i & 0x01)
                        puc_cur_nnz += 4;
                }
                ui_bs_left_edge[1] = u4_bs;
            }
        }
        else
        {
            UWORD8 *puc_curNnzB, *puc_leftNnzB;
            puc_curNnzB = puc_cur_nnz;
            puc_leftNnzB = puc_left_nnz + 16;
            if(ps_leftDeblkMb->u1_mb_type & D_INTRA_MB)
            {
                ui_bs_left_edge[0] = 0x04040404;
            }
            else
            {
                u4_bs = 0;
                for(i = 4; i > 0; i--, puc_cur_nnz += 4)
                {
                    uc_Bs = ((*puc_cur_nnz || *puc_left_nnz)) ? 2 : 1;
                    u4_bs = (u4_bs << 8) | uc_Bs;
                    if(i & 0x01)
                        puc_left_nnz += 4;
                }
                ui_bs_left_edge[0] = u4_bs;
            }

            if((ps_leftDeblkMb + 1)->u1_mb_type & D_INTRA_MB)
            {
                ui_bs_left_edge[1] = 0x04040404;
            }
            else
            {
                u4_bs = 0;
                for(i = 4; i > 0; i--, puc_curNnzB += 4)
                {
                    uc_Bs = ((*puc_curNnzB || *puc_leftNnzB)) ? 2 : 1;
                    u4_bs = (u4_bs << 8) | uc_Bs;
                    if(i & 0x01)
                        puc_leftNnzB += 4;
                }
                ui_bs_left_edge[1] = u4_bs;
            }
        }
        /* Copy The Values in Cur Deblk Mb Parameters */
        ps_cur_deblk_mb->u4_bs_table[4] = ui_bs_left_edge[0];
        ps_cur_deblk_mb->u4_bs_table[9] = ui_bs_left_edge[1];
    }

}

/*!
 **************************************************************************
 * \if Function name : ih264d_fill_bs_for_extra_top_edge \endif
 *
 * \brief
 *    Fills the boundary strength (Bs), for the top extra edge. ock
 *
 * \return
 *    Returns the packed boundary strength(Bs)  MSB -> LSB Bs0|Bs1|Bs2|Bs3
 *
 **************************************************************************
 */
void ih264d_fill_bs_for_extra_top_edge(deblk_mb_t *ps_cur_mb_params,
                                       UWORD8 u1_Edge0_mb_typ,
                                       UWORD8 u1_Edge1_mb_typ,
                                       UWORD8 *pu1_curNnz,
                                       UWORD8 *pu1_topNnz)
{
    UWORD32 u4_bs;
    UWORD8 uc_Bs;
    WORD32 i;
    UWORD8 *pu1_cur_nnz_tmp;
    UWORD8 *pu1_top_nnz_tmp;
    UWORD8 u1_top_edge;
    UWORD8 u1_top_mb_type;
    for(u1_top_edge = 0; u1_top_edge < 2; u1_top_edge++)
    {
        u1_top_mb_type = u1_top_edge ? u1_Edge1_mb_typ : u1_Edge0_mb_typ;
        pu1_cur_nnz_tmp = pu1_curNnz;
        pu1_top_nnz_tmp = pu1_topNnz + (u1_top_edge << 2);

        if((ps_cur_mb_params->u1_mb_type & D_INTRA_MB)
                        + (u1_top_mb_type & D_INTRA_MB))
        {
            u4_bs = 0x03030303;
        }
        else
        {
            u4_bs = 0;
            for(i = 4; i > 0; i--, pu1_cur_nnz_tmp += 1, pu1_top_nnz_tmp += 1)
            {
                uc_Bs = ((*pu1_cur_nnz_tmp || *pu1_top_nnz_tmp)) ? 2 : 1;
                u4_bs = (u4_bs << 8) | uc_Bs;
            }
        }
        if(u1_top_edge)
            ps_cur_mb_params->u4_bs_table[0] = u4_bs;
        else
            ps_cur_mb_params->u4_bs_table[8] = u4_bs;
    }
}


void ih264d_fill_bs_mbedge_4(dec_struct_t * ps_dec,
                             dec_mb_info_t * ps_cur_mb_info,
                             const UWORD16 u2_mbxn_mb)
{

    /* deblk_mb_t Params */
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
    deblkmb_neighbour_t *ps_deblk_top_mb;
    UWORD32 * pu4_bs_table;
    UWORD8 u1_cur_mb_type;

    /* Neighbour availability */
    /* Initialization */
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;


    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + u2_mbxn_mb;

    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;

    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;

    {
        UWORD8 mb_qp_temp;

        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;

        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;

    }

    ps_cur_mb_params->u1_single_call = 1;

    ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
    /* if no deblocking required for current Mb then continue */
    /* Check next Mbs   in Mb group                           */
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
    {
        /* Storing the leftMbtype for next Mb */
        return;
    }

    /* Compute BS function */
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;

    pu4_bs_table[4] = 0x04040404;
    pu4_bs_table[0] = 0x04040404;
    pu4_bs_table[1] = 0;
    pu4_bs_table[2] = 0;
    pu4_bs_table[3] = 0;
    pu4_bs_table[5] = 0;
    pu4_bs_table[6] = 0;
    pu4_bs_table[7] = 0;

}

void ih264d_fill_bs_mbedge_2(dec_struct_t * ps_dec,
                             dec_mb_info_t * ps_cur_mb_info,
                             const UWORD16 u2_mbxn_mb)
{

    /* deblk_mb_t Params */
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
    deblkmb_neighbour_t *ps_deblk_top_mb;
    UWORD32 * pu4_bs_table;
    UWORD8 u1_cur_mb_type;

    /* Neighbour availability */
    /* Initialization */
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;


    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + u2_mbxn_mb;

    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;

    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;

    {
        UWORD8 mb_qp_temp;

        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;

        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;

    }

    ps_cur_mb_params->u1_single_call = 1;

    ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
    /* if no deblocking required for current Mb then continue */
    /* Check next Mbs   in Mb group                           */
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
    {
        /* Storing the leftMbtype for next Mb */
        return;
    }

    /* Compute BS function */
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;

    {
        UWORD32 top_mb_csbp, left_mb_csbp, cur_mb_csbp;
        UWORD32 top_edge, left_edge;

        top_mb_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
        left_mb_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
        cur_mb_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;

        top_mb_csbp = top_mb_csbp >> 12;
        top_edge = top_mb_csbp | (cur_mb_csbp & 0xf);

        if(top_edge)
            pu4_bs_table[0] = 0x02020202;
        else
            pu4_bs_table[0] = 0;

        cur_mb_csbp = cur_mb_csbp & CSBP_LEFT_BLOCK_MASK;
        left_mb_csbp = left_mb_csbp & CSBP_RIGHT_BLOCK_MASK;

        left_edge = cur_mb_csbp | left_mb_csbp;

        if(left_edge)
            pu4_bs_table[4] = 0x02020202;
        else
            pu4_bs_table[4] = 0;

        pu4_bs_table[1] = 0;
        pu4_bs_table[2] = 0;
        pu4_bs_table[3] = 0;
        pu4_bs_table[5] = 0;
        pu4_bs_table[6] = 0;
        pu4_bs_table[7] = 0;
    }

}