From 322e17a5ab67e677f7fb1270faec15461be30d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Mon, 27 Feb 2023 02:35:55 +0100 Subject: [PATCH] render: Bitmap::bytes_per_pixel() -> Bitmap::length_for_size() --- render/src/bitmap.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/render/src/bitmap.rs b/render/src/bitmap.rs index 2e55e8af1..fa57501f3 100644 --- a/render/src/bitmap.rs +++ b/render/src/bitmap.rs @@ -69,7 +69,7 @@ impl Bitmap { /// Ensures that `data` is the correct size for the given `width` and `height`. pub fn new(width: u32, height: u32, format: BitmapFormat, mut data: Vec) -> Self { // If the size is incorrect, either we screwed up or the decoder screwed up. - let expected_len = width as usize * height as usize * format.bytes_per_pixel(); + let expected_len = format.length_for_size(width as usize, height as usize); if data.len() != expected_len { tracing::warn!( "Incorrect bitmap data size, expected {} bytes, got {}", @@ -152,10 +152,10 @@ pub enum BitmapFormat { impl BitmapFormat { #[inline] - pub fn bytes_per_pixel(self) -> usize { + pub fn length_for_size(self, width: usize, height: usize) -> usize { match self { - BitmapFormat::Rgb => 3, - BitmapFormat::Rgba => 4, + BitmapFormat::Rgb => width * height * 3, + BitmapFormat::Rgba => width * height * 4, } } }