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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkMallocPixelRef.h" | 9 #include "SkMallocPixelRef.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 SkBitmap copy; | 138 SkBitmap copy; |
139 if (!source.copyTo(©, ct)) { | 139 if (!source.copyTo(©, ct)) { |
140 ERRORF(r, "SkBitmap::copy failed %d", (int)ct); | 140 ERRORF(r, "SkBitmap::copy failed %d", (int)ct); |
141 continue; | 141 continue; |
142 } | 142 } |
143 SkAutoLockPixels autoLockPixels1(copy); | 143 SkAutoLockPixels autoLockPixels1(copy); |
144 SkAutoLockPixels autoLockPixels2(source); | 144 SkAutoLockPixels autoLockPixels2(source); |
145 REPORTER_ASSERT(r, source.getColor(0, 0) == copy.getColor(0, 0)); | 145 REPORTER_ASSERT(r, source.getColor(0, 0) == copy.getColor(0, 0)); |
146 } | 146 } |
147 } | 147 } |
| 148 |
| 149 static void test_erasecolor_premul(skiatest::Reporter* reporter, SkColorType ct,
SkColor input, |
| 150 SkColor expected) { |
| 151 SkBitmap bm; |
| 152 bm.allocPixels(SkImageInfo::Make(1, 1, ct, kPremul_SkAlphaType)); |
| 153 bm.eraseColor(input); |
| 154 SkDebugf("expected: %x actual: %x\n", expected, bm.getColor(0, 0)); |
| 155 REPORTER_ASSERT(reporter, bm.getColor(0, 0) == expected); |
| 156 } |
| 157 |
| 158 /** |
| 159 * This test checks that eraseColor premultiplies the color correctly. |
| 160 */ |
| 161 DEF_TEST(Bitmap_eraseColor_Premul, r) { |
| 162 SkColor color = 0x80FF0080; |
| 163 test_erasecolor_premul(r, kAlpha_8_SkColorType, color, 0x80000000); |
| 164 test_erasecolor_premul(r, kRGB_565_SkColorType, color, 0xFF840042); |
| 165 test_erasecolor_premul(r, kARGB_4444_SkColorType, color, 0x88FF0080); |
| 166 test_erasecolor_premul(r, kRGBA_8888_SkColorType, color, color); |
| 167 test_erasecolor_premul(r, kBGRA_8888_SkColorType, color, color); |
| 168 } |
OLD | NEW |