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

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: 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
Index: src/codec/SkWebpAdapterCodec.cpp
diff --git a/src/codec/SkWebpAdapterCodec.cpp b/src/codec/SkWebpAdapterCodec.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1a045cd3095adaf1e7fab49ad36b92785489e425
--- /dev/null
+++ b/src/codec/SkWebpAdapterCodec.cpp
@@ -0,0 +1,41 @@
+/*
+ * 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::onGetSubset(SkIRect* desiredSubset) const {
+ return fCodec->getValidSubset(desiredSubset);
+}
+
+SkISize SkWebpAdapterCodec::onGetSampledSubsetDimensions(int sampleSize, const SkIRect& subset)
+ const {
+ float scale = get_scale_from_sample_size(sampleSize);
+ int width = SkTMax(1, SkScalarRoundToInt(scale * (float) subset.width()));
msarett 2015/10/16 18:42:16 Alternatively, we could use get_scaled_dimension()
scroggo 2015/10/16 21:13:55 I suppose this mimics the old behavior? I don't ha
msarett 2015/10/19 16:06:10 Using get_scaled_dimension() would actually be con
+ int height = SkTMax(1, SkScalarRoundToInt(scale * (float) subset.height()));
+ return SkISize::Make(width, height);
+}
+
+SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info, void* pixels,
+ size_t rowBytes, AndroidOptions& options) {
+ SkCodec::Options codecOptions;
+ codecOptions.fZeroInitialized = options.fZeroInitialized;
+ codecOptions.fSubset = options.fSubset;
+ return fCodec->getPixels(info, pixels, rowBytes, &codecOptions, options.fColorPtr,
+ options.fColorCount);
+}

Powered by Google App Engine
This is Rietveld 408576698