silvia-odwyer / photon

⚡ Rust/WebAssembly image processing library
https://silvia-odwyer.github.io/photon
Apache License 2.0
2.66k stars 150 forks source link

batch optimization #187

Open liesauer opened 2 months ago

liesauer commented 2 months ago

let's says i want to doing this:

  1. saturate
  2. darken
  3. wartermark

when it runs, the actual code is something like this

for (x, y) in dimensions {
    // saturate
}
for (x, y) in dimensions {
    // darken
}
for (x, y) in dimensions {
    // watermark
}

with batch optimization, it can be

for (x, y) in dimensions {
    // saturate + darken + watermark
}

it will save tons of loops, is there any feature plans doing this?

i am not english native speaker neither nor a professor on image processing, hope the description clear enough.

liesauer commented 2 months ago

making

for (x, y) in dimensions {
    pixels[x][y] = pixels[x][y] + 1;
}
for (x, y) in dimensions {
    pixels[x][y] = pixels[x][y] * 2;
}

into

for (x, y) in dimensions {
    pixels[x][y] = (pixels[x][y] + 1) * 2;
}

same result but fewer loops