Merge pull request #1359 from storytold/fix/1286-ai-alpha-mask

Part of #1286: constant alpha masks are drawn white
This commit is contained in:
BFlat 2026-10-12 14:17:45 +07:00 committed by GitHub
commit 5432821480
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -605,10 +605,11 @@ fn cover(s: &mut Surface, page: Rect, level: u8, opacity: f32) {
/// An alpha mask of constant `alpha` over the page. A group drawn through it is a transparency
/// group of that opacity that, unlike the writer's opacity groups, is not isolated.
/// The cover is white, so a reader that takes every soft mask as a luminosity mask shows the same.
fn constant_mask(s: &mut Surface, page: Rect, alpha: f32) -> krilla::mask::Mask {
let mut sb = s.stream_builder();
let mut ms = sb.surface();
cover(&mut ms, page, 0, alpha);
cover(&mut ms, page, 255, alpha);
ms.finish();
krilla::mask::Mask::new(sb.finish(), krilla::mask::MaskType::Alpha)
}

View File

@ -76,3 +76,12 @@ fn soft_mask_groups_keep_screen_luminance() {
// The page's group blends in CMYK; the mask's group measures luminance in RGB.
assert!(t.contains("/CS/DeviceCMYK") && t.contains("/S/Luminosity") && t.contains("/CS/DeviceRGB"), "{t}");
}
#[test]
fn constant_alpha_masks_are_white() {
// #1286: a black cover hides the whole page in readers that take the mask's luminosity.
for grouped in [true, false] {
let t = text(&doc(ColorMode::Cmyk, grouped));
assert!(t.contains("/S/Alpha") && t.contains("111rg") && !t.contains("000rg"), "grouped {grouped}: {t}");
}
}