From 0e79a93b9d6f8c97ff8306093979ff6ee80f61d1 Mon Sep 17 00:00:00 2001 From: Sharafudheen Date: Tue, 15 Jun 2021 10:00:59 +0530 Subject: [PATCH 01/16] cast error fix --- lib/widgets/photo_filter.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/widgets/photo_filter.dart b/lib/widgets/photo_filter.dart index 54c4c13..238bba4 100644 --- a/lib/widgets/photo_filter.dart +++ b/lib/widgets/photo_filter.dart @@ -26,7 +26,7 @@ class PhotoFilter extends StatelessWidget { Widget build(BuildContext context) { return FutureBuilder>( future: compute( - applyFilter as FutureOr> Function(Map), + applyFilter, { "filter": filter, "image": image, @@ -188,7 +188,7 @@ class _PhotoFilterSelectorState extends State { if (cachedFilters[filter.name] == null) { return FutureBuilder>( future: compute( - applyFilter as FutureOr> Function(Map), + applyFilter , { "filter": filter, "image": image, @@ -254,7 +254,7 @@ class _PhotoFilterSelectorState extends State { if (cachedFilters[filter?.name ?? "_"] == null) { return FutureBuilder>( future: compute( - applyFilter as FutureOr> Function(Map), + applyFilter as List Function(Map), { "filter": filter, "image": image, @@ -315,7 +315,7 @@ class _PhotoFilterSelectorState extends State { } ///The global applyfilter function -List? applyFilter(Map params) { +FutureOr> applyFilter(Map params) { Filter? filter = params["filter"]; imageLib.Image image = params["image"]; String filename = params["filename"]; @@ -331,7 +331,7 @@ List? applyFilter(Map params) { } ///The global buildThumbnail function -List? buildThumbnail(Map params) { +FutureOr> buildThumbnail(Map params) { int? width = params["width"]; params["image"] = imageLib.copyResize(params["image"], width: width); return applyFilter(params); From 74b4bc7572530a1714d7f133d3fab04465126b30 Mon Sep 17 00:00:00 2001 From: Sharafudheen Date: Tue, 15 Jun 2021 10:04:15 +0530 Subject: [PATCH 02/16] cast removed --- lib/widgets/photo_filter.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/photo_filter.dart b/lib/widgets/photo_filter.dart index 238bba4..31223a7 100644 --- a/lib/widgets/photo_filter.dart +++ b/lib/widgets/photo_filter.dart @@ -254,7 +254,7 @@ class _PhotoFilterSelectorState extends State { if (cachedFilters[filter?.name ?? "_"] == null) { return FutureBuilder>( future: compute( - applyFilter as List Function(Map), + applyFilter, { "filter": filter, "image": image, From 2b1fa06a1952d5c9b8bb4fbb580b4ab95fb240e1 Mon Sep 17 00:00:00 2001 From: Sharafudheen Date: Tue, 15 Jun 2021 15:03:42 +0530 Subject: [PATCH 03/16] Cast error bug fix --- CHANGELOG.md | 4 ++++ pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1bcc2..adf42ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,3 +45,7 @@ ## [3.0.0] - 12 Jun 2021 - Null Safety + +## [3.0.1] - 15 Jun 2021 + +- Cast error bug fix diff --git a/pubspec.yaml b/pubspec.yaml index b10e66c..14dbcd1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: photofilters description: A flutter package for applying various types of filters to an image. You can create your own filters and subfilters too. -version: 3.0.0 +version: 3.0.1 homepage: https://github.com/skkallayath/photofilters environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: From 2b22279edf519fd71f66f59edd609839649e5cd6 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 08:44:23 +0530 Subject: [PATCH 04/16] Example updated to null safety --- example/lib/main.dart | 56 +++++++++++++++++------------------ example/pubspec.yaml | 19 +++++------- example/test/widget_test.dart | 3 +- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index ba9ab0c..f6a6eae 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -15,38 +15,38 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - String fileName; + String fileName = ""; List filters = presetFiltersList; final picker = ImagePicker(); - File imageFile; + File? imageFile; Future getImage(context) async { - final pickedFile = await picker.getImage(source: ImageSource.gallery); - if(pickedFile!=null){ - imageFile = new File(pickedFile.path); - fileName = basename(imageFile.path); - var image = imageLib.decodeImage(await imageFile.readAsBytes()); - image = imageLib.copyResize(image, width: 600); - Map imagefile = await Navigator.push( - context, - new MaterialPageRoute( - builder: (context) => new PhotoFilterSelector( - title: Text("Photo Filter Example"), - image: image, - filters: presetFiltersList, - filename: fileName, - loader: Center(child: CircularProgressIndicator()), - fit: BoxFit.contain, + final pickedFile = await picker.pickImage(source: ImageSource.gallery); + if (pickedFile != null) { + imageFile = new File(pickedFile.path); + fileName = basename(imageFile!.path); + var image = imageLib.decodeImage(await imageFile!.readAsBytes()); + image = imageLib.copyResize(image!, width: 600); + Map imagefile = await Navigator.push( + context, + new MaterialPageRoute( + builder: (context) => new PhotoFilterSelector( + title: Text("Photo Filter Example"), + image: image!, + filters: presetFiltersList, + filename: fileName, + loader: Center(child: CircularProgressIndicator()), + fit: BoxFit.contain, + ), ), - ), - ); - - if (imagefile != null && imagefile.containsKey('image_filtered')) { - setState(() { - imageFile = imagefile['image_filtered']; - }); - print(imageFile.path); - } + ); + + if (imagefile.containsKey('image_filtered')) { + setState(() { + imageFile = imagefile['image_filtered']; + }); + print(imageFile!.path); + } } } @@ -62,7 +62,7 @@ class _MyAppState extends State { ? Center( child: new Text('No image selected.'), ) - : Image.file(new File(imageFile.path)), + : Image.file(new File(imageFile!.path)), ), ), floatingActionButton: new FloatingActionButton( diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1e44b1b..83e1e42 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: photofilters_example description: Demonstrates how to use the photofilters plugin. - +publish_to: none # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. @@ -10,31 +10,26 @@ description: Demonstrates how to use the photofilters plugin. version: 1.0.0+1 environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: sdk: flutter + image_picker: ^0.8.7+5 + path_provider: ^2.0.15 - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + photofilters: + path: ../ dev_dependencies: flutter_test: sdk: flutter - image_picker: - path_provider: - - photofilters: - path: ../ # For information on the generic Dart part of this file, see the # following page: https://www.dartlang.org/tools/pub/pubspec # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. @@ -42,7 +37,7 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - - assets/images/gifloader.gif + - assets/images/gifloader.gif # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 095988f..bdb567b 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -9,7 +9,6 @@ import 'package:flutter_test/flutter_test.dart'; import '../lib/main.dart'; - void main() { testWidgets('Verify Platform version', (WidgetTester tester) async { // Build our app and trigger a frame. @@ -19,7 +18,7 @@ void main() { expect( find.byWidgetPredicate( (Widget widget) => - widget is Text && widget.data.startsWith('Running on:'), + widget is Text && widget.data!.startsWith('Running on:'), ), findsOneWidget); }); From 17722873e254a26df3348c48957fa88690a792a1 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 08:44:58 +0530 Subject: [PATCH 05/16] photofilters_example pubspec cleaned --- example/pubspec.yaml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 83e1e42..20bae74 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,12 +1,6 @@ name: photofilters_example description: Demonstrates how to use the photofilters plugin. publish_to: none -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# Read more about versioning at semver.org. version: 1.0.0+1 environment: @@ -17,7 +11,6 @@ dependencies: sdk: flutter image_picker: ^0.8.7+5 path_provider: ^2.0.15 - photofilters: path: ../ @@ -25,43 +18,7 @@ dev_dependencies: flutter_test: sdk: flutter -# For information on the generic Dart part of this file, see the -# following page: https://www.dartlang.org/tools/pub/pubspec - -# The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: assets: - assets/images/gifloader.gif - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.io/assets-and-images/#resolution-aware. - - # For details regarding adding assets from package dependencies, see - # https://flutter.io/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.io/custom-fonts/#from-packages From a95776762f554d6f9a9936606dd9f12e55a512d8 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 08:48:07 +0530 Subject: [PATCH 06/16] example android dependency updated --- example/.metadata | 38 ++++- example/analysis_options.yaml | 29 ++++ example/android/.gitignore | 13 ++ example/android/app/build.gradle | 139 +++++++++--------- .../android/app/src/debug/AndroidManifest.xml | 7 + .../android/app/src/main/AndroidManifest.xml | 73 +++++---- .../photofiltersexample/MainActivity.java | 13 -- .../com/skkallayath/example/MainActivity.kt | 6 + .../res/drawable-v21/launch_background.xml | 12 ++ .../main/res/drawable/launch_background.xml | 24 +-- .../app/src/main/res/values-night/styles.xml | 18 +++ .../app/src/main/res/values/styles.xml | 26 +++- .../app/src/profile/AndroidManifest.xml | 7 + example/android/build.gradle | 60 ++++---- example/android/gradle.properties | 1 - .../gradle/wrapper/gradle-wrapper.properties | 3 +- example/android/settings.gradle | 26 ++-- 17 files changed, 301 insertions(+), 194 deletions(-) create mode 100644 example/analysis_options.yaml create mode 100644 example/android/.gitignore create mode 100644 example/android/app/src/debug/AndroidManifest.xml delete mode 100644 example/android/app/src/main/java/com/skkallayath/photofiltersexample/MainActivity.java create mode 100644 example/android/app/src/main/kotlin/com/skkallayath/example/MainActivity.kt create mode 100644 example/android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 example/android/app/src/main/res/values-night/styles.xml create mode 100644 example/android/app/src/profile/AndroidManifest.xml diff --git a/example/.metadata b/example/.metadata index 6ec6c8e..41ce369 100644 --- a/example/.metadata +++ b/example/.metadata @@ -1,8 +1,30 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: f37c235c32fc15babe6dc7b7bc2ee4387e5ecf92 - channel: beta +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff + channel: stable + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff + base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff + - platform: android + create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff + base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/android/.gitignore b/example/android/.gitignore new file mode 100644 index 0000000..6f56801 --- /dev/null +++ b/example/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 6e0e981..eeed384 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,67 +1,72 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -apply plugin: 'com.android.application' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - -android { - compileSdkVersion 28 - - lintOptions { - disable 'InvalidPackage' - } - - defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.skkallayath.photofiltersexample" - minSdkVersion 16 - targetSdkVersion 27 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - } - - buildTypes { - release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug - } - } -} - -flutter { - source '../..' -} - -dependencies { - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' - - configurations.all { - resolutionStrategy { - force 'com.android.support:support-v4:27.1.0' - } - } -} +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + namespace "com.skkallayath.example" + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "com.skkallayath.example" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..399f698 --- /dev/null +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index d1ed5b1..80d5f6c 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,39 +1,34 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/example/android/app/src/main/java/com/skkallayath/photofiltersexample/MainActivity.java b/example/android/app/src/main/java/com/skkallayath/photofiltersexample/MainActivity.java deleted file mode 100644 index b287c56..0000000 --- a/example/android/app/src/main/java/com/skkallayath/photofiltersexample/MainActivity.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.skkallayath.photofiltersexample; - -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; - -public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } -} diff --git a/example/android/app/src/main/kotlin/com/skkallayath/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/skkallayath/example/MainActivity.kt new file mode 100644 index 0000000..7394392 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/skkallayath/example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.skkallayath.example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000..f74085f --- /dev/null +++ b/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/example/android/app/src/main/res/drawable/launch_background.xml b/example/android/app/src/main/res/drawable/launch_background.xml index 8403758..304732f 100644 --- a/example/android/app/src/main/res/drawable/launch_background.xml +++ b/example/android/app/src/main/res/drawable/launch_background.xml @@ -1,12 +1,12 @@ - - - - - - - - + + + + + + + + diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..06952be --- /dev/null +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 4c57322..cb1ef88 100644 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -1,8 +1,18 @@ - - - - + + + + + + + diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000..399f698 --- /dev/null +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/build.gradle b/example/android/build.gradle index a120d10..f7eb7f6 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,29 +1,31 @@ -buildscript { - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' - } -} - -allprojects { - repositories { - google() - jcenter() - } -} - -rootProject.buildDir = '../build' -subprojects { - project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { - project.evaluationDependsOn(':app') -} - -task clean(type: Delete) { - delete rootProject.buildDir -} +buildscript { + ext.kotlin_version = '1.7.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 38c8d45..94adc3a 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,4 +1,3 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true android.useAndroidX=true android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 8f690eb..3c472b9 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Mar 29 13:12:52 IST 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 4f14f8e..44e62bc 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,11 @@ -include ':app' - -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() - -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } -} - -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory -} +include ':app' + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" From fc482b5b38a3530d1af7eeac7f241e67b2fb8249 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 08:48:44 +0530 Subject: [PATCH 07/16] flutter_lints package added --- example/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 20bae74..76463b9 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + flutter_lints: ^2.0.1 flutter: uses-material-design: true From d92c88ec1b396eac71cf8b066afde4bbe76d6f71 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 08:54:37 +0530 Subject: [PATCH 08/16] flutter_lints rules followed --- example/lib/main.dart | 44 ++++++++++++++++++----------------- example/pubspec.yaml | 2 ++ example/test/widget_test.dart | 4 ++-- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index f6a6eae..af3ee09 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,17 +4,19 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:path/path.dart'; import 'package:photofilters/photofilters.dart'; -import 'package:image/image.dart' as imageLib; +import 'package:image/image.dart' as imagelib; import 'package:image_picker/image_picker.dart'; -void main() => runApp(new MaterialApp(home: MyApp())); +void main() => runApp(const MaterialApp(home: MyApp())); class MyApp extends StatefulWidget { + const MyApp({super.key}); + @override - _MyAppState createState() => new _MyAppState(); + MyAppState createState() => MyAppState(); } -class _MyAppState extends State { +class MyAppState extends State { String fileName = ""; List filters = presetFiltersList; final picker = ImagePicker(); @@ -23,19 +25,19 @@ class _MyAppState extends State { Future getImage(context) async { final pickedFile = await picker.pickImage(source: ImageSource.gallery); if (pickedFile != null) { - imageFile = new File(pickedFile.path); + imageFile = File(pickedFile.path); fileName = basename(imageFile!.path); - var image = imageLib.decodeImage(await imageFile!.readAsBytes()); - image = imageLib.copyResize(image!, width: 600); + var image = imagelib.decodeImage(await imageFile!.readAsBytes()); + image = imagelib.copyResize(image!, width: 600); Map imagefile = await Navigator.push( context, - new MaterialPageRoute( - builder: (context) => new PhotoFilterSelector( - title: Text("Photo Filter Example"), + MaterialPageRoute( + builder: (context) => PhotoFilterSelector( + title: const Text("Photo Filter Example"), image: image!, filters: presetFiltersList, filename: fileName, - loader: Center(child: CircularProgressIndicator()), + loader: const Center(child: CircularProgressIndicator()), fit: BoxFit.contain, ), ), @@ -45,30 +47,30 @@ class _MyAppState extends State { setState(() { imageFile = imagefile['image_filtered']; }); - print(imageFile!.path); + debugPrint(imageFile!.path); } } } @override Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: new Text('Photo Filter Example'), + return Scaffold( + appBar: AppBar( + title: const Text('Photo Filter Example'), ), body: Center( - child: new Container( + child: Container( child: imageFile == null - ? Center( - child: new Text('No image selected.'), + ? const Center( + child: Text('No image selected.'), ) - : Image.file(new File(imageFile!.path)), + : Image.file(File(imageFile!.path)), ), ), - floatingActionButton: new FloatingActionButton( + floatingActionButton: FloatingActionButton( onPressed: () => getImage(context), tooltip: 'Pick Image', - child: new Icon(Icons.add_a_photo), + child: const Icon(Icons.add_a_photo), ), ); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 76463b9..9f5c491 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -13,6 +13,8 @@ dependencies: path_provider: ^2.0.15 photofilters: path: ../ + path: ^1.8.3 + image: ^3.3.0 dev_dependencies: flutter_test: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index bdb567b..6e65fa8 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -7,12 +7,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../lib/main.dart'; +import 'package:photofilters_example/main.dart'; void main() { testWidgets('Verify Platform version', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(new MyApp()); + await tester.pumpWidget(const MyApp()); // Verify that platform version is retrieved. expect( From 48e634a03fda24e1e86c2d38f7860fd016185527 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 08:57:24 +0530 Subject: [PATCH 09/16] Dart 3.0 sdk updated --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 14dbcd1..f6b8673 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 3.0.1 homepage: https://github.com/skkallayath/photofilters environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: From 70856db028af4dbdcbeac6b6d156516699cb4b89 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 09:01:32 +0530 Subject: [PATCH 10/16] Packages updated --- pubspec.yaml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index f6b8673..1121b55 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,21 +9,17 @@ environment: dependencies: flutter: sdk: flutter - image: ^3.0.2 - meta: ^1.3.0 - path_provider: ^2.0.1 + image: ^4.0.17 + meta: ^1.9.1 + path_provider: ^2.0.15 + image_picker: ^0.8.7+5 + path: ^1.8.3 dev_dependencies: flutter_test: sdk: flutter - test: ^1.16.5 - image_picker: ^0.7.4 - path: ^1.8.0 + test: ^1.24.1 -# For information on the generic Dart part of this file, see the -# following page: https://www.dartlang.org/tools/pub/pubspec - -# The following section is specific to Flutter. flutter: # To add assets to your package, add an assets section, like this: From 054c6260b53cab42aefd5589b0279522e275295d Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 09:46:39 +0530 Subject: [PATCH 11/16] image package updated --- example/pubspec.yaml | 2 +- lib/widgets/photo_filter.dart | 47 +++++++++++++++++------------------ test/test_utils.dart | 9 +++++-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9f5c491..d007192 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: photofilters: path: ../ path: ^1.8.3 - image: ^3.3.0 + image: ^4.0.17 dev_dependencies: flutter_test: diff --git a/lib/widgets/photo_filter.dart b/lib/widgets/photo_filter.dart index 31223a7..16e13cc 100644 --- a/lib/widgets/photo_filter.dart +++ b/lib/widgets/photo_filter.dart @@ -25,13 +25,11 @@ class PhotoFilter extends StatelessWidget { @override Widget build(BuildContext context) { return FutureBuilder>( - future: compute( - applyFilter, - { - "filter": filter, - "image": image, - "filename": filename, - }), + future: compute(applyFilter, { + "filter": filter, + "image": image, + "filename": filename, + }), builder: (BuildContext context, AsyncSnapshot> snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: @@ -187,13 +185,11 @@ class _PhotoFilterSelectorState extends State { Filter filter, imageLib.Image? image, String? filename) { if (cachedFilters[filter.name] == null) { return FutureBuilder>( - future: compute( - applyFilter , - { - "filter": filter, - "image": image, - "filename": filename, - }), + future: compute(applyFilter, { + "filter": filter, + "image": image, + "filename": filename, + }), builder: (BuildContext context, AsyncSnapshot> snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: @@ -253,13 +249,11 @@ class _PhotoFilterSelectorState extends State { Filter? filter, imageLib.Image? image, String? filename) { if (cachedFilters[filter?.name ?? "_"] == null) { return FutureBuilder>( - future: compute( - applyFilter, - { - "filter": filter, - "image": image, - "filename": filename, - }), + future: compute(applyFilter, { + "filter": filter, + "image": image, + "filename": filename, + }), builder: (BuildContext context, AsyncSnapshot> snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: @@ -323,9 +317,14 @@ FutureOr> applyFilter(Map params) { if (filter != null) { filter.apply(_bytes as dynamic, image.width, image.height); } - imageLib.Image _image = - imageLib.Image.fromBytes(image.width, image.height, _bytes); - _bytes = imageLib.encodeNamedImage(_image, filename)!; + + Uint8List bytes = Uint8List.fromList(_bytes); + imageLib.Image _image = imageLib.Image.fromBytes( + width: image.width, height: image.height, bytes: bytes.buffer); + _bytes = imageLib.encodeNamedImage( + filename, + _image, + )!; return _bytes; } diff --git a/test/test_utils.dart b/test/test_utils.dart index 83034f4..334c48a 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -7,6 +7,11 @@ void applyFilterOnFile(Filter filter, String src, String dest) { Image image = decodeImage(File(src).readAsBytesSync())!; var pixels = image.getBytes(); filter.apply(pixels, image.width, image.height); - Image out = Image.fromBytes(image.width, image.height, pixels); - new File(dest).writeAsBytesSync(encodeNamedImage(out, dest)!); + + Image out = Image.fromBytes( + width: image.width, height: image.height, bytes: pixels.buffer); + new File(dest).writeAsBytesSync(encodeNamedImage( + dest, + out, + )!); } From d333eec0ebb6ea64574db3cab88d807ec3f12165 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 09:52:15 +0530 Subject: [PATCH 12/16] flutter_lints package added --- analysis_options.yaml | 29 +++++++++++++++++++++++++++++ pubspec.yaml | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/pubspec.yaml b/pubspec.yaml index 1121b55..f0c2f93 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ dev_dependencies: flutter_test: sdk: flutter test: ^1.24.1 - + flutter_lints: ^2.0.1 flutter: # To add assets to your package, add an assets section, like this: From 9cc62ae2a11f65622084cb31ac83616ee6b49216 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 09:57:46 +0530 Subject: [PATCH 13/16] All Rules of flutter_lints followed --- lib/filters/color_filters.dart | 22 ++-- lib/filters/convolution_filters.dart | 30 ++--- lib/filters/image_filters.dart | 2 +- lib/filters/preset_filters.dart | 184 +++++++++++++-------------- lib/filters/subfilters.dart | 5 +- lib/utils/color_filter_utils.dart | 28 ++-- lib/utils/convolution_kernels.dart | 30 ++--- lib/utils/utils.dart | 16 +-- lib/widgets/photo_filter.dart | 105 +++++++-------- test/convolution_test.dart | 3 +- test/custom_filters_test.dart | 4 +- test/photofilters_test.dart | 3 +- test/test_utils.dart | 2 +- 13 files changed, 219 insertions(+), 215 deletions(-) diff --git a/lib/filters/color_filters.dart b/lib/filters/color_filters.dart index 5bf01a1..3a7ba4c 100644 --- a/lib/filters/color_filters.dart +++ b/lib/filters/color_filters.dart @@ -17,25 +17,25 @@ class ColorFilter extends Filter { super(name: name); @override - void apply(Uint8List bytes, int width, int height) { - for (int i = 0; i < bytes.length; i += 4) { + void apply(Uint8List pixels, int width, int height) { + for (int i = 0; i < pixels.length; i += 4) { RGBA color = RGBA( - red: bytes[i], - green: bytes[i + 1], - blue: bytes[i + 2], - alpha: bytes[i + 3]); + red: pixels[i], + green: pixels[i + 1], + blue: pixels[i + 2], + alpha: pixels[i + 3]); for (ColorSubFilter subFilter in subFilters) { color = subFilter.applyFilter(color); } - bytes[i] = color.red; - bytes[i + 1] = color.green; - bytes[i + 2] = color.blue; - bytes[i + 3] = color.alpha; + pixels[i] = color.red; + pixels[i + 1] = color.green; + pixels[i + 2] = color.blue; + pixels[i + 3] = color.alpha; } } void addSubFilter(ColorSubFilter subFilter) { - this.subFilters.add(subFilter); + subFilters.add(subFilter); } void addSubFilters(List subFilters) { diff --git a/lib/filters/convolution_filters.dart b/lib/filters/convolution_filters.dart index 938f414..ab79805 100644 --- a/lib/filters/convolution_filters.dart +++ b/lib/filters/convolution_filters.dart @@ -3,36 +3,36 @@ import 'package:photofilters/filters/subfilters.dart'; import 'package:photofilters/utils/convolution_kernels.dart'; var presetConvolutionFiltersList = [ - new ImageFilter(name: "Identity") + ImageFilter(name: "Identity") ..addSubFilter(ConvolutionSubFilter.fromKernel(identityKernel)), - new ImageFilter(name: "Sharpen") + ImageFilter(name: "Sharpen") ..addSubFilter(ConvolutionSubFilter.fromKernel(sharpenKernel)), - new ImageFilter(name: "Emboss") + ImageFilter(name: "Emboss") ..addSubFilter(ConvolutionSubFilter.fromKernel(embossKernel)), - new ImageFilter(name: "Colored Edge Detection") + ImageFilter(name: "Colored Edge Detection") ..subFilters .add(ConvolutionSubFilter.fromKernel(coloredEdgeDetectionKernel)), - new ImageFilter(name: "Edge Detection Medium") + ImageFilter(name: "Edge Detection Medium") ..subFilters .add(ConvolutionSubFilter.fromKernel(edgeDetectionMediumKernel)), - new ImageFilter(name: "Edge Detection Hard") + ImageFilter(name: "Edge Detection Hard") ..addSubFilter(ConvolutionSubFilter.fromKernel(edgeDetectionHardKernel)), - new ImageFilter(name: "Blur") + ImageFilter(name: "Blur") ..addSubFilter(ConvolutionSubFilter.fromKernel(blurKernel)), - new ImageFilter(name: "Guassian 3x3") + ImageFilter(name: "Guassian 3x3") ..addSubFilter(ConvolutionSubFilter.fromKernel(guassian3x3Kernel)), - new ImageFilter(name: "Guassian 5x5") + ImageFilter(name: "Guassian 5x5") ..addSubFilter(ConvolutionSubFilter.fromKernel(guassian5x5Kernel)), - new ImageFilter(name: "Guassian 7x7") + ImageFilter(name: "Guassian 7x7") ..addSubFilter(ConvolutionSubFilter.fromKernel(guassian7x7Kernel)), - new ImageFilter(name: "Mean 3x3") + ImageFilter(name: "Mean 3x3") ..addSubFilter(ConvolutionSubFilter.fromKernel(mean3x3Kernel)), - new ImageFilter(name: "Mean 5x5") + ImageFilter(name: "Mean 5x5") ..addSubFilter(ConvolutionSubFilter.fromKernel(mean5x5Kernel)), - new ImageFilter(name: "Low Pass 3x3") + ImageFilter(name: "Low Pass 3x3") ..addSubFilter(ConvolutionSubFilter.fromKernel(lowPass3x3Kernel)), - new ImageFilter(name: "Low Pass 5x5") + ImageFilter(name: "Low Pass 5x5") ..addSubFilter(ConvolutionSubFilter.fromKernel(lowPass5x5Kernel)), - new ImageFilter(name: "High Pass 3x3") + ImageFilter(name: "High Pass 3x3") ..addSubFilter(ConvolutionSubFilter.fromKernel(highPass3x3Kernel)), ]; diff --git a/lib/filters/image_filters.dart b/lib/filters/image_filters.dart index 71d1a77..8f5ca5b 100644 --- a/lib/filters/image_filters.dart +++ b/lib/filters/image_filters.dart @@ -24,7 +24,7 @@ class ImageFilter extends Filter { } void addSubFilter(ImageSubFilter subFilter) { - this.subFilters.add(subFilter); + subFilters.add(subFilter); } void addSubFilters(List subFilters) { diff --git a/lib/filters/preset_filters.dart b/lib/filters/preset_filters.dart index b62af13..f038161 100644 --- a/lib/filters/preset_filters.dart +++ b/lib/filters/preset_filters.dart @@ -17,342 +17,342 @@ class NoFilter extends ColorFilter { // Clarendon: adds light to lighter areas and dark to darker areas class ClarendonFilter extends ColorFilter { ClarendonFilter() : super(name: "Clarendon") { - subFilters.add(new BrightnessSubFilter(.1)); - subFilters.add(new ContrastSubFilter(.1)); - subFilters.add(new SaturationSubFilter(.15)); + subFilters.add(BrightnessSubFilter(.1)); + subFilters.add(ContrastSubFilter(.1)); + subFilters.add(SaturationSubFilter(.15)); } } class AddictiveRedFilter extends ColorFilter { AddictiveRedFilter() : super(name: "AddictiveRed") { - subFilters.add(new AddictiveColorSubFilter(50, 0, 0)); + subFilters.add(AddictiveColorSubFilter(50, 0, 0)); } } class AddictiveBlueFilter extends ColorFilter { AddictiveBlueFilter() : super(name: "AddictiveBlue") { - subFilters.add(new AddictiveColorSubFilter(0, 0, 50)); + subFilters.add(AddictiveColorSubFilter(0, 0, 50)); } } // Gingham: Vintage-inspired, taking some color out class GinghamFilter extends ColorFilter { GinghamFilter() : super(name: "Gingham") { - subFilters.add(new SepiaSubFilter(.04)); - subFilters.add(new ContrastSubFilter(-.15)); + subFilters.add(SepiaSubFilter(.04)); + subFilters.add(ContrastSubFilter(-.15)); } } // Moon: B/W, increase brightness and decrease contrast class MoonFilter extends ColorFilter { MoonFilter() : super(name: "Moon") { - subFilters.add(new GrayScaleSubFilter()); - subFilters.add(new ContrastSubFilter(-.04)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(GrayScaleSubFilter()); + subFilters.add(ContrastSubFilter(-.04)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Lark: Brightens and intensifies colours but not red hues class LarkFilter extends ColorFilter { LarkFilter() : super(name: "Lark") { - subFilters.add(new BrightnessSubFilter(0.08)); - subFilters.add(new GrayScaleSubFilter()); - subFilters.add(new ContrastSubFilter(-.04)); + subFilters.add(BrightnessSubFilter(0.08)); + subFilters.add(GrayScaleSubFilter()); + subFilters.add(ContrastSubFilter(-.04)); } } // Reyes: a new vintage filter, gives your photos a “dusty” look class ReyesFilter extends ColorFilter { ReyesFilter() : super(name: "Reyes") { - subFilters.add(new SepiaSubFilter(0.4)); - subFilters.add(new BrightnessSubFilter(0.13)); - subFilters.add(new ContrastSubFilter(-.05)); + subFilters.add(SepiaSubFilter(0.4)); + subFilters.add(BrightnessSubFilter(0.13)); + subFilters.add(ContrastSubFilter(-.05)); } } // Juno: Brightens colors, and intensifies red and yellow hues class JunoFilter extends ColorFilter { JunoFilter() : super(name: "Juno") { - subFilters.add(new RGBScaleSubFilter(1.01, 1.04, 1)); - subFilters.add(new SaturationSubFilter(0.3)); + subFilters.add(RGBScaleSubFilter(1.01, 1.04, 1)); + subFilters.add(SaturationSubFilter(0.3)); } } // Slumber: Desaturates the image as well as adds haze for a retro, dreamy look – with an emphasis on blacks and blues class SlumberFilter extends ColorFilter { SlumberFilter() : super(name: "Slumber") { - subFilters.add(new BrightnessSubFilter(.1)); - subFilters.add(new SaturationSubFilter(-0.5)); + subFilters.add(BrightnessSubFilter(.1)); + subFilters.add(SaturationSubFilter(-0.5)); } } // Crema: Adds a creamy look that both warms and cools the image class CremaFilter extends ColorFilter { CremaFilter() : super(name: "Crema") { - subFilters.add(new RGBScaleSubFilter(1.04, 1, 1.02)); - subFilters.add(new SaturationSubFilter(-0.05)); + subFilters.add(RGBScaleSubFilter(1.04, 1, 1.02)); + subFilters.add(SaturationSubFilter(-0.05)); } } // Ludwig: A slight hint of desaturation that also enhances light class LudwigFilter extends ColorFilter { LudwigFilter() : super(name: "Ludwig") { - subFilters.add(new BrightnessSubFilter(.05)); - subFilters.add(new SaturationSubFilter(-0.03)); + subFilters.add(BrightnessSubFilter(.05)); + subFilters.add(SaturationSubFilter(-0.03)); } } // Aden: This filter gives a blue/pink natural look class AdenFilter extends ColorFilter { AdenFilter() : super(name: "Aden") { - subFilters.add(new RGBOverlaySubFilter(228, 130, 225, 0.13)); - subFilters.add(new SaturationSubFilter(-0.2)); + subFilters.add(RGBOverlaySubFilter(228, 130, 225, 0.13)); + subFilters.add(SaturationSubFilter(-0.2)); } } // Perpetua: Adding a pastel look, this filter is ideal for portraits class PerpetuaFilter extends ColorFilter { PerpetuaFilter() : super(name: "Perpetua") { - subFilters.add(new RGBScaleSubFilter(1.05, 1.1, 1)); + subFilters.add(RGBScaleSubFilter(1.05, 1.1, 1)); } } // Amaro: Adds light to an image, with the focus on the centre class AmaroFilter extends ColorFilter { AmaroFilter() : super(name: "Amaro") { - subFilters.add(new SaturationSubFilter(0.3)); - subFilters.add(new BrightnessSubFilter(0.15)); + subFilters.add(SaturationSubFilter(0.3)); + subFilters.add(BrightnessSubFilter(0.15)); } } // Mayfair: Applies a warm pink tone, subtle vignetting to brighten the photograph center and a thin black border class MayfairFilter extends ColorFilter { MayfairFilter() : super(name: "Mayfair") { - subFilters.add(new RGBOverlaySubFilter(230, 115, 108, 0.05)); - subFilters.add(new SaturationSubFilter(0.15)); + subFilters.add(RGBOverlaySubFilter(230, 115, 108, 0.05)); + subFilters.add(SaturationSubFilter(0.15)); } } // Rise: Adds a "glow" to the image, with softer lighting of the subject class RiseFilter extends ColorFilter { RiseFilter() : super(name: "Rise") { - subFilters.add(new RGBOverlaySubFilter(255, 170, 0, 0.1)); - subFilters.add(new BrightnessSubFilter(0.09)); - subFilters.add(new SaturationSubFilter(0.1)); + subFilters.add(RGBOverlaySubFilter(255, 170, 0, 0.1)); + subFilters.add(BrightnessSubFilter(0.09)); + subFilters.add(SaturationSubFilter(0.1)); } } // Hudson: Creates an "icy" illusion with heightened shadows, cool tint and dodged center class HudsonFilter extends ColorFilter { HudsonFilter() : super(name: "Hudson") { - subFilters.add(new RGBScaleSubFilter(1, 1, 1.25)); - subFilters.add(new ContrastSubFilter(0.1)); - subFilters.add(new BrightnessSubFilter(0.15)); + subFilters.add(RGBScaleSubFilter(1, 1, 1.25)); + subFilters.add(ContrastSubFilter(0.1)); + subFilters.add(BrightnessSubFilter(0.15)); } } // Valencia: Fades the image by increasing exposure and warming the colors, to give it an antique feel class ValenciaFilter extends ColorFilter { ValenciaFilter() : super(name: "Valencia") { - subFilters.add(new RGBOverlaySubFilter(255, 225, 80, 0.08)); - subFilters.add(new SaturationSubFilter(0.1)); - subFilters.add(new ContrastSubFilter(0.05)); + subFilters.add(RGBOverlaySubFilter(255, 225, 80, 0.08)); + subFilters.add(SaturationSubFilter(0.1)); + subFilters.add(ContrastSubFilter(0.05)); } } // X-Pro II: Increases color vibrance with a golden tint, high contrast and slight vignette added to the edges class XProIIFilter extends ColorFilter { XProIIFilter() : super(name: "X-Pro II") { - subFilters.add(new RGBOverlaySubFilter(255, 255, 0, 0.07)); - subFilters.add(new SaturationSubFilter(0.2)); - subFilters.add(new ContrastSubFilter(0.15)); + subFilters.add(RGBOverlaySubFilter(255, 255, 0, 0.07)); + subFilters.add(SaturationSubFilter(0.2)); + subFilters.add(ContrastSubFilter(0.15)); } } // Sierra: Gives a faded, softer look class SierraFilter extends ColorFilter { SierraFilter() : super(name: "Sierra") { - subFilters.add(new ContrastSubFilter(-0.15)); - subFilters.add(new SaturationSubFilter(0.1)); + subFilters.add(ContrastSubFilter(-0.15)); + subFilters.add(SaturationSubFilter(0.1)); } } // Willow: A monochromatic filter with subtle purple tones and a translucent white border class WillowFilter extends ColorFilter { WillowFilter() : super(name: "Willow") { - subFilters.add(new GrayScaleSubFilter()); - subFilters.add(new RGBOverlaySubFilter(100, 28, 210, 0.03)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(GrayScaleSubFilter()); + subFilters.add(RGBOverlaySubFilter(100, 28, 210, 0.03)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Lo-Fi: Enriches color and adds strong shadows through the use of saturation and "warming" the temperature class LoFiFilter extends ColorFilter { LoFiFilter() : super(name: "Lo-Fi") { - subFilters.add(new ContrastSubFilter(0.15)); - subFilters.add(new SaturationSubFilter(0.2)); + subFilters.add(ContrastSubFilter(0.15)); + subFilters.add(SaturationSubFilter(0.2)); } } // Inkwell: Direct shift to black and white class InkwellFilter extends ColorFilter { InkwellFilter() : super(name: "Inkwell") { - subFilters.add(new GrayScaleSubFilter()); + subFilters.add(GrayScaleSubFilter()); } } // Hefe: Hight contrast and saturation, with a similar effect to Lo-Fi but not quite as dramatic class HefeFilter extends ColorFilter { HefeFilter() : super(name: "Hefe") { - subFilters.add(new ContrastSubFilter(0.1)); - subFilters.add(new SaturationSubFilter(0.15)); + subFilters.add(ContrastSubFilter(0.1)); + subFilters.add(SaturationSubFilter(0.15)); } } // Nashville: Warms the temperature, lowers contrast and increases exposure to give a light "pink" tint – making it feel "nostalgic" class NashvilleFilter extends ColorFilter { NashvilleFilter() : super(name: "Nashville") { - subFilters.add(new RGBOverlaySubFilter(220, 115, 188, 0.12)); - subFilters.add(new ContrastSubFilter(-0.05)); + subFilters.add(RGBOverlaySubFilter(220, 115, 188, 0.12)); + subFilters.add(ContrastSubFilter(-0.05)); } } // Stinson: washing out the colors ever so slightly class StinsonFilter extends ColorFilter { StinsonFilter() : super(name: "Stinson") { - subFilters.add(new BrightnessSubFilter(0.1)); - subFilters.add(new SepiaSubFilter(0.3)); + subFilters.add(BrightnessSubFilter(0.1)); + subFilters.add(SepiaSubFilter(0.3)); } } // Vesper: adds a yellow tint that class VesperFilter extends ColorFilter { VesperFilter() : super(name: "Vesper") { - subFilters.add(new RGBOverlaySubFilter(255, 225, 0, 0.05)); - subFilters.add(new BrightnessSubFilter(0.06)); - subFilters.add(new ContrastSubFilter(0.06)); + subFilters.add(RGBOverlaySubFilter(255, 225, 0, 0.05)); + subFilters.add(BrightnessSubFilter(0.06)); + subFilters.add(ContrastSubFilter(0.06)); } } // Earlybird: Gives an older look with a sepia tint and warm temperature class EarlybirdFilter extends ColorFilter { EarlybirdFilter() : super(name: "Earlybird") { - subFilters.add(new RGBOverlaySubFilter(255, 165, 40, 0.2)); - subFilters.add(new SaturationSubFilter(0.15)); + subFilters.add(RGBOverlaySubFilter(255, 165, 40, 0.2)); + subFilters.add(SaturationSubFilter(0.15)); } } // Brannan: Increases contrast and exposure and adds a metallic tint class BrannanFilter extends ColorFilter { BrannanFilter() : super(name: "Brannan") { - subFilters.add(new ContrastSubFilter(0.2)); - subFilters.add(new RGBOverlaySubFilter(140, 10, 185, 0.1)); + subFilters.add(ContrastSubFilter(0.2)); + subFilters.add(RGBOverlaySubFilter(140, 10, 185, 0.1)); } } // Sutro: Burns photo edges, increases highlights and shadows dramatically with a focus on purple and brown colors class SutroFilter extends ColorFilter { SutroFilter() : super(name: "Sutro") { - subFilters.add(new BrightnessSubFilter(-0.1)); - subFilters.add(new SaturationSubFilter(-0.1)); + subFilters.add(BrightnessSubFilter(-0.1)); + subFilters.add(SaturationSubFilter(-0.1)); } } // Toaster: Ages the image by "burning" the centre and adds a dramatic vignette class ToasterFilter extends ColorFilter { ToasterFilter() : super(name: "Toaster") { - subFilters.add(new SepiaSubFilter(0.1)); - subFilters.add(new RGBOverlaySubFilter(255, 145, 0, 0.2)); + subFilters.add(SepiaSubFilter(0.1)); + subFilters.add(RGBOverlaySubFilter(255, 145, 0, 0.2)); } } // Walden: Increases exposure and adds a yellow tint class WaldenFilter extends ColorFilter { WaldenFilter() : super(name: "Walden") { - subFilters.add(new BrightnessSubFilter(0.1)); - subFilters.add(new RGBOverlaySubFilter(255, 255, 0, 0.2)); + subFilters.add(BrightnessSubFilter(0.1)); + subFilters.add(RGBOverlaySubFilter(255, 255, 0, 0.2)); } } // 1977: The increased exposure with a red tint gives the photograph a rosy, brighter, faded look. class F1977Filter extends ColorFilter { F1977Filter() : super(name: "1977") { - subFilters.add(new RGBOverlaySubFilter(255, 25, 0, 0.15)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(RGBOverlaySubFilter(255, 25, 0, 0.15)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Kelvin: Increases saturation and temperature to give it a radiant "glow" class KelvinFilter extends ColorFilter { KelvinFilter() : super(name: "Kelvin") { - subFilters.add(new RGBOverlaySubFilter(255, 140, 0, 0.1)); - subFilters.add(new RGBScaleSubFilter(1.15, 1.05, 1)); - subFilters.add(new SaturationSubFilter(0.35)); + subFilters.add(RGBOverlaySubFilter(255, 140, 0, 0.1)); + subFilters.add(RGBScaleSubFilter(1.15, 1.05, 1)); + subFilters.add(SaturationSubFilter(0.35)); } } // Maven: darkens images, increases shadows, and adds a slightly yellow tint overal class MavenFilter extends ColorFilter { MavenFilter() : super(name: "Maven") { - subFilters.add(new RGBOverlaySubFilter(225, 240, 0, 0.1)); - subFilters.add(new SaturationSubFilter(0.25)); - subFilters.add(new ContrastSubFilter(0.05)); + subFilters.add(RGBOverlaySubFilter(225, 240, 0, 0.1)); + subFilters.add(SaturationSubFilter(0.25)); + subFilters.add(ContrastSubFilter(0.05)); } } // Ginza: brightens and adds a warm glow class GinzaFilter extends ColorFilter { GinzaFilter() : super(name: "Ginza") { - subFilters.add(new SepiaSubFilter(0.06)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(SepiaSubFilter(0.06)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Skyline: brightens to the image pop class SkylineFilter extends ColorFilter { SkylineFilter() : super(name: "Skyline") { - subFilters.add(new SaturationSubFilter(0.35)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(SaturationSubFilter(0.35)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Dogpatch: increases the contrast, while washing out the lighter colors class DogpatchFilter extends ColorFilter { DogpatchFilter() : super(name: "Dogpatch") { - subFilters.add(new ContrastSubFilter(0.15)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(ContrastSubFilter(0.15)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Brooklyn class BrooklynFilter extends ColorFilter { BrooklynFilter() : super(name: "Brooklyn") { - subFilters.add(new RGBOverlaySubFilter(25, 240, 252, 0.05)); - subFilters.add(new SepiaSubFilter(0.3)); + subFilters.add(RGBOverlaySubFilter(25, 240, 252, 0.05)); + subFilters.add(SepiaSubFilter(0.3)); } } // Helena: adds an orange and teal vibe class HelenaFilter extends ColorFilter { HelenaFilter() : super(name: "Helena") { - subFilters.add(new RGBOverlaySubFilter(208, 208, 86, 0.2)); - subFilters.add(new ContrastSubFilter(0.15)); + subFilters.add(RGBOverlaySubFilter(208, 208, 86, 0.2)); + subFilters.add(ContrastSubFilter(0.15)); } } // Ashby: gives images a great golden glow and a subtle vintage feel class AshbyFilter extends ColorFilter { AshbyFilter() : super(name: "Ashby") { - subFilters.add(new RGBOverlaySubFilter(255, 160, 25, 0.1)); - subFilters.add(new BrightnessSubFilter(0.1)); + subFilters.add(RGBOverlaySubFilter(255, 160, 25, 0.1)); + subFilters.add(BrightnessSubFilter(0.1)); } } // Charmes: a high contrast filter, warming up colors in your image with a red tint class CharmesFilter extends ColorFilter { CharmesFilter() : super(name: "Charmes") { - subFilters.add(new RGBOverlaySubFilter(255, 50, 80, 0.12)); - subFilters.add(new ContrastSubFilter(0.05)); + subFilters.add(RGBOverlaySubFilter(255, 50, 80, 0.12)); + subFilters.add(ContrastSubFilter(0.05)); } } diff --git a/lib/filters/subfilters.dart b/lib/filters/subfilters.dart index cc9544e..421a041 100644 --- a/lib/filters/subfilters.dart +++ b/lib/filters/subfilters.dart @@ -177,9 +177,8 @@ class ConvolutionSubFilter implements ImageSubFilter { ///Apply the [ConvolutionSubFilter] to an Image. @override - void apply(Uint8List pixels, int width, int height) => - image_filter_utils.convolute(pixels, width, height, - this._normalizeKernel(this.weights), this.bias); + void apply(Uint8List pixels, int width, int height) => image_filter_utils + .convolute(pixels, width, height, _normalizeKernel(weights), bias); List _normalizeKernel(List kernel) { num sum = 0; diff --git a/lib/utils/color_filter_utils.dart b/lib/utils/color_filter_utils.dart index 2500043..1b91f0d 100644 --- a/lib/utils/color_filter_utils.dart +++ b/lib/utils/color_filter_utils.dart @@ -1,7 +1,7 @@ import 'dart:math'; import 'package:photofilters/models.dart'; -import 'package:photofilters/utils/utils.dart' as imageUtils; +import 'package:photofilters/utils/utils.dart' as image_utils; int clampPixel(int x) => x.clamp(0, 255); RGBA saturation(RGBA color, num saturation) { @@ -9,7 +9,7 @@ RGBA saturation(RGBA color, num saturation) { num gray = 0.2989 * color.red + 0.5870 * color.green + 0.1140 * color.blue; //weights from CCIR 601 spec - return new RGBA( + return RGBA( red: clampPixel((-gray * saturation + color.red * (1 + saturation)).round()), green: clampPixel( @@ -25,7 +25,7 @@ RGBA hueRotation(RGBA color, int degrees) { double W = sin(degrees * pi / 180); num r = color.red, g = color.green, b = color.blue; - return new RGBA( + return RGBA( red: clampPixel(((.299 + .701 * U + .168 * W) * r + (.587 - .587 * U + .330 * W) * g + (.114 - .114 * U - .497 * W) * b) @@ -46,7 +46,7 @@ RGBA grayscale(RGBA color) { int avg = clampPixel( (0.2126 * color.red + 0.7152 * color.green + 0.0722 * color.blue) .round()); - return new RGBA( + return RGBA( red: avg, green: avg, blue: avg, @@ -57,7 +57,7 @@ RGBA grayscale(RGBA color) { // Adj is 0 (unchanged) to 1 (sepia) RGBA sepia(RGBA color, num adj) { int r = color.red, g = color.green, b = color.blue; - return new RGBA( + return RGBA( red: clampPixel( ((r * (1 - (0.607 * adj))) + (g * .769 * adj) + (b * .189 * adj)) .round()), @@ -71,7 +71,7 @@ RGBA sepia(RGBA color, num adj) { } RGBA invert(RGBA color) { - return new RGBA( + return RGBA( red: clampPixel(255 - color.red), green: clampPixel(255 - color.green), blue: clampPixel(255 - color.blue), @@ -84,7 +84,7 @@ RGBA brightness(RGBA color, num adj) { adj = (adj > 1) ? 1 : adj; adj = (adj < -1) ? -1 : adj; adj = ~~(255 * adj).round(); - return new RGBA( + return RGBA( red: clampPixel(color.red + (adj as int)), green: clampPixel(color.green + adj), blue: clampPixel(color.blue + adj), @@ -93,10 +93,10 @@ RGBA brightness(RGBA color, num adj) { // Better result (slow) - adj should be < 1 (desaturated) to 1 (unchanged) and < 1 RGBA hueSaturation(RGBA color, num adj) { - var hsv = imageUtils.rgbToHsv(color.red, color.green, color.blue); + var hsv = image_utils.rgbToHsv(color.red, color.green, color.blue); hsv[1] = (hsv[1] ?? 0) * adj; - var rgb = imageUtils.hsvToRgb(hsv[0]!, hsv[1]!, hsv[2]!); - return new RGBA( + var rgb = image_utils.hsvToRgb(hsv[0]!, hsv[1]!, hsv[2]!); + return RGBA( red: clampPixel(rgb[0] as int), green: clampPixel(rgb[1] as int), blue: clampPixel(rgb[2] as int), @@ -108,7 +108,7 @@ RGBA hueSaturation(RGBA color, num adj) { RGBA contrast(RGBA color, num adj) { adj *= 255; double factor = (259 * (adj + 255)) / (255 * (259 - adj)); - return new RGBA( + return RGBA( red: clampPixel((factor * (color.red - 128) + 128).round()), green: clampPixel((factor * (color.green - 128) + 128).round()), blue: clampPixel((factor * (color.blue - 128) + 128).round()), @@ -118,7 +118,7 @@ RGBA contrast(RGBA color, num adj) { // ColorOverlay - add a slight color overlay. RGBA colorOverlay(RGBA color, num red, num green, num blue, num scale) { - return new RGBA( + return RGBA( red: clampPixel((color.red - (color.red - red) * scale).round()), green: clampPixel((color.green - (color.green - green) * scale).round()), blue: clampPixel((color.blue - (color.blue - blue) * scale).round()), @@ -128,7 +128,7 @@ RGBA colorOverlay(RGBA color, num red, num green, num blue, num scale) { // RGB Scale RGBA rgbScale(RGBA color, num red, num green, num blue) { - return new RGBA( + return RGBA( red: clampPixel((color.red * red).round()), green: clampPixel((color.green * green).round()), blue: clampPixel((color.blue * blue).round()), @@ -137,7 +137,7 @@ RGBA rgbScale(RGBA color, num red, num green, num blue) { } RGBA addictiveColor(RGBA color, int red, int green, int blue) { - return new RGBA( + return RGBA( red: clampPixel(color.red + red), green: clampPixel(color.green + green), blue: clampPixel(color.blue + blue), diff --git a/lib/utils/convolution_kernels.dart b/lib/utils/convolution_kernels.dart index 9ed4c38..0da5a0d 100644 --- a/lib/utils/convolution_kernels.dart +++ b/lib/utils/convolution_kernels.dart @@ -6,19 +6,19 @@ class ConvolutionKernel extends Object { } ConvolutionKernel identityKernel = - new ConvolutionKernel([0, 0, 0, 0, 1, 0, 0, 0, 0]); + ConvolutionKernel([0, 0, 0, 0, 1, 0, 0, 0, 0]); ConvolutionKernel sharpenKernel = - new ConvolutionKernel([-1, -1, -1, -1, 9, -1, -1, -1, -1]); + ConvolutionKernel([-1, -1, -1, -1, 9, -1, -1, -1, -1]); ConvolutionKernel embossKernel = - new ConvolutionKernel([-1, -1, 0, -1, 0, 1, 0, 1, 1], bias: 128); + ConvolutionKernel([-1, -1, 0, -1, 0, 1, 0, 1, 1], bias: 128); ConvolutionKernel coloredEdgeDetectionKernel = - new ConvolutionKernel([1, 1, 1, 1, -7, 1, 1, 1, 1]); + ConvolutionKernel([1, 1, 1, 1, -7, 1, 1, 1, 1]); ConvolutionKernel edgeDetectionMediumKernel = - new ConvolutionKernel([0, 1, 0, 1, -4, 1, 0, 1, 0]); + ConvolutionKernel([0, 1, 0, 1, -4, 1, 0, 1, 0]); ConvolutionKernel edgeDetectionHardKernel = - new ConvolutionKernel([-1, -1, -1, -1, 8, -1, -1, -1, -1]); + ConvolutionKernel([-1, -1, -1, -1, 8, -1, -1, -1, -1]); -ConvolutionKernel blurKernel = new ConvolutionKernel([ +ConvolutionKernel blurKernel = ConvolutionKernel([ 0, 0, 1, @@ -46,7 +46,7 @@ ConvolutionKernel blurKernel = new ConvolutionKernel([ 0 ]); -ConvolutionKernel guassian3x3Kernel = new ConvolutionKernel([ +ConvolutionKernel guassian3x3Kernel = ConvolutionKernel([ 1, 2, 1, @@ -58,7 +58,7 @@ ConvolutionKernel guassian3x3Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel guassian5x5Kernel = new ConvolutionKernel([ +ConvolutionKernel guassian5x5Kernel = ConvolutionKernel([ 2, 04, 05, @@ -86,7 +86,7 @@ ConvolutionKernel guassian5x5Kernel = new ConvolutionKernel([ 2 ]); -ConvolutionKernel guassian7x7Kernel = new ConvolutionKernel([ +ConvolutionKernel guassian7x7Kernel = ConvolutionKernel([ 1, 1, 2, @@ -138,7 +138,7 @@ ConvolutionKernel guassian7x7Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel mean3x3Kernel = new ConvolutionKernel([ +ConvolutionKernel mean3x3Kernel = ConvolutionKernel([ 1, 1, 1, @@ -150,7 +150,7 @@ ConvolutionKernel mean3x3Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel mean5x5Kernel = new ConvolutionKernel([ +ConvolutionKernel mean5x5Kernel = ConvolutionKernel([ 1, 1, 1, @@ -178,7 +178,7 @@ ConvolutionKernel mean5x5Kernel = new ConvolutionKernel([ 1 ]); -ConvolutionKernel lowPass3x3Kernel = new ConvolutionKernel([ +ConvolutionKernel lowPass3x3Kernel = ConvolutionKernel([ 1, 2, 1, @@ -190,7 +190,7 @@ ConvolutionKernel lowPass3x3Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel lowPass5x5Kernel = new ConvolutionKernel([ +ConvolutionKernel lowPass5x5Kernel = ConvolutionKernel([ 1, 1, 1, @@ -219,4 +219,4 @@ ConvolutionKernel lowPass5x5Kernel = new ConvolutionKernel([ ]); ConvolutionKernel highPass3x3Kernel = - new ConvolutionKernel([0, -0.25, 0, -0.25, 2, -0.25, 0, -0.25, 0]); + ConvolutionKernel([0, -0.25, 0, -0.25, 2, -0.25, 0, -0.25, 0]); diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index d088da0..91c7110 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -5,27 +5,27 @@ List rgbToHsv(num r, num g, num b) { g /= 255; b /= 255; - num _max = max( + num maxVal = max( r, max(g, b), ); - num _min = min( + num minVal = min( r, max(g, b), ); - num? h, s, v = _max; + num? h, s, v = maxVal; - num d = _max - _min; - s = _max == 0 ? 0 : d / _max; + num d = maxVal - minVal; + s = maxVal == 0 ? 0 : d / maxVal; if (max == min) { h = 0; // achromatic } else { - if (_max == r) { + if (maxVal == r) { h = (g - b) / d + (g < b ? 6 : 0); - } else if (_max == g) { + } else if (maxVal == g) { h = (b - r) / d + 2; - } else if (_max == b) { + } else if (maxVal == b) { h = (r - g) / d + 4; } } diff --git a/lib/widgets/photo_filter.dart b/lib/widgets/photo_filter.dart index 16e13cc..92b7aab 100644 --- a/lib/widgets/photo_filter.dart +++ b/lib/widgets/photo_filter.dart @@ -3,18 +3,19 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:image/image.dart' as imageLib; +import 'package:image/image.dart' as imagelib; import 'package:path_provider/path_provider.dart'; import 'package:photofilters/filters/filters.dart'; class PhotoFilter extends StatelessWidget { - final imageLib.Image image; + final imagelib.Image image; final String filename; final Filter filter; final BoxFit fit; final Widget loader; - PhotoFilter({ + const PhotoFilter({ + super.key, required this.image, required this.filename, required this.filter, @@ -38,8 +39,9 @@ class PhotoFilter extends StatelessWidget { case ConnectionState.waiting: return loader; case ConnectionState.done: - if (snapshot.hasError) + if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); + } return Image.memory( snapshot.data as dynamic, fit: fit, @@ -55,7 +57,7 @@ class PhotoFilterSelector extends StatefulWidget { final Widget title; final Color appBarColor; final List filters; - final imageLib.Image image; + final imagelib.Image image; final Widget loader; final BoxFit fit; final String filename; @@ -74,14 +76,14 @@ class PhotoFilterSelector extends StatefulWidget { }) : super(key: key); @override - State createState() => new _PhotoFilterSelectorState(); + State createState() => _PhotoFilterSelectorState(); } class _PhotoFilterSelectorState extends State { String? filename; Map?> cachedFilters = {}; Filter? _filter; - imageLib.Image? image; + imagelib.Image? image; late bool loading; @override @@ -109,19 +111,20 @@ class _PhotoFilterSelectorState extends State { loading ? Container() : IconButton( - icon: Icon(Icons.check), + icon: const Icon(Icons.check), onPressed: () async { setState(() { loading = true; }); var imageFile = await saveFilteredImage(); + // ignore: use_build_context_synchronously Navigator.pop(context, {'image_filtered': imageFile}); }, ) ], ), - body: Container( + body: SizedBox( width: double.infinity, height: double.infinity, child: loading @@ -134,7 +137,7 @@ class _PhotoFilterSelectorState extends State { child: Container( width: double.infinity, height: double.infinity, - padding: EdgeInsets.all(12.0), + padding: const EdgeInsets.all(12.0), child: _buildFilteredImage( _filter, image, @@ -144,34 +147,32 @@ class _PhotoFilterSelectorState extends State { ), Expanded( flex: 2, - child: Container( - child: ListView.builder( - scrollDirection: Axis.horizontal, - itemCount: widget.filters.length, - itemBuilder: (BuildContext context, int index) { - return InkWell( - child: Container( - padding: EdgeInsets.all(5.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - _buildFilterThumbnail( - widget.filters[index], image, filename), - SizedBox( - height: 5.0, - ), - Text( - widget.filters[index].name, - ) - ], - ), + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: widget.filters.length, + itemBuilder: (BuildContext context, int index) { + return InkWell( + child: Container( + padding: const EdgeInsets.all(5.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + _buildFilterThumbnail( + widget.filters[index], image, filename), + const SizedBox( + height: 5.0, + ), + Text( + widget.filters[index].name, + ) + ], ), - onTap: () => setState(() { - _filter = widget.filters[index]; - }), - ); - }, - ), + ), + onTap: () => setState(() { + _filter = widget.filters[index]; + }), + ); + }, ), ), ], @@ -182,7 +183,7 @@ class _PhotoFilterSelectorState extends State { } _buildFilterThumbnail( - Filter filter, imageLib.Image? image, String? filename) { + Filter filter, imagelib.Image? image, String? filename) { if (cachedFilters[filter.name] == null) { return FutureBuilder>( future: compute(applyFilter, { @@ -197,14 +198,15 @@ class _PhotoFilterSelectorState extends State { case ConnectionState.waiting: return CircleAvatar( radius: 50.0, + backgroundColor: Colors.white, child: Center( child: widget.loader, ), - backgroundColor: Colors.white, ); case ConnectionState.done: - if (snapshot.hasError) + if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); + } cachedFilters[filter.name] = snapshot.data; return CircleAvatar( radius: 50.0, @@ -246,7 +248,7 @@ class _PhotoFilterSelectorState extends State { } Widget _buildFilteredImage( - Filter? filter, imageLib.Image? image, String? filename) { + Filter? filter, imagelib.Image? image, String? filename) { if (cachedFilters[filter?.name ?? "_"] == null) { return FutureBuilder>( future: compute(applyFilter, { @@ -262,8 +264,9 @@ class _PhotoFilterSelectorState extends State { case ConnectionState.waiting: return widget.loader; case ConnectionState.done: - if (snapshot.hasError) + if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); + } cachedFilters[filter?.name ?? "_"] = snapshot.data; return widget.circleShape ? SizedBox( @@ -311,27 +314,27 @@ class _PhotoFilterSelectorState extends State { ///The global applyfilter function FutureOr> applyFilter(Map params) { Filter? filter = params["filter"]; - imageLib.Image image = params["image"]; + imagelib.Image image = params["image"]; String filename = params["filename"]; - List _bytes = image.getBytes(); + List bytes0 = image.getBytes(); if (filter != null) { - filter.apply(_bytes as dynamic, image.width, image.height); + filter.apply(bytes0 as dynamic, image.width, image.height); } - Uint8List bytes = Uint8List.fromList(_bytes); - imageLib.Image _image = imageLib.Image.fromBytes( + Uint8List bytes = Uint8List.fromList(bytes0); + imagelib.Image image0 = imagelib.Image.fromBytes( width: image.width, height: image.height, bytes: bytes.buffer); - _bytes = imageLib.encodeNamedImage( + bytes0 = imagelib.encodeNamedImage( filename, - _image, + image0, )!; - return _bytes; + return bytes0; } ///The global buildThumbnail function FutureOr> buildThumbnail(Map params) { int? width = params["width"]; - params["image"] = imageLib.copyResize(params["image"], width: width); + params["image"] = imagelib.copyResize(params["image"], width: width); return applyFilter(params); } diff --git a/test/convolution_test.dart b/test/convolution_test.dart index 47274e8..881929c 100644 --- a/test/convolution_test.dart +++ b/test/convolution_test.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:photofilters/photofilters.dart'; @@ -6,7 +7,7 @@ import 'test_utils.dart'; void main() { test("test Convolution", () { for (var filter in presetConvolutionFiltersList) { - print('Applying ${filter.name}'); + debugPrint('Applying ${filter.name}'); applyFilterOnFile( filter, 'res/bird.jpg', 'out/convolution/${filter.name}.jpg'); } diff --git a/test/custom_filters_test.dart b/test/custom_filters_test.dart index 736b00b..5190f04 100644 --- a/test/custom_filters_test.dart +++ b/test/custom_filters_test.dart @@ -8,7 +8,7 @@ import 'test_utils.dart'; void main() { test("Custom Image filter", () { - var customFilter = new ImageFilter(name: "Custom Image Filter"); + var customFilter = ImageFilter(name: "Custom Image Filter"); customFilter.addSubFilter(ConvolutionSubFilter.fromKernel( coloredEdgeDetectionKernel, )); @@ -31,7 +31,7 @@ void main() { }); test("Custom Color filter", () { - var customFilter = new ColorFilter(name: "Custom Color Filter"); + var customFilter = ColorFilter(name: "Custom Color Filter"); customFilter.addSubFilter(SaturationSubFilter(0.5)); customFilter .addSubFilters([BrightnessSubFilter(0.5), HueRotationSubFilter(30)]); diff --git a/test/photofilters_test.dart b/test/photofilters_test.dart index 12821f4..6a1820b 100644 --- a/test/photofilters_test.dart +++ b/test/photofilters_test.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:test/test.dart'; import 'package:photofilters/photofilters.dart'; import 'test_utils.dart'; @@ -5,7 +6,7 @@ import 'test_utils.dart'; void main() { test("test All", () { for (var filter in presetFiltersList) { - print('Applying ${filter.name}'); + debugPrint('Applying ${filter.name}'); applyFilterOnFile(filter, 'res/bird.jpg', 'out/${filter.name}.jpg'); } }); diff --git a/test/test_utils.dart b/test/test_utils.dart index 334c48a..234720e 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -10,7 +10,7 @@ void applyFilterOnFile(Filter filter, String src, String dest) { Image out = Image.fromBytes( width: image.width, height: image.height, bytes: pixels.buffer); - new File(dest).writeAsBytesSync(encodeNamedImage( + File(dest).writeAsBytesSync(encodeNamedImage( dest, out, )!); From 707490b9c6fd43775fffb2a7fd01679ac5b7dab7 Mon Sep 17 00:00:00 2001 From: jinosh05 Date: Fri, 2 Jun 2023 10:01:03 +0530 Subject: [PATCH 14/16] Changelog updated --- CHANGELOG.md | 7 +++++++ pubspec.yaml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adf42ca..3c6d448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,3 +49,10 @@ ## [3.0.1] - 15 Jun 2021 - Cast error bug fix + +## [3.0.2] - 02 Jun 2023 + +- Dart 3.0 Implemented +- Dependency package version upgrade +- flutter_lints package added +- flutter_lints rules followed diff --git a/pubspec.yaml b/pubspec.yaml index f0c2f93..fbb547d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: photofilters description: A flutter package for applying various types of filters to an image. You can create your own filters and subfilters too. -version: 3.0.1 +version: 3.0.2 homepage: https://github.com/skkallayath/photofilters environment: From c6824696a0c08335893fc1bd170e33b65821e38c Mon Sep 17 00:00:00 2001 From: bat2628 Date: Fri, 3 Nov 2023 15:34:03 +0300 Subject: [PATCH 15/16] Fixing Index out of range Error --- lib/filters/color_filters.dart | 45 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/filters/color_filters.dart b/lib/filters/color_filters.dart index 3a7ba4c..be4eef1 100644 --- a/lib/filters/color_filters.dart +++ b/lib/filters/color_filters.dart @@ -18,21 +18,38 @@ class ColorFilter extends Filter { @override void apply(Uint8List pixels, int width, int height) { - for (int i = 0; i < pixels.length; i += 4) { - RGBA color = RGBA( - red: pixels[i], - green: pixels[i + 1], - blue: pixels[i + 2], - alpha: pixels[i + 3]); - for (ColorSubFilter subFilter in subFilters) { - color = subFilter.applyFilter(color); + int remainingValue = pixels.length % 4; + if (remainingValue == 0) { + for (int i = 0; i < pixels.length; i += 4) { + RGBA color = RGBA( + red: pixels[i], + green: pixels[i + 1], + blue: pixels[i + 2], + alpha: pixels[i + 3]); + for (ColorSubFilter subFilter in subFilters) { + color = subFilter.applyFilter(color); + } + pixels[i] = color.red; + pixels[i + 1] = color.green; + pixels[i + 2] = color.blue; + pixels[i + 3] = color.alpha; } - pixels[i] = color.red; - pixels[i + 1] = color.green; - pixels[i + 2] = color.blue; - pixels[i + 3] = color.alpha; - } - } + } else { + for (int i = 0; i < pixels.length - remainingValue; i += 4) { + RGBA color = RGBA( + red: pixels[i], + green: pixels[i + 1], + blue: pixels[i + 2], + alpha: pixels[i + 3]); + for (ColorSubFilter subFilter in subFilters) { + color = subFilter.applyFilter(color); + } + pixels[i] = color.red; + pixels[i + 1] = color.green; + pixels[i + 2] = color.blue; + pixels[i + 3] = color.alpha; + } + }} void addSubFilter(ColorSubFilter subFilter) { subFilters.add(subFilter); From 7e3eccc465c17b3b6f436f2cac98e48aab20caa4 Mon Sep 17 00:00:00 2001 From: batoul-alani Date: Sun, 21 Jan 2024 10:54:16 +0300 Subject: [PATCH 16/16] Fixing Null check operator used on a null value --- .idea/.gitignore | 3 +++ ersDamascophoto filters | 29 +++++++++++++++++++++++++++++ lib/widgets/photo_filter.dart | 14 ++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 ersDamascophoto filters diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/ersDamascophoto filters b/ersDamascophoto filters new file mode 100644 index 0000000..2709f88 --- /dev/null +++ b/ersDamascophoto filters @@ -0,0 +1,29 @@ +diff.astextplain.textconv=astextplain +filter.lfs.clean=git-lfs clean -- %f +filter.lfs.smudge=git-lfs smudge -- %f +filter.lfs.process=git-lfs filter-process +filter.lfs.required=true +http.sslbackend=openssl +http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt +core.autocrlf=true +core.fscache=true +core.symlinks=false +pull.rebase=false +credential.helper=manager-core +credential.https://dev.azure.com.usehttppath=true +init.defaultbranch=master +user.name=batoul-alani +user.email=batoule50@gmail.com +core.repositoryformatversion=0 +core.filemode=false +core.bare=false +core.logallrefupdates=true +core.symlinks=false +core.ignorecase=true +remote.origin.url=https://github.com/batoul-alani/photofilters.git +remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* +branch.develop.remote=origin +branch.develop.merge=refs/heads/master +branch.develop.github-pr-base-branch=skkallayath#photofilters#master +remote.upstream.url=https://github.com/skkallayath/photofilters.git +remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/* diff --git a/lib/widgets/photo_filter.dart b/lib/widgets/photo_filter.dart index 92b7aab..8f8a9ee 100644 --- a/lib/widgets/photo_filter.dart +++ b/lib/widgets/photo_filter.dart @@ -113,13 +113,15 @@ class _PhotoFilterSelectorState extends State { : IconButton( icon: const Icon(Icons.check), onPressed: () async { - setState(() { - loading = true; - }); - var imageFile = await saveFilteredImage(); + if (cachedFilters[_filter?.name ?? "_"] != null) { + setState(() { + loading = true; + }); + var imageFile = await saveFilteredImage(); - // ignore: use_build_context_synchronously - Navigator.pop(context, {'image_filtered': imageFile}); + // ignore: use_build_context_synchronously + Navigator.pop(context, {'image_filtered': imageFile}); + } }, ) ],