Skip to content

Commit 6cd6127

Browse files
authored
fix(JXL): Correctly set Quality for JPEG XL (#4933)
Distance in JPEG XL isn't linear, causing previous quality settings to scale between lossless and visually lossless, instead of lossless and the lowest quality. Quality | libjxl Distance | Old OIIO Distance |--------|------|------| | 99 | 0.19 | 0.01 | | 90 | 1.00 | 0.01 | | 80 | 1.90 | 0.01 | | 70 | 2.80 | 0.01 | | 60 | 3.70 | 0.02 | | 50 | 4.60 | 0.02 | | 40 | 5.50 | 0.03 | | 30 | 6.40 | 0.03 | | 20 | 8.13 | 0.05 | | 10 | 13.27 | 0.10 | | 1 | 24.24 | 1.00 | | 0 | 25.00 | Error | Thankfully libjxl has a built in function to convert Quality to Distance, so I've swapped it in. Unable to test it myself, but it's a simple fix that I ran by another libjxl dev too. --------- Signed-off-by: Jonathan Brown <[email protected]>
1 parent dcdb216 commit 6cd6127

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/jpegxl.imageio/jxloutput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ JxlOutput::open(const std::string& name, const ImageSpec& newspec,
228228
lossless = true;
229229
} else {
230230
m_basic_info.uses_original_profile = JXL_FALSE;
231-
JxlEncoderSetFrameDistance(
232-
m_frame_settings,
233-
1.0f / static_cast<float>(compqual.second));
231+
const float distance = JxlEncoderDistanceFromQuality(
232+
compqual.second);
233+
JxlEncoderSetFrameDistance(m_frame_settings, distance);
234234
JxlEncoderSetFrameLossless(m_frame_settings, JXL_FALSE);
235235
}
236236
} else { // default to lossless

0 commit comments

Comments
 (0)