feat(libfreetype): implement the color palette and layer functions #15468
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15468"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by VakzOs on 2026-11-03T13:37:14Z.
What
The
libfreetypeexports+AF9KH7aZbc,qCyybpSyZzIandypZKJwPSVgQthrew. The verified NID name database names themFT_Palette_Data_Get,FT_Palette_SelectandFT_Get_Color_Glyph_Layer, andtools/nid_names.pycomputes the same NIDs for those names. They are now implemented insrc/Color.cpp.All three resolve the host
FT_Facebehind the guestFT_FaceRecfrom libSceFreeType and call the bundled FreeType 2.15.0, so their results are FreeType's own.FT_Palette_Data,FT_ColorandFT_LayerIteratorhold onlyFT_UShort,FT_UInt, bytes and pointers, so their console layouts match on Linux and Windows. The guest structs are copied field by field, andstatic_asserts pin their sizes:FT_Palette_Data_Getcopies the palette data on success. Its arrays point into the host face, as in FreeType.FT_Palette_Selectreturns the host face's palette array, read as the guest's 4-byte BGRA colours.FT_Get_Color_Glyph_Layerruns FreeType's iterator on a native copy and writes the iterator state back after every call.docs/dev/debt/libfreetype.mdmoves the three names from the callable-export placeholders to a functional entry.Tested
Linux, GCC 13, Release: the new
guest_legacy_freetype_colorpasses. No colour font ships with the FreeType submodule, so the test embeds a 588-byte font generated with fontTools (script below): four empty glyphs, a COLRv0 table where glyph 1 has layers 2 and 3, and a CPALv1 table with two palettes of two colours plus palette types and labels. The test opens it through the guest API and native FreeType and compares:Not copying the iterator back, or swapping two palette data fields, makes the test fail. The patched module exports the three NIDs and no
FT_*symbols. The test uses only public FreeType headers and an embedded font, so it also builds withANYPS5_USE_SYSTEM_DEPS. All 53guest_freetype*andguest_legacy_freetype*tests pass, andpython3 tools/check_conventions.py --base origin/mainpasses.How the test font was made
The 588-byte
ColorFontarray is generated with fontTools 4.53.1 by the script below. Theheadtimestamps are pinned, so it reproduces the array byte for byte (checked withcmp);xxd -i color.ttfgives the array. SHA-256:ac87d356df87ef60bef614c6a9c4e33500f02671846d87480cc0617bc21e8160.Side note: FreeType 2.15.0 reads CPALv1's 32-bit palette types as 16-bit values, so
palette_flagscomes back as{0, 1}for types{1, 2}. The wrapper returns what FreeType returns, and the test only compares with native FreeType there.tools/pr_overlap.py --branchreports the same PRs as #15447: #15408 (shared newCMakeLists.txtand adjacent lines) and #10606 and #10609 (GuestObjects.hpp, which merges cleanly with both; they already conflict withmain). No export is shared.Not tested on hardware or with a title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T08:05:41Z.
Review: COMMENTED
Checked head
afd33dbd38206891177ec324e4993a5ff7a1597c, base4f41f4c375f5abb487dbd184fbc150f31994d762.No issue found in the three palette/layer functions. I built the production modules on Linux with pinned FreeType
37515cf56ba3349656049edbed89ffc6f6466f2d. The existing color test and a separate ownership probe pass, including after NID patching. Loader traces confirm the palette imports bind to libfreetype.The probe loads generated CPALv0, types-only CPALv1, and labels-only CPALv1 fonts through the guest API. It checks fixed BGRA bytes, absent arrays, invalid-output canaries, and foreground layer index
0xffff. A write through face A's returned palette reaches its realTT_Facestorage. Face B stays unchanged, including after A closes. Switching A from 0 to 1 and back to 0 restores the original bytes.Three deliberate mutations fail the intended assertions: detached palette storage, shared palette storage, and omitted null-field writes. Conventions also pass.
The source checks use pinned ftcolor.c and ttcpal.c. This uses an isolated CMake parent with the production module targets, not a full project build. Unused guest libc imports remain unresolved. No Windows, renderer, title, or console behavior is checked.