msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 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) |
msarett | 90c4d5f | 2015-12-10 13:09:24 -0800 | [diff] [blame] | 13 | : INHERITED(codec) |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 14 | {} |
| 15 | |
| 16 | SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const { |
| 17 | float scale = get_scale_from_sample_size(sampleSize); |
msarett | 90c4d5f | 2015-12-10 13:09:24 -0800 | [diff] [blame] | 18 | return this->codec()->getScaledDimensions(scale); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | bool SkWebpAdapterCodec::onGetSupportedSubset(SkIRect* desiredSubset) const { |
msarett | 90c4d5f | 2015-12-10 13:09:24 -0800 | [diff] [blame] | 22 | return this->codec()->getValidSubset(desiredSubset); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info, void* pixels, |
scroggo | e95a068 | 2015-11-04 04:31:12 -0800 | [diff] [blame] | 26 | size_t rowBytes, const AndroidOptions& options) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 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; |
msarett | 90c4d5f | 2015-12-10 13:09:24 -0800 | [diff] [blame] | 43 | return this->codec()->getPixels(info, pixels, rowBytes, &codecOptions, options.fColorPtr, |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 44 | options.fColorCount); |
| 45 | } |