forge
Explore
Log in

Don't you dare go Hollow

U6: ec-h264 mb.rs: unwrap the leftover bare block around the sub-sample refinement (a block with no scope of its own); conformance.rs rustfmt

Browse files at this commit

73ce7236613534124ff0a7d07e4a136235e6f5a2Ahmet Kaan GümüşParent: 63ba9a7
crates/ec-h264/src/enc/mb.rsmodified+62 -64
@@ -1124,75 +1124,73 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Vec<I
11241124 // capture. The whole-sample winner is re-costed in the same domain
11251125 // first so the two halves of the search compare.
11261126 let sub_satd = !fast || e.fast.me_satd;
1127- {
1128- best.1 = cost_of(best.0, sub_satd);
1129- // Balanced iterates both sub-sample steps to convergence. Fast
1130- // looks at each ring of eight once.
1131- let rings: &[i16] = if !fast {
1132- &[2, 1]
1133- } else {
1134- match e.fast.me_sub {
1135- 0 => &[],
1136- 1 => &[2],
1137- _ => &[2, 1],
1138- }
1139- };
1140- if fast && e.fast.me_sub == 1 {
1141- // The four half-sample neighbours on the axes, then only the
1142- // diagonal the two winning axes point at.
1143- let base = best;
1144- let mut axis = [(base.0, base.1); 2];
1145- for (k, dirs) in [[(2i16, 0i16), (-2, 0)], [(0, 2), (0, -2)]]
1146- .into_iter()
1147- .enumerate()
1148- {
1149- for (dx, dy) in dirs {
1150- let cand = [base.0[0] + dx, base.0[1] + dy];
1151- let c = cost_of(cand, sub_satd);
1152- if c < axis[k].1 {
1153- axis[k] = (cand, c);
1154- }
1155- }
1156- }
1157- let both = axis[0].1 < base.1 && axis[1].1 < base.1;
1158- if both {
1159- let cand = [axis[0].0[0], axis[1].0[1]];
1127+ best.1 = cost_of(best.0, sub_satd);
1128+ // Balanced iterates both sub-sample steps to convergence. Fast
1129+ // looks at each ring of eight once.
1130+ let rings: &[i16] = if !fast {
1131+ &[2, 1]
1132+ } else {
1133+ match e.fast.me_sub {
1134+ 0 => &[],
1135+ 1 => &[2],
1136+ _ => &[2, 1],
1137+ }
1138+ };
1139+ if fast && e.fast.me_sub == 1 {
1140+ // The four half-sample neighbours on the axes, then only the
1141+ // diagonal the two winning axes point at.
1142+ let base = best;
1143+ let mut axis = [(base.0, base.1); 2];
1144+ for (k, dirs) in [[(2i16, 0i16), (-2, 0)], [(0, 2), (0, -2)]]
1145+ .into_iter()
1146+ .enumerate()
1147+ {
1148+ for (dx, dy) in dirs {
1149+ let cand = [base.0[0] + dx, base.0[1] + dy];
11601150 let c = cost_of(cand, sub_satd);
1161- if c < best.1 {
1162- best = (cand, c);
1151+ if c < axis[k].1 {
1152+ axis[k] = (cand, c);
11631153 }
11641154 }
1165- for a in axis {
1166- if a.1 < best.1 {
1167- best = a;
1168- }
1155+ }
1156+ let both = axis[0].1 < base.1 && axis[1].1 < base.1;
1157+ if both {
1158+ let cand = [axis[0].0[0], axis[1].0[1]];
1159+ let c = cost_of(cand, sub_satd);
1160+ if c < best.1 {
1161+ best = (cand, c);
11691162 }
11701163 }
1171- let rings: &[i16] = if fast && e.fast.me_sub == 1 {
1172- &[]
1173- } else {
1174- rings
1175- };
1176- for &step in rings {
1177- let mut improved = true;
1178- while improved {
1179- improved = false;
1180- for (dx, dy) in [
1181- (step, 0),
1182- (-step, 0),
1183- (0, step),
1184- (0, -step),
1185- (step, step),
1186- (-step, -step),
1187- (step, -step),
1188- (-step, step),
1189- ] {
1190- let cand = [best.0[0] + dx, best.0[1] + dy];
1191- let c = cost_of(cand, sub_satd);
1192- if c < best.1 {
1193- best = (cand, c);
1194- improved = !fast;
1195- }
1164+ for a in axis {
1165+ if a.1 < best.1 {
1166+ best = a;
1167+ }
1168+ }
1169+ }
1170+ let rings: &[i16] = if fast && e.fast.me_sub == 1 {
1171+ &[]
1172+ } else {
1173+ rings
1174+ };
1175+ for &step in rings {
1176+ let mut improved = true;
1177+ while improved {
1178+ improved = false;
1179+ for (dx, dy) in [
1180+ (step, 0),
1181+ (-step, 0),
1182+ (0, step),
1183+ (0, -step),
1184+ (step, step),
1185+ (-step, -step),
1186+ (step, -step),
1187+ (-step, step),
1188+ ] {
1189+ let cand = [best.0[0] + dx, best.0[1] + dy];
1190+ let c = cost_of(cand, sub_satd);
1191+ if c < best.1 {
1192+ best = (cand, c);
1193+ improved = !fast;
11961194 }
11971195 }
11981196 }
crates/ec-h264/tests/conformance.rsmodified+18 -21
@@ -1120,29 +1120,26 @@ fn switching_slices_are_refused_by_name() {
11201120 }
11211121 }
11221122
1123-
11241123 /// Extract the video elementary stream of a real file as Annex B.
11251124 fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
1126- run(
1127- &[
1128- "-v",
1129- "error",
1130- "-y",
1131- "-i",
1132- &src.to_string_lossy(),
1133- "-map",
1134- "0:v:0",
1135- "-c",
1136- "copy",
1137- "-bsf:v",
1138- "h264_mp4toannexb",
1139- "-frames:v",
1140- &frames.to_string(),
1141- "-f",
1142- "h264",
1143- &dst.to_string_lossy(),
1144- ],
1145- )
1125+ run(&[
1126+ "-v",
1127+ "error",
1128+ "-y",
1129+ "-i",
1130+ &src.to_string_lossy(),
1131+ "-map",
1132+ "0:v:0",
1133+ "-c",
1134+ "copy",
1135+ "-bsf:v",
1136+ "h264_mp4toannexb",
1137+ "-frames:v",
1138+ &frames.to_string(),
1139+ "-f",
1140+ "h264",
1141+ &dst.to_string_lossy(),
1142+ ])
11461143 }
11471144
11481145 #[test]