Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding BlurHash from Image in dart #3

Closed
aytunch opened this issue Feb 22, 2020 · 10 comments
Closed

Encoding BlurHash from Image in dart #3

aytunch opened this issue Feb 22, 2020 · 10 comments

Comments

@aytunch
Copy link

aytunch commented Feb 22, 2020

First of all thank you for introducing us Flutter community with this great tool. It is a game changer.
For this to reach to broader developers I think we should be able to encode the image to it's corresponding blurhash string. Are you planning on writing a function which does this on the client.
This way we can upload the image along with the blurhash to Firestore and Firebase Storage at the same time.
People might not be using server side code(cloud functions) since they will bring extra pricing/delay/performance issues. If this is not a good way, then I hope someone would show an cloud function example in type script.

@Solido
Copy link
Member

Solido commented Feb 22, 2020

My approach to this problem is base on economics ...
Expensive low level operations are better handled by optimised langs like go, rust or C.
On the long run it's much more cheap.

If would advise to run FAAS using
https://github.com/woltapp/blurhash/tree/master/C

Having a dart encoder on the server side has few advantages and the case of encoding should not be handled by the client.

Thanks for sharing your idea.

@aytunch
Copy link
Author

aytunch commented Feb 22, 2020

@Solido thanks for your reply, it makes sense.
For my last part of the question regarding cloud functions which I am not experienced with, do you have any idea if it is possible to encode the images calling the C library you provided above? Do you have plans on working with the Firestore Cloud Functions part of this great package?

@cbenhagen
Copy link
Contributor

@Solido I agree that most of the time you would want to do this server side but there are cases like ours where it makes a lot of sense to generate the hash on a Flutter based desktop client. Computing power is not the problem there but we could optimize further by wrapping the C library. Would you accept a PR doing the encoding?

@aytunch I am currently using a cloud function to generate the hash using the Python package which also wraps the C library.

@aytunch
Copy link
Author

aytunch commented Feb 22, 2020

@cbenhagen Ben, thanks a lot for these. Just to make sure, is this the way to upload your Python package to Cloud Functions?

Cloud Functions - Python Quickstart

@cbenhagen
Copy link
Contributor

Yes that should get you started. Be sure to checkout the links at the bottom of that document to see more in depth guides on cloud functions.

@aytunch
Copy link
Author

aytunch commented Feb 22, 2020

Inside of the BlurHash Algorithm details they have an example of Swift Decoder and Swift Encoder. I believe Swift is not a backend language. Maybe this can help porting the encoder code to dart from swift.

@Solido
Copy link
Member

Solido commented Feb 22, 2020

@cbenhagen I see the kind of solutions your working on and for some reasons it appears that desktop encoding is the way to go.

We have 3 solutions

  • pure dart
  • plugin
  • ffi

Do you think the last two have any advantages compared to resizing assets and sampling with dart ?

@cbenhagen
Copy link
Contributor

I'd highly prefer a pure Dart solution which uses whatever Flutter provides for resizing. Not sure if the slight speed increase a native solution might bring would justify the burden of maintaining it for all the platforms.

@Solido
Copy link
Member

Solido commented Feb 22, 2020

Let's go for a pure dart implementation yet I'll keep an eye on FFI/Rust later on.

@aytunch
Copy link
Author

aytunch commented Feb 23, 2020

@Solido @cbenhagen I just found out about this package which seems to do the encoding part in Dart. It does not have a nice Widget wrapper though.

BlurHash-Dart

@Solido Solido closed this as completed Mar 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants