]> git.sesse.net Git - x264/blobdiff - common/deblock.c
Use a 16-bit buffer in hpel_filter regardless of bit depth
[x264] / common / deblock.c
index f550d2d1ac84be981a58ab44fd31971b193f495d..97311176ab19130e345fbe1bfc104394728f7611 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * deblock.c: h264 encoder library
+ * deblock.c: deblocking
  *****************************************************************************
- * Copyright (C) 2003-2008 x264 project
+ * Copyright (C) 2003-2010 x264 project
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Loren Merritt <lorenm@u.washington.edu>
@@ -20,6 +20,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@x264.com.
  *****************************************************************************/
 
 #include "common.h"
@@ -316,7 +319,7 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
         int mb_xy = h->mb.i_mb_xy;
         int transform_8x8 = h->mb.mb_transform_size[h->mb.i_mb_xy];
         int intra_cur = IS_INTRA( h->mb.type[mb_xy] );
-        uint8_t (*bs)[4][4] = h->deblock_strength[mb_y&b_interlaced][mb_x];
+        uint8_t (*bs)[4][4] = h->deblock_strength[mb_y&1][mb_x];
 
         pixel *pixy = h->fdec->plane[0] + 16*mb_y*stridey  + 16*mb_x;
         pixel *pixuv = h->fdec->plane[1] + 8*mb_y*strideuv + 16*mb_x;
@@ -383,9 +386,55 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
                                  FILTER( , 1, 2, qp, qpc );
             if( !transform_8x8 ) FILTER( , 1, 3, qp, qpc );
         }
+
+        #undef FILTER
     }
 }
 
+/* For deblock-aware RD.
+ * TODO:
+ *  deblock macroblock edges
+ *  support analysis partitions smaller than 16x16
+ *  deblock chroma
+ *  handle duplicate refs correctly
+ *  handle cavlc+8x8dct correctly
+ */
+void x264_macroblock_deblock( x264_t *h )
+{
+    int qp_thresh = 15 - X264_MIN( h->sh.i_alpha_c0_offset, h->sh.i_beta_offset ) - X264_MAX( 0, h->param.analyse.i_chroma_qp_offset );
+    int qp = h->mb.i_qp;
+    if( qp <= qp_thresh || h->mb.i_type == P_SKIP )
+        return;
+
+    uint8_t (*bs)[4][4] = h->deblock_strength[h->mb.i_mb_y&1][h->mb.i_mb_x];
+    if( IS_INTRA( h->mb.i_type ) )
+        memset( bs, 3, 2*4*4*sizeof(uint8_t) );
+    else
+        h->loopf.deblock_strength( h->mb.cache.non_zero_count, h->mb.cache.ref, h->mb.cache.mv,
+                                   bs, 4 >> h->sh.b_mbaff, h->sh.i_type == SLICE_TYPE_B );
+
+    int transform_8x8 = h->mb.b_transform_8x8;
+    pixel *fdec = h->mb.pic.p_fdec[0];
+
+    #define FILTER( dir, edge )\
+    do\
+    {\
+        deblock_edge( h, fdec + 4*edge*(dir?FDEC_STRIDE:1),\
+                      FDEC_STRIDE, bs[dir][edge], qp, 0,\
+                      h->loopf.deblock_luma[dir] );\
+    } while(0)
+
+    if( !transform_8x8 ) FILTER( 0, 1 );
+                         FILTER( 0, 2 );
+    if( !transform_8x8 ) FILTER( 0, 3 );
+
+    if( !transform_8x8 ) FILTER( 1, 1 );
+                         FILTER( 1, 2 );
+    if( !transform_8x8 ) FILTER( 1, 3 );
+
+    #undef FILTER
+}
+
 #if HAVE_MMX
 void x264_deblock_v_luma_sse2( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 );
 void x264_deblock_h_luma_sse2( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 );