ladybird/Userland
Nico Weber f562c470e2 LibGfx+LibPDF: Simpler and faster N-D linear sampling
Previously, if we wanted to to e.g. do linear interpolation in 2-D,
we'd get a sample point like (1.3, 4.4), then get 4 samples around
it at (1, 4), (2, 4), (1, 5), (2, 5), then reduce the 4 samples
to 2 samples by computing the combined samples
`0.3 * f(1, 4) + 0.7 * f(2, 4)` and `0.3 * f(1, 5) + 0.8 * f(2, 5)`,
and then 1-D linearly blending between these two samples with the
factor 0.4. In the end we'd multiply the first value by 0.3 * 0.4,
the second by 0.7 * 0.4, the third by 0.3 * 0.6, and the third by
0.7 * 0.6, and then sum them all up.

This requires computing and storing 2**N samples, followed by
another 2**N iterations to combine the 2**N sampls to a single value.
(N is in practice either 4 or 3, so 2**N isn't super huge.)

Instead, for every sample we can directly compute the product of
weights and sum them up directly. This lets us omit the second loop
and storing 2**N values, in exchange for doing an additional O(n)
work to compute the product.

Takes

    Build/lagom/bin/image --no-output --invert-cmyk \
        --assign-color-profile \
            Build/lagom/Root/res/icc/Adobe/CMYK/USWebCoatedSWOP.icc \
        --convert-to-color-profile serenity-sRGB.icc \
        cmyk.jpg

form 3.42s to 3.08s on my machine, almost 10% faster (and less code).

Here cmyk.jpg is a 2253x3080 cmyk jpeg, and USWebCoatedSWOP.icc is an
mft2 profile with input tables with 256 samples and a 9x9x9x9 CLUT.

The LibPDF change is covered by TEST_CASE(sampled) in LibPDF.cpp,
and the LibGfx change is basically the same change as the one in
LibPDF (where the test results don't change) and the output
subjectively looks identical. So hopefully this causes indeed no
behavior change :^)
2024-02-04 21:49:23 +01:00
..
Applets Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
Applications Ladybird: Add IPC call for creating a new child tab 2024-02-03 20:51:37 -05:00
BuggieBox checksum: Add support for BLAKE2b 2023-09-17 16:49:35 +03:30
Demos WidgetGallery: Remove quotes around GML boolean values 2024-01-21 08:38:18 -05:00
DevTools HackStudio: Fuzzy-match Locator suggestions 2024-01-30 23:34:21 +00:00
DynamicLoader LibC: Separate arch dependent fenv functions 2024-01-22 20:06:09 -07:00
Games AK+Userland: Return String from human_readable_[digital_]time() 2024-01-25 09:07:32 +01:00
Libraries LibGfx+LibPDF: Simpler and faster N-D linear sampling 2024-02-04 21:49:23 +01:00
Services Ladybird+WebContent: Update IPC calls to handle multiple traversables 2024-02-03 20:51:37 -05:00
Shell Shell: Use reverse iterators for history events 2024-01-23 01:31:25 +03:30
Utilities image: Add an --invert-cmyk option 2024-02-04 21:34:53 +01:00
CMakeLists.txt