@@ -1008,107 +1008,39 @@ static void vp8_loop_filter_simple(uint8_t *y, int ys, uint8_t *u, int uvs, uint
10081008 int mbw , int mbh , int lf_level , int sharpness ,
10091009 int seg_enabled , int seg_abs , const int * seg_lf , const uint8_t * seg_map )
10101010{
1011- int mx , my , bx , by ;
1011+ int mx , my , by , bx ;
10121012 for (my = 0 ; my < mbh ; my ++ )
10131013 {
10141014 for (mx = 0 ; mx < mbw ; mx ++ )
10151015 {
10161016 int mb_lf = lf_level ;
10171017 int seg_id = seg_map ? seg_map [my * mbw + mx ] : 0 ;
1018- int flimit , ilimit ;
1018+ int flimit ;
10191019 if (seg_enabled && seg_abs )
10201020 mb_lf = seg_lf [seg_id ];
10211021 else if (seg_enabled )
10221022 mb_lf = lf_level + seg_lf [seg_id ];
10231023 if (mb_lf < 0 ) mb_lf = 0 ;
10241024 if (mb_lf > 63 ) mb_lf = 63 ;
1025- /* Compute filter limit */
1025+ if ( mb_lf == 0 ) continue ;
10261026 flimit = 2 * mb_lf + (sharpness > 0 ? (sharpness > 4 ? 2 : 1 ) : 0 );
10271027 if (flimit > 63 ) flimit = 63 ;
1028- ilimit = mb_lf ;
1029- if (sharpness > 0 ) {
1030- ilimit >>= (sharpness > 4 ? 2 : 1 );
1031- if (ilimit > 9 - sharpness ) ilimit = 9 - sharpness ;
1032- }
1033- if (ilimit < 1 ) ilimit = 1 ;
1034-
1035- if (mb_lf == 0 ) continue ;
1036-
1037- /* Y plane: filter vertical edges (between columns of 4x4 blocks) */
1038- for (by = 0 ; by < 16 ; by ++ )
1039- {
1040- uint8_t * row = y + (my * 16 + by )* ys + mx * 16 ;
1041- /* MB left edge (stronger filter at MB boundary) */
1042- if (mx > 0 )
1043- {
1044- int p1 = row [-2 ], p0 = row [-1 ], q0 = row [0 ], q1 = row [1 ];
1045- int a = vp8_sc (3 * (q0 - p0 ) + vp8_sc (p1 - q1 ));
1046- if (a < 0 ? - a : a <= flimit ) {
1047- int f = vp8_sc (a + 4 ) >> 3 ;
1048- row [-1 ] = vp8_cl (p0 + f );
1049- row [0 ] = vp8_cl (q0 - f );
1050- }
1051- }
1052- /* Sub-block edges at columns 4, 8, 12 */
1053- for (bx = 4 ; bx < 16 ; bx += 4 )
1054- {
1055- int p1 = row [bx - 2 ], p0 = row [bx - 1 ], q0 = row [bx ], q1 = row [bx + 1 ];
1056- int a = vp8_sc (3 * (q0 - p0 ) + vp8_sc (p1 - q1 ));
1057- if (a < 0 ? - a : a <= ilimit ) {
1058- int f = vp8_sc (a + 4 ) >> 3 ;
1059- row [bx - 1 ] = vp8_cl (p0 + f );
1060- row [bx ] = vp8_cl (q0 - f );
1061- }
1062- }
1063- }
1064- /* Y plane: filter horizontal edges */
1065- for (bx = 0 ; bx < 16 ; bx ++ )
1066- {
1067- /* MB top edge */
1068- if (my > 0 )
1069- {
1070- uint8_t * col = y + (my * 16 )* ys + mx * 16 + bx ;
1071- int p1 = col [-2 * ys ], p0 = col [- ys ], q0 = col [0 ], q1 = col [ys ];
1072- int a = vp8_sc (3 * (q0 - p0 ) + vp8_sc (p1 - q1 ));
1073- if (a < 0 ? - a : a <= flimit ) {
1074- int f = vp8_sc (a + 4 ) >> 3 ;
1075- col [- ys ] = vp8_cl (p0 + f );
1076- col [0 ] = vp8_cl (q0 - f );
1077- }
1078- }
1079- /* Sub-block edges at rows 4, 8, 12 */
1080- for (by = 4 ; by < 16 ; by += 4 )
1081- {
1082- uint8_t * col = y + (my * 16 + by )* ys + mx * 16 + bx ;
1083- int p1 = col [-2 * ys ], p0 = col [- ys ], q0 = col [0 ], q1 = col [ys ];
1084- int a = vp8_sc (3 * (q0 - p0 ) + vp8_sc (p1 - q1 ));
1085- if (a < 0 ? - a : a <= ilimit ) {
1086- int f = vp8_sc (a + 4 ) >> 3 ;
1087- col [- ys ] = vp8_cl (p0 + f );
1088- col [0 ] = vp8_cl (q0 - f );
1089- }
1090- }
1091- }
1092- /* UV planes: filter at MB edges and 8x8 sub-block edges */
1093- /* (simplified: only MB edges for UV) */
1028+ /* Y: left MB edge only */
10941029 if (mx > 0 ) {
1095- for (by = 0 ; by < 8 ; by ++ ) {
1096- uint8_t * ur = u + (my * 8 + by )* uvs + mx * 8 ;
1097- uint8_t * vr = v_plane + (my * 8 + by )* uvs + mx * 8 ;
1098- { int p1 = ur [-2 ],p0 = ur [-1 ],q0 = ur [0 ],q1 = ur [1 ]; int a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 ));
1099- if ((a < 0 ?- a :a )<=flimit ){int f = vp8_sc (a + 4 )>>3 ; ur [-1 ]= vp8_cl (p0 + f ); ur [0 ]= vp8_cl (q0 - f );} }
1100- { int p1 = vr [-2 ],p0 = vr [-1 ],q0 = vr [0 ],q1 = vr [1 ]; int a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 ));
1101- if ((a < 0 ?- a :a )<=flimit ){int f = vp8_sc (a + 4 )>>3 ; vr [-1 ]= vp8_cl (p0 + f ); vr [0 ]= vp8_cl (q0 - f );} }
1030+ for (by = 0 ; by < 16 ; by ++ ) {
1031+ uint8_t * row = y + (my * 16 + by )* ys + mx * 16 ;
1032+ int p1 = row [-2 ],p0 = row [-1 ],q0 = row [0 ],q1 = row [1 ];
1033+ int a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 ));
1034+ if ((a < 0 ?- a :a )<=flimit ) { int f = vp8_sc (a + 4 )>>3 ; row [-1 ]= vp8_cl (p0 + f ); row [0 ]= vp8_cl (q0 - f ); }
11021035 }
11031036 }
1037+ /* Y: top MB edge only */
11041038 if (my > 0 ) {
1105- for (bx = 0 ; bx < 8 ; bx ++ ) {
1106- uint8_t * uc = u + my * 8 * uvs + mx * 8 + bx ;
1107- uint8_t * vc = v_plane + my * 8 * uvs + mx * 8 + bx ;
1108- { int p1 = uc [-2 * uvs ],p0 = uc [- uvs ],q0 = uc [0 ],q1 = uc [uvs ]; int a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 ));
1109- if ((a < 0 ?- a :a )<=flimit ){int f = vp8_sc (a + 4 )>>3 ; uc [- uvs ]= vp8_cl (p0 + f ); uc [0 ]= vp8_cl (q0 - f );} }
1110- { int p1 = vc [-2 * uvs ],p0 = vc [- uvs ],q0 = vc [0 ],q1 = vc [uvs ]; int a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 ));
1111- if ((a < 0 ?- a :a )<=flimit ){int f = vp8_sc (a + 4 )>>3 ; vc [- uvs ]= vp8_cl (p0 + f ); vc [0 ]= vp8_cl (q0 - f );} }
1039+ for (bx = 0 ; bx < 16 ; bx ++ ) {
1040+ uint8_t * col = y + my * 16 * ys + mx * 16 + bx ;
1041+ int p1 = col [-2 * ys ],p0 = col [- ys ],q0 = col [0 ],q1 = col [ys ];
1042+ int a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 ));
1043+ if ((a < 0 ?- a :a )<=flimit ) { int f = vp8_sc (a + 4 )>>3 ; col [- ys ]= vp8_cl (p0 + f ); col [0 ]= vp8_cl (q0 - f ); }
11121044 }
11131045 }
11141046 }
@@ -1588,35 +1520,16 @@ static uint32_t *vp8_decode(const uint8_t *data, size_t len,
15881520 left_nz_dc = 0 ;
15891521 }
15901522
1591- /* Per-MB simple loop filter */
1592- if (filter_type == 1 ) {
1593- int mb_lf_val = lf_level ;
1594- if (seg_enabled && seg_abs ) mb_lf_val = seg_lf [seg_id ];
1595- else if (seg_enabled ) mb_lf_val = lf_level + seg_lf [seg_id ];
1596- if (mb_lf_val < 0 ) mb_lf_val = 0 ; if (mb_lf_val > 63 ) mb_lf_val = 63 ;
1597- if (mb_lf_val > 0 ) {
1598- int fl = 2 * mb_lf_val , il = mb_lf_val ;
1599- if (sharpness > 0 ) { fl += (sharpness > 4 ) ? 2 : 1 ; }
1600- if (fl > 63 ) fl = 63 ;
1601- if (sharpness > 0 ) { il >>= (sharpness > 4 ) ? 2 : 1 ; if (il > 9 - sharpness ) il = 9 - sharpness ; }
1602- if (il < 1 ) il = 1 ;
1603- for (by = 0 ; by < 16 ; by ++ ) {
1604- uint8_t * row = yb + (my * 16 + by )* ys + mx * 16 ;
1605- if (mx > 0 ) { int p1 = row [-2 ],p0 = row [-1 ],q0 = row [0 ],q1 = row [1 ], a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 )); if ((a < 0 ?- a :a )<=fl ){int f = vp8_sc (a + 4 )>>3 ;row [-1 ]= vp8_cl (p0 + f );row [0 ]= vp8_cl (q0 - f );} }
1606- for (bx = 4 ; bx < 16 ; bx += 4 ) { int p1 = row [bx - 2 ],p0 = row [bx - 1 ],q0 = row [bx ],q1 = row [bx + 1 ], a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 )); if ((a < 0 ?- a :a )<=il ){int f = vp8_sc (a + 4 )>>3 ;row [bx - 1 ]= vp8_cl (p0 + f );row [bx ]= vp8_cl (q0 - f );} }
1607- }
1608- for (bx = 0 ; bx < 16 ; bx ++ ) {
1609- if (my > 0 ) { uint8_t * c2 = yb + my * 16 * ys + mx * 16 + bx ; int p1 = c2 [-2 * ys ],p0 = c2 [- ys ],q0 = c2 [0 ],q1 = c2 [ys ], a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 )); if ((a < 0 ?- a :a )<=fl ){int f = vp8_sc (a + 4 )>>3 ;c2 [- ys ]= vp8_cl (p0 + f );c2 [0 ]= vp8_cl (q0 - f );} }
1610- for (by = 4 ; by < 16 ; by += 4 ) { uint8_t * c2 = yb + (my * 16 + by )* ys + mx * 16 + bx ; int p1 = c2 [-2 * ys ],p0 = c2 [- ys ],q0 = c2 [0 ],q1 = c2 [ys ], a = vp8_sc (3 * (q0 - p0 )+ vp8_sc (p1 - q1 )); if ((a < 0 ?- a :a )<=il ){int f = vp8_sc (a + 4 )>>3 ;c2 [- ys ]= vp8_cl (p0 + f );c2 [0 ]= vp8_cl (q0 - f );} }
1611- }
1612- }
1613- }
16141523 }
16151524 }
16161525
16171526 free (above_nz_y ); free (above_nz_u ); free (above_nz_v ); free (above_nz_dc ); free (above_bmodes );
16181527 } /* end context tracking block */
16191528
1529+ /* Apply post-decode simple loop filter */
1530+ if (filter_type == 1 && lf_level > 0 )
1531+ vp8_loop_filter_simple (yb , ys , ub , uvs , vb , mbw , mbh , lf_level , sharpness , seg_enabled , seg_abs , seg_lf , seg_map_buf );
1532+
16201533 /* YUV -> ARGB */
16211534 pix = (uint32_t * )malloc ((size_t )w * h * sizeof (uint32_t ));
16221535 if (!pix ) goto lfail ;
0 commit comments