diff --git a/Cargo.lock b/Cargo.lock index 376f7727..82395802 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -832,7 +832,7 @@ dependencies = [ [[package]] name = "craft-atomic" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "rustix 1.1.6", ] @@ -840,12 +840,20 @@ dependencies = [ [[package]] name = "craft-codepage" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" + +[[package]] +name = "craft-dds" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" +dependencies = [ + "rayon", +] [[package]] name = "craft-dialogs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "block2 0.6.2", "objc2 0.6.5", @@ -858,12 +866,12 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "fixed_decimal", "icu_decimal", @@ -886,8 +894,9 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ + "craft-dds", "craft-jpeg", "craft-metadata", "craft-tiff", @@ -912,7 +921,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "thiserror 2.0.21", ] @@ -920,7 +929,7 @@ dependencies = [ [[package]] name = "craft-keymap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "egui", "serde", @@ -930,7 +939,7 @@ dependencies = [ [[package]] name = "craft-mcmat" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "craft-zip", "serde", @@ -941,7 +950,7 @@ dependencies = [ [[package]] name = "craft-menu" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "craft-keymap", "craft-quit", @@ -954,7 +963,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "serde_json", ] @@ -962,7 +971,7 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "brotli-decompressor", "chrono", @@ -974,7 +983,7 @@ dependencies = [ [[package]] name = "craft-mime" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "chrono", "craft-codepage", @@ -984,7 +993,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "dispatch2", "egui", @@ -995,10 +1004,10 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "craft-image-codecs", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", + "craft-xml", "data-url", "flate2", "kurbo", @@ -1014,18 +1023,10 @@ dependencies = [ [[package]] name = "craft-texture" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=726ad0f8290bedb6ced60fa06200a6b574f9990d#726ad0f8290bedb6ced60fa06200a6b574f9990d" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "bytemuck", "dds", - "thiserror 2.0.21", -] - -[[package]] -name = "craft-texture" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" -dependencies = [ "rayon", "thiserror 2.0.21", ] @@ -1033,7 +1034,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "serde", "thiserror 2.0.21", @@ -1042,7 +1043,7 @@ dependencies = [ [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1063,7 +1064,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "chrono", "dunce", @@ -1090,7 +1091,7 @@ dependencies = [ [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "egui", "objc2 0.6.5", @@ -1101,17 +1102,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" -dependencies = [ - "quick-xml 0.41.0", - "serde", - "thiserror 2.0.21", -] - -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b6d9feed23ceae249b40593ed84a668343091627#b6d9feed23ceae249b40593ed84a668343091627" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "quick-xml 0.41.0", "serde", @@ -1121,7 +1112,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf#a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" +source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc" dependencies = [ "flate2", "thiserror 2.0.21", @@ -2860,7 +2851,7 @@ dependencies = [ name = "materialcraft-engine" version = "0.4.1" dependencies = [ - "craft-texture 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf)", + "craft-texture", "image", "materialcraft-core", "materialcraft-eval", @@ -2877,7 +2868,7 @@ dependencies = [ name = "materialcraft-eval" version = "0.4.1" dependencies = [ - "craft-texture 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf)", + "craft-texture", "half", "materialcraft-core", "materialcraft-nodes", @@ -2895,9 +2886,8 @@ dependencies = [ "craft-mesh", "craft-mime", "craft-svg", - "craft-texture 0.1.0 (git+https://github.com/storytold/craft-libs?rev=726ad0f8290bedb6ced60fa06200a6b574f9990d)", - "craft-texture 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b6d9feed23ceae249b40593ed84a668343091627)", + "craft-texture", + "craft-xml", "dds", "flate2", "image", @@ -2928,7 +2918,7 @@ dependencies = [ name = "materialcraft-nodes" version = "0.4.1" dependencies = [ - "craft-texture 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf)", + "craft-texture", "materialcraft-core", "rayon", ] @@ -2937,7 +2927,7 @@ dependencies = [ name = "materialcraft-render" version = "0.4.1" dependencies = [ - "craft-texture 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf)", + "craft-texture", "materialcraft-core", "materialcraft-geom", "rayon", diff --git a/Cargo.toml b/Cargo.toml index 4500533c..e971cddc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,14 +39,13 @@ license = "MIT OR Apache-2.0" [workspace.dependencies] # Standard Base64 output; strict SBS decoding remains app-local -craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" } -craft-texture-dds = { package = "craft-texture", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "726ad0f8290bedb6ced60fa06200a6b574f9990d", features = ["dds"] } +craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", version = "0.1.0" } # Read 3D meshes through craft-mesh; keep mesh processing app-local -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "57288edafdc45552e30481cc649021de446abfa0", default-features = false, features = ["obj", "gltf"] } -# Shared XML escaping; SBS model and serialization policy stay app-local. -craft-xml = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b6d9feed23ceae249b40593ed84a668343091627" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", default-features = false, features = ["obj", "gltf"] } +# Shared XML escaping; SBS model and serialization policy stay app-local +craft-xml = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" } # Bound SVG parsing and drawing through craft-svg -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "57288edafdc45552e30481cc649021de446abfa0", features = ["tree-render"] } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["tree-render"] } # internal materialcraft-core = { path = "crates/core" } materialcraft-geom = { path = "crates/geom" } @@ -83,28 +82,28 @@ roxmltree = "0.20" flate2 = { version = "1", default-features = false, features = ["rust_backend"] } cap-std = "4" getrandom = "0.3" -# Shared Craft egui components (widget palette, icon buttons, panel docking): storytold/craft-libs, -# MIT OR Apache-2.0, with each dependency pinned to its reviewed revision +# Shared Craft egui components from storytold/craft-libs +# MIT OR Apache-2.0; all shared dependencies use one reviewed revision egui_kittest = "0.37" -craft-mcmat = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" } -craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf", features = ["serde"] } -# Keyboard bindings (chords, dispatch and display text): storytold/craft-libs, MIT OR Apache-2.0. -craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf", features = ["egui"] } -# Native dialogs that do not block the event loop: storytold/craft-libs, MIT OR Apache-2.0. -craft-dialogs = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" } -# The platform quit and the macOS Quit menu item: storytold/craft-libs, MIT OR Apache-2.0. -craft-quit = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf", features = ["egui"] } -craft-menu = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" } -# Who draws the window frame, and an app-drawn strip as the title bar: storytold/craft-libs, MIT OR Apache-2.0. -craft-window = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf", features = ["egui"] } -# Release checks and self-updates for the desktop app: storytold/craft-libs, MIT OR Apache-2.0. -craft-update = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf", features = ["egui"] } -# Atomic persistence, at the suite's current revision. -craft-atomic = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" } -# Parse the optional shared font catalog at build time; the font repository is not a dependency. -craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf" } -# Float image planes and texture sampling for node cooking: storytold/craft-libs, MIT OR Apache-2.0. -craft-texture = { git = "https://github.com/storytold/craft-libs", rev = "a341e86b6d0b31ec5113a4b3e4f07f717a6cf5bf", features = ["parallel"] } +craft-mcmat = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" } +craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["serde"] } +# Keyboard bindings (chords, dispatch and display text): storytold/craft-libs, MIT OR Apache-2.0 +craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["egui"] } +# Native dialogs that do not block the event loop: storytold/craft-libs, MIT OR Apache-2.0 +craft-dialogs = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" } +# The platform quit and the macOS Quit menu item: storytold/craft-libs, MIT OR Apache-2.0 +craft-quit = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["egui"] } +craft-menu = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" } +# Who draws the window frame, and an app-drawn strip as the title bar: storytold/craft-libs, MIT OR Apache-2.0 +craft-window = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["egui"] } +# Release checks and self-updates for the desktop app: storytold/craft-libs, MIT OR Apache-2.0 +craft-update = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["egui"] } +# Atomic persistence, at the suite's current revision +craft-atomic = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" } +# Parse the optional shared font catalog at build time; the font repository is not a dependency +craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" } +# Float image planes and texture sampling for node cooking: storytold/craft-libs, MIT OR Apache-2.0 +craft-texture = { git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["parallel"] } # egui 0.37 and winit: the suite's forks (storytold/egui, storytold/winit), as craft-libs pins them. [patch.crates-io] diff --git a/crates/formats/Cargo.toml b/crates/formats/Cargo.toml index f11dc149..31e468ba 100644 --- a/crates/formats/Cargo.toml +++ b/crates/formats/Cargo.toml @@ -13,12 +13,11 @@ craft-mime = { workspace = true } craft-xml = { workspace = true } craft-mcmat = { workspace = true } materialcraft-core = { workspace = true } -craft-texture = { workspace = true } +craft-texture = { workspace = true, features = ["dds"] } materialcraft-geom = { workspace = true } materialcraft-nodes = { workspace = true } craft-mesh = { workspace = true } image = { workspace = true } -craft-texture-dds = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } diff --git a/crates/formats/src/dds_image.rs b/crates/formats/src/dds_image.rs index 84248a6f..0b0b4d59 100644 --- a/crates/formats/src/dds_image.rs +++ b/crates/formats/src/dds_image.rs @@ -1,14 +1,16 @@ use crate::{FormatError, Result}; -use craft_texture::{Image, Kind, Limits, MAX_SIDE, srgb_to_linear}; +use craft_texture::{Image, ImageError, Kind, Limits, MAX_SIDE, dds, srgb_to_linear}; pub(crate) fn decode(bytes: &[u8], linear: bool) -> Result { - let error = |message: String| FormatError::Image(message); - let mut limits = craft_texture_dds::Limits::default(); + let format_error = |message: String| FormatError::Image(message); + let mut limits = Limits::default(); limits.max_side = MAX_SIDE; - let decoded = craft_texture_dds::dds::decode_first(bytes, &limits).map_err(|e| match e { - craft_texture_dds::dds::DecodeError::Image(craft_texture_dds::ImageError::BadSize(_, _)) => error(format!("DDS dimensions must be 1..={MAX_SIDE}")), - e => error(e.to_string()), + + let decoded = dds::decode_first(bytes, &limits).map_err(|error| match error { + dds::DecodeError::Image(ImageError::BadSize(_, _)) => format_error(format!("DDS dimensions must be 1..={MAX_SIDE}")), + error => format_error(error.to_string()), })?; + let mut data = decoded.rgba; if !linear && !decoded.source_precision_is_f32 { for pixel in data.as_chunks_mut::<4>().0 { @@ -18,5 +20,5 @@ pub(crate) fn decode(bytes: &[u8], linear: bool) -> Result { } } - Image::from_data(decoded.width, decoded.height, Kind::Color, data, &Limits::default()).map_err(|e| error(e.to_string())) + Image::from_data(decoded.width, decoded.height, Kind::Color, data, &Limits::default()).map_err(|error| format_error(error.to_string())) } diff --git a/crates/formats/src/svg.rs b/crates/formats/src/svg.rs index 4ab862fc..20e8f300 100644 --- a/crates/formats/src/svg.rs +++ b/crates/formats/src/svg.rs @@ -30,6 +30,7 @@ fn limits() -> Limits { fn image_resolver() -> ImageResolver { let resolver = ImageResolver::new(Limits { tree_depth: MAX_TOTAL_DEPTH, depth: MAX_TOTAL_DEPTH, ..limits() }); resolver.set_document_depth(MAX_TREE_DEPTH); + resolver } @@ -37,11 +38,12 @@ pub(crate) fn decode(bytes: &[u8]) -> Result { let limits = limits(); let resolver = image_resolver(); let options = usvg::Options { image_href_resolver: resolver.resolver(), ..usvg::Options::default() }; - let svg = tree::text(bytes, &limits).map_err(svg_error)?; - resolver.check_document(&svg).map_err(svg_error)?; - let tree = tree::parse_text(&svg, &limits, &options).map_err(svg_error)?; + + // Bitmap imports do not use the resolver's optional omission counts + let tree = tree::parse(bytes, &limits, &options).map_err(svg_error)?; let size = tree.size().to_int_size(); let (width, height) = (size.width(), size.height()); + if width > MAX_SIDE || height > MAX_SIDE { return Err(FormatError::Image(format!("SVG exceeds {MAX_SIDE} pixels"))); } @@ -49,15 +51,18 @@ pub(crate) fn decode(bytes: &[u8]) -> Result { let pixels = draw::render(&tree, usvg::Transform::identity(), width, height, 0, DRAW_BUDGET) .map_err(|refusal| FormatError::Image(format!("SVG not drawn: {}", refusal.message)))?; + // Release geometry before allocating the float pixel plane + drop(tree); + + // Reuse the transfer curve for every possible 8-bit channel value + const CHANNEL_VALUE_COUNT: usize = u8::MAX as usize + 1; + let linear_channels: [f32; CHANNEL_VALUE_COUNT] = std::array::from_fn(|value| srgb_to_linear(value as f32 / 255.0)); + let linear_channel = |value: u8| linear_channels.get(usize::from(value)).copied().unwrap_or_default(); + Ok(Image::generate(width, height, Kind::Color, |x, y| { let pixel = pixels.pixel(x, y).map(|pixel| pixel.demultiply()); pixel.map_or([0.0; 4], |pixel| { - [ - srgb_to_linear(f32::from(pixel.red()) / 255.0), - srgb_to_linear(f32::from(pixel.green()) / 255.0), - srgb_to_linear(f32::from(pixel.blue()) / 255.0), - f32::from(pixel.alpha()) / 255.0, - ] + [linear_channel(pixel.red()), linear_channel(pixel.green()), linear_channel(pixel.blue()), f32::from(pixel.alpha()) / 255.0] }) })) } @@ -71,6 +76,7 @@ mod tests { #![allow(clippy::unwrap_used)] use super::decode; + use crate::FormatError; fn svg(body: &str) -> Vec { format!(r#"{body}"#).into_bytes() @@ -112,14 +118,32 @@ mod tests { assert!(decode(b"]>"# + ); + + let result = crate::decode(document.as_bytes(), false); + + assert!(matches!(result, Err(FormatError::Image(ref message)) if message.contains("entities expand to too much text")), "{result:?}"); + } + fn nested_groups(levels: usize, inner: &str) -> String { format!("{}{inner}{}", "".repeat(levels), "".repeat(levels)) } fn embedded(levels: usize) -> Vec { use base64::Engine as _; + let inner = svg(&nested_groups(levels, r##""##)); let data = base64::engine::general_purpose::STANDARD.encode(inner); + svg(&nested_groups(30, &format!(r#""#))) } @@ -142,6 +166,7 @@ mod tests { #[test] fn linked_files_are_not_read() { let linked = svg(r#""#); + let image = decode(&linked).unwrap(); assert_eq!(image.get(0, 0, false)[3], 0.0); @@ -150,8 +175,10 @@ mod tests { #[test] fn svgz_is_unpacked() { use std::io::Write; + let mut gz = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::default()); gz.write_all(&svg(r#""#)).unwrap(); + let image = decode(&gz.finish().unwrap()).unwrap(); assert!(image.get(1, 1, false)[2] > 0.9); diff --git a/crates/ui-egui/src/updates_ui.test.rs b/crates/ui-egui/src/updates_ui.test.rs index ab8902fb..36442b40 100644 --- a/crates/ui-egui/src/updates_ui.test.rs +++ b/crates/ui-egui/src/updates_ui.test.rs @@ -19,6 +19,7 @@ fn no_pins() -> std::path::PathBuf { fn app() -> MaterialCraftApp { let mut app = MaterialCraftApp::headless(sample_session(), UiState::default()); app.updates_rt.updater = Updater::new(&crate::UPDATE_APP, "0.1.0").with_pins_path(no_pins()); + app } @@ -48,9 +49,26 @@ fn release() -> craft_update::Release { } } +/// Offers `release()` and ticks until the prompt is open. +/// A fresh updater declines an offer only when the pins file holds a launcher choice, which sets +/// `managed()`. A tick asks for another frame while the offer waits for its thread, so the wait +/// fails when a tick leaves the prompt closed and asks for no frame, instead of ticking forever. +fn offer(updater: &mut Updater) { + updater.offer(release()); + let ctx = egui::Context::default(); + + while !updater.prompt_open() { + assert!(updater.managed().is_none(), "the offer was declined: {} holds a launcher choice", no_pins().display()); + let _ = ctx.run_logic(&egui::RawInput::default(), |ctx| updater.tick(ctx)); + assert!(updater.prompt_open() || updater.managed().is_some() || ctx.has_requested_repaint(), "the offer ended without opening the prompt"); + std::thread::yield_now(); + } +} + pub(super) fn open_prompt(app: &mut MaterialCraftApp) { app.updates_rt.updater = Updater::new(&crate::UPDATE_APP, "0.1.0").with_pins_path(no_pins()); - app.updates_rt.updater.offer(release()); + + offer(&mut app.updates_rt.updater); } #[test] @@ -144,11 +162,15 @@ fn result_window_shows_every_status_but_idle() { #[test] fn an_offered_release_opens_the_prompt_over_the_window() { let mut app = app(); - app.updates_rt.updater.offer(release()); + + offer(&mut app.updates_rt.updater); + assert!(blocks_input(&app)); let mut harness = egui_kittest::Harness::builder().build_ui_state(|ui, app: &mut MaterialCraftApp| crate::windows::show(app, ui.ctx()), app); + harness.run_steps(3); + let _ = harness.get_by_label("LATER"); assert!(harness.state().updates_rt.updater.prompt_open()); } @@ -183,6 +205,7 @@ fn press_export(app: &mut MaterialCraftApp) { events: vec![egui::Event::Key { key: egui::Key::E, physical_key: None, pressed: true, repeat: false, modifiers }], ..Default::default() }; + let mut output = ctx.run_ui(input, |ui| menus::shortcuts(app, ui.ctx())); output.textures_delta.clear(); } @@ -200,11 +223,15 @@ fn the_prompt_and_the_modal_results_hold_the_keyboard() { #[test] fn shortcuts_wait_while_the_prompt_is_open() { let mut idle = app(); + press_export(&mut idle); + assert!(idle.ui.windows.export, "the shortcut works without the prompt"); let mut prompted = app(); - prompted.updates_rt.updater.offer(release()); + offer(&mut prompted.updates_rt.updater); + press_export(&mut prompted); + assert!(!prompted.ui.windows.export); }