Skip to content

Commit e5d512b

Browse files
committed
add a image-crate feature
1 parent fbc3f90 commit e5d512b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ license = "MIT OR Apache-2.0"
1515
audio = ["quad-snd"]
1616
log-rs = ["log"]
1717
glam-serde = ["glam/serde"]
18-
default = []
18+
default = ["image-crate"]
19+
image-crate = ["image"]
1920

2021
[package.metadata.android]
2122
assets = "examples/"
@@ -30,7 +31,7 @@ all-features = true
3031
miniquad = { version = "=0.4.8", features = ["log-impl"] }
3132
quad-rand = "0.2.3"
3233
glam = { version = "0.27", features = ["scalar-math"] }
33-
image = { version = "0.24", default-features = false, features = ["png", "tga"] }
34+
image = { version = "0.24", default-features = false, features = ["png", "tga"], optional = true }
3435
macroquad_macro = { version = "0.1.8", path = "macroquad_macro" }
3536
fontdue = "0.9"
3637
backtrace = { version = "0.3.60", optional = true }

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub enum Error {
66
path: String,
77
},
88
ShaderError(miniquad::ShaderError),
9+
10+
#[cfg(feature = "image-crate")]
911
ImageError(image::ImageError),
1012
UnknownError(&'static str),
1113
}
@@ -22,6 +24,7 @@ impl From<miniquad::ShaderError> for Error {
2224
}
2325
}
2426

27+
#[cfg(feature = "image-crate")]
2528
impl From<image::ImageError> for Error {
2629
fn from(s: image::ImageError) -> Self {
2730
Error::ImageError(s)

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ pub use crate::logging::*;
2626

2727
pub use crate::{color_u8, DroppedFile};
2828

29+
#[cfg(feature = "image-crate")]
2930
pub use image::ImageFormat;

src/texture.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Loading and rendering textures. Also render textures, per-pixel image manipulations.
22
3-
use crate::{
4-
color::Color, file::load_file, get_context, get_quad_context, math::Rect,
5-
text::atlas::SpriteKey, Error,
6-
};
3+
use crate::{color::Color, get_context, get_quad_context, math::Rect, text::atlas::SpriteKey};
4+
5+
#[cfg(feature = "image-crate")]
6+
use crate::{file::load_file, Error};
77

88
pub use crate::quad_gl::FilterMode;
99
use crate::quad_gl::{DrawMode, Vertex};
@@ -94,6 +94,7 @@ impl Image {
9494
}
9595
}
9696

97+
#[cfg(feature = "image-crate")]
9798
/// Creates an Image from a slice of bytes that contains an encoded image.
9899
///
99100
/// If `format` is None, it will make an educated guess on the
@@ -303,6 +304,7 @@ impl Image {
303304
}
304305
}
305306

307+
#[cfg(feature = "image-crate")]
306308
/// Saves this image as a PNG file.
307309
/// This method is not supported on web and will panic.
308310
pub fn export_png(&self, path: &str) {
@@ -327,13 +329,15 @@ impl Image {
327329
}
328330
}
329331

332+
#[cfg(feature = "image-crate")]
330333
/// Loads an [Image] from a file into CPU memory.
331334
pub async fn load_image(path: &str) -> Result<Image, Error> {
332335
let bytes = load_file(path).await?;
333336

334337
Image::from_file_with_format(&bytes, None)
335338
}
336339

340+
#[cfg(feature = "image-crate")]
337341
/// Loads a [Texture2D] from a file into GPU memory.
338342
pub async fn load_texture(path: &str) -> Result<Texture2D, Error> {
339343
let bytes = load_file(path).await?;
@@ -671,6 +675,7 @@ impl Texture2D {
671675
Texture2D::unmanaged(ctx.gl.white_texture)
672676
}
673677

678+
#[cfg(feature = "image-crate")]
674679
/// Creates a Texture2D from a slice of bytes that contains an encoded image.
675680
///
676681
/// If `format` is None, it will make an educated guess on the

0 commit comments

Comments
 (0)