Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #include <cmath> | 1 #include <cmath> |
| 2 | 2 |
| 3 #include "SkBitmap.h" | 3 #include "SkBitmap.h" |
| 4 #include "skpdiff_util.h" | 4 #include "skpdiff_util.h" |
| 5 #include "SkPMetric.h" | 5 #include "SkPMetric.h" |
| 6 | 6 |
| 7 struct RGB { | 7 struct RGB { |
| 8 float r, g, b; | 8 float r, g, b; |
| 9 }; | 9 }; |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 } | 31 } |
| 32 | 32 |
| 33 void readPixel(int x, int y, T* pixel) const { | 33 void readPixel(int x, int y, T* pixel) const { |
| 34 SkASSERT(x >= 0); | 34 SkASSERT(x >= 0); |
| 35 SkASSERT(y >= 0); | 35 SkASSERT(y >= 0); |
| 36 SkASSERT(x < width); | 36 SkASSERT(x < width); |
| 37 SkASSERT(y < height); | 37 SkASSERT(y < height); |
| 38 *pixel = image[y * width + x]; | 38 *pixel = image[y * width + x]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 T * getRow(int y) const { | |
|
djsollen
2013/07/12 18:07:10
T* no space
| |
| 42 return &image[y * width]; | |
| 43 } | |
| 44 | |
| 41 void writePixel(int x, int y, const T& pixel) { | 45 void writePixel(int x, int y, const T& pixel) { |
| 42 SkASSERT(x >= 0); | 46 SkASSERT(x >= 0); |
| 43 SkASSERT(y >= 0); | 47 SkASSERT(y >= 0); |
| 44 SkASSERT(x < width); | 48 SkASSERT(x < width); |
| 45 SkASSERT(y < height); | 49 SkASSERT(y < height); |
| 46 image[y * width + x] = pixel; | 50 image[y * width + x] = pixel; |
| 47 } | 51 } |
| 48 }; | 52 }; |
| 49 | 53 |
| 50 typedef Image2D<float> ImageL; | 54 typedef Image2D<float> ImageL; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 } | 193 } |
| 190 } | 194 } |
| 191 } | 195 } |
| 192 | 196 |
| 193 /// Convolves an image with the given filter in one direction and saves it to th e output image | 197 /// Convolves an image with the given filter in one direction and saves it to th e output image |
| 194 static void convolve(const ImageL* imageL, | 198 static void convolve(const ImageL* imageL, |
| 195 bool vertical, const float* matrix, int radius, | 199 bool vertical, const float* matrix, int radius, |
| 196 ImageL* outImageL) { | 200 ImageL* outImageL) { |
| 197 SkASSERT(imageL->width == outImageL->width); | 201 SkASSERT(imageL->width == outImageL->width); |
| 198 SkASSERT(imageL->height == outImageL->height); | 202 SkASSERT(imageL->height == outImageL->height); |
| 203 | |
| 204 // Keep track of what rows are being operated on for quick access. | |
| 205 int filterCount = radius * 2 + 1; | |
| 206 float * rowPtrs[8]; | |
|
djsollen
2013/07/12 18:07:10
float* here and on 210
| |
| 207 for (int y = radius; y < filterCount; y++) { | |
| 208 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
| |
| 209 } | |
| 210 float * writeRow = outImageL->getRow(0); | |
| 211 | |
| 212 | |
| 199 for (int y = 0; y < imageL->height; y++) { | 213 for (int y = 0; y < imageL->height; y++) { |
| 200 for (int x = 0; x < imageL->width; x++) { | 214 for (int x = 0; x < imageL->width; x++) { |
| 201 float lSum = 0.0f; | 215 float lSum = 0.0f; |
| 202 float l; | |
| 203 for (int xx = -radius; xx <= radius; xx++) { | 216 for (int xx = -radius; xx <= radius; xx++) { |
| 204 int nx = x; | 217 int nx = x; |
| 205 int ny = y; | 218 int ny = y; |
| 206 | 219 |
| 207 // We mirror at edges so that edge pixels that the filter weight ing still makes | 220 // We mirror at edges so that edge pixels that the filter weight ing still makes |
| 208 // sense. | 221 // sense. |
| 209 if (vertical) { | 222 if (vertical) { |
| 210 ny += xx; | 223 ny += xx; |
| 211 if (ny < 0) { | 224 if (ny < 0) { |
| 212 ny = -ny; | 225 ny = -ny; |
| 213 } | 226 } |
| 214 if (ny >= imageL->height) { | 227 if (ny >= imageL->height) { |
| 215 ny = imageL->height + (imageL->height - ny - 1); | 228 ny = imageL->height + (imageL->height - ny - 1); |
| 216 } | 229 } |
| 217 } else { | 230 } else { |
| 218 nx += xx; | 231 nx += xx; |
| 219 if (nx < 0) { | 232 if (nx < 0) { |
| 220 nx = -nx; | 233 nx = -nx; |
| 221 } | 234 } |
| 222 if (nx >= imageL->width) { | 235 if (nx >= imageL->width) { |
| 223 nx = imageL->width + (imageL->width - nx - 1); | 236 nx = imageL->width + (imageL->width - nx - 1); |
| 224 } | 237 } |
| 225 } | 238 } |
| 226 | 239 |
| 227 imageL->readPixel(nx, ny, &l); | |
| 228 float weight = matrix[xx + radius]; | 240 float weight = matrix[xx + radius]; |
| 229 lSum += l * weight; | 241 lSum += rowPtrs[ny - y + radius][nx] * weight; |
| 230 } | 242 } |
| 231 outImageL->writePixel(x, y, lSum); | 243 writeRow[x] = lSum; |
| 232 } | 244 } |
| 245 // As we move down, scroll the row pointers down with us | |
| 246 for (int y = 0; y < filterCount - 1; y++) | |
| 247 { | |
| 248 rowPtrs[y] = rowPtrs[y + 1]; | |
| 249 } | |
| 250 rowPtrs[filterCount - 1] += imageL->width; | |
| 251 writeRow += imageL->width; | |
| 233 } | 252 } |
| 234 } | 253 } |
| 235 | 254 |
| 236 float pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTDArray<Sk IPoint>* poi) { | 255 float pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTDArray<Sk IPoint>* poi) { |
| 237 int width = baselineLAB->width; | 256 int width = baselineLAB->width; |
| 238 int height = baselineLAB->height; | 257 int height = baselineLAB->height; |
| 239 int maxLevels = (int)log2(width < height ? width : height); | 258 int maxLevels = (int)log2(width < height ? width : height); |
| 240 | 259 |
| 241 const float fov = M_PI / 180.0f * 45.0f; | 260 const float fov = M_PI / 180.0f * 45.0f; |
| 242 float contrastSensitivityMax = contrast_sensitivity(3.248f, 100.0f); | 261 float contrastSensitivityMax = contrast_sensitivity(3.248f, 100.0f); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 return fQueuedDiffs[id].result; | 444 return fQueuedDiffs[id].result; |
| 426 } | 445 } |
| 427 | 446 |
| 428 int SkPMetric::getPointsOfInterestCount(int id) { | 447 int SkPMetric::getPointsOfInterestCount(int id) { |
| 429 return fQueuedDiffs[id].poi.count(); | 448 return fQueuedDiffs[id].poi.count(); |
| 430 } | 449 } |
| 431 | 450 |
| 432 SkIPoint* SkPMetric::getPointsOfInterest(int id) { | 451 SkIPoint* SkPMetric::getPointsOfInterest(int id) { |
| 433 return fQueuedDiffs[id].poi.begin(); | 452 return fQueuedDiffs[id].poi.begin(); |
| 434 } | 453 } |
| OLD | NEW |