Skip to content

Commit

Permalink
fix #544 and update deprecation version numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrgani committed Sep 11, 2024
1 parent d72eda5 commit 3755461
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ impl TexturesContext {
pub struct Image {
// FIXME: remove all the deprecation notes once the `Image` fields are private
#[deprecated(
since = "0.4.12",
since = "0.4.14",
note = "this will be made private, use `Image::bytes`, `Image::bytes_mut` or `Image::bytes_vec_mut` for reading and writing instead"
)]
pub bytes: Vec<u8>,
#[deprecated(
since = "0.4.12",
since = "0.4.14",
note = "this will be made private, use `Image::width` or `Image::width_mut` for reading and writing instead"
)]
pub width: u16,
#[deprecated(
since = "0.4.12",
since = "0.4.14",
note = "this will be made private, use `Image::height` or `Image::height_mut` for reading and writing instead"
)]
pub height: u16,
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Image {
}

/// Creates an Image filled with the provided [Color].
#[deprecated(since = "0.4.12", note = "use `Image::filled_with_color` instead")]
#[deprecated(since = "0.4.14", note = "use `Image::filled_with_color` instead")]
pub fn gen_image_color(width: u16, height: u16, color: Color) -> Image {
Image::filled_with_color(width, height, color)
}
Expand Down Expand Up @@ -264,6 +264,21 @@ impl Image {
}
}

/// Replace the bytes of this image with the bytes from `data`.
///
/// # Panics
/// Panics if `data` has a different length than `self.bytes`.
pub fn set_image_data(&mut self, data: &[[u8; 4]]) {
assert_eq!(self.pixel_amount(), data.len());

for i in 0..data.len() {
self.bytes[i * 4] = data[i][0];
self.bytes[i * 4 + 1] = data[i][1];
self.bytes[i * 4 + 2] = data[i][2];
self.bytes[i * 4 + 3] = data[i][3];
}
}

/// Modifies a pixel [Color] in this image.
///
/// # Panics
Expand Down

0 comments on commit 3755461

Please sign in to comment.