mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
LibGfx/ICC: In lerp_nd(), use VLAs for left_index, factor
`x.size()` is 3 or 4 in practice and at most 15 in theory (cf `number_of_components_in_color_space()` in Profile.cpp), so using a VLA for these should be fine from a stack size PoV. They're accessed from two local loops iterating from 0 to `x.size()`, so it's hopefully not too risky from a security PoV either. Takes Build/lagom/bin/image --no-output \ --assign-color-profile \ Build/lagom/Root/res/icc/Adobe/CMYK/USWebCoatedSWOP.icc \ --convert-to-color-profile serenity-sRGB.icc \ cmyk.jpg from 2.81s to 2.74s on my machine, about 2.5% faster.
This commit is contained in:
parent
69df94ec5c
commit
a352099b05
1 changed files with 4 additions and 4 deletions
|
@ -37,13 +37,13 @@ float lerp_1d(ReadonlySpan<T> values, float x)
|
|||
// `sample()` gets a vector where 0 <= i'th coordinate < size(i) and should return the value of the look-up table at that position.
|
||||
inline FloatVector3 lerp_nd(Function<unsigned(size_t)> size, Function<FloatVector3(Vector<unsigned> const&)> sample, Vector<float> const& x)
|
||||
{
|
||||
Vector<unsigned, 4> left_index;
|
||||
Vector<float, 4> factor;
|
||||
unsigned left_index[x.size()];
|
||||
float factor[x.size()];
|
||||
for (size_t i = 0; i < x.size(); ++i) {
|
||||
unsigned n = size(i) - 1;
|
||||
float ec = x[i] * n;
|
||||
left_index.append(min(static_cast<unsigned>(ec), n - 1));
|
||||
factor.append(ec - left_index[i]);
|
||||
left_index[i] = min(static_cast<unsigned>(ec), n - 1);
|
||||
factor[i] = ec - left_index[i];
|
||||
}
|
||||
|
||||
FloatVector3 sample_output {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue