Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Oct 11, 2024
2 parents 6d13765 + 4d1675c commit e45d4cf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions haxe/ui/backend/openfl/FilterConverter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import haxe.ui.backend.openfl.filters.HueRotateFilter;
import haxe.ui.backend.openfl.filters.ContrastFilter;
import haxe.ui.backend.openfl.filters.SaturateFilter;
import haxe.ui.backend.openfl.filters.TintFilter;
import haxe.ui.backend.openfl.filters.InvertFilter;
import haxe.ui.backend.openfl.filters.BrightnessFilter;

class FilterConverter {
public static function convertFilter(input:Filter):BitmapFilter {
Expand Down Expand Up @@ -49,6 +51,12 @@ class FilterConverter {
} else if ((input is haxe.ui.filters.Saturate)) {
var saturate:haxe.ui.filters.Saturate = cast(input, haxe.ui.filters.Saturate);
output = new SaturateFilter(saturate.multiplier).filter;
} else if (input is haxe.ui.filters.Invert) {
var invert:haxe.ui.filters.Invert = cast(input, haxe.ui.filters.Invert);
output = new InvertFilter(invert.multiplier).filter;
} else if (input is haxe.ui.filters.Brightness) {
var brightness:haxe.ui.filters.Brightness = cast(input, haxe.ui.filters.Brightness);
output = new BrightnessFilter(brightness.multiplier).filter;
}

#end
Expand Down
21 changes: 21 additions & 0 deletions haxe/ui/backend/openfl/filters/BrightnessFilter.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package haxe.ui.backend.openfl.filters;

import openfl.filters.ColorMatrixFilter;

class BrightnessFilter {
public var filter:ColorMatrixFilter;

public function new(multiplier:Float = 1) {
// In html, 0 is a black image, 1 has no effect, over it's a multiplier
// So we adapt
if (multiplier <= 1) multiplier = (multiplier -1) * 255;
if (multiplier > 1) multiplier = (multiplier -1) * 110;

filter = new ColorMatrixFilter([
1,0,0,0,multiplier,
0,1,0,0,multiplier,
0,0,1,0,multiplier,
0,0,0,1,0,
0,0,0,0,1]);
}
}
23 changes: 23 additions & 0 deletions haxe/ui/backend/openfl/filters/InvertFilter.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package haxe.ui.backend.openfl.filters;

import openfl.filters.ColorMatrixFilter;

class InvertFilter {
public var filter:ColorMatrixFilter;

/*<filter id="invert">
<feComponentTransfer>
<feFuncR type="table" tableValues="[amount] (1 - [amount])"/>
<feFuncG type="table" tableValues="[amount] (1 - [amount])"/>
<feFuncB type="table" tableValues="[amount] (1 - [amount])"/>
</feComponentTransfer>
</filter>*/

public function new(multiplier:Float = 1) {
filter = new ColorMatrixFilter([
-1*multiplier, 0, 0, 0, 255,
0, -1*multiplier, 0, 0, 255,
0, 0, -1*multiplier, 0, 255,
0, 0, 0, 1, 0]);
}
}

0 comments on commit e45d4cf

Please sign in to comment.