google / jpegli

BSD 3-Clause "New" or "Revised" License
132 stars 13 forks source link

Consider use of libjpeg-turbo extension framework for control over encoder settings #45

Open lovell opened 1 month ago

lovell commented 1 month ago

Hello, thanks for creating jpegli and many of the JPEG-XL features it descends from. This suggestion was originally discussed at https://github.com/lovell/sharp/issues/4018#issuecomment-2053981017 and I'm opening an issue here on the recommendation of https://github.com/lovell/sharp/issues/4018#issuecomment-2437382704


The libjpeg-turbo approved (and mozjpeg implemented) method of configuring a JPEG encoder whilst maintaining ABI compatibility is to use its extension framework.

This is provided via a series of functions such as jpeg_c_bool_param_supported and jpeg_c_set_bool_param (with similar functions for integer, float etc. types). These were added to mozjpeg via https://github.com/mozilla/mozjpeg/commit/db2986c96fcebe10c8700081578e5305fd7bc7dc

As well as fine-grained control over specific encoder features, there is also a simpler JINT_COMPRESS_PROFILE setting that provides a single switch between "use all features" JCP_MAX_COMPRESSION and "do nothing, behave like libjpeg" JCP_FASTEST. This was added to mozjpeg via https://github.com/mozilla/mozjpeg/commit/3e2cf6909c295d6dce5b8d3fd0612d2788a0e55a

For reference, the complete set of features mozjpeg exposes via the extension framework can be seen at https://github.com/mozilla/mozjpeg/blob/6c9f0897afa1c2738d7222a0a9ab49e8b536a267/jpeglib.h#L277-L314