diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index 5c31278493..474a6c0a0c 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -744,7 +744,7 @@ pub fn effect_catalog() -> Vec { "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( diff --git a/crates/effects/src/pixel/pixelate.rs b/crates/effects/src/pixel/pixelate.rs index 0318eb5f45..e7fcf05e08 100644 --- a/crates/effects/src/pixel/pixelate.rs +++ b/crates/effects/src/pixel/pixelate.rs @@ -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, }; diff --git a/crates/effects/src/pixel/tests.rs b/crates/effects/src/pixel/tests.rs index 6dd7942e5e..89b2e7dc16 100644 --- a/crates/effects/src/pixel/tests.rs +++ b/crates/effects/src/pixel/tests.rs @@ -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 diff --git a/crates/render/src/tests/memory.rs b/crates/render/src/tests/memory.rs index 7b68bc74d4..d5009c2072 100644 --- a/crates/render/src/tests/memory.rs +++ b/crates/render/src/tests/memory.rs @@ -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; diff --git a/docs/mcp.md b/docs/mcp.md index 83755a1937..9604e3da61 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -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 diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 74789b33ba..5f5f9644d5 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -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).