Permalink
Browse files

Killed the mosaic math bug finally

  • Loading branch information...
1 parent 19f8f4e commit b72e1c08cb77754d1fa28d0371a6a304c8a9c13f Dave Shea committed Sep 8, 2010
Showing with 10 additions and 17 deletions.
  1. +10 −17 demo/script/paintbrush-0.2.js
@@ -265,23 +265,16 @@ function addFilter(filterType, buffer, c) {
break;
case "filter-mosaic":
-/*
- // faster, but buggy, hence the expansion below as I figure this out
-
- 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;
-*/
-
- var stepX = ((index / 4) % params.mosaicSize) * 4;
- var stepY = (Math.floor(((index / 4) / imgWidth)) % params.mosaicSize) * 4;
-
- var pos = index - stepX - imgWidth * stepY;
- if (imgWidth % params.mosaicSize) {
- pos -= Math.floor((1 - (imgWidth % params.mosaicSize)) * 10) * 4;
- }
-
-
+ // 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.mosaicOpacity, data[pos], thisPixel.r),

0 comments on commit b72e1c0

Please sign in to comment.