Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

matrix convolution bugfix (wasn't taking to right values and wasn't r…

…ight for matrices with size > 3)
  • Loading branch information...
commit 8f1113ee1dad6c025440907d272a220ba24df2f5 1 parent 098389a
@steren steren authored
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;
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.