Skip to content

Conversation

@LucasChollet
Copy link
Member

@LucasChollet LucasChollet commented Oct 26, 2025

Here are some before/after on the images:

Image Buggie @ q75 Buggie @ q90 Buggie @ q100 Big image @ q75 Big image @ q90 Big image @ q100
Before 3240 5111 13.6kB 1 630kB 2 675kB 8 516kB
After 2924 4729 11.8kB 1 542kB 2 594kB 8 161kB
Difference -316, -10% - 383, -7.5% - 1.8kB, -13% -87kB, -5% -80kB, -3% -354kB, -4%

I expected performance to be worse as we're doing more work, but it turns out that this reduces the runtime for big_image.jpg @ q100 by 12%.

@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Oct 26, 2025
This will allow us to insert a pass to compute the most optimal Huffman
tables for this image.
Doing this a bit out of the natural order will allow us to compute
optimized huffman tables.

Note that we need to set the quantizations tables before calling
`fdct_and_quantization()`. So let's move this step to an explicit method
call in `add_image()`.
Compared to master, this gives approximatively 10% size reduction on
buggie.png and a 4% reduction on `big_image.jpg`.
Copy link
Contributor

@nico nico left a comment

Choose a reason for hiding this comment

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

Nice!

It'd be nice to have fewer huffman construction algorithms in the tree (see below), but this is a great step forward :)

if (mode == Mode::CMYK || i < 3) {
TRY(encode_dc(component, i));
TRY(encode_ac(component, i));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit: i find the unrolled version on the lhs easier to understand…)

@nico nico merged commit d8941f0 into SerenityOS:master Nov 3, 2025
14 checks passed
@github-actions github-actions bot removed the 👀 pr-needs-review PR needs review from a maintainer or community member label Nov 3, 2025
@nico
Copy link
Contributor

nico commented Nov 3, 2025

(first commit reminds me a bit of 5th commit of #24633 :))

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.

2 participants