Skip to content

Commit fbfc080

Browse files
committed
Initial commit
0 parents  commit fbfc080

19 files changed

+1269
-0
lines changed

.gitignore

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
build/
32+
33+
# Android related
34+
**/android/**/gradle-wrapper.jar
35+
**/android/.gradle
36+
**/android/captures/
37+
**/android/gradlew
38+
**/android/gradlew.bat
39+
**/android/local.properties
40+
**/android/**/GeneratedPluginRegistrant.java
41+
42+
# iOS/XCode related
43+
**/ios/**/*.mode1v3
44+
**/ios/**/*.mode2v3
45+
**/ios/**/*.moved-aside
46+
**/ios/**/*.pbxuser
47+
**/ios/**/*.perspectivev3
48+
**/ios/**/*sync/
49+
**/ios/**/.sconsign.dblite
50+
**/ios/**/.tags*
51+
**/ios/**/.vagrant/
52+
**/ios/**/DerivedData/
53+
**/ios/**/Icon?
54+
**/ios/**/Pods/
55+
**/ios/**/.symlinks/
56+
**/ios/**/profile
57+
**/ios/**/xcuserdata
58+
**/ios/.generated/
59+
**/ios/Flutter/App.framework
60+
**/ios/Flutter/Flutter.framework
61+
**/ios/Flutter/Flutter.podspec
62+
**/ios/Flutter/Generated.xcconfig
63+
**/ios/Flutter/app.flx
64+
**/ios/Flutter/app.zip
65+
**/ios/Flutter/flutter_assets/
66+
**/ios/Flutter/flutter_export_environment.sh
67+
**/ios/ServiceDefinitions.json
68+
**/ios/Runner/GeneratedPluginRegistrant.*
69+
70+
# Exceptions to above rules.
71+
!**/ios/**/default.mode1v3
72+
!**/ios/**/default.mode2v3
73+
!**/ios/**/default.pbxuser
74+
!**/ios/**/default.perspectivev3
75+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
76+
77+
# local example app
78+
example_app/

.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 0b8abb4724aa590dd0f429683339b1e045a1594d
8+
channel: stable
9+
10+
project_type: package

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.1.0] - TODO: Add release date.
2+
3+
* Initial release with a decoder for blur hashes plus an example app

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 Clemens Keppler
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# blurhash
2+
3+
[Blurhash](https://github.com/woltapp/blurhash/blob/master/Algorithm.md) algorithm implementation for dart. For more information or other implementations go to https://github.com/woltapp/blurhash.
4+
5+
Instead of showing boring placeholders, just show an idea of the picture while the actual picture is loading! Images can be converted to Base83 on your backend or while uploading and send to the client. The client can then decode the Base83 string and draw the blurred image.
6+
7+
| | Original | Blurred |
8+
| ---------- |:------------------------------:| :-----------------------------:|
9+
| **Image** | <img src="resources/unsplash-image.jpg" alt="original" width="210" height=130/> |<img src="resources/blurred.jpg" alt="original" width="255" height=130/> |
10+
11+
Base on the hash `q.NK3Mt7WrofayazbHj[.TkCWBWCj[j@f6azIUWXjZWBWCjsoLayM{ofazayjZa#Wqj[kCWBj[bHWXj[jZWVt7WCs:ofa}axjZay`
12+
13+
##### Example usage
14+
See the example in [example_main](example/lib/example_extended.dart)
15+
<img src="resources/blur.gif" alt="original" width="255"/>
16+
17+
## Getting started
18+
Include the library in your project. Then call the decoder with a valid Base83 string
19+
20+
```Dart
21+
FutureBuilder<ui.Image>(
22+
future: blurhash.Encoder.decodeAsImage(hash, 300, 200),
23+
builder: (context, AsyncSnapshot<ui.Image> snapshot) {
24+
// Use the image
25+
},
26+
)
27+
```
28+
29+
or use the Uint8List
30+
```Dart
31+
Uint8List image = blurhash.Encoder.decode(hash, 300, 200);
32+
```
33+
34+
Credits go to [Dag Ågren](https://github.com/DagAgren) / [Wolt](https://github.com/woltapp) for this idea.

analysis_options.yaml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
analyzer:
2+
exclude:
3+
- "**/*.g.dart"
4+
- lib/example_extended.dart
5+
- lib/example.dart
6+
strong-mode:
7+
implicit-casts: false
8+
implicit-dynamic: false
9+
linter:
10+
rules:
11+
- public_member_api_docs
12+
- annotate_overrides
13+
- avoid_empty_else
14+
- avoid_function_literals_in_foreach_calls
15+
- avoid_init_to_null
16+
- avoid_null_checks_in_equality_operators
17+
- avoid_relative_lib_imports
18+
- avoid_renaming_method_parameters
19+
- avoid_return_types_on_setters
20+
- avoid_returning_null
21+
- avoid_types_as_parameter_names
22+
- avoid_unused_constructor_parameters
23+
- await_only_futures
24+
- camel_case_types
25+
- cancel_subscriptions
26+
- cascade_invocations
27+
- comment_references
28+
- constant_identifier_names
29+
- control_flow_in_finally
30+
- directives_ordering
31+
- empty_catches
32+
- empty_constructor_bodies
33+
- empty_statements
34+
- hash_and_equals
35+
- implementation_imports
36+
- invariant_booleans
37+
- iterable_contains_unrelated_type
38+
- library_names
39+
- library_prefixes
40+
- list_remove_unrelated_type
41+
- no_adjacent_strings_in_list
42+
- no_duplicate_case_values
43+
- non_constant_identifier_names
44+
- null_closures
45+
- always_specify_types
46+
- only_throw_errors
47+
- overridden_fields
48+
- package_api_docs
49+
- package_names
50+
- package_prefixed_library_names
51+
- prefer_adjacent_string_concatenation
52+
- prefer_collection_literals
53+
- prefer_conditional_assignment
54+
- prefer_const_constructors
55+
- prefer_contains
56+
- prefer_equal_for_default_values
57+
- prefer_final_fields
58+
- prefer_initializing_formals
59+
- prefer_interpolation_to_compose_strings
60+
- prefer_is_empty
61+
- prefer_is_not_empty
62+
- prefer_single_quotes
63+
- prefer_typing_uninitialized_variables
64+
- recursive_getters
65+
- slash_for_doc_comments
66+
- test_types_in_equals
67+
- throw_in_finally
68+
- type_init_formals
69+
- unawaited_futures
70+
- unnecessary_brace_in_string_interps
71+
- unnecessary_const
72+
- unnecessary_getters_setters
73+
- unnecessary_lambdas
74+
- unnecessary_new
75+
- unnecessary_null_aware_assignments
76+
- unnecessary_statements
77+
- unnecessary_this
78+
- unrelated_type_equality_checks
79+
- use_rethrow_when_possible
80+
- valid_regexps

example/lib/example.dart

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'dart:ui' as ui;
2+
3+
import 'package:blurhash/blurhash.dart' as blurhash;
4+
import 'package:flutter/material.dart';
5+
6+
void main() => runApp(MyApp());
7+
8+
class MyApp extends StatelessWidget {
9+
@override
10+
Widget build(BuildContext context) {
11+
return MaterialApp(
12+
title: 'Flutter blurhash',
13+
theme: ThemeData(
14+
primarySwatch: Colors.blue,
15+
),
16+
home: MyHomePage(title: 'Flutter blurhash'),
17+
);
18+
}
19+
}
20+
21+
class MyHomePage extends StatefulWidget {
22+
MyHomePage({Key key, this.title}) : super(key: key);
23+
24+
final String title;
25+
26+
@override
27+
_MyHomePageState createState() => _MyHomePageState();
28+
}
29+
30+
class _MyHomePageState extends State<MyHomePage> {
31+
// A correct blurhash
32+
static const hash =
33+
r"q.NK3Mt7WrofayazbHj[.TkCWBWCj[j@f6azIUWXjZWBWCjsoLayM{ofazayjZa#Wqj[kCWBj[bHWXj[jZWVt7WCs:ofa}axjZay";
34+
35+
@override
36+
Widget build(BuildContext context) {
37+
return Scaffold(
38+
appBar: AppBar(
39+
title: Text(widget.title),
40+
),
41+
body: Center(
42+
child: FutureBuilder<ui.Image>(
43+
future: blurhash.Encoder.decodeAsImage(hash, 300, 200),
44+
builder: (context, AsyncSnapshot<ui.Image> snapshot) {
45+
if (snapshot.hasData) {
46+
return CustomPaint(
47+
// Passing our generated blurry image
48+
painter: BlurhashPainter(image: snapshot.data),
49+
child: Container(
50+
width: 300,
51+
height: 200,
52+
),
53+
);
54+
} else if (snapshot.hasError) {
55+
print(snapshot.error);
56+
}
57+
return Container();
58+
},
59+
),
60+
),
61+
);
62+
}
63+
}
64+
65+
class BlurhashPainter extends CustomPainter {
66+
ui.Image image;
67+
68+
BlurhashPainter({this.image});
69+
70+
@override
71+
void paint(Canvas canvas, Size size) {
72+
canvas.drawImage(image, Offset.zero, Paint());
73+
}
74+
75+
@override
76+
bool shouldRepaint(CustomPainter oldDelegate) {
77+
return false;
78+
}
79+
}

0 commit comments

Comments
 (0)