瀏覽代碼

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.
Nico Weber 1 年之前
父節點
當前提交
a352099b05
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      Userland/Libraries/LibGfx/ICC/TagTypes.h

+ 4 - 4
Userland/Libraries/LibGfx/ICC/TagTypes.h

@@ -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.
 // `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)
 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) {
     for (size_t i = 0; i < x.size(); ++i) {
         unsigned n = size(i) - 1;
         unsigned n = size(i) - 1;
         float ec = x[i] * n;
         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 {};
     FloatVector3 sample_output {};