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

Unified Diff: src/codec/SkCodec.cpp

Issue 930283002: Add SkCodec, including PNG implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Check in prebuilt file directly 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 | « include/codec/SkCodec.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec.cpp
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ec36bc75e94e00edd22b857b179a9033a95fe5c1
--- /dev/null
+++ b/src/codec/SkCodec.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCodec.h"
+#include "SkData.h"
+#include "SkCodec_libpng.h"
+#include "SkStream.h"
+
+SkCodec* SkCodec::NewFromStream(SkStream* stream) {
+ if (!stream) {
+ return NULL;
+ }
+ SkAutoTDelete<SkStream> streamDeleter(stream);
+ const bool isPng = SkPngCodec::IsPng(stream);
+ // TODO: Avoid rewinding.
+ if (!stream->rewind()) {
+ return NULL;
+ }
+ if (isPng) {
+ streamDeleter.detach();
+ return SkPngCodec::NewFromStream(stream);
+ }
+ // TODO: Check other image types.
+ return NULL;
+}
+
+SkCodec* SkCodec::NewFromData(SkData* data) {
+ if (!data) {
+ return NULL;
+ }
+ return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data)));
+}
+
+SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
+ : fInfo(info)
+ , fStream(stream)
+ , fNeedsRewind(false)
+{}
+
+bool SkCodec::rewindIfNeeded() {
+ // Store the value of fNeedsRewind so we can update it. Next read will
+ // require a rewind.
+ const bool neededRewind = fNeedsRewind;
+ fNeedsRewind = true;
+ return !neededRewind || fStream->rewind();
+}
« no previous file with comments | « include/codec/SkCodec.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698