Skip to content

Commit

Permalink
Fixes ColorOption.contrast (issue #105) (#107)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Li <[email protected]>
  • Loading branch information
ramtinq and AlexV525 authored Mar 15, 2023
1 parent d4c41dd commit 63372bd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions image_editor_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGE LOG

## 1.0.1

- Fix invalid matrix with `ColorOption.contrast`.

## 1.0.0

Initial version, The platform interface API of [image_editor][].
Expand Down
8 changes: 8 additions & 0 deletions image_editor_platform_interface/lib/src/option/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,16 @@ class ColorOption implements Option {
return ColorOption.scale(brightness, brightness, brightness, 1);
}

/// The contrast translate follows the guide:
/// https://docs.rainmeter.net/tips/colormatrix-guide.
factory ColorOption.contrast(double contrast) {
final m = List<double>.from(defaultColorMatrix);

// final double translate = 255.0 * (1 - contrast) / 2
final double translate = (1 - contrast) * 127.5; // faster
m[4] = translate;
m[9] = translate;
m[14] = translate;
m[0] = contrast;
m[6] = contrast;
m[12] = contrast;
Expand Down
2 changes: 1 addition & 1 deletion image_editor_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: image_editor_platform_interface
description: Edit your image data and output to file/memory on Android and iOS.
version: 1.0.0
version: 1.0.1
repository: https://github.com/fluttercandies/flutter_image_editor

environment:
Expand Down
20 changes: 20 additions & 0 deletions image_editor_platform_interface/test/color_option_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:image_editor_platform_interface/src/option/edit_options.dart';

void main() {
test('contrast = 1 should give us the default matrix', () {
expect(ColorOption.contrast(1).matrix, defaultColorMatrix);
});
test(
'contrast = 0 should have zeros in the diameter, '
'127.5 in last column except for the last row',
() {
final matrix = List.filled(defaultColorMatrix.length, 0.0);
matrix[4] = 127.5;
matrix[9] = 127.5;
matrix[14] = 127.5;
matrix[18] = 1;
expect(ColorOption.contrast(0).matrix, matrix);
},
);
}
8 changes: 7 additions & 1 deletion runnable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ check_code(){
echo "Generate docs in $PWD"
dart pub global run dartdoc

# If have example folder, analyse example code
# Analyze if the "example" folder exists.
if [ -d "example" ]; then
echo "Analyse example code in $PWD"
cd example
flutter pub get
flutter analyze lib
fi

# Run tests if the "test" folder exists.
if [ -d "test" ]; then
echo "Running tests in $PWD"
flutter test
fi
}


Expand Down

0 comments on commit 63372bd

Please sign in to comment.