Color Halftone: draw dark dots on light tones (#10316)

* fix(effects): draw dark dots in RGB Color Halftone

(cherry picked from commit 2dbe91af9f)

* Cover dark-on-light RGB halftone polarity

Updated halftone tests to clarify behavior regarding pixel brightness and dot sizes.

(cherry picked from commit babd60e332)

* effects: bound Color Halftone dots at full coverage

(cherry picked from commit 8fb0bf55607762df6e3acc2ed7ed37a643fea022)

* effects: describe Color Halftone ink coverage

(cherry picked from commit 0dbf12514095b6e12cb4414055d8ac47ee1fbcdc)

* Document the change to saved RGB halftones

* Test the bounded edge overlap of full halftone dots

---------

Co-authored-by: Mex <44814932+MMexicann@users.noreply.github.com>
Co-authored-by: dotCooCoo <RobertLeeLW@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-12-01 14:17:04 +01:00
1 parent 521347a60f
commit e28faa0a94
6 files changed
+47 -11

No files matched your search

+1 -1
View File
@@ -744,7 +744,7 @@ pub fn effect_catalog() -> Vec<EffectInfo> {
"pixelate.colorHalftone",
"Color Halftone…",
PIXELATE,
"{maxRadius: px 4..127 (8; the radius of a dot at full strength, which fills its square cell, in pixels of the Document Raster Effects resolution), channel1: screen angle deg -360..360 (108), channel2: deg (162), channel3: deg (90), channel4: deg (45)} screens each colour channel (red, green, blue: channels 1 to 3; in CMYK documents cyan, magenta, yellow, black: 1 to 4) at its angle into dots whose area follows the channel's mean over their cell",
"{maxRadius: px 4..127 (8; the radius of a dot at full strength, which fills its square cell, in pixels of the Document Raster Effects resolution), channel1: screen angle deg -360..360 (108), channel2: deg (162), channel3: deg (90), channel4: deg (45)} The effect screens cyan, magenta and yellow ink (channels 1 to 3; CMYK mode adds black as channel 4) at their angles into dots whose area follows the cell's mean ink coverage.",
json!({"maxRadius": 8.0, "channel1": 108.0, "channel2": 162.0, "channel3": 90.0, "channel4": 45.0}),
),
r(
+4 -3
View File
@@ -437,7 +437,7 @@ impl Screen {
/// Color Halftone: each channel screened at its angle in square cells sized so that a dot of
/// `max_radius` (pixels of the document's raster grid, `space.line` each) fills one; each cell's
/// dot covers the share of it that is the channel's mean there (white stays white, black black).
/// dot covers the mean ink coverage of that cell (white stays white, black black).
/// Coverage stays as it is.
pub(super) fn color_halftone(px: &mut [[u8; 4]], w: usize, h: usize, space: &PixelSpace, max_radius: f64, angles: [f64; 4]) {
let Some(place) = Place::new(space, w, h) else { return };
@@ -446,7 +446,8 @@ pub(super) fn color_halftone(px: &mut [[u8; 4]], w: usize, h: usize, space: &Pix
if !(side.is_finite() && side / place.px >= 3.0) {
return;
}
let channels = space.channels;
// Screen RGB as dark ink against white, like the CMY channel previews.
let channels = if space.channels == Channels::Rgb { Channels::CmyPlane } else { space.channels };
let n = split([0; 4], channels).1;
let limit = w.saturating_mul(h).saturating_add(4096);
let mut screens = Vec::with_capacity(n);
@@ -478,7 +479,7 @@ pub(super) fn color_halftone(px: &mut [[u8; 4]], w: usize, h: usize, space: &Pix
let mean = if sum[1] > 1e-6 { f64::from(sum[0] / sum[1]) } else { 0.0 };
// Full strength fills the cell, corners too; none leaves no speck.
let radius = match mean {
m if m >= 254.5 / 255.0 => f64::INFINITY,
m if m >= 254.5 / 255.0 => side / std::f64::consts::SQRT_2 + 0.5 * place.px,
m if m <= 0.5 / 255.0 => 0.0,
m => dot_radius(m) * side,
};
+32 -1
View File
@@ -1070,13 +1070,44 @@ fn color_halftone_screens_midtones_into_dots_and_keeps_white_and_black() {
let mut half = image(w, h, |x, _| if x < 32 { grey(160) } else { [0; 4] });
halftone.apply(&mut half, w, h, &space(w, h));
assert!((0..h).all(|y| (32..w).all(|x| at(&half, w, x, y) == [0; 4])));
// Dots are bigger where the image is brighter.
// Brighter areas have fewer dark pixels.
let mut ramp = image(w, h, |x, _| grey((x * 4) as u8));
halftone.apply(&mut ramp, w, h, &space(w, h));
let lit = |x0: usize| (0..h).flat_map(|y| (x0..x0 + 16).map(move |x| (x, y))).filter(|(x, y)| at(&ramp, w, *x, *y)[0] > 127).count();
assert!(lit(8) < lit(40), "{} < {}", lit(8), lit(40));
}
#[test]
fn color_halftone_draws_dark_dots_on_light_rgb() {
let (w, h) = (64, 64);
let halftone = fx("pixelate.colorHalftone", json!({"maxRadius": 8, "channel1": 0, "channel2": 0, "channel3": 0}));
let mut d = image(w, h, |_, _| grey(192));
halftone.apply(&mut d, w, h, &space(w, h));
assert_eq!(at(&d, w, 37, 37), grey(0));
assert_eq!(at(&d, w, 32, 32), grey(255));
}
#[test]
fn color_halftone_full_coverage_only_overlaps_the_edge_of_an_empty_neighbor() {
let (w, h) = (96, 64);
let source = image(w, h, |x, _| grey(if x < w / 2 { 0 } else { 255 }));
let mut screened = source.clone();
fx("pixelate.colorHalftone", json!({"maxRadius": 8, "channel1": 0, "channel2": 0, "channel3": 0})).apply(&mut screened, w, h, &space(w, h));
let half_cell = (8.0 * std::f64::consts::SQRT_2 / 2.0) as usize;
let (edge, y) = (w / 2, h / 2 + half_cell);
assert_eq!(at(&screened, w, edge - half_cell, y), grey(0), "the full cell keeps its center");
assert_eq!(at(&screened, w, edge, y), grey(0), "the round dot crosses the straight cell edge");
let fringe = at(&screened, w, edge + 2, y)[0];
assert!(fringe > 0 && fringe < 255, "the last overlapping column is antialiased: {fringe}");
// With an 8 px radius and the grid aligned to this edge, the circle and its antialiasing
// can reach only the first three columns of white. Check every row, including cell corners.
for y in 0..h {
for x in edge + 3..w {
assert_eq!(at(&screened, w, x, y), grey(255), "unexpected ink at ({x}, {y})");
}
}
}
#[test]
fn color_halftone_sizes_its_dots_in_pixels_of_the_raster_effects_resolution() {
// Max Radius counts the document's raster grid pixels (#3260): 16 px at 144 ppi (lines half a
+5 -5
View File
@@ -2455,8 +2455,8 @@ fn proof_previews_draw_changes_as_a_new_renderer_does() {
}
/// A thumbnail of an object under a filter that treats color channels apart (Color Halftone) is
/// made again when the document's color mode changes: CMYK documents screen ink channels, RGB
/// documents light ones.
/// made again when the document's color mode changes. RGB documents screen three ink planes.
/// CMYK documents screen four ink planes.
#[test]
fn filtered_thumbnails_follow_the_color_mode() {
let _fonts = fonts_steady();
@@ -2464,9 +2464,9 @@ fn filtered_thumbnails_follow_the_color_mode() {
let mut d = Document::new(200.0, 100.0);
d.color_mode = vectorcraft_doc::ColorMode::Cmyk;
let halftone = effect("pixelate.colorHalftone", serde_json::json!({"maxRadius": 4}));
let orange = filled(&mut d, rectangle(Rect::new(20.0, 20.0, 180.0, 80.0)), Paint::solid(Color::rgb(1.0, 0.5, 0.0)), vec![halftone]);
let id = orange.id;
let mut d = with_art(d, vec![orange]);
let gray = filled(&mut d, rectangle(Rect::new(20.0, 20.0, 180.0, 80.0)), Paint::solid(Color::rgb(0.5, 0.5, 0.5)), vec![halftone]);
let id = gray.id;
let mut d = with_art(d, vec![gray]);
let mut r = Renderer::new();
let before = r.render_thumbnail(&d, id, 128).unwrap().pixels;
d.color_mode = vectorcraft_doc::ColorMode::Rgb;
+4
View File
@@ -11438,6 +11438,10 @@ image `object.rasterize` makes with the same options.
{"name":"run_command","arguments":{"command":"effect.apply","params":{"effect":"rasterize","params":{"useDocumentResolution":false,"resolution":150,"background":"white"}}}}
```
Color Halftone (`pixelate.colorHalftone`) screens cyan, magenta and yellow ink in RGB mode and also black ink in CMYK
mode. Dot area follows each cell's mean ink coverage. A full-strength dot has a finite radius that fills the cell,
including its corners.
## Glass textures
Glass (`distort.glass`) takes an image file as its surface in `params.textureImage`, as `{path}` or
+1 -1
View File
@@ -2790,7 +2790,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Rough Pastels' Load Texture:** Effect › Artistic › Rough Pastels… has the same Load Texture… button, and its Texture and Light Direction controls are menus. The loaded image's gray levels are the paper surface (Loaded Texture in the Texture menu, `textureImage` stored with the effect), and Scaling, Relief, Light Direction and Invert act on it as on Brick, Burlap, Canvas and Sandstone (`pixel::tests::rough_pastels_draws_a_loaded_texture_as_its_surface`, `rough_pastels_loads_a_texture_saves_it_and_draws_it`).
- **Bounded effect length inputs (#4638):** Effect dialog fields with defined length ranges (such as Crystallize Cell Size 3..300 pt) clamp immediately on commit and reject invalid inputs visibly with an accent highlight without reverting to sub-minimum values.
- **Color Halftone in raster pixels (#3260):** Max Radius is 4–127 px of the Document Raster Effects resolution, as public documentation gives it, shown in px whatever the document units; documents from before open with their radii in points converted (document version 3), and a file saved for an older app version holds them in points again.
- **Color Halftone in raster pixels (#3260):** Max Radius is 4–127 px of the Document Raster Effects resolution, as public documentation gives it, shown in px whatever the document units; documents from before open with their radii in points converted (document version 3), and a file saved for an older app version holds them in points again. Saved RGB Color Halftone artwork can render differently when reopened: light tones now produce dark dots on a light background, and the first three angle controls now set the cyan, magenta and yellow ink screens. CMYK mode also screens black ink. A full-strength dot reaches its cell corners and can overlap the edge of an adjacent cell. The overlap is bounded by the circle and its antialiased edge.
- **Raster effects after document and view changes:** a cached drop shadow, outer glow or filtered content is made again when something its content reads from outside the object changes: a pattern's art or tiling, a symbol shown inside another symbol, a brush definition, an image's pixels, the raster resolution (De-Interlace, Color Halftone), Page Knockout Group, the substitution highlights (Highlight Substituted Fonts and Highlight Alternate Glyphs in Preferences › Type, Highlight Substituted Glyphs in Document Setup), a layer's Dim Images, the color settings, the fonts, Pixel Preview, Anti-aliased Artwork, Overprint Preview and isolation mode. A thumbnail under Color Halftone or Mezzotint is made again when the document's color mode changes. Raster effects (blur, shadow, glow, grain) drawn after a pattern, radial or freeform gradient fill export at their place and size (#1541, fixes #1536).
- **Drop Shadow's Darkness:** Effect › Stylize › Drop Shadow… has Color and Darkness as radio buttons, each with its field, and the Appearance panel's inline editor has the two radio buttons in its Shade row (`shade`: `color` or `darkness`; `darkness`: 0 to 100%, 100 by default). Color is the default, and a shadow saved without these keys draws as before. With Darkness, the stored source-color model determines the adjustment before document/profile conversion and blur: subtract Darkness/100 from each RGB channel, clamped at zero, or add it to CMYK black K and Gray black, clamped at one, preserving CMYK C/M/Y. At the near-100% endpoint the shadow source becomes gray black before conversion. Shadow opacity stays separate. Original gradient stops follow the same application rule before interpolation; exact resource-level gradient parity remains open. Application SVG export keeps a live filter for simple uniform sRGB sources and uses rendered shadow images for other working RGB profiles, source models and gradients. Low-level SVG filter output warns when this preparation is needed; proportional intermediate SVG filters are not misread as additive Darkness. Exact spot/custom-color and composite-source parity remain open, and resulting CMYK ink values follow the application color pipeline. CSS export leaves the shadow out and marks the object unsupported. When a `.ai`, EPS or PDF opens from its editing data, a Drop Shadow with Darkness in an object's art style is read as one with Color is, with the shadow's Darkness percentage (100% when the style gives none). Behavior reference: Illustrator CC Help (2014, [PDF](https://help.adobe.com/archive/en/illustrator/cc/2014/illustrator_reference.pdf)), page 428 (PDF page 434).