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

Unified Diff: src/codec/SkWebpAdapterCodec.cpp

Issue 1406223002: Create an SkAndroidCodec API separate from SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Win bot fix Created 5 years, 2 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 | « src/codec/SkWebpAdapterCodec.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkWebpAdapterCodec.cpp
diff --git a/src/codec/SkWebpAdapterCodec.cpp b/src/codec/SkWebpAdapterCodec.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0804e748a291e9aaf7f7a8b1bdcdefd4ed7be6ab
--- /dev/null
+++ b/src/codec/SkWebpAdapterCodec.cpp
@@ -0,0 +1,46 @@
+/*
+ * 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 "SkCodecPriv.h"
+#include "SkWebpAdapterCodec.h"
+
+SkWebpAdapterCodec::SkWebpAdapterCodec(SkWebpCodec* codec)
+ : INHERITED(codec->getInfo())
+ , fCodec(codec)
+{}
+
+SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const {
+ float scale = get_scale_from_sample_size(sampleSize);
+ return fCodec->getScaledDimensions(scale);
+}
+
+bool SkWebpAdapterCodec::onGetSupportedSubset(SkIRect* desiredSubset) const {
+ return fCodec->getValidSubset(desiredSubset);
+}
+
+SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info, void* pixels,
+ size_t rowBytes, AndroidOptions& options) {
+ // SkWebpCodec will support pretty much any dimensions that we provide, but we want
+ // to be stricter about the type of scaling that we allow, so we will add an extra
+ // check here.
+ SkISize supportedSize;
+ if (!options.fSubset) {
+ supportedSize = this->onGetSampledDimensions(options.fSampleSize);
+ } else {
+ supportedSize = this->getSampledSubsetDimensions(options.fSampleSize, *options.fSubset);
+ }
+ if (supportedSize != info.dimensions()) {
+ return SkCodec::kInvalidParameters;
+ }
+
+ SkCodec::Options codecOptions;
+ codecOptions.fZeroInitialized = options.fZeroInitialized;
+ codecOptions.fSubset = options.fSubset;
+ return fCodec->getPixels(info, pixels, rowBytes, &codecOptions, options.fColorPtr,
+ options.fColorCount);
+}
« no previous file with comments | « src/codec/SkWebpAdapterCodec.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698