diff options
| author | HampusM <hampus@hampusmat.com> | 2026-03-26 16:42:22 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-03-26 16:43:34 +0100 |
| commit | 9ab41d06b4ff0b52360a8cda756a3b1343a1e2fc (patch) | |
| tree | 5a2be512270ec6a2480b045f218b7a0ba54e00d7 /engine/src/image.rs | |
| parent | 3a92f3c8eacc4b5b51bf31280032113d9840ea03 (diff) | |
Diffstat (limited to 'engine/src/image.rs')
| -rw-r--r-- | engine/src/image.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/engine/src/image.rs b/engine/src/image.rs index cf31a92..ac95f22 100644 --- a/engine/src/image.rs +++ b/engine/src/image.rs @@ -50,6 +50,26 @@ impl Image } } + pub fn from_color_and_alpha( + dimens: impl Into<Dimens<u32>>, + color: impl Into<Color<u8>>, + alpha: u8, + ) -> Self + { + let dimens: Dimens<u32> = dimens.into(); + + let color: Color<u8> = color.into(); + + Self { + inner: image_rs::RgbaImage::from_pixel( + dimens.width, + dimens.height, + image_rs::Rgba([color.red, color.green, color.blue, alpha]), + ) + .into(), + } + } + pub fn dimensions(&self) -> Dimens<u32> { self.inner.dimensions().into() @@ -68,6 +88,11 @@ impl Image } } + pub fn to_rgba8(&self) -> Self + { + Self { inner: self.inner.to_rgba8().into() } + } + pub fn as_bytes(&self) -> &[u8] { self.inner.as_bytes() |
