feat(pngdec): implement the PNG decoder #175
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/175"
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 Qznad on 2026-09-30T10:15:58Z.
What
Implements the 5
libScePngDecentry points (previouslyNotImplemented_nid_no_patch) and addscore/Decoder/Png, the PNG counterpart ofcore/Decoder/Jpegrequested in #146: a shared encoder/decoder with no PRX dependency, so the relinker can use it for the executable icon.core/Decoder/Png(static librarydecoder_png):Decoder::Png::Decode(png)returns RGBA8 for every PNG colour type and bit depth (palette,tRNS, 1-16 bit, Adam7), andDecoder::Png::Encode(pixels, width, height, channels)writes 1-4 channel PNGs. Both use the existingnothings/stbsubmodule (STBI_ONLY_PNG, no stdio, static stb symbols, hidden visibility).Decoder::Png::ParseHeader(png)reads IHDR and walks the chunks up toIDATfortRNS, because stb does not expose colour type, bit depth, interlace or transparency. Chunk lengths are bounds-checked against the buffer.libScePngDec:SceTypes.hppmatch shadPS4's reverse engineering and are unchanged; sizes are now checked withstatic_assert. Error codes0x80690001-0x80690012and the NIDs follow shadPS4.QueryMemorySize/Create/Delete: the handle lives in the caller's memory, aligned to 8, and points to itself;Deleteclears it, so stale and foreign handles returnINVALID_HANDLE.ParseHeadermaps the PNG header toImageInfo(colour space 2/3/4/18/19, Adam7 andtRNSflags).Decodewrites R8G8B8A8 or B8G8R8A8 rows atimage_pitch(0 means packed), fills alpha withalpha_valuewhen the image has no alpha ortRNS, reduces 16-bit to 8-bit, and returns(width << 16) | height, or 0 when either is above 32767, as shadPS4 does.Differences from shadPS4 and assumptions (no documentation available):
QueryMemorySizereturns 0x20; shadPS4 returns the size of its own libpng handle. Memory smaller than that returnsINVALID_WORK_MEMORY.(height - 1) * pitch + width * 4aboveimage_mem_sizereturnsINVALID_SIZE, a pitch belowwidth * 4returnsINVALID_PARAM. shadPS4 writes without checking.INVALID_PARAMfromQueryMemorySizeas fromCreate(shadPS4 returnsINVALID_ADDRthere only).INVALID_SIZE, a nullimage_infoinParseHeaderreturnsINVALID_ADDR, an unreadable headerINVALID_DATA, a failed decodeDECODE_ERROR.max_image_widthis validated at creation but not enforced at decode.Not supported: the 16-bit output attribute throws
std::runtime_errorwhen the PNG really is 16-bit; 8-bit images still decode with it.Tested
Linux (GCC 15.2,
BUILD_TESTING=ON): full build with no warnings in the changed files,ctest66/66 pass, including the 2 new tests:decoder_png: exact round trips for 1-4 channels, Pillow-made fixtures (2-bit palette withtRNS, 16-bit gray, 1-bit gray), hand-built headers (interlace, invalid colour type and bit depth, zero width, bad signature, oversized chunk length, truncation).guest_png_dec: every error path, stale and misaligned handles, RGBA and BGRA output with padded rows, alpha fill, palette transparency, 16-bit input, the packed return value, and the 16-bit output attribute.Also checked:
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion; both tests run clean under ASan and UBSan.tRNS, RGBA, palette with and withouttRNS, and a hand-built Adam7 interlaced RGB image) decoded throughscePngDecDecodeas B8G8R8A8 with a padded pitch match Pillow pixel for pixel, with the padding untouched.libScePngDec.prxexports exactlym0uW+8pFyaw,WC216DD3El4,QbD+eENEwo8,U6h4e5JRPaQand-6srIGbLTIU.Not tested with a title.
Checklist
main; no other open PR implements the same functionslibScePngEnconDecoder::Png::Encodefollows separately)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (16-bit output throws; no new silent stubs).mdfiles or images added to the repository (attach them to this PR)nothings/stb)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-09-30T10:16:23Z.
Progress report (
fc05962→a0e2f88)📈 System libraries: 74.8% (+0.17%, +5 implemented functions)
✅ 5 implemented
scePngDecCreatescePngDecDecodescePngDecDeletescePngDecParseHeaderscePngDecQueryMemorySize