From 5474893376b0c6a5ea27039aebcf6a8e0be889b7 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:24:55 -0700 Subject: [PATCH 1/8] `fn output_image`: Rename `in_0` var to `r#in`. --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 81b8747d5..9ad9418b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -605,20 +605,20 @@ impl Rav1dPicture { unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dResult { let mut res = Ok(()); - let in_0: *mut Rav1dThreadPicture = if c.all_layers != 0 || c.max_spatial_id == 0 { + let r#in: *mut Rav1dThreadPicture = if c.all_layers != 0 || c.max_spatial_id == 0 { &mut c.out } else { &mut c.cache }; - if c.apply_grain == 0 || !(*in_0).p.has_grain() { - rav1d_picture_move_ref(out, &mut (*in_0).p); - rav1d_thread_picture_unref(in_0); + if c.apply_grain == 0 || !(*r#in).p.has_grain() { + rav1d_picture_move_ref(out, &mut (*r#in).p); + rav1d_thread_picture_unref(r#in); } else { - res = rav1d_apply_grain(c, out, &mut (*in_0).p); - rav1d_thread_picture_unref(in_0); + res = rav1d_apply_grain(c, out, &mut (*r#in).p); + rav1d_thread_picture_unref(r#in); } if c.all_layers == 0 && c.max_spatial_id != 0 && !(c.out.p.data[0]).is_null() { - rav1d_thread_picture_move_ref(in_0, &mut c.out); + rav1d_thread_picture_move_ref(r#in, &mut c.out); } return res; } From eebd05063e7f29ff3b316cfdeda52e435eac73ed Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:28:28 -0700 Subject: [PATCH 2/8] `fn output_image`: Remove unused `&mut`. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9ad9418b3..dd4464379 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -614,7 +614,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes rav1d_picture_move_ref(out, &mut (*r#in).p); rav1d_thread_picture_unref(r#in); } else { - res = rav1d_apply_grain(c, out, &mut (*r#in).p); + res = rav1d_apply_grain(c, out, &(*r#in).p); rav1d_thread_picture_unref(r#in); } if c.all_layers == 0 && c.max_spatial_id != 0 && !(c.out.p.data[0]).is_null() { From 45f02a8a8456d4fbe00b4fb55555a2493a53fab8 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:31:25 -0700 Subject: [PATCH 3/8] `struct Rav1dContext::all_layers`: Make a `bool`. --- src/internal.rs | 2 +- src/lib.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/internal.rs b/src/internal.rs index 76bc211c3..6f8ac9b69 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -220,7 +220,7 @@ pub struct Rav1dContext { pub(crate) apply_grain: c_int, pub(crate) operating_point: c_int, pub(crate) operating_point_idc: c_uint, - pub(crate) all_layers: c_int, + pub(crate) all_layers: bool, pub(crate) max_spatial_id: c_int, pub(crate) frame_size_limit: c_uint, pub(crate) strict_std_compliance: c_int, diff --git a/src/lib.rs b/src/lib.rs index dd4464379..a98adda48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -286,7 +286,7 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings (*c).logger = s.logger.clone(); (*c).apply_grain = s.apply_grain; (*c).operating_point = s.operating_point; - (*c).all_layers = s.all_layers; + (*c).all_layers = s.all_layers != 0; (*c).frame_size_limit = s.frame_size_limit; (*c).strict_std_compliance = s.strict_std_compliance; (*c).output_invisible_frames = s.output_invisible_frames; @@ -605,7 +605,7 @@ impl Rav1dPicture { unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dResult { let mut res = Ok(()); - let r#in: *mut Rav1dThreadPicture = if c.all_layers != 0 || c.max_spatial_id == 0 { + let r#in: *mut Rav1dThreadPicture = if c.all_layers || c.max_spatial_id == 0 { &mut c.out } else { &mut c.cache @@ -617,7 +617,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes res = rav1d_apply_grain(c, out, &(*r#in).p); rav1d_thread_picture_unref(r#in); } - if c.all_layers == 0 && c.max_spatial_id != 0 && !(c.out.p.data[0]).is_null() { + if !c.all_layers && c.max_spatial_id != 0 && !(c.out.p.data[0]).is_null() { rav1d_thread_picture_move_ref(r#in, &mut c.out); } return res; @@ -627,7 +627,7 @@ unsafe extern "C" fn output_picture_ready(c: *mut Rav1dContext, drain: c_int) -> if (*c).cached_error.is_err() { return 1 as c_int; } - if (*c).all_layers == 0 && (*c).max_spatial_id != 0 { + if !(*c).all_layers && (*c).max_spatial_id != 0 { if !((*c).out.p.data[0]).is_null() && !((*c).cache.p.data[0]).is_null() { if (*c).max_spatial_id == (*(*c).cache.p.frame_hdr).spatial_id || (*c).out.flags as c_uint & PICTURE_FLAG_NEW_TEMPORAL_UNIT as c_int as c_uint != 0 From e4c980e17de66d72e9a92c45ef56a9cb2872fbe1 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:33:45 -0700 Subject: [PATCH 4/8] `struct Rav1dContext::max_spatial_id`: Make a `bool`. --- src/internal.rs | 2 +- src/lib.rs | 8 ++++---- src/obu.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/internal.rs b/src/internal.rs index 6f8ac9b69..374f0cb0a 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -221,7 +221,7 @@ pub struct Rav1dContext { pub(crate) operating_point: c_int, pub(crate) operating_point_idc: c_uint, pub(crate) all_layers: bool, - pub(crate) max_spatial_id: c_int, + pub(crate) max_spatial_id: bool, pub(crate) frame_size_limit: c_uint, pub(crate) strict_std_compliance: c_int, pub(crate) output_invisible_frames: c_int, diff --git a/src/lib.rs b/src/lib.rs index a98adda48..ed4e18bff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -605,7 +605,7 @@ impl Rav1dPicture { unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dResult { let mut res = Ok(()); - let r#in: *mut Rav1dThreadPicture = if c.all_layers || c.max_spatial_id == 0 { + let r#in: *mut Rav1dThreadPicture = if c.all_layers || !c.max_spatial_id { &mut c.out } else { &mut c.cache @@ -617,7 +617,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes res = rav1d_apply_grain(c, out, &(*r#in).p); rav1d_thread_picture_unref(r#in); } - if !c.all_layers && c.max_spatial_id != 0 && !(c.out.p.data[0]).is_null() { + if !c.all_layers && c.max_spatial_id && !(c.out.p.data[0]).is_null() { rav1d_thread_picture_move_ref(r#in, &mut c.out); } return res; @@ -627,9 +627,9 @@ unsafe extern "C" fn output_picture_ready(c: *mut Rav1dContext, drain: c_int) -> if (*c).cached_error.is_err() { return 1 as c_int; } - if !(*c).all_layers && (*c).max_spatial_id != 0 { + if !(*c).all_layers && (*c).max_spatial_id { if !((*c).out.p.data[0]).is_null() && !((*c).cache.p.data[0]).is_null() { - if (*c).max_spatial_id == (*(*c).cache.p.frame_hdr).spatial_id + if (*c).max_spatial_id == ((*(*c).cache.p.frame_hdr).spatial_id != 0) || (*c).out.flags as c_uint & PICTURE_FLAG_NEW_TEMPORAL_UNIT as c_int as c_uint != 0 { return 1 as c_int; diff --git a/src/obu.rs b/src/obu.rs index b1f8d6854..1669cd2ad 100644 --- a/src/obu.rs +++ b/src/obu.rs @@ -255,9 +255,9 @@ unsafe fn parse_seq_hdr( (*c).operating_point_idc = (*hdr).operating_points[op_idx as usize].idc as c_uint; let spatial_mask = (*c).operating_point_idc >> 8; (*c).max_spatial_id = if spatial_mask != 0 { - ulog2(spatial_mask) + ulog2(spatial_mask) != 0 } else { - 0 as c_int + false }; (*hdr).width_n_bits = (rav1d_get_bits(gb, 4 as c_int)).wrapping_add(1 as c_int as c_uint) as c_int; From e0f9b6d1e070bdf296c11553721b3c01780fefbd Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:34:54 -0700 Subject: [PATCH 5/8] `struct Rav1dContext::apply_grain`: Make a `bool`. --- src/internal.rs | 2 +- src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/internal.rs b/src/internal.rs index 374f0cb0a..263478d3e 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -217,7 +217,7 @@ pub struct Rav1dContext { pub(crate) refmvs_dsp: Rav1dRefmvsDSPContext, pub(crate) intra_edge: Rav1dContext_intra_edge, pub(crate) allocator: Rav1dPicAllocator, - pub(crate) apply_grain: c_int, + pub(crate) apply_grain: bool, pub(crate) operating_point: c_int, pub(crate) operating_point_idc: c_uint, pub(crate) all_layers: bool, diff --git a/src/lib.rs b/src/lib.rs index ed4e18bff..a2af7d7a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -284,7 +284,7 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings ); (*c).allocator = s.allocator.clone(); (*c).logger = s.logger.clone(); - (*c).apply_grain = s.apply_grain; + (*c).apply_grain = s.apply_grain != 0; (*c).operating_point = s.operating_point; (*c).all_layers = s.all_layers != 0; (*c).frame_size_limit = s.frame_size_limit; @@ -610,7 +610,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes } else { &mut c.cache }; - if c.apply_grain == 0 || !(*r#in).p.has_grain() { + if !c.apply_grain || !(*r#in).p.has_grain() { rav1d_picture_move_ref(out, &mut (*r#in).p); rav1d_thread_picture_unref(r#in); } else { From ecb77c5916403dd18f60af5760bf84d80d4759a5 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:43:19 -0700 Subject: [PATCH 6/8] `fn output_image`: Move identical code out of an `if` `else`. --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a2af7d7a6..f01c6ea96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -612,11 +612,10 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes }; if !c.apply_grain || !(*r#in).p.has_grain() { rav1d_picture_move_ref(out, &mut (*r#in).p); - rav1d_thread_picture_unref(r#in); } else { res = rav1d_apply_grain(c, out, &(*r#in).p); - rav1d_thread_picture_unref(r#in); } + rav1d_thread_picture_unref(r#in); if !c.all_layers && c.max_spatial_id && !(c.out.p.data[0]).is_null() { rav1d_thread_picture_move_ref(r#in, &mut c.out); } From 1bb66bdc8f1df35bfb783c35f738704536589683 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:43:55 -0700 Subject: [PATCH 7/8] `fn output_image`: Remove redundant `return`. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f01c6ea96..53ef410bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -619,7 +619,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes if !c.all_layers && c.max_spatial_id && !(c.out.p.data[0]).is_null() { rav1d_thread_picture_move_ref(r#in, &mut c.out); } - return res; + res } unsafe extern "C" fn output_picture_ready(c: *mut Rav1dContext, drain: c_int) -> c_int { From d54b4347eb9c67ceddb442d0d92c14fe3b1d310f Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 18 Oct 2023 23:44:36 -0700 Subject: [PATCH 8/8] `fn output_image`: Add back line breaks from C. --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 53ef410bc..071238c95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -605,6 +605,7 @@ impl Rav1dPicture { unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dResult { let mut res = Ok(()); + let r#in: *mut Rav1dThreadPicture = if c.all_layers || !c.max_spatial_id { &mut c.out } else { @@ -616,6 +617,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes res = rav1d_apply_grain(c, out, &(*r#in).p); } rav1d_thread_picture_unref(r#in); + if !c.all_layers && c.max_spatial_id && !(c.out.p.data[0]).is_null() { rav1d_thread_picture_move_ref(r#in, &mut c.out); }