Skip to content

Commit

Permalink
fn Rav1dPictureDataComponent::with_offset: Replace manual, separate…
Browse files Browse the repository at this point in the history
… `Rav1dPictureDataComponent`, `usize` offset pairs with `Rav1dPictureDataComponentOffset` (#1205)
  • Loading branch information
kkysen authored Jun 18, 2024
2 parents d0a3332 + 0e8fd48 commit 7dd59cf
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 529 deletions.
12 changes: 8 additions & 4 deletions include/dav1d/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ impl Rav1dPictureDataComponent {
BD::pxstride(self.len() - (-stride) as usize)
}

pub fn with_offset<BD: BitDepth>(&self) -> Rav1dPictureDataComponentOffset {
Rav1dPictureDataComponentOffset {
data: self,
offset: self.pixel_offset::<BD>(),
}
}

/// Strided ptr to [`u8`] bytes.
fn as_strided_byte_mut_ptr(&self) -> *mut u8 {
let ptr = self.0.as_mut_ptr();
Expand Down Expand Up @@ -636,10 +643,7 @@ impl Rav1dPicture {
array::from_fn(|i| {
let data = &data[has_chroma as usize * i];
let ss_ver = layout == Rav1dPixelLayout::I420 && i != 0;
let offset = data
.pixel_offset::<BD>()
.wrapping_add_signed(y as isize * data.pixel_stride::<BD>() >> ss_ver as u8);
Rav1dPictureDataComponentOffset { data, offset }
data.with_offset::<BD>() + (y as isize * data.pixel_stride::<BD>() >> ss_ver as u8)
})
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/fg_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ pub(crate) fn rav1d_apply_grain_row<BD: BitDepth>(

// extend padding pixels
if out.p.w as usize & ss_x != 0 {
let luma = &in_data[0];
let mut offset = luma
.pixel_offset::<BD>()
.wrapping_add_signed((row * BLOCK_SIZE) as isize * luma.pixel_stride::<BD>());
for _ in 0..bh {
let padding = &mut *luma.slice_mut::<BD, _>((offset + out.p.w as usize - 1.., ..2));
let luma = in_data[0].with_offset::<BD>();
let luma = luma + (row * BLOCK_SIZE) as isize * luma.pixel_stride::<BD>();
for y in 0..bh {
let luma = luma + (y as isize * (luma.pixel_stride::<BD>() << ss_y));
let padding = &mut *(luma + (out.p.w as usize - 1)).slice_mut::<BD>(2);
padding[1] = padding[0];
offset = offset.wrapping_add_signed(luma.pixel_stride::<BD>() << ss_y);
}
}

Expand Down
Loading

0 comments on commit 7dd59cf

Please sign in to comment.