r/FlutterDev • • Nov 01 '26

Discussion I built a zero-copy Rust + Flutter raw photo editor to process 50MP images at 60fps (Lightroom alternative)

Hey everyone, I’m Prit. Over the last few months, I’ve been building ApertureX, a 100% offline, open-source raw photo editor.

Building a desktop-class image engine on Flutter meant overcoming massive memory and threading bottlenecks. Decompressing a 50-megapixel raw image requires around 200MB of continuous RAM. If you try to pass that across standard platform channels or even do a deep copy over FFI, the OS will aggressively kill the app for Out-Of-Memory (OOM) violations, and your frame rate drops to zero.

Here is how I bypassed Flutter's standard rendering constraints to achieve 60fps computational photography:

  • Absolute Zero-Copy FFI: The Rust backend maintains absolute, singular ownership of the high-resolution pixel payload. Instead of copying arrays across the bridge to Dart, Rust allocates the pixels on the heap and transmits merely the memory address pointer to Flutter.
  • Tile-Based Rendering Cache: Processing full frames is mathematically impossible on mid-tier Android devices. The Rust engine cuts the viewport into 512x512 pixel chunks. These tiles are managed by a strictly bounded Least Recently Used (LRU) cache, which automatically purges the oldest elements the moment the memory budget is exceeded.
  • Hardware Acceleration (SIMD): To run spatial filters (like Dehaze and Clarity) without melting the phone, the Rust engine bypasses scalar execution. It targets ARM NEON intrinsics natively, loading four 32-bit floats into a 128-bit NEON register to process four pixels simultaneously.
  • Oklab Color Science via 3D LUTs: Operating in standard sRGB violates the additive physics of light, causing unnatural hue shifts. I moved all color math to the Oklab perceptual color space. To hit 60fps on the frontend, this math is baked into a 33x33x33 3D Lookup Table that Flutter's Impeller engine renders instantly.

The UI uses a dual-shell design (a Snapseed-style invisible gesture trackball for quick flow-state editing, and a Lightroom-style panel for deep pro work), heavily relying on Riverpod for the DAG (Directed Acyclic Graph) edit history.

I would love for you to try the APK, tear apart my flutter_rust_bridge implementation, or drop some feedback on the UI ergonomics.

Repo & Website:https://prit-007.github.io/ApertureX/

Happy to answer any questions about the FFI bridge, the math, or the rendering pipeline!

17 Upvotes

7 comments sorted by

1

u/BCGigsterWide Nov 02 '26 edited Nov 02 '26

I see that you are still using rust_builder, I recently moved my project over to hooks and native assets. You should give it a try.

Also why did you implement your own simd vector multiplication? Shouldn't a simple loop auto vectorize just fine? And if not why not use a crate?

1

u/dev-paradise-007 Nov 02 '26

Good points! On the rust_builder vs native_assets front—you are totally right. native_assets is the future for FFI in Flutter, and migrating to it is actually on my roadmap for v0.4. I just started with cargokit/rust_builder because it gave me immediate, reliable multi-platform builds out of the gate while I was fighting the core memory architecture.

Regarding SIMD: I initially relied on compiler auto-vectorization and crates like std::simd (which is great for portable loop unrolling). However, when you are trying to squeeze 60fps out of a mid-tier Android device running heavy integral image summations (for the Guided Filter), standard auto-vectorization was occasionally too brittle across varying compiler targets.

By explicitly targeting ARM NEON intrinsics (std::arch::aarch64), I can guarantee that we are loading four 32-bit floats into a 128-bit register and executing fused multiply-adds exactly when needed. It is definitely more verbose, but it gives absolute, deterministic control over the thermal envelope and execution time on mobile processors.

1

u/brightcanyon Nov 02 '26

for the 512x512 tiling, how do you handle spatial filters like dehaze or clarity across tile boundaries without getting visible seams? usually you need an overlap padding region per chunk, curious if that messes with your cache eviction math at all

2

u/dev-paradise-007 Nov 02 '26

This is the exact bottleneck that makes spatial filters hard to do on tiles! You are right—if you process a tile in isolation, you get a hard gradient seam where the kernel runs out of neighboring data.

We solve this with overlap padding. If the viewport needs a 512x512 tile, and we are applying a Clarity kernel with a 20px radius, the Rust engine's Region-of-Interest decoder actually fetches a 552x552 block from the raw data. We run the mathematics over that entire padded block, mathematically discard the outer 20-pixel rim (which contains the boundary calculation errors), and then stitch the pristine 512x512 core back into the rendering stream.

It does increase the temporary memory footprint for that single tile calculation, but since the LRU cache is strictly bounded by absolute byte weight, the cache manager just automatically evicts older tiles slightly faster if the padding pushes the total allocation over the envelope limit. The end result is totally seam-free filtering without blowing up the memory budget.

3

u/Bachihani Nov 03 '26

thnx claude