Skip to content

Commit

Permalink
fn has_grain: Cleanup and refactor (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen authored Nov 7, 2023
2 parents 05f75e2 + 3b275e2 commit bd71bb4
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::include::dav1d::headers::Dav1dFrameHeader;
use crate::include::dav1d::headers::Dav1dITUTT35;
use crate::include::dav1d::headers::Dav1dSequenceHeader;
use crate::include::dav1d::headers::Rav1dContentLightLevel;
use crate::include::dav1d::headers::Rav1dFilmGrainData;
use crate::include::dav1d::headers::Rav1dFrameHeader;
use crate::include::dav1d::headers::Rav1dITUTT35;
use crate::include::dav1d::headers::Rav1dMasteringDisplay;
Expand Down Expand Up @@ -587,13 +588,19 @@ pub unsafe extern "C" fn dav1d_parse_sequence_header(
.into()
}

unsafe fn has_grain(pic: *const Rav1dPicture) -> c_int {
let fgdata = &(*(*pic).frame_hdr).film_grain.data;
return ((*fgdata).num_y_points != 0
|| (*fgdata).num_uv_points[0] != 0
|| (*fgdata).num_uv_points[1] != 0
|| (*fgdata).clip_to_restricted_range && (*fgdata).chroma_scaling_from_luma)
as c_int;
impl Rav1dFilmGrainData {
fn has_grain(&self) -> bool {
self.num_y_points != 0
|| self.num_uv_points[0] != 0
|| self.num_uv_points[1] != 0
|| self.clip_to_restricted_range && self.chroma_scaling_from_luma
}
}

impl Rav1dPicture {
unsafe fn has_grain(&self) -> bool {
(*self.frame_hdr).film_grain.data.has_grain()
}
}

unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dResult {
Expand All @@ -603,7 +610,7 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes
} else {
&mut c.cache
};
if c.apply_grain == 0 || has_grain(&mut (*in_0).p) == 0 {
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);
} else {
Expand Down Expand Up @@ -858,7 +865,7 @@ pub(crate) unsafe fn rav1d_apply_grain(
out: &mut Rav1dPicture,
in_0: &Rav1dPicture,
) -> Rav1dResult {
if has_grain(in_0) == 0 {
if !in_0.has_grain() {
rav1d_picture_ref(out, in_0);
return Ok(());
}
Expand Down

0 comments on commit bd71bb4

Please sign in to comment.