dart_lut 0.0.4+hotfix.1

Dart native js
Flutter Android iOS web

The implementation of image processing via 3D LUT (LookUp Tables). It's written on the pure Dart language so that it can be used with Flutter, CLI and web.

example/main.dart

import 'dart:io';

import 'package:dart_lut/src/lut.dart';
import 'package:image/image.dart';
import 'package:args/args.dart';
import 'package:path/path.dart' as path;

void main(List<String> args) async {
  final parser = ArgParser()
    ..addOption('lut-file', abbr: 'l')
    ..addOption('in-img', abbr: 'i')
    ..addOption('out-dir', abbr: 'o', defaultsTo: './out');

  final argsRes = parser.parse(args);

  _run(argsRes);
}

void _run(final ArgResults argResult) {
  var inputs = argResult['in-img'];

  if (!(inputs is Iterable)) {
    inputs = [inputs];
  }

  for (var img in inputs) {
    final imageFile = File(img);

    final lutPath = argResult['lut-file'];

    final lutFile = File(lutPath);

    final lut = LUT.fromString(lutFile.readAsStringSync());

    lut.isLoaded.listen((data) async {
      final image = decodeImage(imageFile.readAsBytesSync());
      final sw = Stopwatch()..start();
      final interp = InterpolationType.trilinear;

      final v = lut.applySync(image.getBytes(), interp);

      print('lut apply in ${sw.elapsed}');
      sw.stop();
      final image2 = Image.fromBytes(image.width, image.height, v);
      final outputFile = new File(
          '${argResult['out-dir']}/${path.basename(imageFile.path)}_${path.basename(lutFile.path)}_$interp.jpg')
        ..writeAsBytesSync(encodeJpg(image2));
      print('output image write to: ${outputFile.path}');
    });
  }
}

void _runStreamed(final ArgResults argResult) async {
  for (var img in argResult['in-img']) {
    final imageFile = File(img);

    final lutFile = File(argResult['lut-file']);

    final lut = LUT.fromString(lutFile.readAsStringSync());

    final isLoaded = await lut.awaitLoading();
    if (isLoaded) {
      final image = decodeImage(imageFile.readAsBytesSync());
      final interp = InterpolationType.trilinear;
      lut.applyAsStream(image.getBytes(), interp).listen((result) {
        //print('#${result.toRadixString(16).padLeft(4, '0')}');
      });
    }
  }
}
3
likes
100
pub points
21%
popularity

Publisher

dart.tools

The implementation of image processing via 3D LUT (LookUp Tables). It's written on the pure Dart language so that it can be used with Flutter, CLI and web.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on dart_lut