Index: experimental/skpdiff/SkPMetric.cpp |
diff --git a/experimental/skpdiff/SkPMetric.cpp b/experimental/skpdiff/SkPMetric.cpp |
index a9628539b556584a888d2cbe1443692261aeba4c..1bf448fd0bc9c0e6af2e566a0d1110155a57c780 100644 |
--- a/experimental/skpdiff/SkPMetric.cpp |
+++ b/experimental/skpdiff/SkPMetric.cpp |
@@ -38,6 +38,10 @@ struct Image2D { |
*pixel = image[y * width + x]; |
} |
+ T * getRow(int y) const { |
djsollen
2013/07/12 18:07:10
T* no space
|
+ return &image[y * width]; |
+ } |
+ |
void writePixel(int x, int y, const T& pixel) { |
SkASSERT(x >= 0); |
SkASSERT(y >= 0); |
@@ -196,10 +200,19 @@ static void convolve(const ImageL* imageL, |
ImageL* outImageL) { |
SkASSERT(imageL->width == outImageL->width); |
SkASSERT(imageL->height == outImageL->height); |
+ |
+ // Keep track of what rows are being operated on for quick access. |
+ int filterCount = radius * 2 + 1; |
+ float * rowPtrs[8]; |
djsollen
2013/07/12 18:07:10
float* here and on 210
|
+ for (int y = radius; y < filterCount; y++) { |
+ rowPtrs[y] = imageL->getRow(y - radius); |
djsollen
2013/07/12 18:07:10
how can you ensure that y is never greater than 7?
Zach Reizner
2013/07/12 18:51:43
convolve is static and only ever called from pmetr
|
+ } |
+ float * writeRow = outImageL->getRow(0); |
+ |
+ |
for (int y = 0; y < imageL->height; y++) { |
for (int x = 0; x < imageL->width; x++) { |
float lSum = 0.0f; |
- float l; |
for (int xx = -radius; xx <= radius; xx++) { |
int nx = x; |
int ny = y; |
@@ -224,12 +237,18 @@ static void convolve(const ImageL* imageL, |
} |
} |
- imageL->readPixel(nx, ny, &l); |
float weight = matrix[xx + radius]; |
- lSum += l * weight; |
+ lSum += rowPtrs[ny - y + radius][nx] * weight; |
} |
- outImageL->writePixel(x, y, lSum); |
+ writeRow[x] = lSum; |
+ } |
+ // As we move down, scroll the row pointers down with us |
+ for (int y = 0; y < filterCount - 1; y++) |
+ { |
+ rowPtrs[y] = rowPtrs[y + 1]; |
} |
+ rowPtrs[filterCount - 1] += imageL->width; |
+ writeRow += imageL->width; |
} |
} |