Skip to content

Honor JPEG encoding options when keeping gain maps - #4600

Draft
gregbenz wants to merge 2 commits into
lovell:mainfrom
gregbenz:codex/gainmap-encoder-pr-final
Draft

Honor JPEG encoding options when keeping gain maps#4600
gregbenz wants to merge 2 commits into
lovell:mainfrom
gregbenz:codex/gainmap-encoder-pr-final

Conversation

@gregbenz

@gregbenz gregbenz commented Sep 8, 2026

Copy link
Copy Markdown

When keeping a gain map, sharp currently ignores some requested JPEG settings for the SDR base photograph. This fixes cases such as:

  • progressive: true now produces a progressive base JPEG.
  • optimiseCoding: true now enables optimized Huffman coding for the base JPEG, allowing smaller files without changing decoded pixels.
  • At quality 95, chromaSubsampling: '4:2:0' now produces a 4:2:0 base JPEG instead of 4:4:4.

This works for both file and buffer output. Gain-map encoding stays the same, with chroma subsampling disabled. There are no new public APIs, and generating gain maps from scRGB works as before.

This builds on #4599, so its source-lifetime fix also appears in the diff until that PR is merged. The encoder changes are in the final commit, 53f3c89, so they can be reviewed separately.

In matched local builds on macOS, all three new tests fail without the fix, and all 11 gain-map tests pass with it. They check the base JPEG settings, decode the gain map, and confirm that changing optimized coding leaves the decoded base and map pixels unchanged.

The API docs are also updated. JavaScript lint passes, and C++ lint previously passed on the same production code. This uses the base-image JPEG options added in libvips/libvips#4975, which is already merged but still needs to reach sharp’s released dependency bundle. Validation against that bundle, the full unit suite, and other platforms remains outstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant