看了 HEVC spec (JCTVC-L1003) 中的 deblocking 部分, 总结一下:
对于一个picture, 是先滤vertical edge, 再滤horizontal edge, 只对PU和TU的边界(picture 边界不滤)进行filter, 如果TU/PU < 8x8, 那就只对位于8x8 grid上的PU/TU edge进行filter. BS的赋值以及filter or not的decision是以4个pixel line为单位的,因为PU/TU最小的width/height是4.
spec和software (HM)中都是以CU为单位来滤的,当然也可以用别的实现方式,只要结果一样就可以。具体如下:
1. (vertical edge 滤波) for each CU in one picture:
1). 对于该CU内所有vertical edges, 标记 filter_flag = 0;
2). 标记该CU内所有vertical TU edge的filter_flag = 1; 如果以下有任一个条件满足,标记最左edge的filter_flag=0:
- 它是picture edge;
- is the left boundary of the tile and loop_filter_across_tiles_enabled_flag is equal to 0
- is the left boundary of the slice and slice_loop_filter_across_slice_enabled_flag is equal to
3). 标记该CU 内所有 vertical PU edge (不管最左边界)的filter_flag=1
4). 对于该CU内所有horizontal 坐标为8的倍数,vertical 坐标为4的倍数的vertical edge, 求BS (边界强度)
5). 对于该CU内所有horizontal 坐标为8的倍数,vertical 坐标为4的倍数的vertical edge,根据BS的值是否为0,对Luma vertical edge 滤波(具体滤波操作略去)。是否滤波以及strong/weak filter的选择还要经过像素级的判断,这里略去,然后还要经过如下判断:
- 如果该边界的filter_edge=0, 则BS=0
- 否则,根据intra mode or not, cbf=0/1, mv difference 等规则求BS。
- 如果该edge 左侧pixel p0 满足以下两个条件中任一个,则该edge左侧的pixel 值不变
- pcm_loop_filter_disabled_flag is equal to 1 and pcm_flag[xp0][yp0] is equal to 1
- cu_transquant_bypass_flag of the CU that includes p0 is equal to 1
- 如果该edge 右侧pixel q0 满足以下两个条件中任一个,则该edge右侧的pixel 值不变
- pcm_loop_filter_disabled_flag is equal to 1 and pcm_flag[xq0][yq0] is equal to 1
- cu_transquant_bypass_flag of the CU that includes q0 is equal to 1
6). 对于该CU内所有horizontal 坐标为8的倍数,vertical 坐标为4的倍数的vertical edge,如果BS=2 (intra mode) ,则对chroma edge 滤波 (具体滤波操作略去)。 但是以下情况不滤:
- 如果该edge 左侧pixel p0 满足以下两个条件中任一个,则该edge左侧的pixel 值不变
- pcm_loop_filter_disabled_flag is equal to 1 and pcm_flag[2*xp0][2*yp0] is equal to 1
- cu_transquant_bypass_flag of the CU that includes p0 is equal to 1
- 如果该edge 右侧pixel q0 满足以下两个条件中任一个,则该edge右侧的pixel 值不变
- pcm_loop_filter_disabled_flag is equal to 1 and pcm_flag[2*xq0][2*yq0] is equal to 1
- cu_transquant_bypass_flag of the CU that includes q0 is equal to 1
2. (horizontal edge 滤波) for each CU in one picture:
跟以上vertical edge 类似,不再赘述。