22*
33* FILTER.js
44* @version: 1.9.0
5- * @built on 2023-09-20 11:18:18
5+ * @built on 2023-09-20 15:35:50
66* @dependencies: Asynchronous.js
77*
88* JavaScript Image Processing Library
1212*
1313* FILTER.js
1414* @version: 1.9.0
15- * @built on 2023-09-20 11:18:18
15+ * @built on 2023-09-20 15:35:50
1616* @dependencies: Asynchronous.js
1717*
1818* JavaScript Image Processing Library
@@ -2250,7 +2250,7 @@ return {
22502250' float g = gradient_suppressed(img, pix, dp, magnitude_scale, magnitude_limit, magnitude_max);',
22512251' if (g >= high) return vec4(vec3(1.0), a);',
22522252' 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);',
22542254'}'
22552255].join('\n'),
22562256'hysteresis': [
@@ -3659,7 +3659,7 @@ function getProgram(gl, shader, programCache)
36593659}
36603660function GLSLFilter(filter)
36613661{
3662- var self = this, glsls = [], glsl = null, io = {},
3662+ var self = this, glsls = [], glsl = null, shaders = {}, io = {},
36633663 prev_output = function(glsl) {
36643664 return glsl._prev && glsl._prev._output && HAS.call(io, glsl._prev._output) ? io[glsl._prev._output] : null;
36653665 };
@@ -3792,9 +3792,11 @@ function GLSLFilter(filter)
37923792 };
37933793 return self;
37943794 };
3795- self.shader = function(shader, iterations) {
3795+ self.shader = function(shader, iterations, name ) {
37963796 if (glsl)
37973797 {
3798+ if (shader && HAS.call(shaders, shader)) shader = shaders[shader];
3799+ if (name && shader) shaders[name] = shader;
37983800 glsl.shader = shader || null;
37993801 glsl.iterations = iterations || 1;
38003802 }
@@ -15776,7 +15778,7 @@ FILTER.Create({
1577615778 //needed arrays
1577715779 tile, diagonal, mask,
1577815780 a1, a2, a3, i, j,
15779- index, N, N2, imSize;
15781+ index, indexd, N, N2, imSize;
1578015782
1578115783 //find largest side of the image
1578215784 //and resize the image to become square
@@ -15785,19 +15787,21 @@ FILTER.Create({
1578515787 N2 = stdMath.round(N/2);
1578615788 imSize = im.length;
1578715789 tile = new FILTER.ImArray(imSize);
15788- diagonal = getdiagonal(im, N, N2);
15790+ // diagonal = getdiagonal(im, N, N2);
1578915791 mask = getmask(self.type, N, N2);
1579015792
1579115793 //Create the tile
1579215794 for (j=0,i=0; j<N; ++i)
1579315795 {
1579415796 if (i >= N) {i=0; ++j;}
1579515797 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]*/);
1580115805 tile[index+3] = im[index+3];
1580215806 }
1580315807
@@ -15810,7 +15814,7 @@ FILTER.Create({
1581015814 }
1581115815});
1581215816
15813- function getdiagonal(im, N, N2)
15817+ /* function getdiagonal(im, N, N2)
1581415818{
1581515819 var imSize = im.length,
1581615820 diagonal = new FILTER.ImArray(imSize),
@@ -15826,7 +15830,7 @@ function getdiagonal(im, N, N2)
1582615830 diagonal[index+3] = im[k+3];
1582715831 }
1582815832 return diagonal;
15829- }
15833+ }*/
1583015834function getmask(masktype, N, N2)
1583115835{
1583215836 var size = N*N, mask = new FILTER.Array8U(size),
@@ -15901,13 +15905,13 @@ function glsl(filter)
1590115905 'void main(void) {',
1590215906 ' gl_FragColor = interpolate(pix, img, wh, nwh);',
1590315907 '}'
15904- ].join('\n'))
15908+ ].join('\n'), 1, 'resize' )
1590515909 .dimensions(function(w, h, io) {io.w = w; io.h = h; w = stdMath.max(w, h); return [w, w];})
1590615910 .input('wh', function(filter, nw, nh, w, h) {return [w, h];})
1590715911 .input('nwh', function(filter, nw, nh, w, h) {return [nw, nh];})
1590815912 .output('image')
1590915913 .end()
15910- .begin()
15914+ /* .begin()
1591115915 .shader([
1591215916 'varying vec2 pix;',
1591315917 'uniform sampler2D img;',
@@ -15922,7 +15926,7 @@ function glsl(filter)
1592215926 '}'
1592315927 ].join('\n'))
1592415928 .output('diagonal')
15925- .end()
15929+ .end()*/
1592615930 .begin()
1592715931 .shader([
1592815932 'varying vec2 pix;',
@@ -15959,33 +15963,27 @@ function glsl(filter)
1595915963 .shader([
1596015964 'varying vec2 pix;',
1596115965 'uniform sampler2D mask;',
15962- 'uniform sampler2D diagonal;',
1596315966 'uniform sampler2D image;',
15967+ '/*uniform sampler2D diagonal;*/',
1596415968 'void main(void) {',
1596515969 ' 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;',
1596915976 ' 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);',
1597215979 '}'
1597315980 ].join('\n'))
1597415981 .input('mask', true)
15975- .input('diagonal')
1597615982 .input('image')
15983+ //.input('diagonal')
1597715984 .end()
1597815985 .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')
1598915987 .dimensions(function(w, h, io) {return [io.w, io.h];})
1599015988 .input('wh', function(filter, nw, nh, w, h) {return [w, h];})
1599115989 .input('nwh', function(filter, nw, nh, w, h) {return [nw, nh];})
0 commit comments