mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-02 06:17:22 -06:00
Every tests/*.rs file is its own executable that links the whole crate graph. Move each crate's test files into tests/it/ as modules of one tests/it/main.rs; helper modules under tests/common move with them. These keep their own binary (own process): - engine panic_hunt: a process-wide panic hook counts every panic. - engine text_gamma: changes the process-wide text gamma. - engine smart_filter_stages, mask_cache_purge: assert on global caches. - codecs pnm_peak_memory: reads the process's peak RSS. - photocraft mac_menu_appkit: harness = false.
39 lines
1.6 KiB
Rust
39 lines
1.6 KiB
Rust
//! Paint Bucket and Gradient keep alpha on a transparency-locked layer, as Edit › Fill and the
|
||
//! brushes do (#1104).
|
||
|
||
use photocraft_engine::Session;
|
||
use serde_json::json;
|
||
|
||
/// A transparent layer with a red stroke across it, transparency locked.
|
||
fn locked() -> Session {
|
||
let mut s = Session::new();
|
||
s.execute("file.new", json!({"width": 40, "height": 30})).unwrap();
|
||
s.execute("layer.new.layer", json!({})).unwrap();
|
||
s.execute("paint.stroke", json!({"points": [[5, 10], [20, 10]], "size": 8, "hardness": 1.0, "color": "#ff0000"})).unwrap();
|
||
s.execute("layer.lockLayers", json!({"transparency": true})).unwrap();
|
||
s
|
||
}
|
||
|
||
fn px(s: &Session, x: i32, y: i32) -> [f32; 4] {
|
||
let st = s.active().unwrap();
|
||
st.active_layer.and_then(|id| st.doc.layer(id)).unwrap().surface().unwrap().rgba(x, y)
|
||
}
|
||
|
||
#[test]
|
||
fn bucket_keeps_alpha() {
|
||
let mut s = locked();
|
||
s.execute("paint.bucket", json!({"x": 30, "y": 25, "color": "#0000ff", "antiAlias": false})).unwrap();
|
||
assert_eq!(px(&s, 30, 25)[3], 0.0, "transparent pixel became opaque");
|
||
s.execute("paint.bucket", json!({"x": 12, "y": 10, "color": "#0000ff", "antiAlias": false})).unwrap();
|
||
assert_eq!(px(&s, 12, 10), [0.0, 0.0, 1.0, 1.0], "the opaque stroke is still recoloured");
|
||
}
|
||
|
||
#[test]
|
||
fn gradient_keeps_alpha() {
|
||
let mut s = locked();
|
||
s.execute("paint.gradient", json!({"from": [0, 0], "to": [40, 30]})).unwrap();
|
||
assert_eq!(px(&s, 30, 25)[3], 0.0, "transparent pixel became opaque");
|
||
assert_eq!(px(&s, 12, 10)[3], 1.0);
|
||
assert_ne!(px(&s, 12, 10), [1.0, 0.0, 0.0, 1.0], "the opaque stroke is still painted");
|
||
}
|