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 12 matching lines...) Expand all Loading... |
23 baseline->width() <= 0 || baseline->height() <= 0 || | 23 baseline->width() <= 0 || baseline->height() <= 0 || |
24 baseline->config() != test->config()) { | 24 baseline->config() != test->config()) { |
25 return false; | 25 return false; |
26 } | 26 } |
27 | 27 |
28 int width = baseline->width(); | 28 int width = baseline->width(); |
29 int height = baseline->height(); | 29 int height = baseline->height(); |
30 | 30 |
31 // Prepare the POI alpha mask if needed | 31 // Prepare the POI alpha mask if needed |
32 if (computeMask) { | 32 if (computeMask) { |
33 result->poiAlphaMask.setConfig(SkBitmap::kA8_Config, width, height); | 33 result->poiAlphaMask.allocPixels(SkImageInfo::MakeA8(width, height)); |
34 result->poiAlphaMask.allocPixels(); | |
35 result->poiAlphaMask.lockPixels(); | |
36 result->poiAlphaMask.eraseARGB(SK_AlphaOPAQUE, 0, 0, 0); | 34 result->poiAlphaMask.eraseARGB(SK_AlphaOPAQUE, 0, 0, 0); |
37 } | 35 } |
38 | 36 |
39 // Prepare the pixels for comparison | 37 // Prepare the pixels for comparison |
40 result->poiCount = 0; | 38 result->poiCount = 0; |
41 baseline->lockPixels(); | 39 baseline->lockPixels(); |
42 test->lockPixels(); | 40 test->lockPixels(); |
43 for (int y = 0; y < height; y++) { | 41 for (int y = 0; y < height; y++) { |
44 // Grab a row from each image for easy comparison | 42 // Grab a row from each image for easy comparison |
45 unsigned char* baselineRow = (unsigned char*)baseline->getAddr(0, y); | 43 unsigned char* baselineRow = (unsigned char*)baseline->getAddr(0, y); |
(...skipping 14 matching lines...) Expand all Loading... |
60 if (computeMask) { | 58 if (computeMask) { |
61 result->poiAlphaMask.unlockPixels(); | 59 result->poiAlphaMask.unlockPixels(); |
62 } | 60 } |
63 | 61 |
64 // Calculates the percentage of identical pixels | 62 // Calculates the percentage of identical pixels |
65 result->result = 1.0 - ((double)result->poiCount / (width * height)); | 63 result->result = 1.0 - ((double)result->poiCount / (width * height)); |
66 result->timeElapsed = get_seconds() - startTime; | 64 result->timeElapsed = get_seconds() - startTime; |
67 | 65 |
68 return true; | 66 return true; |
69 } | 67 } |
OLD | NEW |