brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.18k stars 266 forks source link

Use off-screen canvas rendering for speed? #534

Closed lukehutch closed 1 year ago

lukehutch commented 1 year ago

Why on earth does image implement image scaling, cropping, etc. using custom Dart code, rather than relying on off-screen Canvas rendering (which is orders of magnitude faster)?

var recorder = PictureRecorder();
var canvas = Canvas(recorder);
canvas.drawImage(Offset.zero, myImage);
canvas.transform( ... some transformation ...)
var picture = recorder.endRecording();
picture.toImage(100, 100).then((ui.Image) {
  var png = ui.Image.toByteData(format: ... )
}

Also, why does image even implement its own jpeg/png codecs, when that is built into the Flutter platform?

The only reason I can think of is that image is for use serverside, for a non-Flutter project -- but then couldn't a faster Canvas-derived version of each operator be used when running image code on Flutter?

brendan-duncan commented 1 year ago

This library was written long before Flutter existed.

lukehutch commented 1 year ago

Makes sense. Do you have any interest in adding Flutter acceleration support for image operations running in Flutter?

brendan-duncan commented 1 year ago

Regardless of interest, unfortunately I just don't have any time. I've never actually used Flutter, other than answering an occasional support question with these Dart libraries I wrote a long time ago. I maintain this library because no one else will, and I feel bad I don't have time to do more.

One of the challenging aspects of Dart & Flutter is cross platform support. People use the library for mobile, web, and server applications. So adding features that are not written in pure Dart become more challenging.

But I agree, adding native implemented optimizations for commonly used operations would be wonderful.

lukehutch commented 1 year ago

Sorry, this bug was filed before I understood that image is a non-Flutter, Dart-pure project. I'll close this. Thanks!