support 888x, 1010102, and 101010x in SkPixmap::erase()
... and a few more methods to make it possible to write the new test.
Bug: oss-fuzz:6606
Change-Id: Ie8dd221059579248405f165a93c324c8ba518fd4
Reviewed-on: https://skia-review.googlesource.com/112400
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
index f62288c..b404938 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -226,3 +226,34 @@
SkDEBUGCODE(bm.validate();)
}
+// At the time of writing, SkBitmap::erase() works when the color is zero for all formats,
+// but some formats failed when the color is non-zero!
+DEF_TEST(Bitmap_erase, r) {
+ SkColorType colorTypes[] = {
+ kRGB_565_SkColorType,
+ kARGB_4444_SkColorType,
+ kRGB_888x_SkColorType,
+ kRGBA_8888_SkColorType,
+ kBGRA_8888_SkColorType,
+ kRGB_101010x_SkColorType,
+ kRGBA_1010102_SkColorType,
+ };
+
+ for (SkColorType ct : colorTypes) {
+ SkImageInfo info = SkImageInfo::Make(1,1, (SkColorType)ct, kPremul_SkAlphaType);
+
+ SkBitmap bm;
+ bm.allocPixels(info);
+
+ bm.eraseColor(0x00000000);
+ if (SkColorTypeIsAlwaysOpaque(ct)) {
+ REPORTER_ASSERT(r, bm.getColor(0,0) == 0xff000000);
+ } else {
+ REPORTER_ASSERT(r, bm.getColor(0,0) == 0x00000000);
+ }
+
+ bm.eraseColor(0xaabbccdd);
+ REPORTER_ASSERT(r, bm.getColor(0,0) != 0xff000000);
+ REPORTER_ASSERT(r, bm.getColor(0,0) != 0x00000000);
+ }
+}