Skip to content

Commit

Permalink
Fix p5 to p81
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Dec 9, 2021
1 parent 81de9d1 commit 57d2cfd
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 118 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dovi_tool"
version = "1.3.1"
version = "1.3.2"
authors = ["quietvoid"]
edition = "2018"
rust-version = "1.51.0"
Expand Down
Binary file added assets/tests/profile5-02.bin
Binary file not shown.
Binary file added assets/tests/profile8_from_profile5-02.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion dolby_vision/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dolby_vision"
version = "1.3.1"
version = "1.3.2"
authors = ["quietvoid"]
edition = "2018"
rust-version = "1.55.0"
Expand Down
13 changes: 4 additions & 9 deletions dolby_vision/src/rpu/dovi_rpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,10 @@ impl DoviRpu {
self.header.bl_video_full_range_flag = false;

self.header.num_pivots_minus_2 = [0, 0, 0];
self.header
.pred_pivot_value
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(2);
v[0] = 0;
v[1] = 1023;
});
self.header.pred_pivot_value.iter_mut().for_each(|v| {
v.clear();
v.extend(&[0, 1023]);
});

if let Some(ref mut rpu_data_mapping) = self.rpu_data_mapping {
rpu_data_mapping.p5_to_p81();
Expand Down
142 changes: 37 additions & 105 deletions dolby_vision/src/rpu/rpu_data_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,133 +319,65 @@ impl RpuDataMapping {
}

pub fn p5_to_p81(&mut self) {
self.mapping_idc
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
self.mapping_idc.iter_mut().for_each(|v| {
v.clear();
v.push(0);
});

self.mapping_param_pred_flag
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = false;
});
self.mapping_param_pred_flag.iter_mut().for_each(|v| {
v.clear();
v.push(false);
});

self.num_mapping_param_predictors
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
self.num_mapping_param_predictors.iter_mut().for_each(|v| {
v.clear();
v.push(0);
});

self.diff_pred_part_idx_mapping_minus1
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
v.clear();
v.push(0);
});

self.poly_order_minus1
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
self.poly_order_minus1.iter_mut().for_each(|v| {
v.clear();
v.push(0);
});

self.linear_interp_flag
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = false;
});
self.linear_interp_flag.iter_mut().for_each(|v| {
v.clear();
v.push(false);
});

self.pred_linear_interp_value_int
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
.for_each(|v| v.clear());

self.pred_linear_interp_value
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
.for_each(|v| v.clear());

self.poly_coef_int
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v.iter_mut().filter(|v| !v.is_empty()).for_each(|v2| {
v2.truncate(2);
v2[0] = 0;
v2[1] = 1;
});
});
self.poly_coef_int.iter_mut().for_each(|v| {
v.clear();
v.push(vec![0, 1]);
});

self.poly_coef
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v.iter_mut().filter(|v| !v.is_empty()).for_each(|v2| {
v2.truncate(2);
v2[0] = 0;
v2[1] = 0;
});
});
self.poly_coef.iter_mut().for_each(|v| {
v.clear();
v.push(vec![0, 0]);
});

self.mmr_order_minus1
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
self.mmr_order_minus1.iter_mut().for_each(|v| v.clear());

self.mmr_constant_int
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
self.mmr_constant_int.iter_mut().for_each(|v| v.clear());

self.mmr_constant
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = 0;
});
self.mmr_constant.iter_mut().for_each(|v| v.clear());

self.mmr_coef_int
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = vec![];
});
self.mmr_coef_int.iter_mut().for_each(|v| v.clear());

self.mmr_coef
.iter_mut()
.filter(|v| !v.is_empty())
.for_each(|v| {
v.truncate(1);
v[0] = vec![];
});
self.mmr_coef.iter_mut().for_each(|v| v.clear());
}

pub fn p8_default() -> RpuDataMapping {
Expand Down
64 changes: 64 additions & 0 deletions src/dovi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ pub fn _parse_file(input: PathBuf) -> Result<(Vec<u8>, DoviRpu)> {
Ok((original_data, dovi_rpu))
}

fn _debug(data: &[u8]) -> Result<()> {
use crate::dovi::OUT_NAL_HEADER;
use std::fs::OpenOptions;
use std::io::Write;

let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open("test.bin")?;

file.write_all(OUT_NAL_HEADER)?;
file.write_all(&data[2..])?;

file.flush()?;

Ok(())
}

#[test]
fn profile4() -> Result<()> {
let (original_data, dovi_rpu) = _parse_file(PathBuf::from("./assets/tests/profile4.bin"))?;
Expand Down Expand Up @@ -329,3 +348,48 @@ fn p8_to_mel() -> Result<()> {

Ok(())
}

#[test]
fn profile5_to_p81() -> Result<()> {
let (original_data, mut dovi_rpu) = _parse_file(PathBuf::from("./assets/tests/profile5.bin"))?;
assert_eq!(dovi_rpu.dovi_profile, 5);
let mut parsed_data = dovi_rpu.write_hevc_unspec62_nalu()?;

assert_eq!(&original_data[4..], &parsed_data[2..]);

// Profile 5 to 8.1
let (p81_data, p81_rpu) = _parse_file(PathBuf::from("./assets/tests/profile8.bin"))?;
assert_eq!(p81_rpu.dovi_profile, 8);

dovi_rpu.convert_with_mode(3)?;
parsed_data = dovi_rpu.write_hevc_unspec62_nalu()?;
assert_eq!(&p81_data[4..], &parsed_data[2..]);

assert_eq!(dovi_rpu.dovi_profile, 8);

Ok(())
}

#[test]
fn profile5_to_p81_2() -> Result<()> {
let (original_data, mut dovi_rpu) =
_parse_file(PathBuf::from("./assets/tests/profile5-02.bin"))?;
assert_eq!(dovi_rpu.dovi_profile, 5);
let mut parsed_data = dovi_rpu.write_hevc_unspec62_nalu()?;

assert_eq!(&original_data[4..], &parsed_data[2..]);

// Profile 5 to 8.1
let (p81_data, p81_rpu) = _parse_file(PathBuf::from(
"./assets/tests/profile8_from_profile5-02.bin",
))?;
assert_eq!(p81_rpu.dovi_profile, 8);

dovi_rpu.convert_with_mode(3)?;
parsed_data = dovi_rpu.write_hevc_unspec62_nalu()?;
assert_eq!(&p81_data[4..], &parsed_data[2..]);

assert_eq!(dovi_rpu.dovi_profile, 8);

Ok(())
}

0 comments on commit 57d2cfd

Please sign in to comment.