fix(jpegenc): honor chroma sampling and encode true grayscale JPEGs #485

Merged
RomainROCH merged 1 commit from upstream-pr/485 into main 2026-10-06 09:29:12 +00:00
RomainROCH commented 2026-10-04 03:41:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RomainROCH on 2026-10-04T03:41:31Z.


What

Encode the requested chroma sampling explicitly and produce grayscale JPEGs with one component. The previous writer selected 4:2:0 or 4:4:4 from quality alone, so accepted 4:2:2 requests produced 4:2:0 and grayscale requests produced three components.

Build libjpeg-turbo 3.2.0 from its pinned source submodule as a static library. Use its TurboJPEG API for encoding; retain stb for decoding and header inspection. Remove the sampling-dependent quality cap and the resolved technical-debt entry. Preserve the existing guest API's parameter restrictions.

Tested

Current tested commit: 4b1093d7b992dd3d99af33303ecaa2cac3fdbe77, synchronized with main at 2cf901bcffef9ee1e12fe272e63a9978ceefed0d. The documentation conflict is resolved: current technical-debt entries are preserved, with only the obsolete JPEG entry removed. Documentation links and git diff --check pass. The PR's code blobs are unchanged by this synchronization.

  • Upstream Build: Linux passed. Windows compilation and library builds passed, but CTest failed in agc_driver (0xc0000374) and guest_audio_in_no_device (0xc0000409). JPEG tests passed. The Windows PR check remains failed; rerunning it requires maintainer permissions.
  • Independent fork Build at the same commit: Linux and Windows passed. Both previously failing tests passed all three repetitions on Windows; the upstream failures were not reproduced in this execution.

Both workflows used --repeat until-fail:3, with 183 registered CTest cases per platform. Eight Linux cases and 43 Windows cases were skipped in each workflow. The failing test sources and their target dependencies match main and do not depend on JPEG. The exact base Build also passed; the cause of the upstream Windows failures remains unconfirmed.

Previous focused validation at 3c54f6f7a8e2fcd26c10c6b7e60039bd92c16999: Windows x64, MinGW-w64 GCC 15.2.0, using the project's libc runtime. Codec and guest encoder tests inspect SOF component counts and sampling factors for 4:4:4, 4:2:2, 4:2:0 and grayscale, including odd dimensions and 4:2:2 at quality 100, plus decoded pixels and existing argument/output-capacity errors. An upstream probe confirmed that the previous encoder produced three-component grayscale output and switched sampling from 0x22 at quality 90 to 0x11 at quality 100.

