diff options
-rw-r--r-- | src/core/SkBitmap.cpp | 9 | ||||
-rw-r--r-- | tests/BitmapTest.cpp | 23 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 6fd97dc241..1691c9d0af 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -572,10 +572,15 @@ SkColor SkBitmap::getColor(int x, int y) const { SkPMColor c = SkPixel4444ToPixel32(addr[0]); return SkUnPreMultiply::PMColorToColor(c); } - case kBGRA_8888_SkColorType: + case kBGRA_8888_SkColorType: { + uint32_t* addr = this->getAddr32(x, y); + SkPMColor c = SkSwizzle_BGRA_to_PMColor(addr[0]); + return SkUnPreMultiply::PMColorToColor(c); + } case kRGBA_8888_SkColorType: { uint32_t* addr = this->getAddr32(x, y); - return SkUnPreMultiply::PMColorToColor(addr[0]); + SkPMColor c = SkSwizzle_RGBA_to_PMColor(addr[0]); + return SkUnPreMultiply::PMColorToColor(c); } default: SkASSERT(false); diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp index 4d68e73dbe..2bd8490b77 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp @@ -122,3 +122,26 @@ DEF_TEST(Bitmap, reporter) { test_bigalloc(reporter); test_peekpixels(reporter); } + +/** + * This test checks that getColor works for both swizzles. + */ +DEF_TEST(Bitmap_getColor_Swizzle, r) { + SkBitmap source; + source.allocN32Pixels(1,1); + source.eraseColor(SK_ColorRED); + SkColorType colorTypes[] = { + kRGBA_8888_SkColorType, + kBGRA_8888_SkColorType, + }; + for (SkColorType ct : colorTypes) { + SkBitmap copy; + if (!source.copyTo(©, ct)) { + ERRORF(r, "SkBitmap::copy failed %d", (int)ct); + continue; + } + SkAutoLockPixels autoLockPixels1(copy); + SkAutoLockPixels autoLockPixels2(source); + REPORTER_ASSERT(r, source.getColor(0, 0) == copy.getColor(0, 0)); + } +} |