Fix gray png BRD tests
Before my recent CL, these were not run at all (because the decode
color type was gray and the bitmap color type was alpha).
https://skia-review.googlesource.com/c/6088/
Now that these are being run, we should mark the bitmap as
gray so they draw correctly.
BUG=skia:
Change-Id: I9bdfe97671a60da2bcbef55377e1c1b2bd326f8f
Reviewed-on: https://skia-review.googlesource.com/6160
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 78e9c55..50b9163 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -106,6 +106,16 @@
return SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy);
}
+static inline void alpha8_to_gray8(SkBitmap* bitmap) {
+ // Android requires kGray8 bitmaps to be tagged as kAlpha8. Here we convert
+ // them back to kGray8 so our test framework can draw them correctly.
+ if (kAlpha_8_SkColorType == bitmap->info().colorType()) {
+ SkImageInfo newInfo = bitmap->info().makeColorType(kGray_8_SkColorType)
+ .makeAlphaType(kOpaque_SkAlphaType);
+ *const_cast<SkImageInfo*>(&bitmap->info()) = newInfo;
+ }
+}
+
Error BRDSrc::draw(SkCanvas* canvas) const {
SkColorType colorType = canvas->imageInfo().colorType();
if (kRGB_565_SkColorType == colorType &&
@@ -148,6 +158,7 @@
fSampleSize, colorType, false)) {
return "Cannot decode (full) region.";
}
+ alpha8_to_gray8(&bitmap);
canvas->drawBitmap(bitmap, 0, 0);
return "";
}
@@ -202,6 +213,7 @@
return "Cannot decode region.";
}
+ alpha8_to_gray8(&bitmap);
canvas->drawBitmapRect(bitmap,
SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder,
(SkScalar) (subsetWidth / fSampleSize),