Skip to content

Commit af0eaaf

Browse files
committed
format code and get rid of unused variables
1 parent 75ef372 commit af0eaaf

File tree

4 files changed

+32
-40
lines changed

4 files changed

+32
-40
lines changed

src/h264/decoder.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ impl Decoder {
226226
}
227227

228228
for plane_name in [ColorPlane::Cb, ColorPlane::Cr] {
229-
let chroma_qp = get_chroma_qp(qp as i32, slice.pps.chroma_qp_index_offset, 0).try_into().unwrap();
229+
let chroma_qp =
230+
get_chroma_qp(qp as i32, slice.pps.chroma_qp_index_offset, 0)
231+
.try_into()
232+
.unwrap();
230233
info!("QP: {qp} chroma qp: {chroma_qp}");
231234
let chroma_plane = &mut frame.planes[plane_name as usize];
232235
let residuals = if let Some(residual) = imb.residual.as_ref() {
@@ -348,7 +351,6 @@ pub fn get_chroma_qp(luma_qp: i32, chroma_qp_offset: i32, qp_bd_offset_c: i32) -
348351
qp_c + qp_bd_offset_c
349352
}
350353

351-
352354
// Section 8.3.1.1 Derivation process for Intra4x4PredMode
353355
pub fn render_luma_4x4_intra_prediction(
354356
slice: &Slice,
@@ -657,6 +659,7 @@ pub fn render_chroma_intra_prediction(
657659
let loc = Point { x: loc.x >> chroma_shift.width, y: loc.y >> chroma_shift.width };
658660
let mb_width = MB_WIDTH >> chroma_shift.width;
659661
let mb_height = MB_HEIGHT >> chroma_shift.height;
662+
let offset = point_to_plain_offset(loc);
660663

661664
#[inline]
662665
fn sum(slice: &[u8]) -> u32 {
@@ -670,14 +673,13 @@ pub fn render_chroma_intra_prediction(
670673
let y = loc.y as usize;
671674
let mut src_row = [0; 16];
672675
src_row[0..mb_width].copy_from_slice(&target.row(y as isize - 1)[x..(x + mb_width)]);
673-
let mut target_slice = target.mut_slice(point_to_plain_offset(loc));
676+
let mut target_slice = target.mut_slice(offset);
674677
for row in target_slice.rows_iter_mut().take(mb_height) {
675678
row[0..mb_width].copy_from_slice(&src_row[0..mb_width]);
676679
}
677680
}
678681
Intra_Chroma_Pred_Mode::Horizontal => {
679682
// Section 8.3.4.2 Specification of Intra_Chroma_Horizontal prediction mode
680-
let offset = point_to_plain_offset(loc);
681683
let mut target_slice = target.mut_slice(PlaneOffset { x: offset.x - 1, ..offset });
682684
for row in target_slice.rows_iter_mut().take(mb_height) {
683685
let src = row[0];
@@ -686,7 +688,6 @@ pub fn render_chroma_intra_prediction(
686688
}
687689
Intra_Chroma_Pred_Mode::DC => {
688690
// Section 8.3.4.1 Specification of Intra_Chroma_DC prediction mode
689-
let offset = point_to_plain_offset(loc);
690691

691692
// Calculate the sum of all the values at the top of the current block
692693
let mut top_left = None;
@@ -711,9 +712,10 @@ pub fn render_chroma_intra_prediction(
711712
}
712713

713714
for blk_idx in 0..4 {
714-
const DEFAULT_VALUE : u32 = 1 << 7; // = 1 << ( BitDepthC − 1 )
715+
const DEFAULT_VALUE: u32 = 1 << 7; // = 1 << ( BitDepthC − 1 )
715716
let result = match blk_idx {
716-
0 => { // If ( xO, yO ) is equal to ( 0, 0 ) or xO and yO are greater than 0
717+
0 => {
718+
// If ( xO, yO ) is equal to ( 0, 0 ) or xO and yO are greater than 0
717719
if let (Some(left), Some(top)) = (left_top, top_left) {
718720
(left + top + 4) >> 3
719721
} else if let Some(s) = top_left {
@@ -724,7 +726,8 @@ pub fn render_chroma_intra_prediction(
724726
DEFAULT_VALUE
725727
}
726728
}
727-
1 => { // If xO is greater than 0 and yO is equal to 0
729+
1 => {
730+
// If xO is greater than 0 and yO is equal to 0
728731
if let Some(s) = top_right {
729732
(s + 2) >> 2
730733
} else if let Some(s) = left_top {
@@ -733,7 +736,8 @@ pub fn render_chroma_intra_prediction(
733736
DEFAULT_VALUE
734737
}
735738
}
736-
2 => { // If xO is equal to 0 and yO is greater than 0
739+
2 => {
740+
// If xO is equal to 0 and yO is greater than 0
737741
if let Some(s) = left_bottom {
738742
(s + 2) >> 2
739743
} else if let Some(s) = top_left {
@@ -742,8 +746,8 @@ pub fn render_chroma_intra_prediction(
742746
DEFAULT_VALUE
743747
}
744748
}
745-
3 => { // If xO is equal to 0 and yO is greater than 0
746-
if let (Some(left), Some(top)) = (left_bottom, top_right) {
749+
3 => {
750+
if let (Some(left), Some(top)) = (left_bottom, top_right) {
747751
(left + top + 4) >> 3
748752
} else if let Some(s) = top_right {
749753
(s + 2) >> 2
@@ -753,7 +757,7 @@ pub fn render_chroma_intra_prediction(
753757
DEFAULT_VALUE
754758
}
755759
}
756-
_ => unreachable!()
760+
_ => unreachable!(),
757761
};
758762

759763
let mut blk_loc = get_4x4chroma_block_location(blk_idx);
@@ -768,10 +772,7 @@ pub fn render_chroma_intra_prediction(
768772
Intra_Chroma_Pred_Mode::Plane => {
769773
// Section 8.3.4.4 Specification of Intra_Chroma_Plane prediction mode
770774
// yCF = 0 and xCF = 0
771-
let mut offset = point_to_plain_offset(loc);
772-
offset.x -= 1;
773-
offset.y -= 1;
774-
let target_slice = target.slice(offset);
775+
let target_slice = target.slice(PlaneOffset { x: offset.x - 1, y: offset.y - 1 });
775776
let mut h = 0;
776777
let mut top_row = [0u8; 9];
777778
top_row.copy_from_slice(&target_slice[0][0..9]);
@@ -793,7 +794,6 @@ pub fn render_chroma_intra_prediction(
793794
let b = (34 * h + 32) >> 6;
794795
let c = (34 * v + 32) >> 6;
795796

796-
let offset = point_to_plain_offset(loc);
797797
let mut target_slice = target.mut_slice(offset);
798798
for (y, row) in target_slice.rows_iter_mut().take(mb_height).enumerate() {
799799
for (x, pixel) in row.iter_mut().take(mb_width).enumerate() {

src/h264/macroblock.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ pub const fn get_4x4luma_block_location(idx: u8) -> Point {
102102

103103
// Section 6.4.7 Inverse 4x4 chroma block scanning process
104104
pub fn get_4x4chroma_block_location(idx: u8) -> Point {
105-
let idx = idx as u32;
106-
let x = inverse_raster_scan(idx, 4, 4, 8, false);
107-
let y = inverse_raster_scan(idx, 4, 4, 8, true);
108-
Point { x, y }
105+
match idx {
106+
0 => Point { x: 0, y: 0 },
107+
1 => Point { x: 4, y: 0 },
108+
2 => Point { x: 0, y: 4 },
109+
3 => Point { x: 4, y: 4 },
110+
_ => unreachable!(),
111+
}
109112
}
110113

111114
// Section 6.4.13.1 Derivation process for 4x4 luma block indices

src/h264/residual.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,7 @@ impl Residual {
152152
ColorPlane::Cr => &self.chroma_cr_dc_level,
153153
_ => unreachable!(),
154154
};
155-
let mut dcs_block = Block2x2 {
156-
samples: [
157-
[dcs[0], dcs[1]],
158-
[dcs[2], dcs[3]],
159-
]
160-
};
155+
let mut dcs_block = Block2x2 { samples: [[dcs[0], dcs[1]], [dcs[2], dcs[3]]] };
161156
dcs_block = transform_chroma_dc(&dcs_block);
162157
dc_scale_2x2_block(&mut dcs_block, qp);
163158

@@ -324,15 +319,15 @@ pub fn dc_scale_2x2_block(block: &mut Block2x2, qp: u8) {
324319
let is_inter = false;
325320
for row in block.samples.iter_mut() {
326321
for c in row.iter_mut() {
327-
let d = (*c * level_scale_4x4(is_inter, m, 0) << (qp / 6)) >> 5;
322+
let d = (*c * level_scale_4x4(is_inter, m, 0) << (qp / 6)) >> 5;
328323
*c = d;
329324
}
330325
}
331326
}
332327

333328
// Section 8.5.10 Scaling and transformation process for DC transform coefficients for Intra_16x16
334329
pub fn transform_dc(block: &Block4x4) -> Block4x4 {
335-
let b = &block.samples;
330+
let b = &block.samples;
336331
let mut result = Block4x4::default();
337332
let r = &mut result.samples;
338333

@@ -388,12 +383,7 @@ pub fn transform_chroma_dc(block: &Block2x2) -> Block2x2 {
388383
let hc10 = c[0][0] - c[1][0];
389384
let hc11 = c[0][1] - c[1][1];
390385

391-
Block2x2 {
392-
samples: [
393-
[hc00 + hc01, hc00 - hc01],
394-
[hc10 + hc11, hc10 - hc11],
395-
],
396-
}
386+
Block2x2 { samples: [[hc00 + hc01, hc00 - hc01], [hc10 + hc11, hc10 - hc11]] }
397387
}
398388

399389
pub fn unzip_block_4x4(block: &[i32]) -> Block4x4 {
@@ -527,14 +517,11 @@ mod tests {
527517
pub fn test_transform_4x4_zeros() {
528518
test_transform_4x4(
529519
Block4x4 { samples: [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] },
530-
Block4x4 {
531-
samples: [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
532-
},
520+
Block4x4 { samples: [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] },
533521
28,
534522
);
535523
}
536524

537-
538525
#[test]
539526
pub fn test_transform_4x4_ex1() {
540527
test_transform_4x4(

src/y4m_cmp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pub fn compare_frames(
4747
if let Some((x, y, a, e)) = compare_plane(width / 2, height / 2, actual_v, expected_v) {
4848
let width_in_mb = width / 2 / chroma_mb_width;
4949
let mb_idx = x / chroma_mb_width + (y / chroma_mb_width) * width_in_mb;
50-
result.push_str(&format!("V-plane mismatch at {x},{y} (MB:{mb_idx}) width_in_mb:{width_in_mb} : {a} != {e}\n"));
50+
result.push_str(&format!(
51+
"V-plane mismatch at {x},{y} (MB:{mb_idx}) width_in_mb:{width_in_mb} : {a} != {e}\n"
52+
));
5153
}
5254

5355
result

0 commit comments

Comments
 (0)