linebender / linebender/tiny-skia

Hairline stroking at half-pixel offset + `LineCap::Square` produces artifacts

Open
#44 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
1.6k
Forks
99
Avg merge
2h 52m
Merged PRs (30d)
1

Description

```rust
use tiny_skia::*;

fn main() {
let mut paint = Paint::default();
paint.set_color_rgba8(255, 0, 0, 255);
paint.anti_alias = true;

let path = {
let mut pb = PathBuilder::new();
pb.move_to(2.5, 1.5);
pb.line_to(5.5, 1.5);
pb.line_to(5.5, 5.5);
pb.line_to(2.5, 5.5);
pb.close();
pb.finish().unwrap()
};

let mut stroke = Stroke::default();
stroke.width = 1.0;
stroke.line_cap = LineCap::Square;

let mut pixmap = Pixmap::new(7, 7).unwrap();
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
pixmap.save_png("image.png").unwrap();
}
```

produces (8x upscale, actual/expected):

![image](https://user-images.githubusercontent.com/725494/152811135-de807b9d-004b-47dc-894c-db6487392812.png)
![image2](https://user-images.githubusercontent.com/725494/152811971-7674842a-6978-4a75-b670-5c83141d8ad2.png)

This issue can be "fixed" by not using `LineCap::Square`, by using larger stroke width (which would simply disable hairline stroking) and by closing the path manually, without relying on ClosePath/Z.

The Skia itself produces similar results, but not quite the same. Not sure if this is actually a Skia bug or an intentional behaviour.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Rust reproduction and compare its generated image with the attached actual and expected results. Trace hairline stroking with a half-pixel offset, LineCap::Square, and ClosePath/Z, then compare the behavior with Skia. Done means determining whether the artifact is intentional or correcting it with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.