Skip to content

Commit

Permalink
fn BitDepth::pxstride: Implement generically over BitDepths.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Feb 28, 2024
1 parent 82062a9 commit 8105376
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions include/common/bitdepth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ pub trait BitDepth: Clone + Copy {
clip(pixel, 0.into(), self.bitdepth_max())
}

fn pxstride(n: usize) -> usize;
fn pxstride(n: usize) -> usize {
let scale = mem::size_of::<Self::Pixel>();
debug_assert!(n % scale == 0);
n / scale
}

fn bitdepth(&self) -> u8;

Expand Down Expand Up @@ -238,10 +242,6 @@ impl BitDepth for BitDepth8 {
DisplayPixel8(pixel)
}

fn pxstride(n: usize) -> usize {
n
}

fn bitdepth(&self) -> u8 {
Self::BITDEPTH
}
Expand Down Expand Up @@ -319,11 +319,6 @@ impl BitDepth for BitDepth16 {
DisplayPixel16(pixel)
}

fn pxstride(n: usize) -> usize {
debug_assert!(n & 1 == 0);
n >> 1
}

fn bitdepth(&self) -> u8 {
(Self::Pixel::BITS - self.bitdepth_max.leading_zeros()) as u8
}
Expand Down

0 comments on commit 8105376

Please sign in to comment.