Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ci): repair preview tests and reduce WebAssembly size

Gustavo Zigerad72d1d1fd0c
diff --git a/Cargo.toml b/Cargo.toml
index 663d268c3..98218d37f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -127,6 +127,14 @@ opt-level = "z"
[profile.wasm-release.package.naga]
opt-level = "z"
+# The browser UI toolkit favors size to stay within the WebAssembly upload budget.
+[profile.wasm-release.package.egui]
+opt-level = "z"
+[profile.wasm-release.package.epaint]
+opt-level = "z"
+[profile.wasm-release.package.eframe]
+opt-level = "z"
+
# Pixel processing keeps its speed-oriented optimization level.
[profile.wasm-release.package.photocraft-raster]
opt-level = 3
diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs
index 3da073520..eea7ba67e 100644
--- a/crates/ui-egui/src/filter_dialog.rs
+++ b/crates/ui-egui/src/filter_dialog.rs
@@ -1915,12 +1915,25 @@ mod tests {
_ => panic!("a smart object"),
};
let k = 4;
- let shown = preview_document(&doc, Some(layer), "image.adjustments.curves", &json!({"points": [[0, 20], [90, 150], [255, 230]]}), k).unwrap();
+ let params = json!({"points": [[0, 20], [90, 150], [255, 230]]});
+ let shown = preview_document(&doc, Some(layer), "image.adjustments.curves", &params, k).unwrap();
+ let full = preview_document(&doc, Some(layer), "image.adjustments.curves", &params, 1).unwrap();
+ let photocraft_doc::LayerContent::Smart(full_sm) = &full.layer(layer).unwrap().content else { panic!("a smart object") };
+ let reference = photocraft_algo::resample::resize_surface(full_sm.cache.as_ref().unwrap(), 0.25, 0.25, photocraft_algo::resample::Resample::Bicubic);
let photocraft_doc::LayerContent::Smart(sm) = &shown.layer(layer).unwrap().content else { panic!("a smart object") };
assert_eq!(sm.smart_filters.len(), 1, "the preview adds the Curves smart filter");
assert_eq!(shown.size, crate::proxy::proxy_document(&doc, k).size);
// The 16 px square at (16, 16) is a 4 px square at (4, 4) on the proxy, not 16 px at (16, 16).
- for (x, y) in [(4, 4), (5, 6), (7, 7)] {
+ // Bicubic reduction blends the square's boundary with transparency; compare all alpha
+ // values with a reduced full-size result, and require opacity only in the interior.
+ for y in 0..shown.size.height as i32 {
+ for x in 0..shown.size.width as i32 {
+ let expected = reference.pixel(x, y).last().copied().unwrap();
+ let actual = alpha(&shown, x, y);
+ assert!((actual - expected).abs() <= 1.0 / 255.0, "({x}, {y}): alpha {actual}, expected {expected}");
+ }
+ }
+ for (x, y) in [(5, 5), (5, 6), (6, 6)] {
assert!(alpha(&shown, x, y) > 0.99, "({x}, {y}) is inside the reduced square");
}
for (x, y) in [(2, 2), (9, 9), (12, 12), (15, 15)] {
diff --git a/crates/ui-egui/src/profile_open_tests.rs b/crates/ui-egui/src/profile_open_tests.rs
index 2ede8ffef..b071048de 100644
--- a/crates/ui-egui/src/profile_open_tests.rs
+++ b/crates/ui-egui/src/profile_open_tests.rs
@@ -13,7 +13,9 @@ use photocraft_doc::{Color, ColorMode, Document, SampleType, Size};
use photocraft_engine::Session;
use serde_json::Value;
-const USE: &str = "Use the embedded profile (Adobe RGB (1998)-compatible (Photocraft))";
+fn use_embedded() -> String {
+ format!("Use the embedded profile ({})", photocraft_cms::Builtin::AdobeRgbCompat.description())
+}
const CONVERT: &str = "Convert to the working space (sRGB IEC61966-2.1)";
const DISCARD: &str = "Discard the embedded profile (don't color manage)";
@@ -125,7 +127,7 @@ fn files_opened_together_ask_one_at_a_time_before_each_opens() {
assert_eq!(docs(&h), answered, "background {background}: a file opens only after its prompt");
let name = asked(&h);
assert!(!answered.contains(&name), "background {background}: {name} asked twice");
- answer(&mut h, USE);
+ answer(&mut h, &use_embedded());
answered.push(name);
}
in_order(background, &answered);
@@ -217,6 +219,7 @@ fn a_held_file_still_reports_its_missing_fonts() {
#[test]
fn each_answer_applies_to_its_own_file() {
+ let use_embedded = use_embedded();
for background in [false, true] {
let mut h = harness(background);
open_three(&mut h);
@@ -229,7 +232,7 @@ fn each_answer_applies_to_its_own_file() {
match name {
"a.png" => CONVERT,
"b.png" => DISCARD,
- _ => USE,
+ _ => &use_embedded,
},
);
answered.push(name);
@@ -249,7 +252,7 @@ fn cancel_opens_neither_the_file_nor_the_ones_still_to_come() {
open_three(&mut h);
let first = asked(&h);
in_order(background, &[first]);
- answer(&mut h, USE);
+ answer(&mut h, &use_embedded());
click(&mut h, "Cancel");
settle(&mut h);
assert!(h.state().ui.dialogs.is_empty(), "background {background}: no prompt left");