+fn do_b_mc_4x4bi(frm: &mut NASimpleVideoFrame<u8>, xpos: usize, ypos: usize, mv: &[MV; 2], ref_pic0: Option<&SimpleFrame>, weight0: &WeightInfo, ref_pic1: Option<&SimpleFrame>, weight1: &WeightInfo, mc_dsp: &mut H264MC) {
+ if !weight0.is_weighted() || !weight1.is_weighted() {
+ match (ref_pic0, ref_pic1) {
+ (Some(buf0), Some(buf1)) => {
+ mc_dsp.do_mc(frm, buf0, xpos, ypos, 4, 4, mv[0]);
+ mc_dsp.do_mc_avg(frm, buf1, xpos, ypos, 4, 4, mv[1]);
+ },
+ (Some(buf0), None) => {
+ mc_dsp.do_mc(frm, buf0, xpos, ypos, 4, 4, mv[0]);
+ },
+ (None, Some(buf1)) => {
+ mc_dsp.do_mc(frm, buf1, xpos, ypos, 4, 4, mv[1]);
+ },
+ (None, None) => {
+ mc_dsp.gray_block(frm, xpos, ypos, 4, 4);
+ },
+ };
+ } else {
+ let mut tmp0 = McBlock::new();
+ let mut tmp1 = McBlock::new();
+ match (ref_pic0, ref_pic1) {
+ (Some(buf0), Some(buf1)) => { // do both and avg
+ mc_dsp.mc_blocks(&mut tmp0, buf0, xpos, ypos, 4, 4, mv[0]);
+ mc_dsp.mc_blocks(&mut tmp1, buf1, xpos, ypos, 4, 4, mv[1]);
+
+ let yoff = frm.offset[0] + xpos + ypos * frm.stride[0];
+ let yw = match (weight0.luma_weighted, weight1.luma_weighted) {
+ (true, true) => [weight0.luma_weight, weight0.luma_offset, weight1.luma_weight, weight1.luma_offset, weight0.luma_shift as i8],
+ (true, false) => [weight0.luma_weight, weight0.luma_offset, 1 << weight0.luma_shift, 0, weight0.luma_shift as i8],
+ (false, true) => [1 << weight1.luma_shift, 0, weight1.luma_weight, weight1.luma_offset, weight1.luma_shift as i8],
+ (false, false) => [1, 0, 1, 0, 0],
+ };
+ (mc_dsp.put_block_weighted2[1])(&mut frm.data[yoff..], frm.stride[0], &tmp0.y, &tmp1.y, 4, yw);
+
+ for chroma in 0..2 {
+ let cstride = frm.stride[chroma + 1];
+ let coff = frm.offset[chroma + 1] + xpos / 2 + ypos / 2 * cstride;
+ let cw0 = weight0.chroma_weight[chroma];
+ let co0 = weight0.chroma_offset[chroma];
+ let cw1 = weight1.chroma_weight[chroma];
+ let co1 = weight1.chroma_offset[chroma];
+ let cw = match (weight0.chroma_weighted, weight1.chroma_weighted) {
+ (true, true) => [cw0, co0, cw1, co1, weight0.luma_shift as i8],
+ (true, false) => [cw0, co0, 1 << weight0.luma_shift, 0, weight0.luma_shift as i8],
+ (false, true) => [1 << weight1.luma_shift, 0, cw1, co1, weight1.luma_shift as i8],
+ (false, false) => [1, 0, 1, 0, 0],
+ };
+ let csrc0 = if chroma == 0 { &tmp0.u } else { &tmp0.v };
+ let csrc1 = if chroma == 0 { &tmp1.u } else { &tmp1.v };
+ (mc_dsp.put_block_weighted2[0])(&mut frm.data[coff..], cstride, csrc0, csrc1, 2, cw);
+ }
+ },
+ _ => {
+ mc_dsp.gray_block(frm, xpos, ypos, 4, 4);
+ },
+ };
+ }
+}
+
+fn get_weights(slice_hdr: &SliceHeader, frame_refs: &SimplifiedSliceRefs, mode: BMode, weight_mode: u8, ref_l0: PicRef, ref_l1: PicRef) -> (WeightInfo, WeightInfo) {