2
2
*
3
3
* FILTER.js
4
4
* @version: 1.9.0
5
- * @built on 2023-09-20 11:18:18
5
+ * @built on 2023-09-20 15:35:50
6
6
* @dependencies: Asynchronous.js
7
7
*
8
8
* JavaScript Image Processing Library
12
12
*
13
13
* FILTER.js
14
14
* @version: 1.9.0
15
- * @built on 2023-09-20 11:18:18
15
+ * @built on 2023-09-20 15:35:50
16
16
* @dependencies: Asynchronous.js
17
17
*
18
18
* JavaScript Image Processing Library
@@ -2250,7 +2250,7 @@ return {
2250
2250
' float g = gradient_suppressed(img, pix, dp, magnitude_scale, magnitude_limit, magnitude_max);',
2251
2251
' if (g >= high) return vec4(vec3(1.0), a);',
2252
2252
' else if (g < low) return vec4(vec3(0.0), a);',
2253
- ' return vec4(vec3(/*clamp((g-low)/(high-low)-0.1, 0.0, 0.9)/0.9*/0.1 ), a);',
2253
+ ' return vec4(vec3(/*clamp((g-low)/(high-low)-0.1, 0.0, 0.9)/0.9*/0.01 ), a);',
2254
2254
'}'
2255
2255
].join('\n'),
2256
2256
'hysteresis': [
@@ -3659,7 +3659,7 @@ function getProgram(gl, shader, programCache)
3659
3659
}
3660
3660
function GLSLFilter(filter)
3661
3661
{
3662
- var self = this, glsls = [], glsl = null, io = {},
3662
+ var self = this, glsls = [], glsl = null, shaders = {}, io = {},
3663
3663
prev_output = function(glsl) {
3664
3664
return glsl._prev && glsl._prev._output && HAS.call(io, glsl._prev._output) ? io[glsl._prev._output] : null;
3665
3665
};
@@ -3792,9 +3792,11 @@ function GLSLFilter(filter)
3792
3792
};
3793
3793
return self;
3794
3794
};
3795
- self.shader = function(shader, iterations) {
3795
+ self.shader = function(shader, iterations, name ) {
3796
3796
if (glsl)
3797
3797
{
3798
+ if (shader && HAS.call(shaders, shader)) shader = shaders[shader];
3799
+ if (name && shader) shaders[name] = shader;
3798
3800
glsl.shader = shader || null;
3799
3801
glsl.iterations = iterations || 1;
3800
3802
}
@@ -15776,7 +15778,7 @@ FILTER.Create({
15776
15778
//needed arrays
15777
15779
tile, diagonal, mask,
15778
15780
a1, a2, a3, i, j,
15779
- index, N, N2, imSize;
15781
+ index, indexd, N, N2, imSize;
15780
15782
15781
15783
//find largest side of the image
15782
15784
//and resize the image to become square
@@ -15785,19 +15787,21 @@ FILTER.Create({
15785
15787
N2 = stdMath.round(N/2);
15786
15788
imSize = im.length;
15787
15789
tile = new FILTER.ImArray(imSize);
15788
- diagonal = getdiagonal(im, N, N2);
15790
+ // diagonal = getdiagonal(im, N, N2);
15789
15791
mask = getmask(self.type, N, N2);
15790
15792
15791
15793
//Create the tile
15792
15794
for (j=0,i=0; j<N; ++i)
15793
15795
{
15794
15796
if (i >= N) {i=0; ++j;}
15795
15797
index = i+j*N;
15796
- a1 = mask[index]; a2 = mask[(i+N2) % N + ((j+N2) % N)*N];
15797
- a3 = a1+a2; a1 /= a3; a2 /= a3; index <<= 2;
15798
- tile[index ] = ~~(a1*im[index ] + a2*diagonal[index ]);
15799
- tile[index+1] = ~~(a1*im[index+1] + a2*diagonal[index+1]);
15800
- tile[index+2] = ~~(a1*im[index+2] + a2*diagonal[index+2]);
15798
+ indexd = ((i+N2) % N) + ((j+N2) % N)*N;
15799
+ a1 = mask[index]; a2 = mask[indexd];
15800
+ a3 = a1+a2; a1 /= a3; a2 /= a3;
15801
+ index <<= 2; indexd <<= 2;
15802
+ tile[index ] = ~~(a1*im[index ] + a2*im[indexd ]/*diagonal[index ]*/);
15803
+ tile[index+1] = ~~(a1*im[index+1] + a2*im[indexd+1]/*diagonal[index+1]*/);
15804
+ tile[index+2] = ~~(a1*im[index+2] + a2*im[indexd+2]/*diagonal[index+2]*/);
15801
15805
tile[index+3] = im[index+3];
15802
15806
}
15803
15807
@@ -15810,7 +15814,7 @@ FILTER.Create({
15810
15814
}
15811
15815
});
15812
15816
15813
- function getdiagonal(im, N, N2)
15817
+ /* function getdiagonal(im, N, N2)
15814
15818
{
15815
15819
var imSize = im.length,
15816
15820
diagonal = new FILTER.ImArray(imSize),
@@ -15826,7 +15830,7 @@ function getdiagonal(im, N, N2)
15826
15830
diagonal[index+3] = im[k+3];
15827
15831
}
15828
15832
return diagonal;
15829
- }
15833
+ }*/
15830
15834
function getmask(masktype, N, N2)
15831
15835
{
15832
15836
var size = N*N, mask = new FILTER.Array8U(size),
@@ -15901,13 +15905,13 @@ function glsl(filter)
15901
15905
'void main(void) {',
15902
15906
' gl_FragColor = interpolate(pix, img, wh, nwh);',
15903
15907
'}'
15904
- ].join('\n'))
15908
+ ].join('\n'), 1, 'resize' )
15905
15909
.dimensions(function(w, h, io) {io.w = w; io.h = h; w = stdMath.max(w, h); return [w, w];})
15906
15910
.input('wh', function(filter, nw, nh, w, h) {return [w, h];})
15907
15911
.input('nwh', function(filter, nw, nh, w, h) {return [nw, nh];})
15908
15912
.output('image')
15909
15913
.end()
15910
- .begin()
15914
+ /* .begin()
15911
15915
.shader([
15912
15916
'varying vec2 pix;',
15913
15917
'uniform sampler2D img;',
@@ -15922,7 +15926,7 @@ function glsl(filter)
15922
15926
'}'
15923
15927
].join('\n'))
15924
15928
.output('diagonal')
15925
- .end()
15929
+ .end()*/
15926
15930
.begin()
15927
15931
.shader([
15928
15932
'varying vec2 pix;',
@@ -15959,33 +15963,27 @@ function glsl(filter)
15959
15963
.shader([
15960
15964
'varying vec2 pix;',
15961
15965
'uniform sampler2D mask;',
15962
- 'uniform sampler2D diagonal;',
15963
15966
'uniform sampler2D image;',
15967
+ '/*uniform sampler2D diagonal;*/',
15964
15968
'void main(void) {',
15965
15969
' vec4 im = texture2D(image, pix);',
15966
- ' vec2 pix2 = pix + vec2(0.5);',
15967
- ' if (pix2.x > 1.0) pix2.x -= 1.0;',
15968
- ' if (pix2.y > 1.0) pix2.y -= 1.0;',
15970
+ ' vec2 pixd = pix - vec2(0.5);',
15971
+ ' if (pixd.x < 0.0) pixd.x += 1.0;',
15972
+ ' if (pixd.y < 0.0) pixd.y += 1.0;',
15973
+ ' vec2 pixm = pix + vec2(0.5);',
15974
+ ' if (pixm.x > 1.0) pixm.x -= 1.0;',
15975
+ ' if (pixm.y > 1.0) pixm.y -= 1.0;',
15969
15976
' float a1 = texture2D(mask, pix).a;',
15970
- ' float a2 = texture2D(mask, pix2 ).a;',
15971
- ' gl_FragColor = vec4(mix(im.rgb, texture2D(diagonal, pix).rgb, a2/(a1+a2)), im.a);',
15977
+ ' float a2 = texture2D(mask, pixm ).a;',
15978
+ ' gl_FragColor = vec4(mix(im.rgb, /* texture2D(diagonal, pix)*/texture2D(image, pixd ).rgb, a2/(a1+a2)), im.a);',
15972
15979
'}'
15973
15980
].join('\n'))
15974
15981
.input('mask', true)
15975
- .input('diagonal')
15976
15982
.input('image')
15983
+ //.input('diagonal')
15977
15984
.end()
15978
15985
.begin()
15979
- .shader([
15980
- 'varying vec2 pix;',
15981
- 'uniform sampler2D img;',
15982
- 'uniform vec2 wh;',
15983
- 'uniform vec2 nwh;',
15984
- ImageUtil.glsl()['interpolate'],
15985
- 'void main(void) {',
15986
- ' gl_FragColor = interpolate(pix, img, wh, nwh);',
15987
- '}'
15988
- ].join('\n'))
15986
+ .shader('resize')
15989
15987
.dimensions(function(w, h, io) {return [io.w, io.h];})
15990
15988
.input('wh', function(filter, nw, nh, w, h) {return [w, h];})
15991
15989
.input('nwh', function(filter, nw, nh, w, h) {return [nw, nh];})
0 commit comments