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

Unified Diff: dm/DMSrcSink.cpp

Issue 978823002: Run CodecSrc DM. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, plus cleanups Created 5 years, 10 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..6ff023d270af1571437db7225088f8118001b497 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -13,8 +13,6 @@
#include "SkStream.h"
#include "SkXMLWriter.h"
-DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder");
-
namespace DM {
GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
@@ -38,6 +36,108 @@ Name GMSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+CodecSrc::CodecSrc(Path path, SkColorType dstCT, SkAlphaType dstAT, SkipZeroes skip,
+ Scanlines scanlines)
+ : fPath(path)
+ , fDstColorType(dstCT)
+ , fDstAlphaType(dstAT)
+ , fSkipZeroes(skip)
+ , fScanlines(scanlines) {}
+
+Error CodecSrc::draw(SkCanvas* canvas) const {
mtklein 2015/03/06 00:25:25 Can we use non-fatal errors here to have this Code
scroggo 2015/03/06 20:40:27 That could work. Although I'm still trying to wrap
scroggo 2015/03/06 20:43:45 My other thought is that the config you choose wil
scroggo 2015/03/13 21:34:33 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 info;
+ if (!codec->getInfo(&info)) {
+ return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
+ }
+ info = SkImageInfo::Make(info.width(), info.height(), fDstColorType,
+ fDstAlphaType, info.profileType());
+ SkBitmap bitmap;
+ 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);
+ if (kSkipZeroes == fSkipZeroes) {
+ memset(bitmap.getPixels(), 0, bitmap.getSafeSize());
+ // TODO: modify the setting on codec.
+ }
+
+ // TODO: Support other scanline modes.
+ SkASSERT(kNormal_Scanlines == fScanlines);
+
+ 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:
+ 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);
+}
+
+// This code mimics code in DecodingBench. Can we unify?
+const char* color_type_name(SkColorType colorType) {
+ switch(colorType) {
+ case kN32_SkColorType:
+ return "N32";
+ case kRGB_565_SkColorType:
+ return "565";
+ case kAlpha_8_SkColorType:
+ return "Alpha8";
+ default:
+ return "Unknown";
+ }
+}
+
+const char* alpha_type_name(SkAlphaType alphaType) {
+ switch (alphaType) {
+ case kUnpremul_SkAlphaType:
+ return "Unpremul";
+ case kPremul_SkAlphaType:
+ return "Premul";
+ case kOpaque_SkAlphaType:
+ return "Opaque";
+ default:
+ // We only support the above three.
+ SkASSERT(false);
+ return "";
+ }
+}
+
+Name CodecSrc::name() const {
+ return SkStringPrintf("%s_%s_%s", SkOSPath::Basename(fPath.c_str()).c_str(),
+ color_type_name(fDstColorType),
+ alpha_type_name(fDstAlphaType));
+}
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
Error ImageSrc::draw(SkCanvas* canvas) const {
@@ -49,48 +149,13 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
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