Skip to content

Commit

Permalink
Use size() method for size calculations (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaind authored Oct 7, 2023
1 parent 38a66af commit 74e111f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,26 +332,28 @@ impl PictureWrapper {
}

if unsafe {
let size = color_mode.size() as i32;

match color_mode {
ColorMode::Rgba => webp::WebPPictureImportRGBA(
&mut self.picture,
data.as_ptr(),
self.picture.width * 4,
self.picture.width * size,
),
ColorMode::Bgra => webp::WebPPictureImportBGRA(
&mut self.picture,
data.as_ptr(),
self.picture.width * 4,
self.picture.width * size,
),
ColorMode::Rgb => webp::WebPPictureImportRGB(
&mut self.picture,
data.as_ptr(),
self.picture.width * 3,
self.picture.width * size,
),
ColorMode::Bgr => webp::WebPPictureImportBGR(
&mut self.picture,
data.as_ptr(),
self.picture.width * 3,
self.picture.width * size,
),
}
} == 0
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ pub enum ColorMode {
}

impl ColorMode {
/// Return the pixel bytesize for the color mode
pub fn size(&self) -> usize {
match self {
Self::Rgb => 3,
Self::Rgba => 4,
Self::Bgra => 4,
Self::Bgr => 3,
Self::Rgb | Self::Bgr => 3,
Self::Rgba | Self::Bgra => 4,
}
}
}
Expand Down

0 comments on commit 74e111f

Please sign in to comment.