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

Unified Diff: dm/DMSrcSink.cpp

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Enabled kIndex8 testing in dm, Created a test for SkSwizzler::Fill() Created 5 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
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index de9ee76c8076611960e4a9849fa402326776155b..9c16684195adb387b3cce53ea487235709de671d 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -52,7 +52,11 @@ Name GMSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-CodecSrc::CodecSrc(Path path, Mode mode) : fPath(path), fMode(mode) {}
+CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType)
+ : fPath(path)
+ , fMode(mode)
+ , fDstColorType(dstColorType)
+{}
Error CodecSrc::draw(SkCanvas* canvas) const {
SkImageInfo canvasInfo;
@@ -72,21 +76,60 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
}
- SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType());
+ // Choose the color type to decode to
+ SkImageInfo decodeInfo;
+ SkColorType canvasColorType = canvasInfo.colorType();
+ switch (fDstColorType) {
+ case kGetFromCanvas_DstColorType:
+ decodeInfo = codec->getInfo().makeColorType(canvasColorType);
+ break;
+ case kIndex8_Always_DstColorType:
+ if (kRGB_565_SkColorType == canvasColorType) {
+ return Error::Nonfatal("Do not test decoding to kIndex8 when the canvas is 565.");
+ } else if (kIndex_8_SkColorType != codec->getInfo().colorType()) {
scroggo 2015/04/07 21:15:34 nit: This may be a matter of preference, but I don
msarett 2015/04/08 13:59:10 Done.
+ return Error::Nonfatal("Do not test decoding to kIndex8 when the image is not "
+ "natively kIndex8.");
+ }
+ decodeInfo = codec->getInfo();
scroggo 2015/04/07 21:15:34 nit: You could move this into the declaration of d
msarett 2015/04/08 13:59:10 Done.
+ break;
+ case kGrayscale_Always_DstColorType:
+ if (kRGB_565_SkColorType == canvasColorType) {
+ return Error::Nonfatal("Do not test decoding to kGray when the canvas is 565.");
+ } else if (kGray_8_SkColorType != codec->getInfo().colorType()) {
+ return Error::Nonfatal("Do not test decoding to kGray when the image is not "
+ "natively kGray.");
+ }
+ decodeInfo = codec->getInfo();
+ break;
+ }
+
+ // Construct a color table for the decode if necessary
+ SkAutoTUnref<SkColorTable> colorTable(NULL);
+ SkPMColor* colorPtr = NULL;
+ int* colorCountPtr = NULL;
+ int maxColors = 256;
+ if (kIndex_8_SkColorType == decodeInfo.colorType()) {
+ SkPMColor colors[maxColors];
+ colorTable.reset(SkNEW_ARGS(SkColorTable, (colors, maxColors)));
+ colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
+ colorCountPtr = &maxColors;
+ }
+
+ // FIXME: Currently we cannot draw unpremultiplied sources.
if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) {
- // FIXME: Currently we cannot draw unpremultiplied sources.
decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
}
SkBitmap bitmap;
- if (!bitmap.tryAllocPixels(decodeInfo)) {
+ if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) {
return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
decodeInfo.width(), decodeInfo.height());
}
switch (fMode) {
case kNormal_Mode:
- switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes())) {
+ switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), NULL,
+ colorPtr, colorCountPtr)) {
case SkImageGenerator::kSuccess:
// We consider incomplete to be valid, since we should still decode what is
// available.

Powered by Google App Engine
This is Rietveld 408576698