Skip to content

Commit

Permalink
Add ContrastMode to contrast command
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed May 22, 2024
1 parent 7fa05e9 commit 3a7d3fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Image colorOffset(Image src, { num red = 0, num green = 0, num blue = 0, num alp
### [contrast](https://pub.dev/documentation/image/latest/image/contrast.html)

```dart
Image contrast(Image src, { required num contrast, Image? mask, Channel maskChannel = Channel.luminance })
Image contrast(Image src, { required num contrast, Image? mask, Channel maskChannel = Channel.luminance,
ContrastMode mode = ContrastMode.proprtional})
```

![contrast](images/filter/contrast.png)
Expand Down
6 changes: 5 additions & 1 deletion lib/src/command/filter/contrast_cmd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ class ContrastCmd extends Command {
final num _contrast;
Command? mask;
Channel maskChannel;
g.ContrastMode mode;

ContrastCmd(Command? input,
{num contrast = 100.0, this.mask, this.maskChannel = Channel.luminance})
{num contrast = 100.0,
this.mask,
this.maskChannel = Channel.luminance,
this.mode = g.ContrastMode.proportional})
: _contrast = contrast,
super(input);

Expand Down
3 changes: 2 additions & 1 deletion lib/src/filter/contrast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Image contrast(Image src,
} else {
if (contrast != _lastContrast) {
_lastContrast = contrast;
/// 0.12 is an arbitrary adjustment to use 100 as mid point

/// 0.12 is an arbitrary adjustment to use 100 as mid point
contrast = (contrast / 100.0) - 0.12;
_contrast = Uint8List(256);
for (var i = 0; i < 256; ++i) {
Expand Down

0 comments on commit 3a7d3fa

Please sign in to comment.