Files
harfbuzz/src
Behdad EsfahbodandArthur031221 f20f4c20bc [raster] Fix background color and stride handling (#6310)
* [raster] Fix background color premultiplication and stride handling

ensure_initialized()'s background fill had two bugs:

1. The background pixel was built with HB_COLOR(blue, green, red,
   alpha), which packs channels through HB_TAG's bit layout
   (b<<24 | g<<16 | r<<8 | a). Every other pixel in this buffer is
   premultiplied BGRA32 (b | g<<8 | r<<16 | a<<24, see hb-raster.hh's
   SRC_OVER comment: "premultiplied src over premultiplied dst"), so
   the background was both unpremultiplied and in the wrong byte
   positions: a half-transparent red background (blue=0, green=0,
   red=255, alpha=128) filled the buffer with 0x0000ff80 instead of
   the correct premultiplied 0x80800000.

2. The fill then wrote that pixel into a contiguous run of
   width * height uint32_t slots starting at the buffer origin,
   assuming every row is packed at exactly width * 4 bytes. Once a
   caller sets a stride wider than that (row padding, alignment,
   embedding the glyph image inside a larger atlas), the fill drifts
   across row boundaries after the first row, leaving later rows
   partially uninitialized or wrongly colored.

Build bg with color_to_premul_pixel(), the same helper solid fills
already use, and fill row by row using the actual stride.

Added two regression tests in test/api/test-raster.cc:
test_background_premultiplied (default stride, half-alpha background,
checks the stored pixel is premultiplied) and test_background_stride
(stride much wider than width * 4, opaque background, checks every
row).

Assisted-by: Claude

* [raster] Handle unaligned background strides

A caller-supplied stride does not have to be word-aligned, so casting
each row to uint32_t * can perform misaligned stores.

Use hb_packed_t<uint32_t> for the row writes, and exercise an odd
stride in the regression test with byte-wise pixel checks.

Tests: meson test -C build

Assisted-by: Codex <noreply@openai.com>

---------

Co-authored-by: Arthur031221 <levi74108520963@gmail.com>
2026-10-01 20:11:49 -06:00
..
2026-09-21 11:02:29 -06:00
2026-09-09 12:15:31 -06:00
2026-08-12 18:27:23 -06:00
2026-03-10 09:56:47 -03:00
2026-03-09 22:37:07 -06:00
2024-03-30 02:20:21 +02:00
2025-08-15 00:54:52 -06:00
2026-07-31 04:31:26 +03:00
2026-07-31 04:31:26 +03:00
2025-03-13 01:07:35 -06:00
2023-01-12 10:44:08 -07:00
…
2025-10-17 15:23:05 -06:00
2026-02-24 16:57:44 -03:00
2025-03-12 23:56:52 -06:00
2023-02-21 18:07:53 +02:00
2026-08-31 11:54:42 -06:00
2026-09-21 00:41:07 +03:00
2026-07-31 04:31:26 +03:00
2026-09-21 00:41:07 +03:00
2026-09-21 00:41:07 +03:00
2025-03-12 18:27:27 -06:00
2025-07-20 21:40:37 +03:00
2025-03-24 00:33:53 +02:00
2025-09-15 23:56:25 -06:00
…
…
2026-04-20 05:10:48 +02:00
2026-04-20 05:10:48 +02:00
2024-10-27 16:14:53 -07:00
…
2023-08-25 07:51:05 -06:00
2023-06-03 14:56:47 -06:00
2025-04-08 01:58:10 -06:00
2025-08-07 22:38:58 -06:00
2026-07-31 17:49:40 +03:00
2026-07-31 17:49:40 +03:00
2023-02-11 23:52:58 +02:00
2025-08-07 22:38:58 -06:00
2026-03-19 00:45:24 +02:00
2025-11-11 12:29:06 -07:00
2024-04-16 17:10:09 -06:00
2026-07-31 04:31:26 +03:00
2026-09-21 00:41:07 +03:00
2026-09-21 00:41:07 +03:00
2026-04-18 10:58:44 -06:00
2025-11-10 02:55:44 -07:00
2026-09-21 00:41:07 +03:00
2025-09-23 11:23:03 -04:00
2026-08-26 22:27:05 +03:00
2026-08-19 16:00:05 -06:00
2025-07-23 21:39:23 +03:00
2025-08-07 22:38:58 -06:00
2024-08-23 08:58:50 -06:00
2026-07-31 17:49:40 +03:00
2025-01-11 18:13:18 +02:00
2026-07-30 12:00:47 -06:00
2026-08-25 14:47:33 -06:00
2026-07-31 17:49:40 +03:00
2025-07-24 22:47:08 -06:00
…
2023-04-27 00:48:00 +02:00
2025-08-28 15:58:39 -06:00
2026-04-20 01:29:49 +02:00
2026-04-20 01:29:49 +02:00
2026-10-01 02:34:38 +03:00
2023-03-31 17:33:45 -06:00
2025-03-07 18:19:29 -07:00
2026-08-12 18:33:09 -06:00
…
2023-01-12 17:04:24 -07:00