Skip to content
Browse files

Merge pull request #3 from Steren/master

Convolution code
  • Loading branch information...
2 parents 098389a + 8f1113e commit ad48757f317d741bd8c37a8567f42efee2f5bb3b @mezzoblue committed Jul 26, 2011
Showing with 5 additions and 3 deletions.
  1. +5 −3 paintbrush.js
View
8 paintbrush.js
@@ -270,8 +270,10 @@ function addFilter(filterType, buffer, c) {
// make sure the matrix adds up to 1
/* matrix = normalizeMatrix(matrix); */
- // calculate the dimensions, just in case this ever expands to 5 and beyond
+ // calculate the size of the matrix
var matrixSize = Math.sqrt(matrix.length);
+ // also store the size of the kernel radius (half the size of the matrix)
+ var kernelRadius = Math.floor(matrixSize / 2);
// loop through every pixel
for (var i = 1; i < imgWidth - 1; i++) {
@@ -285,7 +287,7 @@ function addFilter(filterType, buffer, c) {
for (var w = 0; w < matrixSize; w++) {
// get a refence to a pixel position in the matrix
- var r = convertCoordinates(i + h - 1, j + w - 1, imgWidth) << 2;
+ var r = convertCoordinates(i + w - kernelRadius, j + h - kernelRadius, imgWidth) << 2;
// find RGB values for that pixel
var currentPixel = {
@@ -592,4 +594,4 @@ function stashInDom(img, originalSuffix) {
} else {
return false;
}
-}
+}

0 comments on commit ad48757

Please sign in to comment.
Something went wrong with that request. Please try again.