* [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>