feat(libScePngEnc): implement PNG encoding #227

Merged
adriadam10 merged 1 commit from upstream-pr/227 into main 2026-10-02 19:08:05 +00:00
adriadam10 commented 2026-10-01 17:14:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T17:14:56Z.


What

Implements the four libScePngEnc exports on top of the shared PNG encoder in core/Decoder/Png (#175).

  • scePngEncQueryMemorySize / scePngEncCreate validate the create parameters and place a small tagged context in the caller's memory; scePngEncDelete invalidates it.
  • scePngEncEncode reads R8G8B8A8 or B8G8R8A8 rows with the given pitch, writes an RGB or RGBA PNG, and returns its size (also in PngEncOutputInfo). A too small output buffer returns DATA_OVERFLOW with an empty output info.
  • Decoder::Png::Encode gets optional EncodeOptions (compression level, filter) so compression_level and filter_type are honoured. stb keeps both in globals, so they are set under a mutex. Existing callers are unchanged.
  • Structs added to SceTypes.hpp, with size checks.

Signatures, struct layout, error codes (0x8069010x) and validation follow both KytyPS5 and shadPS4, which agree. Where they differ: max_filter_number up to 5 as in shadPS4; pitch is honoured for RGBA too (shadPS4 ignores it there).

Gap, listed in TechnicalDebt.md: stb cannot restrict adaptive filtering to a subset of filters, so a filter_type mask other than "all" uses its first filter.

Tested

Linux (CachyOS, GCC): new guest_png_enc test (core/libs/tests/GuestPngEnc.cpp) encodes a padded-pitch image in all four pixel format / color space combinations and decodes it back with Decoder::Png, checking every pixel; it also covers every error path and the output overflow. It fails on each of four injected bugs (BGR swap removed, pitch ignored, overflow not detected, compression level unchecked). decoder_png test extended for the new options. Full suite passes. Windows only through CI. No title tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4707068302 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/227). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T17:14:56Z. --- ### What Implements the four `libScePngEnc` exports on top of the shared PNG encoder in `core/Decoder/Png` (#175). - `scePngEncQueryMemorySize` / `scePngEncCreate` validate the create parameters and place a small tagged context in the caller's memory; `scePngEncDelete` invalidates it. - `scePngEncEncode` reads R8G8B8A8 or B8G8R8A8 rows with the given pitch, writes an RGB or RGBA PNG, and returns its size (also in `PngEncOutputInfo`). A too small output buffer returns `DATA_OVERFLOW` with an empty output info. - `Decoder::Png::Encode` gets optional `EncodeOptions` (compression level, filter) so `compression_level` and `filter_type` are honoured. stb keeps both in globals, so they are set under a mutex. Existing callers are unchanged. - Structs added to `SceTypes.hpp`, with size checks. Signatures, struct layout, error codes (`0x8069010x`) and validation follow both [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/main/src/libs/libPngEnc.cpp) and shadPS4, which agree. Where they differ: `max_filter_number` up to 5 as in shadPS4; pitch is honoured for RGBA too (shadPS4 ignores it there). Gap, listed in `TechnicalDebt.md`: stb cannot restrict adaptive filtering to a subset of filters, so a `filter_type` mask other than "all" uses its first filter. ### Tested Linux (CachyOS, GCC): new `guest_png_enc` test (`core/libs/tests/GuestPngEnc.cpp`) encodes a padded-pitch image in all four pixel format / color space combinations and decodes it back with `Decoder::Png`, checking every pixel; it also covers every error path and the output overflow. It fails on each of four injected bugs (BGR swap removed, pitch ignored, overflow not detected, compression level unchecked). `decoder_png` test extended for the new options. Full suite passes. Windows only through CI. No title tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-01 17:15:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T17:15:24Z.


Progress report (01eaae0 → 58f90ee)

📈 System libraries: 80.9% (+0.14%, +4 implemented functions)

✅ 4 implemented
Library Name
libScePngEnc scePngEncCreate
libScePngEnc scePngEncDelete
libScePngEnc scePngEncEncode
libScePngEnc scePngEncQueryMemorySize
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5936627127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/227#issuecomment-5936627127). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T17:15:24Z. --- <!-- progress-report --> ### Progress report (01eaae0 → 58f90ee) 📈 **System libraries**: 80.9% (+0.14%, +4 implemented functions) <details> <summary>✅ 4 implemented</summary> | Library | Name | | - | - | | libScePngEnc | `scePngEncCreate` | | libScePngEnc | `scePngEncDelete` | | libScePngEnc | `scePngEncEncode` | | libScePngEnc | `scePngEncQueryMemorySize` | </details>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!227
No description provided.