Skip to content

Commit

Permalink
Feature-gate all image formats (#15586)
Browse files Browse the repository at this point in the history
# Objective

Bevy supports feature gates for each format it supports, but several
formats that it loads via the `image` crate do not have feature gates.
Additionally, the QOI format is supported by the `image` crate and
wasn't available at all. This fixes that.

## Solution

The following feature gates are added:

* `avif`
* `ff` (Farbfeld)
* `gif`
* `ico`
* `qoi`
* `tiff`

None of these formats are enabled by default, despite the fact that all
these formats appeared to be enabled by default before. Since
`default-features` was disabled for the `image` crate, it's likely that
using any of these formats would have errored by default before this
change, although this probably needs additional testing.

## Testing

The changes seemed minimal enough that a compile test would be
sufficient.

## Migration guide

Image formats that previously weren't feature-gated are now
feature-gated, meaning they will have to be enabled if you use them:

* `avif`
* `ff` (Farbfeld)
* `gif`
* `ico`
* `tiff`

Additionally, the `qoi` feature has been added to support loading QOI
format images.

Previously, these formats appeared in the enum by default, but weren't
actually enabled via the `image` crate, potentially resulting in weird
bugs. Now, you should be able to add these features to your projects to
support them properly.
  • Loading branch information
clarfonthey authored Oct 7, 2024
1 parent 0a1d60f commit 8adc9e9
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 144 deletions.
87 changes: 53 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,40 @@ unused_qualifications = "warn"

[features]
default = [
"android-game-activity",
"android-game-activity",
"android_shared_stdcxx",
"animation",
"bevy_asset",
"bevy_state",
"bevy_audio",
"bevy_color",
"bevy_gilrs",
"bevy_scene",
"bevy_winit",
"bevy_core_pipeline",
"bevy_gilrs",
"bevy_gizmos",
"bevy_gltf",
"bevy_pbr",
"bevy_picking",
"bevy_sprite_picking_backend",
"bevy_ui_picking_backend",
"bevy_gltf",
"bevy_remote",
"bevy_render",
"bevy_scene",
"bevy_sprite",
"bevy_sprite_picking_backend",
"bevy_state",
"bevy_text",
"bevy_ui",
"bevy_remote",
"bevy_ui_picking_backend",
"bevy_winit",
"custom_cursor",
"default_font",
"hdr",
"multi_threaded",
"png",
"hdr",
"vorbis",
"x11",
"bevy_gizmos",
"android_shared_stdcxx",
"tonemapping_luts",
"smaa_luts",
"default_font",
"webgl2",
"sysinfo_plugin",
"android-game-activity",
"custom_cursor",
"tonemapping_luts",
"vorbis",
"webgl2",
"x11",
]

# Provides an implementation for picking sprites
Expand Down Expand Up @@ -242,38 +243,56 @@ trace_tracy_memory = [
# Tracing support
trace = ["bevy_internal/trace"]

# AVIF image format support
avif = ["bevy_internal/avif"]

# Basis Universal compressed texture support
basis-universal = ["bevy_internal/basis-universal"]

# BMP image format support
bmp = ["bevy_internal/bmp"]

# DDS compressed texture support
dds = ["bevy_internal/dds"]

# EXR image format support
exr = ["bevy_internal/exr"]

# Farbfeld image format support
ff = ["bevy_internal/ff"]

# GIF image format support
gif = ["bevy_internal/gif"]

# HDR image format support
hdr = ["bevy_internal/hdr"]

# PNG image format support
png = ["bevy_internal/png"]
# KTX2 compressed texture support
ktx2 = ["bevy_internal/ktx2"]

# TGA image format support
tga = ["bevy_internal/tga"]
# ICO image format support
ico = ["bevy_internal/ico"]

# JPEG image format support
jpeg = ["bevy_internal/jpeg"]

# BMP image format support
bmp = ["bevy_internal/bmp"]
# PNG image format support
png = ["bevy_internal/png"]

# WebP image format support
webp = ["bevy_internal/webp"]
# PNM image format support, includes pam, pbm, pgm and ppm
pnm = ["bevy_internal/pnm"]

# Basis Universal compressed texture support
basis-universal = ["bevy_internal/basis-universal"]
# QOI image format support
qoi = ["bevy_internal/qoi"]

# DDS compressed texture support
dds = ["bevy_internal/dds"]
# TGA image format support
tga = ["bevy_internal/tga"]

# KTX2 compressed texture support
ktx2 = ["bevy_internal/ktx2"]
# TIFF image format support
tiff = ["bevy_internal/tiff"]

# PNM image format support, includes pam, pbm, pgm and ppm
pnm = ["bevy_internal/pnm"]
# WebP image format support
webp = ["bevy_internal/webp"]

# For KTX2 supercompression
zlib = ["bevy_internal/zlib"]
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_core_pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
dds = ["bevy_render/dds"]
dds = ["bevy_render/dds", "bevy_image/dds"]
trace = []
webgl = []
webgpu = []
tonemapping_luts = ["bevy_render/ktx2", "bevy_render/zstd"]
smaa_luts = ["bevy_render/ktx2", "bevy_render/zstd"]
tonemapping_luts = ["bevy_render/ktx2", "bevy_image/ktx2", "bevy_image/zstd"]
smaa_luts = ["bevy_render/ktx2", "bevy_image/ktx2", "bevy_image/zstd"]

[dependencies]
# bevy
Expand All @@ -28,6 +28,7 @@ bevy_core = { path = "../bevy_core", version = "0.15.0-dev" }
bevy_color = { path = "../bevy_color", version = "0.15.0-dev" }
bevy_derive = { path = "../bevy_derive", version = "0.15.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.15.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.15.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.15.0-dev" }
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
dds = ["bevy_render/dds", "bevy_core_pipeline/dds"]
dds = ["bevy_render/dds", "bevy_image/dds", "bevy_core_pipeline/dds"]
pbr_transmission_textures = ["bevy_pbr/pbr_transmission_textures"]
pbr_multi_layer_material_textures = [
"bevy_pbr/pbr_multi_layer_material_textures",
Expand All @@ -26,6 +26,7 @@ bevy_core = { path = "../bevy_core", version = "0.15.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.15.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev" }
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.15.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.15.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.15.0-dev" }
bevy_pbr = { path = "../bevy_pbr", version = "0.15.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
Expand Down
19 changes: 14 additions & 5 deletions crates/bevy_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
png = ["image/png"]
# Image formats
avif = ["image/avif"]
basis-universal = ["dep:basis-universal"]
bmp = ["image/bmp"]
dds = ["ddsfile"]
exr = ["image/exr"]
ff = ["image/ff"]
gif = ["image/gif"]
hdr = ["image/hdr"]
tga = ["image/tga"]
ktx2 = ["dep:ktx2"]
ico = ["image/ico"]
jpeg = ["image/jpeg"]
bmp = ["image/bmp"]
webp = ["image/webp"]
dds = ["ddsfile"]
png = ["image/png"]
pnm = ["image/pnm"]
qoi = ["image/qoi"]
tga = ["image/tga"]
tiff = ["image/tiff"]
webp = ["image/webp"]

# For ktx2 supercompression
zlib = ["flate2"]
Expand Down
Loading

0 comments on commit 8adc9e9

Please sign in to comment.