Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Unified Diff: experimental/skpdiff/SkPMetric.cpp

Issue 19107002: improve convolve speed of skpdiff using direct pointers (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | experimental/skpdiff/skpdiff.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « no previous file | experimental/skpdiff/skpdiff.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698