{
weightluma = 1;
h->sh.weight[0][0].i_denom = denom = h->sh.weight[j][0].i_denom;
+ assert( x264_clip3( denom, 0, 7 ) == denom );
}
assert( h->sh.weight[j][0].i_denom == denom );
+ assert( x264_clip3( h->sh.weight[j][0].i_scale, 0, 127 ) == h->sh.weight[j][0].i_scale );
+ assert( x264_clip3( h->sh.weight[j][0].i_offset, -128, 127 ) == h->sh.weight[j][0].i_offset );
h->fenc->weighted[j] = h->mb.p_weight_buf[buffer_next++] +
h->fenc->i_stride[0] * i_padv + PADH;
}
SET_WEIGHT( h->fenc->weight[0][0], 1, 1, 0, h->fenc->weight[0][0].i_offset );
}
x264_weighted_reference_duplicate( h, 0, weight_none );
- w[0] = h->fenc->weight[0][0];
- w[0].i_offset--;
- h->mc.weight_cache( h, &w[0] );
- x264_weighted_reference_duplicate( h, 0, w );
+ if( h->fenc->weight[0][0].i_offset > -128 )
+ {
+ w[0] = h->fenc->weight[0][0];
+ w[0].i_offset--;
+ h->mc.weight_cache( h, &w[0] );
+ x264_weighted_reference_duplicate( h, 0, w );
+ }
}
}
else if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_BLIND )
ref_mean = (float)ref_sum / (fenc->i_lines[0] * fenc->i_width[0]);
//early termination
-
if( fabs( ref_mean - fenc_mean ) < 0.5 && fabsf( 1 - (float)fenc_var / ref_var ) < epsilon )
return;
x264_emms();
/* FIXME: More analysis can be done here on SAD vs. SATD termination. */
- if( !found || (minscale == 1<<mindenom && minoff == 0) || minscore >= fenc->i_width[0] * fenc->i_lines[0] * 2 )
+ /* 0.2% termination derived experimentally to avoid weird weights in frames that are mostly intra. */
+ if( !found || (minscale == 1<<mindenom && minoff == 0) || (float)minscore / origscore > 0.998 )
{
SET_WEIGHT( weights[0], 0, 1, 0, 0 );
return;