Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mozjpeg instead of libjpeg-turbo #20

Merged
merged 1 commit into from Aug 10, 2022
Merged

Conversation

atjn
Copy link
Contributor

@atjn atjn commented Aug 10, 2022

Hello again :)

I would strongly recommend using mozjpeg for JPEG encoding. It is identical to libjpeg-turbo, but has some added patches that significantly improves compression without sacrificing image quality. It is used in many popular image suites, including other ports of libvips.

If you need to use libjpeg-turbo to test bleeding-edge updates, it is very easy to change back to. I can even add a flag to automatically switch between the two if you'd like.

@kleisauke kleisauke added the enhancement New feature or request label Aug 10, 2022
@kleisauke kleisauke added this to the v0.0.4 milestone Aug 10, 2022
Copy link
Owner

@kleisauke kleisauke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @atjn,

Thanks for the PR! The reason that I used libjpeg-turbo instead of mozjpeg was that the latest version of mozjpeg (4.0.3) was a bit out-of-sync. But you're right, we could just build against mozjpeg's master branch instead (which is based upon libjpeg-turbo 2.1.3).

Note that libvips resets to libjpeg-turbo's JCP_FASTEST defaults so this can be considered a "no-op" unless mozjpeg features are explicitly set, see: lovell/sharp-libvips#89.

This will be in v0.0.4.

@kleisauke
Copy link
Owner

FWIW, the Windows CI failure is unrelated to this and should be fixed with commit 5823efb.

@kleisauke kleisauke merged commit cbcf752 into kleisauke:master Aug 10, 2022
kleisauke added a commit that referenced this pull request Aug 10, 2022
@atjn
Copy link
Contributor Author

atjn commented Aug 10, 2022

Cool!

The reason that I used libjpeg-turbo instead of mozjpeg was that the latest version of mozjpeg (4.0.3) was a bit out-of-sync.

Yeah that is a bit weird.

Note that libvips resets to libjpeg-turbo's JCP_FASTEST defaults so this can be considered a "no-op" unless mozjpeg features are explicitly set, see: lovell/sharp-libvips#89.

Good to know, thanks!
Would it make sense for this port to enable some mozjpeg features by default? I would be happy to play around with it, if you are open to it.

@atjn atjn deleted the mozjpeg branch August 10, 2022 11:56
@kleisauke
Copy link
Owner

kleisauke commented Aug 10, 2022

Would it make sense for this port to enable some mozjpeg features by default?

Good question. I think we shouldn't deviate too much from libvips default settings. The mozjpeg settings can be controlled with these options:

wasm-vips/lib/vips.d.ts

Lines 7316 to 7331 in a51b0e2

/**
* Apply trellis quantisation to each 8x8 block.
*/
trellis_quant?: boolean
/**
* Apply overshooting to samples with extreme values.
*/
overshoot_deringing?: boolean
/**
* Split spectrum of dct coefficients into separate scans.
*/
optimize_scans?: boolean
/**
* Use predefined quantization table with given index.
*/
quant_table?: number

Which are guarded in libvips with the HAVE_JPEG_EXT_PARAMS condition:
https://github.com/libvips/libvips/blob/7e961b46718b32d654a1c10e9261cdbbd5ccb9b6/libvips/foreign/vips2jpeg.c#L613-L670

I'm aware that sharp has a shortcut option that would enable these settings at once (it also enables optimize_coding by default), see:
https://sharp.pixelplumbing.com/api-output#jpeg

A better option would be to provide a polyfill for sharp, based on wasm-vips, as discussed in this Twitter thread:
https://twitter.com/lovell/status/1395710714799665163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants