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

Unified Diff: dm/DMSrcSink.cpp

Issue 930283002: Add SkCodec, including PNG implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Handle rewinding. 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
« no previous file with comments | « no previous file | gyp/codec.gyp » ('j') | gyp/codec.gyp » ('J')
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 b44f1d78180e94e9d9f5505789024e5db42c4007..a615b78e7aa34b5296e8332f5ea4036531800a39 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1,6 +1,7 @@
#include "DMSrcSink.h"
#include "SamplePipeControllers.h"
#include "SkCommonFlags.h"
+#include "SkCodec.h"
#include "SkDocument.h"
#include "SkMultiPictureDraw.h"
#include "SkNullCanvas.h"
@@ -11,6 +12,8 @@
#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) {}
@@ -45,9 +48,32 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
if (fDivisor == 0) {
// Decode the full image.
SkBitmap bitmap;
- if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
- dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
- return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ 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);
+ }
+ bitmap.allocPixels(info);
+ SkAutoLockPixels alp(bitmap);
djsollen 2015/02/25 16:02:19 aren't the pixels locked during allocPixels if you
scroggo 2015/02/25 18:00:54 Yes. In fact I initially left this line out, if yo
+ const SkImageGenerator::Result result = codec->getPixels(info, bitmap.getPixels(),
+ bitmap.rowBytes());
+ if (result != SkImageGenerator::kSuccess) {
+ return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
+ }
+ } else {
djsollen 2015/02/25 16:02:19 else if
scroggo 2015/02/25 18:00:54 In this case, I actually like the current code bet
+ if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
+ dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
+ return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ }
}
encoded.reset((SkData*)NULL); // Might as well drop this when we're done with it.
canvas->drawBitmap(bitmap, 0,0);
« no previous file with comments | « no previous file | gyp/codec.gyp » ('j') | gyp/codec.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698