Index: encoder/macroblock.c =================================================================== --- encoder/macroblock.c (Revision 295) +++ encoder/macroblock.c (Arbeitskopie) @@ -578,8 +578,26 @@ const int i_dst = h->mb.pic.i_stride[0]; uint8_t *p_dst = &h->mb.pic.p_fdec[0][8 * (i&1) + 8 * (i>>1) * i_dst]; int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]]; + int j; + uint8_t i_bak[8]; + /* backup the original samples and emulate the not available topright samples*/ + if(!(h->mb.i_neighbour8[i] & 4)&&(h->mb.i_neighbour8[i] & 2)){ + for(j=0;j<8;j++){ + i_bak[j] = p_dst[j +8 - i_dst]; + p_dst[j + 8 - i_dst] = p_dst[7 - i_dst]; + } + } + h->predict_8x8[i_mode]( p_dst, i_dst, h->mb.i_neighbour8[i] ); + + /*restore the original samples*/ + if(!(h->mb.i_neighbour8[i] & 4)&&(h->mb.i_neighbour8[i] & 2)){ + for(j=0;j<8;j++){ + p_dst[j +8 - i_dst] = i_bak[j]; + } + } + x264_mb_encode_i8x8( h, i, i_qp ); h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]] = x264_mb_pred_mode4x4_fix(i_mode); } @@ -592,8 +610,26 @@ const int i_dst = h->mb.pic.i_stride[0]; uint8_t *p_dst = &h->mb.pic.p_fdec[0][4 * block_idx_x[i] + 4 * block_idx_y[i] * i_dst]; int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]]; + int j; + uint8_t i_bak[4]; + /* backup the original samples and emulate the not available topright samples*/ + if(!(h->mb.i_neighbour4[i] & 4) && (h->mb.i_neighbour4[i] & 2)){ + for(j=0;j<4;j++){ + i_bak[j] = p_dst[j + 4 - i_dst]; + p_dst[j + 4 - i_dst] = p_dst[3 - i_dst]; + } + } + h->predict_4x4[i_mode]( p_dst, i_dst ); + + /*restore the original samples*/ + if(!(h->mb.i_neighbour4[i] & 4) && (h->mb.i_neighbour4[i] & 2)){ + for(j=0;j<4;j++){ + p_dst[j + 4 - i_dst] = i_bak[j]; + } + } + x264_mb_encode_i4x4( h, i, i_qp ); h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] = x264_mb_pred_mode4x4_fix(i_mode); } Index: encoder/analyse.c =================================================================== --- encoder/analyse.c (Revision 295) +++ encoder/analyse.c (Arbeitskopie) @@ -364,9 +364,7 @@ static void predict_4x4_mode_available( unsigned int i_neighbour, int *mode, int *pi_count ) { - /* FIXME even when b_tr == 0 there is some case where missing pixels - * are emulated and thus more mode are available TODO - * analysis and encode should be fixed too */ + int b_l = i_neighbour & MB_LEFT; int b_t = i_neighbour & MB_TOP; int b_tr = i_neighbour & MB_TOPRIGHT; @@ -407,6 +405,12 @@ *mode++ = I_PRED_4x4_VL; (*pi_count) += 2; } + else if( b_t && !b_tr ) + { + *mode++ = I_PRED_4x4_DDL; + *mode++ = I_PRED_4x4_VL; + (*pi_count) += 2; + } } static void x264_mb_analyse_intra_chroma( x264_t *h, x264_mb_analysis_t *a ) @@ -532,6 +536,8 @@ int i_best; int x, y; int i_pred_mode; + int i; + uint8_t i_bak[4]; i_pred_mode= x264_mb_predict_intra4x4_mode( h, idx ); x = block_idx_x[idx]; @@ -542,6 +548,15 @@ i_best = COST_MAX; predict_4x4_mode_available( h->mb.i_neighbour4[idx], predict_mode, &i_max ); + + /* backup the original samples and emulate the not available topright samples*/ + if(!(h->mb.i_neighbour4[idx] & 4) && (h->mb.i_neighbour4[idx] & 2)){ + for(i=0;i<4;i++){ + i_bak[i] = p_src_by[i +4 - i_stride]; + p_src_by[i + 4 - i_stride] = p_src_by[3 - i_stride]; + } + } + for( i = 0; i < i_max; i++ ) { int i_sad; @@ -562,6 +577,13 @@ } a->i_sad_i4x4 += i_best; + /*restore the original samples*/ + if(!(h->mb.i_neighbour4[idx] & 4) && (h->mb.i_neighbour4[idx] & 2)){ + for(i=0;i<4;i++){ + p_src_by[i + 4 - i_stride] = i_bak[i]; + } + } + /* we need to encode this block now (for next ones) */ h->predict_4x4[a->i_predict4x4[x][y]]( p_dst_by, i_stride ); x264_mb_encode_i4x4( h, idx, a->i_qp ); @@ -600,6 +622,8 @@ int i_best; int x, y; int i_pred_mode; + int i; + uint8_t i_bak[8]; i_pred_mode= x264_mb_predict_intra4x4_mode( h, 4*idx ); x = idx&1; @@ -610,6 +634,15 @@ i_best = COST_MAX; predict_4x4_mode_available( h->mb.i_neighbour8[idx], predict_mode, &i_max ); + + /* backup the original samples and emulate the not available topright samples*/ + if(!(h->mb.i_neighbour8[idx] & 4)&&(h->mb.i_neighbour8[idx] & 2)){ + for(i=0;i<8;i++){ + i_bak[i] = p_src_by[i + 8 - i_stride]; + p_src_by[i + 8 - i_stride] = p_src_by[7 - i_stride]; + } + } + for( i = 0; i < i_max; i++ ) { int i_sad; @@ -631,6 +664,13 @@ } a->i_sad_i8x8 += i_best; + /*restore the original samples*/ + if(!(h->mb.i_neighbour8[idx] & 4)&&(h->mb.i_neighbour8[idx] & 2)){ + for(i=0;i<8;i++){ + p_src_by[i + 8 - i_stride] = i_bak[i]; + } + } + /* we need to encode this block now (for next ones) */ h->predict_8x8[a->i_predict8x8[x][y]]( p_dst_by, i_stride, h->mb.i_neighbour ); x264_mb_encode_i8x8( h, idx, a->i_qp );