mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
test(tools): pin the Indexed pattern row this change lets go, and name its follow-up
#12887 measured a second half of the rule the reference application holds: it refuses an Indexed pattern from another image, whose colours are not in the document's colour table, and paints only the one carrying that table. Tracking the source mode and not the table lets that case paint. Pin it exactly as it behaves now - the tile's red and green land in a document whose table holds neither - so the follow-up (#16642) is met with a test that says which way the behaviour has to go, and record the same thing where the field is documented: how a repeat definition of pixels already in the library picks its source, and that the PSD raw-block comparison now covers the new field. An index written before the source member still loads the whole pattern with no source, which the library test now strips the member to prove.
This commit is contained in:
1 parent
3c6e332fc5
commit
ca431fde00
4 files changed
+48
-1
No files matched your search
@@ -72,7 +72,9 @@ pub struct Pattern {
|
||||
/// Indexed source stores an RGB surface), so this is the only place the mode survives. `None`
|
||||
/// for a pattern whose source is not a document of a known mode: the built-ins, and patterns
|
||||
/// read from a `.pat` or PSD block, which say what their pixels are but not what they came
|
||||
/// from. Not part of the id: the same pixels keep one id whatever their source.
|
||||
/// from. Not part of the id: the same pixels keep one id whatever their source, and the id is
|
||||
/// how the library and a document dedupe, so defining pixels that are already stored keeps the
|
||||
/// source mode of the pattern that got there first.
|
||||
pub source_mode: Option<ColorMode>,
|
||||
pub surface: Surface,
|
||||
}
|
||||
|
||||
@@ -563,6 +563,20 @@ fn patterns_survive_a_restart() {
|
||||
|
||||
let (u, _) = session(&dir);
|
||||
assert_eq!(user_patterns(&u), [("Toner".to_string(), 8)]);
|
||||
|
||||
// An index written before the source member: the pattern still loads, whole but with no
|
||||
// source recorded, so nothing written by the older build is lost or refused differently.
|
||||
let index = dir.0.join(PATTERNS_FILE);
|
||||
let mut manifest: serde_json::Value = serde_json::from_slice(&std::fs::read(&index).unwrap()).unwrap();
|
||||
for entry in manifest["patterns"].as_array_mut().unwrap() {
|
||||
assert!(entry.as_object_mut().unwrap().remove("source_mode").is_some(), "the writer named the member");
|
||||
}
|
||||
std::fs::write(&index, serde_json::to_vec_pretty(&manifest).unwrap()).unwrap();
|
||||
let (older, w) = session(&dir);
|
||||
assert!(w.iter().all(|w| !w.contains("Toner")), "{w:?}");
|
||||
let toner = older.patterns.items.iter().find(|p| p.name == "Toner").cloned().unwrap();
|
||||
assert_eq!(toner.source_mode, None, "an older index records no source");
|
||||
assert_eq!((toner.width, toner.height), (8, 6), "its pixels and size still load");
|
||||
}
|
||||
|
||||
fn define_pattern(s: &mut Session, name: &str, color: &str, width: u32) {
|
||||
|
||||
@@ -146,6 +146,35 @@ fn an_indexed_source_pattern_paints_in_other_documents_as_before() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The one measured row of #12887 this change knowingly does not keep: the reference refuses an
|
||||
/// Indexed pattern from ANOTHER image, whose colours are not in the document's colour table, and
|
||||
/// paints only the one that carries that table. PhotoCraft records the source mode, not the table,
|
||||
/// so this paints - the deviation tracked as #16642, pinned here exactly as it behaves, with the
|
||||
/// landed colours shown to be outside the document's own table.
|
||||
#[test]
|
||||
fn a_pattern_defined_in_another_indexed_document_paints_today() {
|
||||
let mut s = crate::session();
|
||||
let pat = indexed_doc_and_pattern(&mut s);
|
||||
// A second Indexed document, cyan over magenta: its own exact palette, which holds none of the
|
||||
// tile's red, green and blue.
|
||||
s.execute("file.new", json!({"width": 64, "height": 64, "depth": 8, "mode": "rgb"})).unwrap();
|
||||
for (y, color) in [(0, "#00ffff"), (32, "#ff00ff")] {
|
||||
s.execute("select.rect", json!({"x": 0, "y": y, "width": 64, "height": 32})).unwrap();
|
||||
s.execute("edit.fill", json!({"color": color})).unwrap();
|
||||
}
|
||||
s.execute("select.deselect", json!({})).unwrap();
|
||||
to_indexed(&mut s);
|
||||
let table = s.active().unwrap().doc.color_table.clone().expect("an Indexed document has a colour table");
|
||||
assert!(!table.colors.contains(&[255, 0, 0]), "the second table holds {table:?}");
|
||||
let before = state(&s);
|
||||
assert_eq!(press_refusal(&s, &stroke(&pat, false)), None, "no refusal for a foreign Indexed source");
|
||||
s.execute("paint.patternStamp", stroke(&pat, false)).unwrap_or_else(|e| panic!("foreign Indexed source: {e}"));
|
||||
let after = state(&s);
|
||||
assert_eq!(after.1, before.1 + 1, "one history step");
|
||||
assert_eq!(after.0[25 * 64 + 5], [1.0, 0.0, 0.0, 1.0], "the tile's red lands, though this table has no red");
|
||||
assert_eq!(after.0[25 * 64 + 12], [0.0, 1.0, 0.0, 1.0], "and its green, which this table lacks too");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pattern_whose_source_is_not_an_indexed_image_is_refused_in_an_indexed_document() {
|
||||
let mut s = crate::session();
|
||||
|
||||
@@ -265,6 +265,8 @@ pub fn export_global_blocks_with_warnings(doc: &Document, warnings: &mut Vec<Str
|
||||
|
||||
fn export_global_blocks_with_warnings_limit(doc: &Document, warnings: &mut Vec<String>, limit: u64) -> Vec<photocraft_doc::PsdGlobalBlock> {
|
||||
let raw = &doc.metadata.psd_global_blocks;
|
||||
// The comparison covers every field, `Pattern::source_mode` included; a pattern this reader
|
||||
// decoded names no source on either side, so a file's blocks are still reused verbatim.
|
||||
if from_global_blocks(doc) == doc.patterns {
|
||||
return repair_legacy_blocks(raw);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user