Skip to content

Commit ee44d73

Browse files
committedSep 20, 2023
v.1.9.0 (contd)
* some more simplifications
1 parent fa80889 commit ee44d73

File tree

5 files changed

+64
-68
lines changed

5 files changed

+64
-68
lines changed
 

‎build/filter.js

+32-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
@@ -12,7 +12,7 @@
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
}
36603660
function 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+
}*/
1583015834
function 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];})

‎build/filter.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/plugins/SeamlessTile.js

+25-29
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ FILTER.Create({
5050
//needed arrays
5151
tile, diagonal, mask,
5252
a1, a2, a3, i, j,
53-
index, N, N2, imSize;
53+
index, indexd, N, N2, imSize;
5454

5555
//find largest side of the image
5656
//and resize the image to become square
@@ -59,19 +59,21 @@ FILTER.Create({
5959
N2 = stdMath.round(N/2);
6060
imSize = im.length;
6161
tile = new FILTER.ImArray(imSize);
62-
diagonal = getdiagonal(im, N, N2);
62+
//diagonal = getdiagonal(im, N, N2);
6363
mask = getmask(self.type, N, N2);
6464

6565
//Create the tile
6666
for (j=0,i=0; j<N; ++i)
6767
{
6868
if (i >= N) {i=0; ++j;}
6969
index = i+j*N;
70-
a1 = mask[index]; a2 = mask[(i+N2) % N + ((j+N2) % N)*N];
71-
a3 = a1+a2; a1 /= a3; a2 /= a3; index <<= 2;
72-
tile[index ] = ~~(a1*im[index ] + a2*diagonal[index ]);
73-
tile[index+1] = ~~(a1*im[index+1] + a2*diagonal[index+1]);
74-
tile[index+2] = ~~(a1*im[index+2] + a2*diagonal[index+2]);
70+
indexd = ((i+N2) % N) + ((j+N2) % N)*N;
71+
a1 = mask[index]; a2 = mask[indexd];
72+
a3 = a1+a2; a1 /= a3; a2 /= a3;
73+
index <<= 2; indexd <<= 2;
74+
tile[index ] = ~~(a1*im[index ] + a2*im[indexd ]/*diagonal[index ]*/);
75+
tile[index+1] = ~~(a1*im[index+1] + a2*im[indexd+1]/*diagonal[index+1]*/);
76+
tile[index+2] = ~~(a1*im[index+2] + a2*im[indexd+2]/*diagonal[index+2]*/);
7577
tile[index+3] = im[index+3];
7678
}
7779

@@ -84,7 +86,7 @@ FILTER.Create({
8486
}
8587
});
8688

87-
function getdiagonal(im, N, N2)
89+
/*function getdiagonal(im, N, N2)
8890
{
8991
var imSize = im.length,
9092
diagonal = new FILTER.ImArray(imSize),
@@ -100,7 +102,7 @@ function getdiagonal(im, N, N2)
100102
diagonal[index+3] = im[k+3];
101103
}
102104
return diagonal;
103-
}
105+
}*/
104106
function getmask(masktype, N, N2)
105107
{
106108
var size = N*N, mask = new FILTER.Array8U(size),
@@ -175,13 +177,13 @@ function glsl(filter)
175177
'void main(void) {',
176178
' gl_FragColor = interpolate(pix, img, wh, nwh);',
177179
'}'
178-
].join('\n'))
180+
].join('\n'), 1, 'resize')
179181
.dimensions(function(w, h, io) {io.w = w; io.h = h; w = stdMath.max(w, h); return [w, w];})
180182
.input('wh', function(filter, nw, nh, w, h) {return [w, h];})
181183
.input('nwh', function(filter, nw, nh, w, h) {return [nw, nh];})
182184
.output('image')
183185
.end()
184-
.begin()
186+
/*.begin()
185187
.shader([
186188
'varying vec2 pix;',
187189
'uniform sampler2D img;',
@@ -196,7 +198,7 @@ function glsl(filter)
196198
'}'
197199
].join('\n'))
198200
.output('diagonal')
199-
.end()
201+
.end()*/
200202
.begin()
201203
.shader([
202204
'varying vec2 pix;',
@@ -233,33 +235,27 @@ function glsl(filter)
233235
.shader([
234236
'varying vec2 pix;',
235237
'uniform sampler2D mask;',
236-
'uniform sampler2D diagonal;',
237238
'uniform sampler2D image;',
239+
'/*uniform sampler2D diagonal;*/',
238240
'void main(void) {',
239241
' vec4 im = texture2D(image, pix);',
240-
' vec2 pix2 = pix + vec2(0.5);',
241-
' if (pix2.x > 1.0) pix2.x -= 1.0;',
242-
' if (pix2.y > 1.0) pix2.y -= 1.0;',
242+
' vec2 pixd = pix - vec2(0.5);',
243+
' if (pixd.x < 0.0) pixd.x += 1.0;',
244+
' if (pixd.y < 0.0) pixd.y += 1.0;',
245+
' vec2 pixm = pix + vec2(0.5);',
246+
' if (pixm.x > 1.0) pixm.x -= 1.0;',
247+
' if (pixm.y > 1.0) pixm.y -= 1.0;',
243248
' float a1 = texture2D(mask, pix).a;',
244-
' float a2 = texture2D(mask, pix2).a;',
245-
' gl_FragColor = vec4(mix(im.rgb, texture2D(diagonal, pix).rgb, a2/(a1+a2)), im.a);',
249+
' float a2 = texture2D(mask, pixm).a;',
250+
' gl_FragColor = vec4(mix(im.rgb, /*texture2D(diagonal, pix)*/texture2D(image, pixd).rgb, a2/(a1+a2)), im.a);',
246251
'}'
247252
].join('\n'))
248253
.input('mask', true)
249-
.input('diagonal')
250254
.input('image')
255+
//.input('diagonal')
251256
.end()
252257
.begin()
253-
.shader([
254-
'varying vec2 pix;',
255-
'uniform sampler2D img;',
256-
'uniform vec2 wh;',
257-
'uniform vec2 nwh;',
258-
ImageUtil.glsl()['interpolate'],
259-
'void main(void) {',
260-
' gl_FragColor = interpolate(pix, img, wh, nwh);',
261-
'}'
262-
].join('\n'))
258+
.shader('resize')
263259
.dimensions(function(w, h, io) {return [io.w, io.h];})
264260
.input('wh', function(filter, nw, nh, w, h) {return [w, h];})
265261
.input('nwh', function(filter, nw, nh, w, h) {return [nw, nh];})

‎src/util/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ return {
739739
' float g = gradient_suppressed(img, pix, dp, magnitude_scale, magnitude_limit, magnitude_max);',
740740
' if (g >= high) return vec4(vec3(1.0), a);',
741741
' else if (g < low) return vec4(vec3(0.0), a);',
742-
' return vec4(vec3(/*clamp((g-low)/(high-low)-0.1, 0.0, 0.9)/0.9*/0.1), a);',
742+
' return vec4(vec3(/*clamp((g-low)/(high-low)-0.1, 0.0, 0.9)/0.9*/0.01), a);',
743743
'}'
744744
].join('\n'),
745745
'hysteresis': [

‎src/util/glsl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function getProgram(gl, shader, programCache)
144144
}
145145
function GLSLFilter(filter)
146146
{
147-
var self = this, glsls = [], glsl = null, io = {},
147+
var self = this, glsls = [], glsl = null, shaders = {}, io = {},
148148
prev_output = function(glsl) {
149149
return glsl._prev && glsl._prev._output && HAS.call(io, glsl._prev._output) ? io[glsl._prev._output] : null;
150150
};
@@ -277,9 +277,11 @@ function GLSLFilter(filter)
277277
};
278278
return self;
279279
};
280-
self.shader = function(shader, iterations) {
280+
self.shader = function(shader, iterations, name) {
281281
if (glsl)
282282
{
283+
if (shader && HAS.call(shaders, shader)) shader = shaders[shader];
284+
if (name && shader) shaders[name] = shader;
283285
glsl.shader = shader || null;
284286
glsl.iterations = iterations || 1;
285287
}

0 commit comments

Comments
 (0)
Please sign in to comment.