OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDifferentPixelsMetric.h" | 8 #include "SkDifferentPixelsMetric.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 uint32_t* testRow = static_cast<uint32_t *>(test->getAddr(0, y)); | 66 uint32_t* testRow = static_cast<uint32_t *>(test->getAddr(0, y)); |
67 for (int x = 0; x < width; x++) { | 67 for (int x = 0; x < width; x++) { |
68 // Compare one pixel at a time so each differing pixel can be noted | 68 // Compare one pixel at a time so each differing pixel can be noted |
69 // TODO(epoger): This loop looks like a good place to work on perfor
mance, | 69 // TODO(epoger): This loop looks like a good place to work on perfor
mance, |
70 // but we should run the code through a profiler to be sure. | 70 // but we should run the code through a profiler to be sure. |
71 uint32_t baselinePixel = baselineRow[x]; | 71 uint32_t baselinePixel = baselineRow[x]; |
72 uint32_t testPixel = testRow[x]; | 72 uint32_t testPixel = testRow[x]; |
73 if (baselinePixel != testPixel) { | 73 if (baselinePixel != testPixel) { |
74 result->poiCount++; | 74 result->poiCount++; |
75 | 75 |
76 int redDiff = abs(static_cast<int>(SkColorGetR(baselinePixel) - | 76 int redDiff = SkTAbs(static_cast<int>(SkColorGetR(baselinePixel)
- |
77 SkColorGetR(testPixel))); | 77 SkColorGetR(testPixel))); |
78 if (redDiff > maxRedDiff) {maxRedDiff = redDiff;} | 78 if (redDiff > maxRedDiff) {maxRedDiff = redDiff;} |
79 int greenDiff = abs(static_cast<int>(SkColorGetG(baselinePixel)
- | 79 int greenDiff = SkTAbs(static_cast<int>(SkColorGetG(baselinePixe
l) - |
80 SkColorGetG(testPixel))); | 80 SkColorGetG(testPixel)))
; |
81 if (greenDiff > maxGreenDiff) {maxGreenDiff = greenDiff;} | 81 if (greenDiff > maxGreenDiff) {maxGreenDiff = greenDiff;} |
82 int blueDiff = abs(static_cast<int>(SkColorGetB(baselinePixel) - | 82 int blueDiff = SkTAbs(static_cast<int>(SkColorGetB(baselinePixel
) - |
83 SkColorGetB(testPixel))); | 83 SkColorGetB(testPixel))); |
84 if (blueDiff > maxBlueDiff) {maxBlueDiff = blueDiff;} | 84 if (blueDiff > maxBlueDiff) {maxBlueDiff = blueDiff;} |
85 | 85 |
86 if (bitmapsToCreate.alphaMask) { | 86 if (bitmapsToCreate.alphaMask) { |
87 *result->poiAlphaMask.getAddr8(x,y) = SK_AlphaTRANSPARENT; | 87 *result->poiAlphaMask.getAddr8(x,y) = SK_AlphaTRANSPARENT; |
88 } | 88 } |
89 if (bitmapsToCreate.rgbDiff) { | 89 if (bitmapsToCreate.rgbDiff) { |
90 *result->rgbDiffBitmap.getAddr32(x,y) = | 90 *result->rgbDiffBitmap.getAddr32(x,y) = |
91 SkColorSetRGB(redDiff, greenDiff, blueDiff); | 91 SkColorSetRGB(redDiff, greenDiff, blueDiff); |
92 } | 92 } |
93 if (bitmapsToCreate.whiteDiff) { | 93 if (bitmapsToCreate.whiteDiff) { |
(...skipping 18 matching lines...) Expand all Loading... |
112 if (bitmapsToCreate.whiteDiff) { | 112 if (bitmapsToCreate.whiteDiff) { |
113 result->whiteDiffBitmap.unlockPixels(); | 113 result->whiteDiffBitmap.unlockPixels(); |
114 } | 114 } |
115 | 115 |
116 // Calculates the percentage of identical pixels | 116 // Calculates the percentage of identical pixels |
117 result->result = 1.0 - ((double)result->poiCount / (width * height)); | 117 result->result = 1.0 - ((double)result->poiCount / (width * height)); |
118 result->timeElapsed = get_seconds() - startTime; | 118 result->timeElapsed = get_seconds() - startTime; |
119 | 119 |
120 return true; | 120 return true; |
121 } | 121 } |
OLD | NEW |