mindustry logic execution, map- and schematic- parsing and rendering
slightly optimize overlay_*
bendn 2023-08-03
parent bbbf6d4 · commit c2eaf97
-rw-r--r--Cargo.toml2
-rw-r--r--src/utils/image.rs11
2 files changed, 8 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 147734c..8b157e8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mindus"
-version = "1.5.0"
+version = "1.5.1"
edition = "2021"
description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)"
authors = [
diff --git a/src/utils/image.rs b/src/utils/image.rs
index 8291c7d..ccf9632 100644
--- a/src/utils/image.rs
+++ b/src/utils/image.rs
@@ -63,9 +63,10 @@ impl ImageUtils for RgbaImage {
fn overlay_at(&mut self, with: &RgbaImage, x: u32, y: u32) -> &mut Self {
for j in 0..with.height() {
for i in 0..with.width() {
- let get = with.get_pixel(i, j);
+ use image::{GenericImageView, GenericImage};
+ let get = unsafe { with.unsafe_get_pixel(i, j) };
if get[3] > 128 {
- self.put_pixel(i + x, j + y, *get);
+ unsafe { self.unsafe_put_pixel(i + x, j + y, get) };
}
}
}
@@ -78,14 +79,16 @@ impl ImageUtils for RgbaImage {
let local = std::mem::take(self);
let mut own = local.into_raw();
let other = with.as_raw();
- assert!(own.len() % 4 == 0 && other.len() % 4 == 0);
+ if own.len() % 4 != 0 || other.len() % 4 != 0 {
+ unsafe { std::hint::unreachable_unchecked() };
+ }
for (i, other_pixels) in other.array_chunks::<4>().enumerate() {
if other_pixels[3] > 128 {
let own_pixels = unsafe { own.get_unchecked_mut(i * 4..i * 4 + 4) };
own_pixels.copy_from_slice(other_pixels);
}
}
- *self = image::RgbaImage::from_raw(w, h, own).unwrap();
+ *self = unsafe { image::RgbaImage::from_raw(w, h, own).unwrap_unchecked() };
self
}