RazrFalcon / tiny-skia

A tiny Skia subset ported to Rust
BSD 3-Clause "New" or "Revised" License
1.05k stars 67 forks source link

Repeated clipping makes things more transparent #40

Closed laurmaedje closed 2 years ago

laurmaedje commented 2 years ago

I use tiny-skia to generate reference images for some tests and, after making a change to some clipping code, I noticed that some renderings turned out ever so slightly different than before. It turns out that for a ClipMask it makes a difference whether you intersect the same path once or multiple times. Repeatedly intersecting with the same path reduces the alpha levels of pixels inside the path by one each time. The culprit is this line, which for a=255 and b=255 results in 254 (and after 100 intersections it's down to 155). I'm not sure what the correct calculation would be but the current behaviour seems a bit unintuitive to me.

RazrFalcon commented 2 years ago

Yes, this is a bug. Masking was done from scratch, because Skia's implementation is ridiculously complex (but way faster). Looks like I've messed up rounding.