native_filters 0.0.4+alpha

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

Core Image and GPUImage filters package for Flutter #

A flutter package for iOS and Android for applying filter to image and video. Support all filters from Core Image on iOS.

Installation #

Add native_filters package as a dependency in your pubspec.yaml file.

iOS #

No additional configuration required, the plugin work out of the box.

Android #

No additional configuration required, the plugin work out of the box.

Example #

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:native_filters/native_filters.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';

void main() => runApp(new MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _filtersFactory = const FilterFactory();
  Filter _filter;
  File _output;
  Uint8List _data;

  String get asset => 'images/test.jpg';

  @override
  void initState() {
    super.initState();
    _prepare().then((_) => setState(() {}));
  }

  Future<void> _prepare() async {
    final directory = await getTemporaryDirectory();
    final uuid = Uuid();
    final path = '${directory.path}/${uuid.v4()}.jpg';
    if (defaultTargetPlatform == TargetPlatform.iOS) {
      _filter = await _filtersFactory.create('CIPhotoEffectMono');
    }
    if (defaultTargetPlatform == TargetPlatform.android) {
      _filter = await _filtersFactory.create('GPUImageFalseColorFilter');
    }
    await _filter?.setAssetSource(asset);
    _output = File(path);
    await _filter?.export(_output);
    _data = await _filter?.binaryOutput;
  }

  @override
  void dispose() {
    _filtersFactory.dispose(_filter);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(_filter?.name ?? 'Initializing...'),
      ),
      body: Center(
        child: _output == null
            ? CircularProgressIndicator()
            : Column(
                children: <Widget>[
                  Expanded(
                    child: imagePreview1,
                  ),
                  SizedBox(height: 3),
                  Expanded(
                    child: imagePreview2,
                  )
                ],
              ),
      ),
    );
  }

  Widget get imagePreview1 {
    if (_output != null) {
      return Image.file(_output);
    }
    return Text('Failed to process and save image');
  }

  Widget get imagePreview2 {
    if (_data != null) {
      return Image.memory(_data);
    }
    return Text('Failed to process image');
  }
}

Previews #

alt ios result

alt android result

Plugin data types support #

The following table shows how to pass values GPUImageFilter:

GPUAttributeClassFilterable methodDescription
floatsetNum
intsetNum
booleansetBoolValue
PointFsetPointValue
float[]setDoubleArrayValue
float[]setColorValueIf name of function points on color value
PointF[]setPointArrayValue

The following table shows how to pass values CIFilter:

CIAttributeClassCIAttributeTypeFilterable methodDescription
NSNumber*setNum
NSNumberCIAttributeTypeBooleansetBoolValue
CIColorsetColorValue
CIVectorCIAttributeTypePositionsetPointValue
CIVectorCIAttributeTypeOffsetsetPointValue
CIVectorCIAttributeTypeRectanglesetPointArrayValue
CIVectorCIAttributeTypePosition3setDoubleArrayValue
CIVectorsetDoubleArrayValue
NSValue*setDoubleArrayValue

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

native_filters #

0.0.1+alpha - 1 Jun 2020 #

  • Added CIFilter wrapper
  • Added platform views for filters demo
  • Implemented video and image processing.
  • Added grouping CIFilters

0.0.2+alpha - 7 Jun 2020 #

  • Fixed package structure

0.0.3+alpha - 14 Jun 2020 #

  • Added GPUImage wrapper for Android
  • Implemented image processing on Android.
  • Implemented grouping GPUImage filters.

0.0.4+alpha - 21 Jun 2020 #

  • Added API to set custom attributes for filter

example/lib/main.dart

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:native_filters/native_filters.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';

void main() => runApp(new MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _filtersFactory = const FilterFactory();
  Filter _filter;
  File _output;
  Uint8List _data;

  String get asset => 'images/test.jpg';

  @override
  void initState() {
    super.initState();
    _prepare().then((_) => setState(() {}));
  }

  Future<void> _prepare() async {
    final directory = await getTemporaryDirectory();
    final uuid = Uuid();
    final path = '${directory.path}/${uuid.v4()}.jpg';
    if (defaultTargetPlatform == TargetPlatform.iOS) {
      _filter = await _filtersFactory.create('CIPhotoEffectMono');
    }
    if (defaultTargetPlatform == TargetPlatform.android) {
      _filter = await _filtersFactory.create('GPUImageFalseColorFilter');
    }
    await _filter?.setAssetSource(asset);
    _output = File(path);
    await _filter?.export(_output);
    _data = await _filter?.binaryOutput;
  }

  @override
  void dispose() {
    _filtersFactory.dispose(_filter);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(_filter?.name ?? 'Initializing...'),
      ),
      body: Center(
        child: _output == null
            ? CircularProgressIndicator()
            : Column(
                children: <Widget>[
                  Expanded(
                    child: imagePreview1,
                  ),
                  SizedBox(height: 3),
                  Expanded(
                    child: imagePreview2,
                  )
                ],
              ),
      ),
    );
  }

  Widget get imagePreview1 {
    if (_output != null) {
      return Image.file(_output);
    }
    return Text('Failed to process and save image');
  }

  Widget get imagePreview2 {
    if (_data != null) {
      return Image.memory(_data);
    }
    return Text('Failed to process image');
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  native_filters: ^0.0.4+alpha

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:native_filters/native_filters.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
16
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:native_filters/native_filters.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:native_filters/native_filters.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:native_filters/native_filters.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:native_filters/native_filters.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • native_filters that is a package requiring null.

Health suggestions

Fix lib/widgets/image_preview.dart. (-0.50 points)

Analysis of lib/widgets/image_preview.dart reported 1 hint:

line 18 col 41: 'FilterImagePreview' is deprecated and shouldn't be used. For demonstration purposes only.

Fix lib/widgets/video_preview.dart. (-0.50 points)

Analysis of lib/widgets/video_preview.dart reported 1 hint:

line 18 col 46: 'FilterVideoPreview' is deprecated and shouldn't be used. For demonstration purposes only.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test