Browse files

Killed the mosaic math bug finally

  • Loading branch information...
1 parent b72e1c0 commit 81f51cc6d6d53e0451a431d4c3b59aa38bb29c85 Dave Shea committed Sep 7, 2010
Showing with 14 additions and 6 deletions.
  1. +14 −6 paintbrush-0.2.js
View
20 paintbrush-0.2.js
@@ -263,13 +263,21 @@ function addFilter(filterType) {
break;
case "filter-mosaic":
- var stepX = ((index >> 2) % params.mosaicSize) << 2;
- var stepY = (Math.floor(((index >> 2) / img.width)) % params.mosaicSize) << 2;
- var pos = index - stepX - img.width * stepY;
+ // a bit more verbose to reduce amount of math necessary
+ var pos = index >> 2;
+ var stepY = Math.floor(pos / imgWidth);
+ var stepY1 = stepY % params.mosaicSize;
+ var stepX = pos - (stepY * imgWidth);
+ var stepX1 = stepX % params.mosaicSize;
+
+ if (stepY1) pos -= stepY1 * imgWidth;
+ if (stepX1) pos -= stepX1;
+ pos = pos << 2;
+
data = setRGB(data, index,
- findColorDifference(params.mosaicAmount, data[pos], thisPixel.r),
- findColorDifference(params.mosaicAmount, data[pos + 1], thisPixel.g),
- findColorDifference(params.mosaicAmount, data[pos + 2], thisPixel.b));
+ findColorDifference(params.mosaicOpacity, data[pos], thisPixel.r),
+ findColorDifference(params.mosaicOpacity, data[pos + 1], thisPixel.g),
+ findColorDifference(params.mosaicOpacity, data[pos + 2], thisPixel.b));
break;
case "filter-noise":

0 comments on commit 81f51cc

Please sign in to comment.