No game testing; synthetic image tests do not establish title compatibility.

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; no silent stubs added
  • No notes, investigation files or images added to the repository
  • 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:4731659982 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/485). Originally posted by [RomainROCH](https://github.com/RomainROCH) on 2026-10-04T03:41:31Z. --- ### What Encode the requested chroma sampling explicitly and produce grayscale JPEGs with one component. The previous writer selected 4:2:0 or 4:4:4 from quality alone, so accepted 4:2:2 requests produced 4:2:0 and grayscale requests produced three components. Build libjpeg-turbo 3.2.0 from its pinned source submodule as a static library. Use its TurboJPEG API for encoding; retain stb for decoding and header inspection. Remove the sampling-dependent quality cap and the resolved technical-debt entry. Preserve the existing guest API's parameter restrictions. ### Tested Current tested commit: `4b1093d7b992dd3d99af33303ecaa2cac3fdbe77`, synchronized with `main` at `2cf901bcffef9ee1e12fe272e63a9978ceefed0d`. The documentation conflict is resolved: current technical-debt entries are preserved, with only the obsolete JPEG entry removed. Documentation links and `git diff --check` pass. The PR's code blobs are unchanged by this synchronization. - [Upstream Build](https://github.com/boykopovar/AnyPS5/actions/runs/37223411751): Linux passed. Windows compilation and library builds passed, but CTest failed in `agc_driver` (`0xc0000374`) and `guest_audio_in_no_device` (`0xc0000409`). JPEG tests passed. The Windows PR check remains failed; rerunning it requires maintainer permissions. - [Independent fork Build at the same commit](https://github.com/RomainROCH/AnyPS5/actions/runs/37223821064): Linux and Windows passed. Both previously failing tests passed all three repetitions on Windows; the upstream failures were not reproduced in this execution. Both workflows used `--repeat until-fail:3`, with 183 registered CTest cases per platform. Eight Linux cases and 43 Windows cases were skipped in each workflow. The failing test sources and their target dependencies match `main` and do not depend on JPEG. The [exact base Build](https://github.com/boykopovar/AnyPS5/actions/runs/37193766065) also passed; the cause of the upstream Windows failures remains unconfirmed. Previous focused validation at `3c54f6f7a8e2fcd26c10c6b7e60039bd92c16999`: Windows x64, MinGW-w64 GCC 15.2.0, using the project's libc runtime. Codec and guest encoder tests inspect SOF component counts and sampling factors for 4:4:4, 4:2:2, 4:2:0 and grayscale, including odd dimensions and 4:2:2 at quality 100, plus decoded pixels and existing argument/output-capacity errors. An upstream probe confirmed that the previous encoder produced three-component grayscale output and switched sampling from 0x22 at quality 90 to 0x11 at quality 100. No game testing; synthetic image tests do not establish title compatibility. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [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
oneandonlydean commented 2026-10-04 07:10:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:10:41Z.


Thanks, this closes the TechnicalDebt entry properly: grayscale requests now give a one-component JPEG, 4:2:2 is honoured, and libjpeg-turbo 3.2.0 comes in as a pinned submodule built from source. It conflicts with main now in docs/dev/TechnicalDebt.md, because the neighbouring lines changed (#350 removed the relinker icon entry and #434 edited the --to-intel one). Could you rebase? Once that's resolved I think it's ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977590326 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/485#issuecomment-5977590326). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T07:10:41Z. --- Thanks, this closes the TechnicalDebt entry properly: grayscale requests now give a one-component JPEG, 4:2:2 is honoured, and libjpeg-turbo 3.2.0 comes in as a pinned submodule built from source. It conflicts with main now in `docs/dev/TechnicalDebt.md`, because the neighbouring lines changed (#350 removed the relinker icon entry and #434 edited the `--to-intel` one). Could you rebase? Once that's resolved I think it's ready.
oneandonlydean commented 2026-10-05 07:26:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T07:26:28Z.


Thanks for the earlier rebase. Two TechnicalDebt changes landed on main today next to the lines this PR edits, so docs/dev/TechnicalDebt.md conflicts again:

  • #588 rewrote the --to-intel line (SHA-1 with a memory operand is now lowered, so it now reads "SHA-1 and SHA-256 instructions with a RIP-relative operand fail ...").
  • #537 added the v_rcp, v_rsq, v_sqrt, v_log, v_exp, v_sin and v_cos line right after the libSceJpegEnc line that this PR removes.

The fix is to remove only the libSceJpegEnc line and keep main's version of the other two. Could you rebase once more?

The Windows job of the last run also failed, in agc_driver and guest_audio_in_no_device. Neither touches the JPEG code, so it may be unrelated, but the rebase will give a fresh run to check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5990011265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/485#issuecomment-5990011265). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T07:26:28Z. --- Thanks for the earlier rebase. Two TechnicalDebt changes landed on main today next to the lines this PR edits, so `docs/dev/TechnicalDebt.md` conflicts again: - #588 rewrote the `--to-intel` line (SHA-1 with a memory operand is now lowered, so it now reads "SHA-1 and SHA-256 instructions with a RIP-relative operand fail ..."). - #537 added the `v_rcp, v_rsq, v_sqrt, v_log, v_exp, v_sin and v_cos` line right after the libSceJpegEnc line that this PR removes. The fix is to remove only the libSceJpegEnc line and keep main's version of the other two. Could you rebase once more? The Windows job of the last run also failed, in `agc_driver` and `guest_audio_in_no_device`. Neither touches the JPEG code, so it may be unrelated, but the rebase will give a fresh run to check.
oneandonlydean commented 2026-10-06 05:34:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:30Z.


Thanks, the rebase removes only the libSceJpegEnc line and keeps main's --to-intel and v_rcp, v_rsq, ... lines, as I asked, and the encoder commit is otherwise unchanged. The Linux job passed. The Windows job of this run never started because no runner picked it up, so it needs a re-run. That's on the CI side, not this branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010067800 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/485#issuecomment-6010067800). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T05:34:30Z. --- Thanks, the rebase removes only the libSceJpegEnc line and keeps main's `--to-intel` and `v_rcp, v_rsq, ...` lines, as I asked, and the encoder commit is otherwise unchanged. The Linux job passed. The Windows job of this run never started because no runner picked it up, so it needs a re-run. That's on the CI side, not this branch.
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!485
No description provided.