Skip to content

Commit

Permalink
Update dependency on image
Browse files Browse the repository at this point in the history
This causes a minor break in backwards compatibility, due to images
own break, involving the Format enum.

Also, only require features necessary to support standard-required
formats (jpg+png, see specification/2.0/schema/image.schema.json).
A convenience feature to enable parallel JPEG decoding is also added.
  • Loading branch information
nuew committed Apr 1, 2019
1 parent e8a2c4c commit 5e6d62f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ base64 = { optional = true, version = "0.6" }
byteorder = "1.1"
cgmath = "0.15"
gltf-json = { path = "gltf-json", version = "0.11.3" }
image = { optional = true, version = "0.19" }
lazy_static = "0.2"

[dependencies.image]
default-features = false
features = ["jpeg", "png_codec"]
optional = true
version = "0.21"

[features]
default = ["import", "utils", "names"]
extras = ["gltf-json/extras"]
names = ["gltf-json/names"]
utils = []
import = ["base64", "image"]
KHR_materials_pbrSpecularGlossiness = ["gltf-json/KHR_materials_pbrSpecularGlossiness"]
image_jpeg_rayon = ["image/jpeg_rayon"]

[[example]]
name = "gltf-display"
Expand Down
10 changes: 9 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub enum Format {

/// Red, green, blue, alpha.
R8G8B8A8,

/// Blue, green, red.
B8G8R8,

/// Blue, green, red, alpha.
B8G8R8A8,
}

/// Describes an image data source.
Expand Down Expand Up @@ -127,12 +133,14 @@ impl Data {
/// Note: We don't implement `From<DynamicImage>` since we don't want
/// to expose such functionality to the user.
pub(crate) fn new(image: DynamicImage) -> Self {
use image_crate::GenericImage;
use image_crate::GenericImageView;
let format = match image {
DynamicImage::ImageLuma8(_) => Format::R8,
DynamicImage::ImageLumaA8(_) => Format::R8G8,
DynamicImage::ImageRgb8(_) => Format::R8G8B8,
DynamicImage::ImageRgba8(_) => Format::R8G8B8A8,
DynamicImage::ImageBgr8(_) => Format::B8G8R8,
DynamicImage::ImageBgra8(_) => Format::B8G8R8A8,
};
let (width, height) = image.dimensions();
let pixels = image.raw_pixels();
Expand Down

0 comments on commit 5e6d62f

Please sign in to comment.