diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index d1ed5b1..e715928 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> - + android:name="flutterEmbedding" + android:value="2" /> 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 index b287c56..d49cd3e 100644 --- a/example/android/app/src/main/java/com/skkallayath/photofiltersexample/MainActivity.java +++ b/example/android/app/src/main/java/com/skkallayath/photofiltersexample/MainActivity.java @@ -1,13 +1,6 @@ package com.skkallayath.photofiltersexample; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } } diff --git a/example/lib/main.dart b/example/lib/main.dart index ba9ab0c..eb7dd0d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -7,68 +7,69 @@ import 'package:photofilters/photofilters.dart'; 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 { - String fileName; List filters = presetFiltersList; final picker = ImagePicker(); - File imageFile; + File? imageFile; Future getImage(context) async { - final pickedFile = await picker.getImage(source: ImageSource.gallery); + 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, + final File imageFile = File(pickedFile.path); + final String fileName = basename(imageFile.path); + var image = imageLib.decodeImage(await imageFile.readAsBytes())!; + image = imageLib.copyResize(image, width: 600); + Map imagefile = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => 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(() { + this.imageFile = imagefile['image_filtered']; + }); + print(imageFile.path); + } } } @override Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: new Text('Photo Filter Example'), + return Scaffold( + appBar: AppBar( + title: Text('Photo Filter Example'), ), body: Center( - child: new Container( + child: Container( child: imageFile == null ? Center( - child: new Text('No image selected.'), + 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: Icon(Icons.add_a_photo), ), ); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1e44b1b..b660b60 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -10,7 +10,7 @@ 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: ">=2.18.0 <3.0.0" dependencies: flutter: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 095988f..fd824a2 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -13,13 +13,13 @@ import '../lib/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(MyApp()); // Verify that platform version is retrieved. expect( find.byWidgetPredicate( (Widget widget) => - widget is Text && widget.data.startsWith('Running on:'), + widget is Text && (widget.data?.startsWith('Running on:') ?? false), ), findsOneWidget); }); diff --git a/lib/filters/convolution_filters.dart b/lib/filters/convolution_filters.dart index 938f414..f4a1b4a 100644 --- a/lib/filters/convolution_filters.dart +++ b/lib/filters/convolution_filters.dart @@ -2,37 +2,37 @@ import 'package:photofilters/filters/image_filters.dart'; import 'package:photofilters/filters/subfilters.dart'; import 'package:photofilters/utils/convolution_kernels.dart'; -var presetConvolutionFiltersList = [ - new ImageFilter(name: "Identity") +final presetConvolutionFiltersList = [ + 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/filters.dart b/lib/filters/filters.dart index f5cddc0..2d1cca2 100644 --- a/lib/filters/filters.dart +++ b/lib/filters/filters.dart @@ -3,7 +3,7 @@ import 'dart:typed_data'; ///The [Filter] class to define a Filter consists of multiple [SubFilter]s abstract class Filter extends Object { final String name; - Filter({required this.name}); + const Filter({required this.name}); ///Apply the [SubFilter] to an Image. void apply(Uint8List pixels, int width, int height); diff --git a/lib/filters/image_filters.dart b/lib/filters/image_filters.dart index 71d1a77..1aeb987 100644 --- a/lib/filters/image_filters.dart +++ b/lib/filters/image_filters.dart @@ -9,7 +9,7 @@ mixin ImageSubFilter on SubFilter { } class ImageFilter extends Filter { - List subFilters; + final List subFilters; ImageFilter({required String name}) : subFilters = [], diff --git a/lib/filters/preset_filters.dart b/lib/filters/preset_filters.dart index b62af13..faa60cf 100644 --- a/lib/filters/preset_filters.dart +++ b/lib/filters/preset_filters.dart @@ -17,346 +17,346 @@ 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 +// Reyes: a 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)); } } -List presetFiltersList = [ +final List presetFiltersList = [ NoFilter(), AddictiveBlueFilter(), AddictiveRedFilter(), diff --git a/lib/models.dart b/lib/models.dart index 099f6b2..c32190f 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -4,5 +4,5 @@ class RGBA extends Object { final int blue; final int alpha; - RGBA({this.red = 0, this.green = 0, this.blue = 0, this.alpha = 0}); + const RGBA({this.red = 0, this.green = 0, this.blue = 0, this.alpha = 0}); } diff --git a/lib/utils/color_filter_utils.dart b/lib/utils/color_filter_utils.dart index 2500043..caaacad 100644 --- a/lib/utils/color_filter_utils.dart +++ b/lib/utils/color_filter_utils.dart @@ -6,10 +6,10 @@ import 'package:photofilters/utils/utils.dart' as imageUtils; int clampPixel(int x) => x.clamp(0, 255); RGBA saturation(RGBA color, num saturation) { saturation = (saturation < -1) ? -1 : saturation; - num gray = 0.2989 * color.red + + final 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( @@ -21,11 +21,11 @@ RGBA saturation(RGBA color, num saturation) { } RGBA hueRotation(RGBA color, int degrees) { - double U = cos(degrees * pi / 180); - double W = sin(degrees * pi / 180); + final double U = cos(degrees * pi / 180); + final double W = sin(degrees * pi / 180); - num r = color.red, g = color.green, b = color.blue; - return new RGBA( + final num r = color.red, g = color.green, b = color.blue; + return RGBA( red: clampPixel(((.299 + .701 * U + .168 * W) * r + (.587 - .587 * U + .330 * W) * g + (.114 - .114 * U - .497 * W) * b) @@ -43,10 +43,10 @@ RGBA hueRotation(RGBA color, int degrees) { } RGBA grayscale(RGBA color) { - int avg = clampPixel( + final 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, @@ -56,8 +56,8 @@ 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( + final int r = color.red, g = color.green, b = color.blue; + 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); + final hsv = imageUtils.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( + final rgb = imageUtils.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), @@ -107,8 +107,8 @@ RGBA hueSaturation(RGBA color, num adj) { // Contrast - the adj value should be -1 to 1 RGBA contrast(RGBA color, num adj) { adj *= 255; - double factor = (259 * (adj + 255)) / (255 * (259 - adj)); - return new RGBA( + final double factor = (259 * (adj + 255)) / (255 * (259 - adj)); + 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..515d05a 100644 --- a/lib/utils/convolution_kernels.dart +++ b/lib/utils/convolution_kernels.dart @@ -2,23 +2,23 @@ class ConvolutionKernel extends Object { final List convolution; final double bias; - ConvolutionKernel(this.convolution, {this.bias = 0.0}); + const ConvolutionKernel(this.convolution, {this.bias = 0.0}); } -ConvolutionKernel identityKernel = - new ConvolutionKernel([0, 0, 0, 0, 1, 0, 0, 0, 0]); -ConvolutionKernel sharpenKernel = - new 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 coloredEdgeDetectionKernel = - new ConvolutionKernel([1, 1, 1, 1, -7, 1, 1, 1, 1]); -ConvolutionKernel edgeDetectionMediumKernel = - new ConvolutionKernel([0, 1, 0, 1, -4, 1, 0, 1, 0]); -ConvolutionKernel edgeDetectionHardKernel = - new ConvolutionKernel([-1, -1, -1, -1, 8, -1, -1, -1, -1]); +const ConvolutionKernel identityKernel = + ConvolutionKernel([0, 0, 0, 0, 1, 0, 0, 0, 0]); +const ConvolutionKernel sharpenKernel = + ConvolutionKernel([-1, -1, -1, -1, 9, -1, -1, -1, -1]); +const ConvolutionKernel embossKernel = + ConvolutionKernel([-1, -1, 0, -1, 0, 1, 0, 1, 1], bias: 128); +const ConvolutionKernel coloredEdgeDetectionKernel = + ConvolutionKernel([1, 1, 1, 1, -7, 1, 1, 1, 1]); +const ConvolutionKernel edgeDetectionMediumKernel = + ConvolutionKernel([0, 1, 0, 1, -4, 1, 0, 1, 0]); +const ConvolutionKernel edgeDetectionHardKernel = + ConvolutionKernel([-1, -1, -1, -1, 8, -1, -1, -1, -1]); -ConvolutionKernel blurKernel = new ConvolutionKernel([ +const ConvolutionKernel blurKernel = ConvolutionKernel([ 0, 0, 1, @@ -46,7 +46,7 @@ ConvolutionKernel blurKernel = new ConvolutionKernel([ 0 ]); -ConvolutionKernel guassian3x3Kernel = new ConvolutionKernel([ +const ConvolutionKernel guassian3x3Kernel = ConvolutionKernel([ 1, 2, 1, @@ -58,7 +58,7 @@ ConvolutionKernel guassian3x3Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel guassian5x5Kernel = new ConvolutionKernel([ +const ConvolutionKernel guassian5x5Kernel = ConvolutionKernel([ 2, 04, 05, @@ -86,7 +86,7 @@ ConvolutionKernel guassian5x5Kernel = new ConvolutionKernel([ 2 ]); -ConvolutionKernel guassian7x7Kernel = new ConvolutionKernel([ +const ConvolutionKernel guassian7x7Kernel = ConvolutionKernel([ 1, 1, 2, @@ -138,7 +138,7 @@ ConvolutionKernel guassian7x7Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel mean3x3Kernel = new ConvolutionKernel([ +const ConvolutionKernel mean3x3Kernel = ConvolutionKernel([ 1, 1, 1, @@ -150,7 +150,7 @@ ConvolutionKernel mean3x3Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel mean5x5Kernel = new ConvolutionKernel([ +const ConvolutionKernel mean5x5Kernel = ConvolutionKernel([ 1, 1, 1, @@ -178,7 +178,7 @@ ConvolutionKernel mean5x5Kernel = new ConvolutionKernel([ 1 ]); -ConvolutionKernel lowPass3x3Kernel = new ConvolutionKernel([ +const ConvolutionKernel lowPass3x3Kernel = ConvolutionKernel([ 1, 2, 1, @@ -190,7 +190,7 @@ ConvolutionKernel lowPass3x3Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel lowPass5x5Kernel = new ConvolutionKernel([ +const ConvolutionKernel lowPass5x5Kernel = ConvolutionKernel([ 1, 1, 1, @@ -218,5 +218,5 @@ ConvolutionKernel lowPass5x5Kernel = new ConvolutionKernel([ 1, ]); -ConvolutionKernel highPass3x3Kernel = - new ConvolutionKernel([0, -0.25, 0, -0.25, 2, -0.25, 0, -0.25, 0]); +const ConvolutionKernel highPass3x3Kernel = + ConvolutionKernel([0, -0.25, 0, -0.25, 2, -0.25, 0, -0.25, 0]); diff --git a/lib/utils/image_filter_utils.dart b/lib/utils/image_filter_utils.dart index c245359..434a4d4 100644 --- a/lib/utils/image_filter_utils.dart +++ b/lib/utils/image_filter_utils.dart @@ -7,8 +7,8 @@ int clampPixel(int x) => x.clamp(0, 255); void saturation(Uint8List bytes, num saturation) { saturation = (saturation < -1) ? -1 : saturation; for (int i = 0; i < bytes.length; i += 4) { - num r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; - num gray = + final num r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; + final num gray = 0.2989 * r + 0.5870 * g + 0.1140 * b; //weights from CCIR 601 spec bytes[i] = clampPixel((-gray * saturation + bytes[i] * (1 + saturation)).round()); @@ -20,11 +20,11 @@ void saturation(Uint8List bytes, num saturation) { } void hueRotation(Uint8List bytes, int degrees) { - double U = cos(degrees * pi / 180); - double W = sin(degrees * pi / 180); + final double U = cos(degrees * pi / 180); + final double W = sin(degrees * pi / 180); for (int i = 0; i < bytes.length; i += 4) { - num r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; + final num r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; bytes[i] = clampPixel(((.299 + .701 * U + .168 * W) * r + (.587 - .587 * U + .330 * W) * g + (.114 - .114 * U - .497 * W) * b) @@ -42,8 +42,8 @@ void hueRotation(Uint8List bytes, int degrees) { void grayscale(Uint8List bytes) { for (int i = 0; i < bytes.length; i += 4) { - int r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; - int avg = clampPixel((0.2126 * r + 0.7152 * g + 0.0722 * b).round()); + final int r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; + final int avg = clampPixel((0.2126 * r + 0.7152 * g + 0.0722 * b).round()); bytes[i] = avg; bytes[i + 1] = avg; bytes[i + 2] = avg; @@ -53,7 +53,7 @@ void grayscale(Uint8List bytes) { // Adj is 0 (unchanged) to 1 (sepia) void sepia(Uint8List bytes, num adj) { for (int i = 0; i < bytes.length; i += 4) { - int r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; + final int r = bytes[i], g = bytes[i + 1], b = bytes[i + 2]; bytes[i] = clampPixel( ((r * (1 - (0.607 * adj))) + (g * .769 * adj) + (b * .189 * adj)) .round()); @@ -89,9 +89,9 @@ void brightness(Uint8List bytes, num adj) { // Better result (slow) - adj should be < 1 (desaturated) to 1 (unchanged) and < 1 void hueSaturation(Uint8List bytes, num adj) { for (int i = 0; i < bytes.length; i += 4) { - var hsv = rgbToHsv(bytes[i], bytes[i + 1], bytes[i + 2]); + final hsv = rgbToHsv(bytes[i], bytes[i + 1], bytes[i + 2]); hsv[1] = (hsv[1] ?? 0) * adj; - var rgb = hsvToRgb(hsv[0]!, hsv[1]!, hsv[2]!); + final rgb = hsvToRgb(hsv[0]!, hsv[1]!, hsv[2]!); bytes[i] = clampPixel(rgb[0] as int); bytes[i + 1] = clampPixel(rgb[1] as int); bytes[i + 2] = clampPixel(rgb[2] as int); @@ -101,7 +101,7 @@ void hueSaturation(Uint8List bytes, num adj) { // Contrast - the adj value should be -1 to 1 void contrast(Uint8List bytes, num adj) { adj *= 255; - double factor = (259 * (adj + 255)) / (255 * (259 - adj)); + final double factor = (259 * (adj + 255)) / (255 * (259 - adj)); for (int i = 0; i < bytes.length; i += 4) { bytes[i] = clampPixel((factor * (bytes[i] - 128) + 128).round()); bytes[i + 1] = clampPixel((factor * (bytes[i + 1] - 128) + 128).round()); @@ -132,29 +132,29 @@ void rgbScale(Uint8List bytes, num red, num green, num blue) { // Convolute - weights are 3x3 matrix void convolute( Uint8List pixels, int width, int height, List weights, num bias) { - var bytes = Uint8List.fromList(pixels); - int side = sqrt(weights.length).round(); - int halfSide = ~~(side / 2).round() - side % 2; - int sw = width; - int sh = height; + final bytes = Uint8List.fromList(pixels); + final int side = sqrt(weights.length).round(); + final int halfSide = ~~(side / 2).round() - side % 2; + final int sw = width; + final int sh = height; - int w = sw; - int h = sh; + final int w = sw; + final int h = sh; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { - int sy = y; - int sx = x; - int dstOff = (y * w + x) * 4; + final int sy = y; + final int sx = x; + final int dstOff = (y * w + x) * 4; num r = bias, g = bias, b = bias; for (int cy = 0; cy < side; cy++) { for (int cx = 0; cx < side; cx++) { - int scy = sy + cy - halfSide; - int scx = sx + cx - halfSide; + final int scy = sy + cy - halfSide; + final int scx = sx + cx - halfSide; if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { - int srcOff = (scy * sw + scx) * 4; - num wt = weights[cy * side + cx]; + final int srcOff = (scy * sw + scx) * 4; + final num wt = weights[cy * side + cx]; r += bytes[srcOff] * wt; g += bytes[srcOff + 1] * wt; diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index d088da0..3d34bb5 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -5,44 +5,43 @@ List rgbToHsv(num r, num g, num b) { g /= 255; b /= 255; - num _max = max( + final num _max = max( r, max(g, b), ); - num _min = min( + final num _min = min( r, max(g, b), ); - num? h, s, v = _max; + final num h, s, v = _max; - num d = _max - _min; + final num d = _max - _min; s = _max == 0 ? 0 : d / _max; if (max == min) { h = 0; // achromatic - } else { - if (_max == r) { - h = (g - b) / d + (g < b ? 6 : 0); - } else if (_max == g) { - h = (b - r) / d + 2; - } else if (_max == b) { - h = (r - g) / d + 4; - } + } else if (_max == r) { + h = (g - b) / d + (g < b ? 6 : 0); + } else if (_max == g) { + h = (b - r) / d + 2; + } else if (_max == b) { + h = (r - g) / d + 4; + } + else { + h = 0; } - - h = h ?? 0 / 6; return [h, s, v]; } List hsvToRgb(num h, num s, num v) { - int r = 0, g = 0, b = 0; + final int r, g, b; - int i = (h * 6).floor(); - int f = h * 6 - i as int; - int p = v * (1 - s) as int; - int q = v * (1 - f * s) as int; - int t = v * (1 - (1 - f) * s) as int; + final int i = (h * 6).floor(); + final int f = h * 6 - i as int; + final int p = v * (1 - s) as int; + final int q = v * (1 - f * s) as int; + final int t = v * (1 - (1 - f) * s) as int; switch (i % 6) { case 0: @@ -75,6 +74,10 @@ List hsvToRgb(num h, num s, num v) { g = p; b = q; break; + default: + r = 0; + g = 0; + b = 0; } return [r * 255, g * 255, b * 255]; diff --git a/lib/widgets/photo_filter.dart b/lib/widgets/photo_filter.dart index 31223a7..6f8ff2d 100644 --- a/lib/widgets/photo_filter.dart +++ b/lib/widgets/photo_filter.dart @@ -14,7 +14,7 @@ class PhotoFilter extends StatelessWidget { final BoxFit fit; final Widget loader; - PhotoFilter({ + const PhotoFilter({ required this.image, required this.filename, required this.filter, @@ -76,7 +76,7 @@ class PhotoFilterSelector extends StatefulWidget { }) : super(key: key); @override - State createState() => new _PhotoFilterSelectorState(); + State createState() => _PhotoFilterSelectorState(); } class _PhotoFilterSelectorState extends State { @@ -315,24 +315,22 @@ class _PhotoFilterSelectorState extends State { } ///The global applyfilter function -FutureOr> applyFilter(Map params) { - Filter? filter = params["filter"]; - imageLib.Image image = params["image"]; - String filename = params["filename"]; - List _bytes = image.getBytes(); +List applyFilter(Map params) { + final Filter? filter = params["filter"]; + final imageLib.Image image = params["image"]; + final String filename = params["filename"]; + final Uint8List _bytes = image.getBytes(); 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)!; - - return _bytes; + imageLib.Image.fromBytes(width: image.width, height: image.height, bytes: _bytes.buffer); + return imageLib.encodeNamedImage(filename, _image)!; } ///The global buildThumbnail function -FutureOr> buildThumbnail(Map params) { - int? width = params["width"]; +List buildThumbnail(Map params) { + final int? width = params["width"]; params["image"] = imageLib.copyResize(params["image"], width: width); return applyFilter(params); } diff --git a/pubspec.yaml b/pubspec.yaml index 14dbcd1..f93e0e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - image: ^3.0.2 + image: ^4.0.12 meta: ^1.3.0 path_provider: ^2.0.1 @@ -17,8 +17,8 @@ dev_dependencies: flutter_test: sdk: flutter test: ^1.16.5 - image_picker: ^0.7.4 - path: ^1.8.0 + image_picker: ^0.8.6+1 + path: ^1.8.2 # For information on the generic Dart part of this file, see the # following page: https://www.dartlang.org/tools/pub/pubspec diff --git a/test/convolution_test.dart b/test/convolution_test.dart index 47274e8..dbab435 100644 --- a/test/convolution_test.dart +++ b/test/convolution_test.dart @@ -5,7 +5,7 @@ import 'test_utils.dart'; void main() { test("test Convolution", () { - for (var filter in presetConvolutionFiltersList) { + for (final filter in presetConvolutionFiltersList) { print('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..a012f75 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"); + final 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"); + final 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..9e01961 100644 --- a/test/photofilters_test.dart +++ b/test/photofilters_test.dart @@ -4,7 +4,7 @@ import 'test_utils.dart'; void main() { test("test All", () { - for (var filter in presetFiltersList) { + for (final filter in presetFiltersList) { print('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 83034f4..c509bb1 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -4,9 +4,9 @@ import 'package:image/image.dart'; import 'package:photofilters/filters/filters.dart'; void applyFilterOnFile(Filter filter, String src, String dest) { - Image image = decodeImage(File(src).readAsBytesSync())!; - var pixels = image.getBytes(); + final Image image = decodeImage(File(src).readAsBytesSync())!; + final 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)!); + final Image out = Image.fromBytes(width: image.width, height: image.height, bytes: pixels.buffer); + File(dest).writeAsBytesSync(encodeNamedImage(dest, out)!); }