OLD | NEW |
(Empty) | |
| 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 |
| 12 SkWebpAdapterCodec::SkWebpAdapterCodec(SkWebpCodec* codec) |
| 13 : INHERITED(codec->getInfo()) |
| 14 , fCodec(codec) |
| 15 {} |
| 16 |
| 17 SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const { |
| 18 float scale = get_scale_from_sample_size(sampleSize); |
| 19 return fCodec->getScaledDimensions(scale); |
| 20 } |
| 21 |
| 22 bool SkWebpAdapterCodec::onGetSupportedSubset(SkIRect* desiredSubset) const { |
| 23 return fCodec->getValidSubset(desiredSubset); |
| 24 } |
| 25 |
| 26 SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info,
void* pixels, |
| 27 size_t rowBytes, AndroidOptions& options) { |
| 28 // SkWebpCodec will support pretty much any dimensions that we provide, but
we want |
| 29 // to be stricter about the type of scaling that we allow, so we will add an
extra |
| 30 // check here. |
| 31 SkISize supportedSize; |
| 32 if (!options.fSubset) { |
| 33 supportedSize = this->onGetSampledDimensions(options.fSampleSize); |
| 34 } else { |
| 35 supportedSize = this->getSampledSubsetDimensions(options.fSampleSize, *o
ptions.fSubset); |
| 36 } |
| 37 if (supportedSize != info.dimensions()) { |
| 38 return SkCodec::kInvalidParameters; |
| 39 } |
| 40 |
| 41 SkCodec::Options codecOptions; |
| 42 codecOptions.fZeroInitialized = options.fZeroInitialized; |
| 43 codecOptions.fSubset = options.fSubset; |
| 44 return fCodec->getPixels(info, pixels, rowBytes, &codecOptions, options.fCol
orPtr, |
| 45 options.fColorCount); |
| 46 } |
OLD | NEW |