summaryrefslogtreecommitdiff
path: root/engine/src/image.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/image.rs')
-rw-r--r--engine/src/image.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/engine/src/image.rs b/engine/src/image.rs
index b01ea53..fd6629e 100644
--- a/engine/src/image.rs
+++ b/engine/src/image.rs
@@ -70,22 +70,25 @@ impl Image
Self::from((color, size))
}
+ #[must_use]
pub fn dimensions(&self) -> Dimens<u32>
{
self.inner.dimensions().into()
}
+ #[must_use]
pub fn color_type(&self) -> ColorType
{
self.inner.color().into()
}
+ #[must_use]
pub fn color_space_is_srgb(&self) -> bool
{
- match self.inner.color_space().primaries {
- image_rs::metadata::CicpColorPrimaries::SRgb => true,
- _ => false,
- }
+ matches!(
+ self.inner.color_space().primaries,
+ image_rs::metadata::CicpColorPrimaries::SRgb
+ )
}
/// Returns a immutable view of a subsection of this image.
@@ -93,14 +96,16 @@ impl Image
///
/// # Panics
/// Panics if the view would be out of bounds
+ #[must_use]
pub fn sub_view(&self, offset: Vec2<u32>, size: Dimens<u32>) -> SubView<'_>
{
assert!(offset.x + size.width <= self.dimensions().width);
assert!(offset.y + size.height <= self.dimensions().height);
- SubView { image: &self, offset, size }
+ SubView { image: self, offset, size }
}
+ #[must_use]
pub fn to_rgba8(&self) -> Self
{
Self { inner: self.inner.to_rgba8().into() }
@@ -108,6 +113,7 @@ impl Image
/// Consumes the image and returns a RGBA8 image. If it already is RGBA8, the image is
/// returned as is. If not, the image is converted to RGBA8.
+ #[must_use]
pub fn into_rgba8(self) -> Self
{
Self {
@@ -115,11 +121,13 @@ impl Image
}
}
+ #[must_use]
pub fn as_bytes(&self) -> &[u8]
{
self.inner.as_bytes()
}
+ #[must_use]
pub fn into_bytes(self) -> Vec<u8>
{
self.inner.into_bytes()
@@ -303,6 +311,7 @@ pub struct SubView<'image>
impl SubView<'_>
{
+ #[must_use]
pub fn to_image(&self) -> Image
{
fn create_sub_image<Image>(