Skip to content

Anti-aliased line/circle rendering and grayscale PNG output - #22

Open
Grizaster wants to merge 1 commit into
GOODBOY008:mainfrom
Grizaster:render-aa
Open

Anti-aliased line/circle rendering and grayscale PNG output#22
Grizaster wants to merge 1 commit into
GOODBOY008:mainfrom
Grizaster:render-aa

Conversation

@Grizaster

Copy link
Copy Markdown

Overview

This PR improves rendering quality by adding anti-aliasing for all line and circle primitives, and switches PNG output from 1-bit monochrome to 8-bit grayscale (matching Labelary's default X-Quality: Grayscale output).

Rendering Improvements

Anti-aliased diagonal lines (^GD)

  • Thin lines (thickness ≤ 1): Replaced Bresenham (draw_line_segment_mut) with Xiaolin Wu's algorithm (draw_antialiased_line_segment_mut) for smooth edges
  • Thick lines (thickness > 1): Custom parallelogram fill with per-pixel coverage at the left and right edges. The previous draw_polygon_mut approach only drew the outline, not the filled shape

Anti-aliased circles (^GC)

  • Replaced draw_filled_circle_mut and the binary distance-check ring with a per-pixel coverage-based approach
  • Both inner and outer ring edges use a 1px-wide coverage ramp (distance ± 0.5) for smooth anti-aliased edges

Grayscale PNG output

  • Removed the binary threshold (pixel > 128 ? 255 : 0) from encode_png
  • PNG output is now 8-bit grayscale, preserving anti-aliasing from the renderer
  • Matches Labelary's default X-Quality: Grayscale output

Tests

  • Updated unit_png_encoder tests: assert grayscale passthrough instead of binary threshold behavior
  • Fixed clippy manual_clamp warnings: use clamp() instead of max().min()
  • Increased dhlparceluk golden test tolerance from 5.5% to 6.0% (5.57% diff due to anti-aliasing)
  • Regenerated all testdata/diffs/ after rendering changes

Files Changed

  • src/drawers/renderer.rs — anti-aliased line and circle rendering
  • src/images/monochrome.rs — grayscale PNG encoding (removed binary threshold)
  • tests/unit_png_encoder.rs — updated tests
  • tests/e2e_golden.rs — tolerance adjustment
  • docs/DIFF_THRESHOLDS.md — updated tolerance
  • testdata/diffs/* — regenerated diff images and reports

Rendering improvements:
- Thin diagonal lines (^GD t≤1): replace Bresenham with Xiaolin Wu's
  algorithm (draw_antialiased_line_segment_mut) for smooth edges
- Thick diagonal lines (^GD t>1): custom parallelogram fill with
  per-pixel coverage at left/right edges
- Circles (^GC): per-pixel distance-based coverage for both inner and
  outer ring edges, producing smooth anti-aliased edges
- PNG output: remove binary threshold, output 8-bit grayscale to
  preserve anti-aliasing (matches Labelary default Grayscale quality)

Tests:
- Update unit_png_encoder tests for grayscale passthrough
- Increase dhlparceluk golden test tolerance (5.5% → 6.0%)
- Regenerate all testdata/diffs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants