mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Refuse Art History Brush painting in Indexed Color and Bitmap
This commit is contained in:
1 parent
1553cd3c9e
commit
236595cacf
2 files changed
+63
-8
No files matched your search
@@ -216,19 +216,21 @@ fn source_surface(s: &Session, id: Option<photocraft_doc::LayerId>, p: &Value) -
|
||||
} else {
|
||||
paint_source(st, p, CMD)?
|
||||
};
|
||||
refuse_format(&st.doc, &doc)?;
|
||||
refuse_format(&st.doc, &doc, pixels)?;
|
||||
super::history_source(s, id, p, CMD)
|
||||
.map_err(|e| if pixels && crate::channel_cmds::read_target_surface(&doc, id, p).is_err() { EngineError::Other(LACKS_LAYER.into()) } else { e })
|
||||
}
|
||||
|
||||
/// A source of another colour mode, then any document but an 8-bit one, refused with the reference
|
||||
/// application's alert texts (#12637). The 16-bit text was seen with one layer only; two layers,
|
||||
/// or a depth change after the source, showed "not directly editable", so that text covers every
|
||||
/// other 16-bit case.
|
||||
fn refuse_format(doc: &photocraft_doc::Document, source: &photocraft_doc::Document) -> Result<()> {
|
||||
use photocraft_color::SampleType;
|
||||
let why = if source.mode != doc.mode {
|
||||
/// A Bitmap pixel stroke refuses before the source-mode comparison. An Indexed Color pixel stroke
|
||||
/// checks the source mode first (#18506). Other mode and depth refusals keep their order (#12637).
|
||||
fn refuse_format(doc: &photocraft_doc::Document, source: &photocraft_doc::Document, pixels: bool) -> Result<()> {
|
||||
use photocraft_color::{ColorMode, SampleType};
|
||||
let why = if pixels && doc.mode == ColorMode::Bitmap {
|
||||
"it does not work with Bitmap images (convert image to Grayscale mode to edit)."
|
||||
} else if source.mode != doc.mode {
|
||||
"the current color mode does not match that of the history state."
|
||||
} else if pixels && doc.mode == ColorMode::Indexed {
|
||||
"it cannot paint in the current color mode."
|
||||
} else {
|
||||
match doc.depth {
|
||||
SampleType::U8 => return Ok(()),
|
||||
@@ -624,6 +626,10 @@ mod art_history_mode_mismatch_tests;
|
||||
#[path = "art_history_depth_tests.rs"]
|
||||
mod art_history_depth_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "art_history_indexed_bitmap_tests.rs"]
|
||||
mod art_history_indexed_bitmap_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "art_history_refusal_tests.rs"]
|
||||
mod refusal_tests;
|
||||
@@ -0,0 +1,49 @@
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::art_history_noop_state_tests::{held_back_session, steps, stroke};
|
||||
use crate::Session;
|
||||
|
||||
const INDEXED: &str = "Could not use the art history brush because it cannot paint in the current color mode.";
|
||||
const MODE: &str = "Could not use the art history brush because the current color mode does not match that of the history state.";
|
||||
const BITMAP: &str = "Could not use the art history brush because it does not work with Bitmap images (convert image to Grayscale mode to edit).";
|
||||
|
||||
fn last_row(session: &Session) -> usize {
|
||||
session.active().unwrap().history.entries().len() - 1
|
||||
}
|
||||
|
||||
fn assert_refused(session: &mut Session, state: usize, points: Value, expected: &str) {
|
||||
let history = steps(session);
|
||||
let document = session.active().unwrap().doc.clone();
|
||||
let error = stroke(session, json!({"state": state, "points": points, "tolerance": 0})).unwrap_err().to_string();
|
||||
assert_eq!(error, expected, "source row {state}, points {points}");
|
||||
assert_eq!(steps(session), history, "the refusal adds no history step");
|
||||
assert_eq!(session.active().unwrap().doc, document, "the refusal leaves the pixels unchanged");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indexed_art_history_refuses_pixels_after_checking_the_source_mode() {
|
||||
let mut session = held_back_session(8);
|
||||
let rgb = last_row(&session);
|
||||
session.execute("image.mode.indexedColor", json!({})).unwrap();
|
||||
let indexed = last_row(&session);
|
||||
session.execute("edit.fill", json!({"color": "#ffffff"})).unwrap();
|
||||
for points in [json!([[24, 16]]), json!([[8, 16], [40, 16]])] {
|
||||
assert_refused(&mut session, indexed, points.clone(), INDEXED);
|
||||
assert_refused(&mut session, rgb, points, MODE);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitmap_art_history_refuses_pixels_before_checking_the_source_mode() {
|
||||
let mut session = held_back_session(8);
|
||||
let rgb = last_row(&session);
|
||||
session.execute("image.mode.grayscale", json!({})).unwrap();
|
||||
let grayscale = last_row(&session);
|
||||
session.execute("image.mode.bitmap", json!({"method": "threshold"})).unwrap();
|
||||
let bitmap = last_row(&session);
|
||||
for state in [bitmap, grayscale, rgb] {
|
||||
for points in [json!([[24, 16]]), json!([[8, 16], [40, 16]])] {
|
||||
assert_refused(&mut session, state, points, BITMAP);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user