+
+ /* RD selection for chroma prediction */
+ predict_8x8chroma_mode_available( h->mb.i_neighbour, predict_mode, &i_max );
+ if( i_max > 1 )
+ {
+ i_thresh = a->i_satd_i8x8chroma * 5/4;
+
+ for( i = j = 0; i < i_max; i++ )
+ if( a->i_satd_i8x8chroma_dir[i] < i_thresh &&
+ predict_mode[i] != a->i_predict8x8chroma )
+ {
+ predict_mode[j++] = predict_mode[i];
+ }
+ i_max = j;
+
+ if( i_max > 0 )
+ {
+ int i_chroma_lambda = i_qp0_cost2_table[h->mb.i_chroma_qp];
+ /* the previous thing encoded was x264_intra_rd(), so the pixels and
+ * coefs for the current chroma mode are still around, so we only
+ * have to recount the bits. */
+ i_best = x264_rd_cost_i8x8_chroma( h, i_chroma_lambda, a->i_predict8x8chroma, 0 );
+ for( i = 0; i < i_max; i++ )
+ {
+ i_mode = predict_mode[i];
+ h->predict_8x8c[i_mode]( h->mb.pic.p_fdec[1] );
+ h->predict_8x8c[i_mode]( h->mb.pic.p_fdec[2] );
+ /* if we've already found a mode that needs no residual, then
+ * probably any mode with a residual will be worse.
+ * so avoid dct on the remaining modes to improve speed. */
+ i_satd = x264_rd_cost_i8x8_chroma( h, i_chroma_lambda, i_mode, h->mb.i_cbp_chroma != 0x00 );
+ COPY2_IF_LT( i_best, i_satd, a->i_predict8x8chroma, i_mode );
+ }
+ h->mb.i_chroma_pred_mode = a->i_predict8x8chroma;
+ }
+ }