1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCodec.h"
9 #include "SkCodecPriv.h"
10 #include "SkWebpAdapterCodec.h"
11
SkWebpAdapterCodec(SkWebpCodec * codec)12 SkWebpAdapterCodec::SkWebpAdapterCodec(SkWebpCodec* codec)
13 : INHERITED(codec)
14 {}
15
onGetSampledDimensions(int sampleSize) const16 SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const {
17 float scale = get_scale_from_sample_size(sampleSize);
18 return this->codec()->getScaledDimensions(scale);
19 }
20
onGetSupportedSubset(SkIRect * desiredSubset) const21 bool SkWebpAdapterCodec::onGetSupportedSubset(SkIRect* desiredSubset) const {
22 return this->codec()->getValidSubset(desiredSubset);
23 }
24
onGetAndroidPixels(const SkImageInfo & info,void * pixels,size_t rowBytes,const AndroidOptions & options)25 SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info, void* pixels,
26 size_t rowBytes, const AndroidOptions& options) {
27 // SkWebpCodec will support pretty much any dimensions that we provide, but we want
28 // to be stricter about the type of scaling that we allow, so we will add an extra
29 // check here.
30 SkISize supportedSize;
31 if (!options.fSubset) {
32 supportedSize = this->onGetSampledDimensions(options.fSampleSize);
33 } else {
34 supportedSize = this->getSampledSubsetDimensions(options.fSampleSize, *options.fSubset);
35 }
36 if (supportedSize != info.dimensions()) {
37 return SkCodec::kInvalidParameters;
38 }
39
40 SkCodec::Options codecOptions;
41 codecOptions.fZeroInitialized = options.fZeroInitialized;
42 codecOptions.fSubset = options.fSubset;
43 return this->codec()->getPixels(info, pixels, rowBytes, &codecOptions, options.fColorPtr,
44 options.fColorCount);
45 }
46