Skip to content

Commit

Permalink
refactoring gl convolution filter
Browse files Browse the repository at this point in the history
  • Loading branch information
easylogic committed Aug 25, 2018
1 parent 92046ea commit a154970
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 121 deletions.
44 changes: 3 additions & 41 deletions addon/codemirror-colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3113,53 +3113,34 @@ function emboss$1() {
}

function gaussianBlur$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

amount = parseParamNumber$2(amount);
var C = amount / 100;
var C = parseParamNumber$2(amount) * (1 / 16);

return convolution$1(weight$1([1, 2, 1, 2, 4, 2, 1, 2, 1], 1 / 16 * C));
return convolution$1(weight$1([1, 2, 1, 2, 4, 2, 1, 2, 1], C));
}

function gaussianBlur5x$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, 36, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1]);
}

function grayscale2$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([0.3, 0.3, 0.3, 0, 0, 0.59, 0.59, 0.59, 0, 0, 0.11, 0.11, 0.11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}

function kirschHorizontal$1() {
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

count = parseParamNumber$2(count);
return convolution$1([5, 5, 5, -3, 0, -3, -3, -3, -3]);
}

function kirschVertical$1() {
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

count = parseParamNumber$2(count);
return convolution$1([5, -3, -3, 5, 0, -3, 5, -3, -3]);
}

function laplacian$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([-1, -1, -1, -1, 8, -1, -1, -1, -1]);
}

function laplacian5x$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]);
}

Expand All @@ -3176,23 +3157,14 @@ function motionBlur3$1() {
}

function negative$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([-1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1]);
}

function sepia2$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([0.393, 0.349, 0.272, 0, 0, 0.769, 0.686, 0.534, 0, 0, 0.189, 0.168, 0.131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}

function sharpen$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([0, -1, 0, -1, 5, -1, 0, -1, 0]);
}

Expand All @@ -3205,16 +3177,10 @@ function sobelVertical$1() {
}

function transparency$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 1]);
}

function unsharpMasking$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 256;

amount = parseParamNumber$2(amount);
return convolution$1(weight$1([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1], -1 / 256));
}

Expand Down Expand Up @@ -3331,10 +3297,6 @@ function gamma$1() {
return shader('\n outColor = vec4(pow(pixelColor.r, ' + C + '), pow(pixelColor.g, ' + C + '), pow(pixelColor.b, ' + C + '), pixelColor.a );\n ');
}

/**
* F.gradient('red', 'blue', 'yellow', 'white', 10)
* F.gradient('red, blue, yellow, white, 10')
*/
function gradient$1() {
// 전체 매개변수 기준으로 파싱
// 색이 아닌 것 기준으로 scale 변수로 인식
Expand Down
44 changes: 7 additions & 37 deletions dist/codemirror-colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3162,54 +3162,39 @@ function emboss$1() {
return convolution$1([amount * -2.0, -amount, 0.0, -amount, 1.0, amount, 0.0, amount, amount * 2.0]);
}

/**
*
* @param {Number} amount 0..1
*/
function gaussianBlur$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

amount = parseParamNumber$2(amount);
var C = amount / 100;
var C = parseParamNumber$2(amount) * (1 / 16);

return convolution$1(weight$1([1, 2, 1, 2, 4, 2, 1, 2, 1], 1 / 16 * C));
return convolution$1(weight$1([1, 2, 1, 2, 4, 2, 1, 2, 1], C));
}

function gaussianBlur5x$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, 36, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1]);
}

function grayscale2$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([0.3, 0.3, 0.3, 0, 0, 0.59, 0.59, 0.59, 0, 0, 0.11, 0.11, 0.11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}

function kirschHorizontal$1() {
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

count = parseParamNumber$2(count);
return convolution$1([5, 5, 5, -3, 0, -3, -3, -3, -3]);
}

function kirschVertical$1() {
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

count = parseParamNumber$2(count);
return convolution$1([5, -3, -3, 5, 0, -3, 5, -3, -3]);
}

function laplacian$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([-1, -1, -1, -1, 8, -1, -1, -1, -1]);
}

