OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/color_analysis.h" | 5 #include "ui/gfx/color_analysis.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 return (abs(expected - static_cast<int>(channel)) <= 1); | 142 return (abs(expected - static_cast<int>(channel)) <= 1); |
143 } | 143 } |
144 | 144 |
145 // Compute minimal and maximal graylevel (or alphalevel) of the input |bitmap|. | 145 // Compute minimal and maximal graylevel (or alphalevel) of the input |bitmap|. |
146 // |bitmap| has to be allocated and configured to kA8_Config. | 146 // |bitmap| has to be allocated and configured to kA8_Config. |
147 void Calculate8bitBitmapMinMax(const SkBitmap& bitmap, | 147 void Calculate8bitBitmapMinMax(const SkBitmap& bitmap, |
148 uint8_t* min_gl, | 148 uint8_t* min_gl, |
149 uint8_t* max_gl) { | 149 uint8_t* max_gl) { |
150 SkAutoLockPixels bitmap_lock(bitmap); | 150 SkAutoLockPixels bitmap_lock(bitmap); |
151 DCHECK(bitmap.getPixels()); | 151 DCHECK(bitmap.getPixels()); |
152 DCHECK(bitmap.config() == SkBitmap::kA8_Config); | 152 DCHECK(bitmap.colorType() == kAlpha_8_SkColorType); |
msw
2014/07/07 19:47:51
nit: DCHECK_EQ
reed1
2014/07/07 19:51:46
Done.
| |
153 DCHECK(min_gl); | 153 DCHECK(min_gl); |
154 DCHECK(max_gl); | 154 DCHECK(max_gl); |
155 *min_gl = std::numeric_limits<uint8_t>::max(); | 155 *min_gl = std::numeric_limits<uint8_t>::max(); |
156 *max_gl = std::numeric_limits<uint8_t>::min(); | 156 *max_gl = std::numeric_limits<uint8_t>::min(); |
157 for (int y = 0; y < bitmap.height(); ++y) { | 157 for (int y = 0; y < bitmap.height(); ++y) { |
158 uint8_t* current_color = bitmap.getAddr8(0, y); | 158 uint8_t* current_color = bitmap.getAddr8(0, y); |
159 for (int x = 0; x < bitmap.width(); ++x, ++current_color) { | 159 for (int x = 0; x < bitmap.width(); ++x, ++current_color) { |
160 *min_gl = std::min(*min_gl, *current_color); | 160 *min_gl = std::min(*min_gl, *current_color); |
161 *max_gl = std::max(*max_gl, *current_color); | 161 *max_gl = std::max(*max_gl, *current_color); |
162 } | 162 } |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 496 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
497 | 497 |
498 EXPECT_EQ(0, min_gl); | 498 EXPECT_EQ(0, min_gl); |
499 EXPECT_EQ(255, max_gl); | 499 EXPECT_EQ(255, max_gl); |
500 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); | 500 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); |
501 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); | 501 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); |
502 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); | 502 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); |
503 } | 503 } |
504 | 504 |
505 } // namespace color_utils | 505 } // namespace color_utils |
OLD | NEW |