feat(jpegenc): implement the JPEG encoder #146
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/146"
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-29T09:15:46Z.
What
Implements the 4
libSceJpegEncentry points (previouslyNotImplemented_nid_no_patchwith no parameters), and adds a shared JPEG encoder/decoder incore/Decoder/Jpegthat has no PRX dependency, so the relinker can use it later for the executable icon.core/Decoder/Jpeg(static librarydecoder_jpeg):Decoder::Jpeg::Encode(pixels, width, height, channels, quality)andDecoder::Jpeg::Decode(jpeg)on top of stb (stb_image_write.h/stb_image.h), added as thenothings/stbsubmodule and compiled from source insrc/Jpeg.cpponly. stb is compiled withSTB_*_STATIC,STBI_ONLY_JPEGand no stdio, and the library uses hidden visibility, so nothing but the 4 Sony functions is exported fromlibSceJpegEnc.prx.libSceJpegEnc:JpegEncCreateParam,JpegEncEncodeParam,JpegEncOutputInfoinSceTypes.hpp, sizes checked withstatic_assert. Layouts, error codes (0x80650101-0x80650104), the 0x800 memory size and the validation rules follow shadPS4's reverse engineering of the same library.QueryMemorySize/Create/Delete: the handle is placed in the caller's memory aligned to 0x20 and points to itself;Deleteclears it, so stale, misaligned and foreign handles returnINVALID_HANDLE.Encode: validates every argument, reads the image row by row using the pitch, converts R8G8B8A8, B8G8R8A8, Y8U8Y8V8 and Y8 to packed RGB or gray, encodes, and copies the result into the caller's buffer.output_infomay be null.Assumptions (no documentation available):
compression_ratiois 0-255 with higher meaning more compression, as documented for the PS VitasceJpegEncoderSetCompressionRatio. It maps linearly to quality 100..1, capped at 90 for subsampled output so stb emits 4:2:0.jpeg_sizereturnsINVALID_SIZEand writes nothing.INVALID_PARAM(shadPS4 does not check it).Not supported: MJPEG encode mode and a positive restart interval throw
std::runtime_error. 4:2:2 requests are encoded as 4:2:0, and grayscale requests as a 3-component JPEG with neutral chroma; both are listed inTechnicalDebt.md.Tested
Linux (GCC 15.2,
BUILD_TESTING=ON): full build with no warnings in the changed files,ctest60/60 pass, including the 2 new tests:decoder_jpeg: RGB and gray round trips throughEncode/Decode, invalid arguments, garbage input.guest_jpeg_enc: every create/delete/encode error path, stale and misaligned handles, and real encodes of RGBA with padded rows, BGRA, Y8U8Y8V8 and Y8 that are decoded back and compared with the input.Also checked:
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion, and both tests plus an edge-case program (1x1, 37x23 with padded pitch, 33x17 Y8U8Y8V8, 1920x1080 B8G8R8A8 with a 2048-pixel pitch, several compression ratios) run clean under ASan and UBSan.compression_ratiorises.libSceJpegEnc.prxexports exactlyK+rocojkr-I,j1LyMdaM+C0,QbrU0cUghEMando6ZgXfFdWXQ, the NIDs shadPS4 registers for these functions.Not tested on Windows or with a title.
Checklist
main; no other open PR implements the same functionscore/Decoder/Pnggoes in a separate PR, as discussed)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (unsupported modes throw; the two encoding approximations are listed under Functional).mdfiles or images added to the repository (attach them to this PR)nothings/stb)Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-29T09:54:31Z.
Do you know the lightest submodule that will encode and decode PNG and JPG files? Relinker will also need decoder and encoder functionality (to set the icon), and relinker shouldn't depend on PRX. So, you should place the decoder and encoder in the core/Decoder/Png and core/Decoder/Jpeg folders.
Imported from boykopovar/AnyPS5. Originally posted by Qznad on 2026-09-29T10:11:40Z.
Thanks for the direction. stb (nothings/stb) looks like the lightest option: it is header-only with no dependencies, and one submodule covers all four cases (stb_image_write.h encodes PNG and JPEG, stb_image.h decodes both). It is already added as a submodule in this branch.
I will move the JPEG encode/decode code into core/Decoder/Jpeg as a small library with no PRX dependency, and make libSceJpegEnc use it, so the relinker can use it later for icons.
Should core/Decoder/Png also be part of this PR, or would you prefer it in #86 or a separate follow-up, to keep this PR to one topic?
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-29T13:09:05Z.
it's better to make a separate pr for png
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-09-29T14:32:42Z.
Progress report (
2e97617→f9f02e3)📈 System libraries: 72.65% (+0.14%, +4 implemented functions)
✅ 4 implemented
sceJpegEncCreatesceJpegEncDeletesceJpegEncEncodesceJpegEncQueryMemorySize