Skip to content

Commit

Permalink
Change bytes_per_pixel to usize.
Browse files Browse the repository at this point in the history
  • Loading branch information
lte678 committed Oct 12, 2024
1 parent da3c4c8 commit a8231d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Canvas {
pub fn new(size: Vector2I, format: Format) -> Canvas {
Canvas::with_stride(
size,
size.x() as usize * format.bytes_per_pixel() as usize,
size.x() as usize * format.bytes_per_pixel(),
format,
)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Canvas {

let size = dst_rect.size();

let dest_bytes_per_pixel = self.format.bytes_per_pixel() as usize;
let dest_bytes_per_pixel = self.format.bytes_per_pixel();
let dest_row_stride = size.x() as usize * dest_bytes_per_pixel;
let src_row_stride = utils::div_round_up(size.x() as usize, 8);

Expand Down Expand Up @@ -173,8 +173,8 @@ impl Canvas {
src_stride: usize,
src_format: Format,
) {
let src_bytes_per_pixel = src_format.bytes_per_pixel() as usize;
let dest_bytes_per_pixel = self.format.bytes_per_pixel() as usize;
let src_bytes_per_pixel = src_format.bytes_per_pixel();
let dest_bytes_per_pixel = self.format.bytes_per_pixel();

for y in 0..rect.height() {
let (dest_row_start, src_row_start) = (
Expand Down Expand Up @@ -216,7 +216,7 @@ pub enum Format {
impl Format {
/// Returns the number of bits per pixel that this image format corresponds to.
#[inline]
pub fn bits_per_pixel(self) -> u8 {
pub fn bits_per_pixel(self) -> usize {
match self {
Format::Rgba32 => 32,
Format::Rgb24 => 24,
Expand All @@ -226,7 +226,7 @@ impl Format {

/// Returns the number of color channels per pixel that this image format corresponds to.
#[inline]
pub fn components_per_pixel(self) -> u8 {
pub fn components_per_pixel(self) -> usize{
match self {
Format::Rgba32 => 4,
Format::Rgb24 => 3,
Expand All @@ -236,13 +236,13 @@ impl Format {

/// Returns the number of bits per color channel that this image format contains.
#[inline]
pub fn bits_per_component(self) -> u8 {
pub fn bits_per_component(self) -> usize {
self.bits_per_pixel() / self.components_per_pixel()
}

/// Returns the number of bytes per pixel that this image format corresponds to.
#[inline]
pub fn bytes_per_pixel(self) -> u8 {
pub fn bytes_per_pixel(self) -> usize {
self.bits_per_pixel() / 8
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/core_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl Font {
Some(canvas.pixels.as_mut_ptr() as *mut _),
canvas.size.x() as usize,
canvas.size.y() as usize,
canvas.format.bits_per_component() as usize,
canvas.format.bits_per_component(),
canvas.stride,
&cg_color_space,
cg_image_format,
Expand Down
3 changes: 1 addition & 2 deletions src/loaders/directwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ impl Font {
} else {
Format::Rgb24
};
let texture_bits_per_pixel = texture_format.bits_per_pixel();
let texture_bytes_per_pixel = texture_bits_per_pixel as usize / 8;
let texture_bytes_per_pixel = texture_format.bytes_per_pixel();
let texture_size = Vector2I::new(texture_width, texture_height);
let texture_stride = texture_width as usize * texture_bytes_per_pixel;

Expand Down

0 comments on commit a8231d7

Please sign in to comment.