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

Unified Diff: dm/DMSrcSink.cpp

Issue 978823002: Run CodecSrc DM. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove unneeded include. Created 5 years, 9 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
« dm/DM.cpp ('K') | « dm/DMSrcSink.h ('k') | no next file » | 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 5ca66c50e207c4809f41396e907d354d4d78a17d..69feb1da13d95f08d4a21fe84f6ebc6bad5e7c27 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -38,59 +38,98 @@ Name GMSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+CodecSrc::CodecSrc(Path path) : fPath(path) {}
+
+Error CodecSrc::draw(SkCanvas* canvas) const {
+ SkImageInfo canvasInfo;
+ if (NULL == canvas->peekPixels(&canvasInfo, NULL)) {
+ return Error::Nonfatal("No need to test decoding to non-raster backend.");
mtklein 2015/03/17 20:24:15 // TODO: rethink with JPGs ?
scroggo 2015/03/19 12:57:55 Done.
+ }
+
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ if (!encoded) {
+ return SkStringPrintf("Couldn't read %s.", fPath.c_str());
+ }
+
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ if (!codec) {
+ return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ }
+
+ SkImageInfo decodeInfo;
+ if (!codec->getInfo(&decodeInfo)) {
+ return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
+ }
+
+ decodeInfo = decodeInfo.makeColorType(canvasInfo.colorType());
+ if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) {
+ // FIXME: Currently we cannot draw unpremultiplied sources.
+ decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
+ }
+
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocPixels(decodeInfo)) {
+ return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
+ decodeInfo.width(), decodeInfo.height());
+ }
+
+ SkAutoLockPixels alp(bitmap);
mtklein 2015/03/17 20:24:15 This seems fine, but it's not needed right? SkBit
scroggo 2015/03/19 12:57:54 The implementation of tryAllocPixels does lock aut
+ const SkImageGenerator::Result result = codec->getPixels(decodeInfo, bitmap.getPixels(),
+ bitmap.rowBytes());
+ switch (result) {
mtklein 2015/03/17 20:24:15 Might consider fusing into switch (codec->getPixe
scroggo 2015/03/19 12:57:54 Done.
+ case SkImageGenerator::kSuccess:
+ // We consider incomplete to be valid, since we should still decode what is
+ // available.
+ case SkImageGenerator::kIncompleteInput:
+ canvas->drawBitmap(bitmap, 0, 0);
+ return "";
+ case SkImageGenerator::kInvalidConversion:
+ return Error::Nonfatal("Incompatible colortype conversion");
+ default:
+ // Everything else is considered a failure.
+ return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
+ }
+}
+
+SkISize CodecSrc::size() const {
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkImageInfo info;
+ if (codec && codec->getInfo(&info)) {
+ return info.dimensions();
+ }
+ return SkISize::Make(0,0);
+}
+
+Name CodecSrc::name() const {
+ return SkOSPath::Basename(fPath.c_str());
+}
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
Error ImageSrc::draw(SkCanvas* canvas) const {
+ SkImageInfo canvasInfo;
+ if (NULL == canvas->peekPixels(&canvasInfo, NULL)) {
+ return Error::Nonfatal("No need to test decoding to non-raster backend.");
scroggo 2015/03/19 12:57:54 I've also added a TODO to ImageSrc to use deferred
+ }
+
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- const SkColorType dstColorType = canvas->imageInfo().colorType();
+ const SkColorType dstColorType = canvasInfo.colorType();
if (fDivisor == 0) {
// Decode the full image.
SkBitmap bitmap;
- if (FLAGS_codec) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
- if (!codec) {
- return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
- }
- SkImageInfo info;
- if (!codec->getInfo(&info)) {
- return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
- }
- info = info.makeColorType(dstColorType);
- if (info.alphaType() == kUnpremul_SkAlphaType) {
- // FIXME: Currently we cannot draw unpremultiplied sources.
- info = info.makeAlphaType(kPremul_SkAlphaType);
- }
- if (!bitmap.tryAllocPixels(info)) {
- return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
- info.width(), info.height());
- }
- SkAutoLockPixels alp(bitmap);
- const SkImageGenerator::Result result = codec->getPixels(info, bitmap.getPixels(),
- bitmap.rowBytes());
- switch (result) {
- case SkImageGenerator::kSuccess:
- // We consider incomplete to be valid, since we should still decode what is
- // available.
- case SkImageGenerator::kIncompleteInput:
- break;
- case SkImageGenerator::kInvalidConversion:
- return Error::Nonfatal("Incompatible colortype conversion");
- default:
- // Everything else is considered a failure.
- return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
- }
- } else {
- if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
- dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
- return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
- }
- if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
- // Do not draw a bitmap with alpha to a destination without alpha.
- return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
- }
+ if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
+ dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
+ return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ }
+ if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
+ // Do not draw a bitmap with alpha to a destination without alpha.
+ return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
}
encoded.reset((SkData*)NULL); // Might as well drop this when we're done with it.
canvas->drawBitmap(bitmap, 0,0);
« dm/DM.cpp ('K') | « dm/DMSrcSink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698