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

Unified Diff: dm/DMSrcSink.cpp

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Create codec before pushing srcs 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..613f798aab161fb8100eb9afbebbe05f7c5a0852 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -52,9 +52,16 @@ Name GMSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-CodecSrc::CodecSrc(Path path, Mode mode) : fPath(path), fMode(mode) {}
+CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkCodec* codec)
+ : fPath(path)
+ , fMode(mode)
+ , fDstColorType(dstColorType)
+ , fCodec(codec)
+{}
Error CodecSrc::draw(SkCanvas* canvas) const {
+ SkASSERT(NULL != fCodec.get());
scroggo 2015/04/08 17:21:27 Maybe put this assert in the constructor?
msarett 2015/04/08 19:35:40 Done.
+
SkImageInfo canvasInfo;
if (NULL == canvas->peekPixels(&canvasInfo, NULL)) {
// TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferred decode to
@@ -62,31 +69,48 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
return Error::Nonfatal("No need to test decoding to non-raster backend.");
}
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- if (!encoded) {
- return SkStringPrintf("Couldn't read %s.", fPath.c_str());
+ // Choose the color type to decode to
+ SkImageInfo decodeInfo = fCodec->getInfo();
+ SkColorType canvasColorType = canvasInfo.colorType();
+ switch (fDstColorType) {
+ case kIndex8_Always_DstColorType:
+ case kGrayscale_Always_DstColorType:
+ if (kRGB_565_SkColorType == canvasColorType) {
+ return Error::Nonfatal("Testing decode to 565 is uninteresting.");
scroggo 2015/04/08 17:21:27 Maybe "Testing non-565 to 565 is uninteresting"?
msarett 2015/04/08 19:35:40 Done.
+ }
+ break;
+ default:
+ decodeInfo = decodeInfo.makeColorType(canvasColorType);
+ break;
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
- if (!codec) {
- return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ // 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;
}
- SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType());
+ // 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 (fCodec->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.
@@ -100,7 +124,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
break;
case kScanline_Mode: {
- SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decodeInfo);
+ SkScanlineDecoder* scanlineDecoder = fCodec->getScanlineDecoder(decodeInfo);
if (NULL == scanlineDecoder) {
return Error::Nonfatal("Cannot use scanline decoder for all images");
}

Powered by Google App Engine
This is Rietveld 408576698