Commit Graph
20116 Commits
Author SHA1 Message Date
Behdad Esfahbod 6bfdaabc8a raster-paint: specialize rect clip hot loops 2026-02-23 23:48:18 -03:00
Behdad Esfahbod 46782abcaa [raster] Micro-optimize 2026-02-23 23:28:59 -03:00
Behdad Esfahbod 8bb0641ad3 [util] Add -n/--num-iterations to raster-all tools 2026-02-23 22:35:30 -03:00
Behdad Esfahbod 90ef078e46 [util] Centralize --num-iterations and skip repeat shaping for raster 2026-02-23 22:34:19 -03:00
Behdad Esfahbod f1e6108523 [util] Add raster --num-iterations loops and recycle draw image 2026-02-23 22:34:14 -03:00
Behdad EsfahbodandClaude Opus 4.6 d7d17ee055 raster: fix winding carry for edges left of the surface
When an edge fell to the left of the rendering surface (col < 0),
cell_add() discarded its winding contribution entirely.  For glyphs
whose outlines extend beyond the surface bounds (e.g. COLR v1
spliceMask clip glyphs), this caused the interior winding number to
stay zero, producing empty rasterizations.

Fix by forwarding the cover delta to column 0 so the left-to-right
sweep picks up the correct accumulated winding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 22:31:24 -03:00
Behdad Esfahbod 87c8946640 util/hb-ft-raster: remove upem_font normalization 2026-02-23 22:31:24 -03:00
Behdad Esfahbod 426ab081d3 util/raster-output: remove upem_font normalization
Was leftover from hb-draw design picked up by agents.
2026-02-23 22:31:24 -03:00
Behdad Esfahbod 1350d2a470 [cmap] Fix CodeXL warning
Fixes https://github.com/harfbuzz/harfbuzz/issues/5753
2026-02-23 18:44:50 -03:00
Behdad Esfahbod 742f79da08 raster: remove extents_from_glyph_extents API
Remove hb_raster_extents_from_glyph_extents and switch callers to the new transform-aware set_glyph_extents APIs on raster draw/paint. Also add test coverage for transformed glyph extents and update section symbol listings.
2026-02-23 12:10:41 -03:00
dependabot[bot] 63fd3de0c7 build(deps): bump github/codeql-action from 4.32.3 to 4.32.4
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.32.3 to 4.32.4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9e907b5e64f6b83e7804b09294d44122997950d6...89a39a4e59826350b863aa6b6252a07ad50cf83e)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.32.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-23 15:10:48 +02:00
Behdad Esfahbod dc532931d6 raster: streamline scanline hot paths 2026-02-22 19:26:42 -03:00
Behdad Esfahbod 5f4319400b [raster-draw] Combine two passes
20% speedup. Devised by codex.
2026-02-22 19:20:34 -03:00
Behdad Esfahbod dfcdf16c0f [hb-raster] Don't write out to terminal 2026-02-22 19:09:51 -03:00
Behdad Esfahbod d6be64a89b [raster] Remove duplicate documentation block
https://github.com/harfbuzz/harfbuzz/pull/5749#pullrequestreview-3838613326
2026-02-22 18:59:06 -03:00
Behdad Esfahbod 550a52009a Merge pull request #5749 from harfbuzz/hb-raster
Add `harfbuzz-raster` CPU rasterization library
2026-02-22 14:35:36 -07:00
Behdad Esfahbod 85ea4f92cf raster: match FreeType quadratic recursive flatness criterion
This is also slower than what we have, but produces much closer
results to FreeType.
2026-02-22 18:18:39 -03:00
Behdad Esfahbod 07c82109c4 raster: match FreeType cubic recursive flatness criterion
This is slightly slower, but matches FreeType rasterization for OTF
fonts much better.
2026-02-22 18:13:41 -03:00
Behdad Esfahbod 646fef15fb util: drop PNG-only color detection in raster tools 2026-02-22 15:29:17 -03:00
Behdad Esfahbod 5c01a87ae5 docs: add hb_raster_extents_from_glyph_extents section entry 2026-02-22 15:20:10 -03:00
Behdad Esfahbod 603ea5e1f2 raster-paint: require explicit extents and add helper 2026-02-22 15:18:40 -03:00
Behdad Esfahbod 830c097d09 raster-paint: clear internal render state between calls 2026-02-22 15:03:39 -03:00
Behdad EsfahbodandClaude Opus 4.6 c24ade3596 raster: emit PPM from all raster tools, add color support to hb-raster-all
hb-raster-all now renders color glyphs via hb_raster_paint_t and checks
the image format (A8 vs BGRA32) when writing PPM output. hb-ft-raster-all
also switched from PGM to PPM for consistency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:41:40 -03:00
Behdad EsfahbodandClaude Opus 4.6 917d18735f raster: always emit PPM for consistent output format
Both hb-raster and hb-ft-raster now always produce PPM (color) output,
compositing alpha over foreground/background colors. This makes the
output format consistent regardless of whether the font has color data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:21:09 -03:00
Behdad Esfahbod 9683497463 Revert "raster: fix seam at shared contour endpoints via row splitting"
This reverts commit 6f4ad84ce5d6a69260c03b7dfc727a09dbe0a6dc.
2026-02-22 14:21:09 -03:00
Behdad EsfahbodandClaude Opus 4.6 8788d49250 raster: fix seam at shared contour endpoints via row splitting
Pre-compute seam rows during edge bucketing where one edge's yH matches
another edge's yL at a mid-pixel-row y-coordinate. For these rare rows
(typically 2 per glyph), split into two sub-rows and sum absolute alpha
values to avoid winding cancellation. Non-seam rows take the exact same
code path with only a single branch check overhead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:21:09 -03:00
Behdad Esfahbod e66df7ac66 Revert "raster: fix seam at shared contour endpoints by splitting row"
This reverts commit af884ced9e76b630178a338584031b5ae127d95a.
2026-02-22 14:21:09 -03:00
Behdad EsfahbodandClaude Opus 4.6 cff6be61b9 raster: fix seam at shared contour endpoints by splitting row
When two contours share a y coordinate that falls mid-pixel-row,
their edges contribute opposite-winding cover values at different
fractional heights.  The analytic formula |cover·512 − area|
computes the signed sum, which partially cancels, producing a
visible one-row artifact.