function laplacian5x$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]);
}

Expand All @@ -3226,23 +3211,14 @@ function motionBlur3$1() {
}

function negative$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([-1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1]);
}

function sepia2$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([0.393, 0.349, 0.272, 0, 0, 0.769, 0.686, 0.534, 0, 0, 0.189, 0.168, 0.131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}

function sharpen$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([0, -1, 0, -1, 5, -1, 0, -1, 0]);
}

Expand All @@ -3255,16 +3231,10 @@ function sobelVertical$1() {
}

function transparency$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

amount = parseParamNumber$2(amount);
return convolution$1([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 1]);
}

function unsharpMasking$1() {
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 256;

amount = parseParamNumber$2(amount);
return convolution$1(weight$1([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1], -1 / 256));
}

Expand Down
2 changes: 1 addition & 1 deletion dist/codemirror-colorpicker.min.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/gaussian-blur-5x.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {
weight
} from '../util'

export default function gaussianBlur5x (amount = 100) {
amount = parseParamNumber(amount)
const C = amount / 100;
export default function gaussianBlur5x () {
return convolution([
1, 4, 6, 4, 1,
4, 16, 24, 16, 4,
Expand Down
11 changes: 7 additions & 4 deletions src/util/gl/filter/matrix/gaussian-blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import {
weight
} from '../util'

export default function gaussianBlur (amount = 100) {
amount = parseParamNumber(amount)
const C = amount / 100;
/**
*
* @param {Number} amount 0..1
*/
export default function gaussianBlur (amount = 1) {
const C = parseParamNumber(amount) * (1/16)

return convolution(weight([
1, 2, 1,
2, 4, 2,
1, 2, 1
], (1/16) * C ));
], C ));
}
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/grayscale2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function grayscale2 (amount = 100) {
amount = parseParamNumber(amount)
export default function grayscale2 () {
return convolution([
0.3, 0.3, 0.3, 0, 0,
0.59, 0.59, 0.59, 0, 0,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/kirsch-horizontal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function kirschHorizontal (count = 1) {
count = parseParamNumber(count)
export default function kirschHorizontal () {
return convolution([
5, 5, 5,
-3, 0, -3,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/kirsch-vertical.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function kirschVertical (count = 1) {
count = parseParamNumber(count)
export default function kirschVertical () {
return convolution([
5, -3, -3,
5, 0, -3,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/laplacian-5x.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function laplacian5x (amount = 100) {
amount = parseParamNumber(amount)
export default function laplacian5x () {
return convolution([
-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/laplacian.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function laplacian (amount = 100) {
amount = parseParamNumber(amount)
export default function laplacian () {
return convolution([
-1, -1, -1,
-1, 8, -1,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/negative.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function negative (amount = 100) {
amount = parseParamNumber(amount)
export default function negative () {
return convolution([
-1, 0, 0, 0, 0,
0, -1, 0, 0, 0,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/sepia2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function sepia2 (amount = 100) {
amount = parseParamNumber(amount)
export default function sepia2 () {
return convolution([
0.393, 0.349, 0.272, 0, 0,
0.769, 0.686, 0.534, 0, 0,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/sharpen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function sharpen (amount = 100) {
amount = parseParamNumber(amount)
export default function sharpen () {
return convolution([
0, -1, 0,
-1, 5, -1,
Expand Down
5 changes: 0 additions & 5 deletions src/util/gl/filter/matrix/sobel.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/transparency.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
parseParamNumber,
convolution
} from '../util'

export default function transparency (amount = 100) {
amount = parseParamNumber(amount)
export default function transparency () {
return convolution([
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
Expand Down
4 changes: 1 addition & 3 deletions src/util/gl/filter/matrix/unsharp-masking.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
parseParamNumber,
convolution,
weight
} from '../util'

export default function unsharpMasking (amount = 256) {
amount = parseParamNumber(amount)
export default function unsharpMasking () {
return convolution(weight([
1, 4, 6, 4, 1,
4, 16, 24, 16, 4,
Expand Down

0 comments on commit a154970

Please sign in to comment.