Code Monkey home page Code Monkey logo

blurhash's Introduction

blurhash

pub package

Compact representation of a placeholder for an image.

Platform Support

Android iOS Web
✔️ ✔️ ✔️

Usage

To use this plugin, add blurhash as a dependency in your pubspec.yaml file.

Example

void blurHashEncode() async {
  ByteData bytes = await rootBundle.load("image.jpg");
  Uint8List pixels = bytes.buffer.asUint8List();
  var blurHash = await BlurHash.encode(pixels, 4, 3);
}

void blurHashDecode() async {
  Uint8List? imageDataBytes;
  try {
    imageDataBytes = await BlurHash.decode(blurhash, 20, 12);
  } on PlatformException catch (e) {
    throw Exception(e.message);
  }
}

blurhash's People

Contributors

lyio avatar mazzonem avatar raincal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blurhash's Issues

Support web, desktop

Why this package move algorithm to the native platforms? Its not reusable due to this. You can use blurhash_dart package and isolates to move work in the background.

Any chance of an "encode" option

Love the idea of this library, an encode would be great to send up with uploaded images (well at least for me as my backend servers are pretty dumb!)

0.3.0 release?

Will there be a proper 0.3.0 release anytime soon? We have been using the pre-release version for quite some time now and I was wondering when the -nullsafey.1 will be dropped.

Example use causes Poor performance

when using this package for the first time, I structured my widget after the example included.

  @override
  void initState() {
    super.initState();
//    blurHashDecode();
  }

  Future<void> blurHashDecode() async {
    Uint8List imageDataBytes;
    try {
      // Decodes a BlurHash string to bytes
      imageDataBytes = await BlurHash.decode("LGKB2RMzk?yY-;w|~pIoOunOM_jD", 256, 256);
    } on PlatformException catch (e) {
      print(e.message);
    }

    if (!mounted) return;

    setState(() {
      _imageDataBytes = imageDataBytes;
    });
  }

But if I use this widget in a scrolling list, it will lock up the app for a few seconds when I try to scroll. I found that this is caused by the decoding being done in the init state. I can comment out that single line, (blurHashDecode();)and it is just fine.

I think I will need to do the decoding elsewhere in my app. perhaps in the constructor of the data object, and then store the decoded bytes in a field of the data object itself.

Are there any suggestions, that may imrove performance here?

Android build not working

Version: 1.0.0
Flutter: 2.2
Platform: Android

While building my app for Android, an error pops up and the build fails.

e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-0.2.1/android/src/main/kotlin/com/raincal/blurhash/Base83.kt: (3, 17): Redeclaration: Base83
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-0.2.1/android/src/main/kotlin/com/raincal/blurhash/BlurHashDecoder.kt: (10, 8): Redeclaration: BlurHashDecoder
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-0.2.1/android/src/main/kotlin/com/raincal/blurhash/BlurHashEncoder.kt: (10, 8): Redeclaration: BlurHashEncoder
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-0.2.1/android/src/main/kotlin/com/raincal/blurhash/BlurhashPlugin.kt: (12, 7): Redeclaration: BlurhashPlugin
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-0.2.1/android/src/main/kotlin/com/raincal/blurhash/Utils.kt: (7, 17): Redeclaration: Utils
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-1.0.0/android/src/main/kotlin/com/raincal/blurhash/Base83.kt: (3, 17): Redeclaration: Base83
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-1.0.0/android/src/main/kotlin/com/raincal/blurhash/BlurHashDecoder.kt: (10, 8): Redeclaration: BlurHashDecoder
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-1.0.0/android/src/main/kotlin/com/raincal/blurhash/BlurHashEncoder.kt: (10, 8): Redeclaration: BlurHashEncoder
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-1.0.0/android/src/main/kotlin/com/raincal/blurhash/BlurhashPlugin.kt: (16, 7): Redeclaration: BlurhashPlugin
e: /Users/albertjanp/Documents/Development/Software/flutter/.pub-cache/hosted/pub.dartlang.org/blurhash-1.0.0/android/src/main/kotlin/com/raincal/blurhash/Utils.kt: (7, 17): Redeclaration: Utils

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':blurhash:compileReleaseKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 59s

Taking 30-40 seconds for image size 500KB

It takes around 30-40 seconds to generate blur hash if image size is 500KB or bigger. Here is the code

static Future<String> encode(Uint8List bytes) async {
  final blurHash = await BlurHash.encode(bytes, 3, 4);
  return blurHash;
}

Why isn't this package pure dart

The computation shouldn't be much slower in pure dart, but it results in web, desktop and mobile support, an single codebase instead of the binding and the native implementations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.