kekland / croppy

A fully customizable image cropper for Flutter, in Flutter
MIT License
105 stars 30 forks source link

Cropping performance on Web #3

Closed kekland closed 1 year ago

kekland commented 1 year ago

On web, clicking "Done" takes a long time until the image is cropped. This is due to the cropping function running in Dart, that has a complexity of O(W*H) (which gets compiled to JS, and it's even worse there). A potential solution would be to rewrite the cropping function in C/C++, and use dart:ffi to call it.

talamaska commented 1 year ago

have you tried using compute to make the cropping off the main thread?

kekland commented 1 year ago

@talamaska I'm worried about the overhead of copying an entire image Uint8List to a separate isolate. I will try both approaches (with compute and dart:ffi) and see which one would work better

kekland commented 1 year ago

@talamaska nvm, seems like an approach with Canvas and PictureRecorder seems to work the best, as we just delegate everything to Flutter. This also results in better images as it will use a bicubic interpolation instead of a bilinear one. See https://github.com/kekland/croppy/commit/b45f04f21b9d1826c0a4c2f9e171ed3fbe3d240f

kekland commented 1 year ago

Seems to work fine on Web now. Closing this, but if anything pops up, feel free to reopen.