Fix by detecting these seam rows (an edge yH matching another
edge's yL within the same pixel row) and splitting into sub-rows.
Each sub-row's |cover·512 − area| is computed independently, then
the absolute alpha values are summed.  This gives correct coverage
because each sub-row has consistent winding direction.

Performance impact is negligible: seam detection piggybacks on the
existing edge-removal loop (zero cost for non-seam rows), and
sub-row processing only runs for the rare seam rows (typically 1-2
per glyph).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:21:09 -03:00
Behdad Esfahbod 8a087adaa4 hb-raster: Fix docs 2026-02-22 02:48:45 -03:00
Behdad Esfahbod 6ebc871e8a [hb-draw] Remove --no-color 2026-02-22 02:31:00 -03:00
Behdad EsfahbodandClaude Opus 4.6 174a2f3b3d raster: fix sweep gradient angle mapping and REFLECT extend mode
Two bugs fixed:
- atan2f returns [-pi,pi] but sweep gradient angles are in [0,2*pi];
  normalize pixel angle to [0,2*pi) so the seam matches the OT spec.
- REFLECT extend mode was identical to REPEAT because floorf after
  the initial mod made period always 0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 02:05:06 -03:00
Behdad EsfahbodandClaude Opus 4.6 7951782491 hb-raster: add --foreground and --background CLI options
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:47:34 -03:00
Behdad EsfahbodandClaude Opus 4.6 a544ff5d6d raster: fix clip rectangle for non-axis-aligned transforms
When the current transform has rotation/skew, push_clip_rectangle now
rasterizes the actual transformed quad using edge cross-product tests
instead of approximating with an axis-aligned bounding box.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:40:45 -03:00
Behdad EsfahbodandClaude Opus 4.6 63d7a12963 raster: optimize paint loops to skip transparent clip regions
Track bounding box (min_x/y, max_x/y) on all clip masks. Paint
callbacks (solid fill, image, gradients) now iterate only within
the clip bounding box instead of the full surface.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:39:29 -03:00
Behdad EsfahbodandClaude Opus 4.6 7585a488f1 raster: move compositing code to hb-raster-image.cc
Move pixel helpers (div255, src_over, alpha_mul, pack_pixel) to
hb-raster.hh as shared inline functions with hb_raster_ prefix.
Move all blend mode implementations and hb_raster_composite_images()
to hb-raster-image.cc for reuse outside of paint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:35:19 -03:00
Behdad EsfahbodandClaude Opus 4.6 400a80282a raster: implement all 28 composite blend modes
Implement the full set of hb_paint_composite_mode_t blend modes:
- Porter-Duff (13): CLEAR, SRC, DEST, SRC_OVER, DEST_OVER, SRC_IN,
  DEST_IN, SRC_OUT, DEST_OUT, SRC_ATOP, DEST_ATOP, XOR, PLUS
- Separable (11): MULTIPLY, SCREEN, OVERLAY, DARKEN, LIGHTEN,
  COLOR_DODGE, COLOR_BURN, HARD_LIGHT, SOFT_LIGHT, DIFFERENCE, EXCLUSION
- HSL (4): HUE, SATURATION, COLOR, LUMINOSITY

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:31:28 -03:00
Behdad EsfahbodandClaude Opus 4.6 a6952e6523 raster: add hb_raster_paint_set_foreground() API
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:29:53 -03:00
Behdad EsfahbodandClaude Opus 4.6 49838acdad raster: add hb_raster_paint_t for color glyph rendering
Implement a software paint backend (hb_raster_paint_t) that renders
COLRv0/v1 color glyphs into BGRA32 pixel buffers with no external
dependencies. Implements all 14 hb_paint_funcs_t callbacks including
solid fills, linear/radial/sweep gradients, glyph clipping, rectangle
clipping, group compositing, and BGRA image blitting.

Update hb-raster utility to detect color fonts and use the paint path,
outputting PPM (RGB) instead of PGM (greyscale).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:24:44 -03:00
Behdad Esfahbod 5e4c105c6f cairo: remove raster mode API and hb-view --raster 2026-02-22 00:20:31 -03:00
Behdad Esfahbod afee4ee43b util: add hb-ft-raster-all 2026-02-21 20:22:48 -03:00
Behdad Esfahbod dd4758159a raster: use cubic curve-based chord error bound 2026-02-21 20:06:05 -03:00
Behdad EsfahbodandClaude Sonnet 4.6 6421457605 hb-raster: introduce HB_RASTER_FLAT_THRESH
Define HB_RASTER_FLAT_THRESH 0.25f for the maximum Bézier deviation in
pixels; each flattener squares it locally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 19:49:15 -03:00
Behdad Esfahbod 1a5d3f8c12 hb-raster: Use 6 bits of subpixel for positioning 2026-02-21 19:41:48 -03:00
Behdad Esfahbod c05dcff644 hb-raster: Remove stale comment 2026-02-21 19:33:28 -03:00
Behdad EsfahbodandClaude Sonnet 4.6 811da7bf30 hb-raster: use forward differencing for cubic Bézier flattening
Same approach as the quadratic: control-point deviation also shrinks 4×
per de Casteljau subdivision, so err² shrinks 16× per level, giving the
same upfront subdivision-count formula.  The cubic adds a constant third
difference d³f = 6·a·h³ and one extra accumulator in the inner loop.

Keep the recursive de Casteljau version as flatten_cubic_recursive
(static HB_UNUSED inline, depth=0 default).  flatten_cubic() dispatches
to flatten_cubic_fd() by default.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 19:29:26 -03:00
Behdad EsfahbodandClaude Sonnet 4.6 1f873fc632 hb-raster: keep both quadratic flatteners, dispatch to forward-differencing
Revive the recursive de Casteljau flattener as flatten_quadratic_recursive
(static inline, depth=0 default argument) alongside the forward-differencing
flatten_quadratic_fd.  flatten_quadratic() dispatches to the fd variant by
default.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 19:22:56 -03:00
Behdad EsfahbodandClaude Opus 4.6 f3be7f2ef1 hb-raster: use forward differencing for quadratic Bézier flattening
Exploit the property that quadratic Bézier error shrinks exactly 4×
per de Casteljau subdivision.  Compute the subdivision count upfront,
then iterate with constant-cost additions (forward differencing)
instead of recursive branching.  ~1.5% speedup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-21 19:05:50 -03:00
Behdad Esfahbod 38a3c13ec7 hb-raster: Use 8 bytes subpixel resolution
So we can generate smooth 256 levels of horizontal/vertical lines.
2026-02-21 18:38:04 -03:00
Behdad EsfahbodandClaude Opus 4.6 3ba27ca777 hb-raster: make fixed-point precision configurable
Replace all hardcoded 64/63/6/128/8192/4096/13 constants with
HB_RASTER_PIXEL_BITS / HB_RASTER_ONE_PIXEL / HB_RASTER_PIXEL_MASK /
HB_RASTER_FULL_COVERAGE macros.  Changing HB_RASTER_PIXEL_BITS from
6 (26.6, current) to 8 (24.8, like FreeType's rasterizer) switches
the entire pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-21 18:27:24 -03:00
Behdad EsfahbodandClaude Opus 4.6 ecce9de28a hb-raster: pass y_top directly to edge_sweep_row
Avoid recomputing y_top = py << 6 inside edge_sweep_row; the caller
already has it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-21 18:08:19 -03:00