Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Unified Diff: dm/DMSrcSink.cpp

Issue 1835083002: Support RGBA/BGRA swizzles using SkEncodedInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@skencodedinfo
Patch Set: Fix bugs Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DMSrcSink.h ('k') | include/codec/SkEncodedInfo.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 3f4667931bdbe503e8c05e771c995fe4ea4b6d89..458eab7a38862506d27997a2c71c911db2036c3c 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -112,6 +112,9 @@ Error BRDSrc::draw(SkCanvas* canvas) const {
case CodecSrc::kGrayscale_Always_DstColorType:
colorType = kGray_8_SkColorType;
break;
+ default:
+ SkASSERT(false);
+ break;
}
SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy));
@@ -273,6 +276,18 @@ bool CodecSrc::veto(SinkFlags flags) const {
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
+// Allows us to test decodes to non-native 8888.
+void swap_rb_if_necessary(SkBitmap& bitmap, CodecSrc::DstColorType dstColorType) {
+ if (CodecSrc::kNonNative8888_Always_DstColorType != dstColorType) {
+ return;
+ }
+
+ for (int y = 0; y < bitmap.height(); y++) {
+ uint32_t* row = (uint32_t*) bitmap.getAddr(0, y);
+ SkOpts::RGBA_to_BGRA(row, row, bitmap.width());
+ }
+}
+
// FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339.
// This allows us to still test unpremultiplied decodes.
void premultiply_if_necessary(SkBitmap& bitmap) {
@@ -319,6 +334,13 @@ bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
}
*decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType);
break;
+ case CodecSrc::kNonNative8888_Always_DstColorType:
+#ifdef SK_PMCOLOR_IS_RGBA
+ *decodeInfo = decodeInfo->makeColorType(kBGRA_8888_SkColorType);
+#else
+ *decodeInfo = decodeInfo->makeColorType(kRGBA_8888_SkColorType);
+#endif
+ break;
default:
if (kRGB_565_SkColorType == canvasColorType &&
kOpaque_SkAlphaType != decodeInfo->alphaType()) {
@@ -380,7 +402,13 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
factory = &zeroFactory;
options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
}
- if (!bitmap.tryAllocPixels(decodeInfo, factory, colorTable.get())) {
+
+ SkImageInfo bitmapInfo = decodeInfo;
+ if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
+ kBGRA_8888_SkColorType == decodeInfo.colorType()) {
+ bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
+ }
+ if (!bitmap.tryAllocPixels(bitmapInfo, factory, colorTable.get())) {
return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
decodeInfo.width(), decodeInfo.height());
}
@@ -400,6 +428,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
}
premultiply_if_necessary(bitmap);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
@@ -434,6 +463,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
premultiply_if_necessary(bitmap);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
@@ -489,6 +519,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
}
premultiply_if_necessary(bitmap);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
@@ -514,6 +545,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
premultiply_if_necessary(bitmap);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
@@ -573,6 +605,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
fPath.c_str(), W, H, result);
}
premultiply_if_necessary(subsetBm);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToScalar(top));
// translate by the scaled height.
top += decodeInfo.height();
@@ -661,7 +694,12 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
}
SkBitmap bitmap;
- if (!bitmap.tryAllocPixels(decodeInfo, nullptr, colorTable.get())) {
+ SkImageInfo bitmapInfo = decodeInfo;
+ if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
+ kBGRA_8888_SkColorType == decodeInfo.colorType()) {
+ bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
+ }
+ if (!bitmap.tryAllocPixels(bitmapInfo, nullptr, colorTable.get())) {
return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
decodeInfo.width(), decodeInfo.height());
}
@@ -683,6 +721,7 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
}
premultiply_if_necessary(bitmap);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmap(bitmap, 0, 0);
return "";
}
@@ -741,6 +780,7 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
SkRect rect = SkRect::MakeXYWH(0, 0, (SkScalar) finalScaledWidth,
(SkScalar) finalScaledHeight);
premultiply_if_necessary(bitmap);
+ swap_rb_if_necessary(bitmap, fDstColorType);
canvas->drawBitmapRect(bitmap, rect, rect, nullptr);
return "";
}
« no previous file with comments | « dm/DMSrcSink.h ('k') | include/codec/SkEncodedInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698