Index: encoder/macroblock.c =================================================================== --- encoder/macroblock.c (Revision 295) +++ encoder/macroblock.c (Arbeitskopie) @@ -592,8 +592,23 @@ 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]]; + uint32_t bak=0; + uint32_t *p_bak=0; + /* backup the original samples and emulate the not available topright samples*/ + if(!(h->mb.i_neighbour4[i] & 4) && (h->mb.i_neighbour4[i] & 2)){ + p_bak = (uint32_t*) &p_dst[4 - i_dst]; + bak = p_bak[0]; + p_bak[0] = p_dst[3 - i_dst]*0x01010101; + } + 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)){ + p_bak[0] = bak; + } + 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; + uint32_t bak=0; + uint32_t *p_bak=0; i_pred_mode= x264_mb_predict_intra4x4_mode( h, idx ); x = block_idx_x[idx]; @@ -542,6 +548,14 @@ 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)){ + p_bak = (uint32_t*) &p_src_by[4 - i_stride]; + bak = p_bak[0]; + p_bak[0] = p_src_by[3 - i_stride]*0x01010101; + } + for( i = 0; i < i_max; i++ ) { int i_sad; @@ -562,6 +576,11 @@ } a->i_sad_i4x4 += i_best; + /*restore the original samples*/ + if(!(h->mb.i_neighbour4[idx] & 4) && (h->mb.i_neighbour4[idx] & 2)){ + p_bak[0] = bak; + } + /* 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 ); @@ -610,6 +629,7 @@ i_best = COST_MAX; predict_4x4_mode_available( h->mb.i_neighbour8[idx], predict_mode, &i_max ); + for( i = 0; i < i_max; i++ ) { int i_sad;