+ mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);
+ clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];
+ }
+ y_to_deblock = mvmasks[POS_CUR]
+ | (mvmasks[POS_BOTTOM] << 16);
+ /* This pattern contains bits signalling that horizontal edges of
+ * the current block can be filtered.
+ * That happens when either of adjacent subblocks is coded or lies on
+ * the edge of 8x8 blocks with motion vectors differing by more than
+ * 3/4 pel in any component (any edge orientation for some reason).
+ */
+ y_h_deblock = y_to_deblock
+ | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)
+ | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);
+ /* This pattern contains bits signalling that vertical edges of
+ * the current block can be filtered.
+ * That happens when either of adjacent subblocks is coded or lies on
+ * the edge of 8x8 blocks with motion vectors differing by more than
+ * 3/4 pel in any component (any edge orientation for some reason).
+ */
+ y_v_deblock = y_to_deblock
+ | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)
+ | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);
+ if(!mb_x)
+ y_v_deblock &= ~MASK_Y_LEFT_COL;
+ if(!row)
+ y_h_deblock &= ~MASK_Y_TOP_ROW;
+ if(row == s->mb_height - 1 || (mb_strong[POS_CUR] | mb_strong[POS_BOTTOM]))
+ y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);
+ /* Calculating chroma patterns is similar and easier since there is
+ * no motion vector pattern for them.
+ */
+ for(i = 0; i < 2; i++){
+ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];
+ c_v_deblock[i] = c_to_deblock[i]
+ | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)
+ | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);
+ c_h_deblock[i] = c_to_deblock[i]
+ | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)
+ | (uvcbp[POS_CUR][i] << 2);
+ if(!mb_x)
+ c_v_deblock[i] &= ~MASK_C_LEFT_COL;
+ if(!row)
+ c_h_deblock[i] &= ~MASK_C_TOP_ROW;
+ if(row == s->mb_height - 1 || (mb_strong[POS_CUR] | mb_strong[POS_BOTTOM]))
+ c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);
+ }
+
+ for(j = 0; j < 16; j += 4){
+ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;
+ for(i = 0; i < 4; i++, Y += 4){
+ int ij = i + j;
+ int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
+ int dither = j ? ij : i*4;
+
+ // if bottom block is coded then we can filter its top edge
+ // (or bottom edge of this block, which is the same)
+ if(y_h_deblock & (MASK_BOTTOM << ij)){
+ rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,
+ s->linesize, dither,
+ y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,
+ clip_cur, alpha, beta, betaY,
+ 0, 0, 0);
+ }
+ // filter left block edge in ordinary mode (with low filtering strength)
+ if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] | mb_strong[POS_LEFT]))){
+ if(!i)
+ clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
+ else
+ clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
+ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
+ clip_cur,
+ clip_left,
+ alpha, beta, betaY, 0, 0, 1);
+ }
+ // filter top edge of the current macroblock when filtering strength is high
+ if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] | mb_strong[POS_TOP])){
+ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
+ clip_cur,
+ mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,
+ alpha, beta, betaY, 0, 1, 0);
+ }
+ // filter left block edge in edge mode (with high filtering strength)
+ if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] | mb_strong[POS_LEFT])){
+ clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
+ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
+ clip_cur,
+ clip_left,
+ alpha, beta, betaY, 0, 1, 1);
+ }