| 2345 | } |
| 2346 | |
| 2347 | function convolve_even(src, dst, mask, width, height) { |
| 2348 | for (var y = 0; y < height; y++) { |
| 2349 | for (var x = 0; x < width; x++) { |
| 2350 | var a = imGet(src, x, y, width, height, 3)/255; |
| 2351 | for (var rgba = 0; rgba < 4; rgba++) { |
| 2352 | var sum = mask[0] * (a==0?255:imGet(src, x, y, width, height, rgba)) * (a==0||rgba==3?1:a); |
| 2353 | for (var i = 1; i < mask.length; i++) { |
| 2354 | var a1 = imGet(src, Math.max(x-i,0), y, width, height, 3)/255; |
| 2355 | var a2 = imGet(src, Math.min(x+i, width-1), y, width, height, 3)/255; |
| 2356 | sum += mask[i] * |
| 2357 | ((a1==0?255:imGet(src, Math.max(x-i,0), y, width, height, rgba)) * (a1==0||rgba==3?1:a1) + |
| 2358 | (a2==0?255:imGet(src, Math.min(x+i, width-1), y, width, height, rgba)) * (a2==0||rgba==3?1:a2)); |
| 2359 | } |
| 2360 | imSet(dst, y, x, height, width, rgba, sum); |
| 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | function imGet(img, x, y, width, height, rgba) { |
| 2367 | return img[y*width*4 + x*4 + rgba]; |