blob: 5aefe5d805ec6c93d967c90941b93927e5bd8461 [file] [log] [blame]
msarett3d9d7a72015-10-21 10:27:10 -07001/*
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
12SkWebpAdapterCodec::SkWebpAdapterCodec(SkWebpCodec* codec)
msarett90c4d5f2015-12-10 13:09:24 -080013 : INHERITED(codec)
msarett3d9d7a72015-10-21 10:27:10 -070014{}
15
16SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const {
17 float scale = get_scale_from_sample_size(sampleSize);
msarett90c4d5f2015-12-10 13:09:24 -080018 return this->codec()->getScaledDimensions(scale);
msarett3d9d7a72015-10-21 10:27:10 -070019}
20
21bool SkWebpAdapterCodec::onGetSupportedSubset(SkIRect* desiredSubset) const {
msarett90c4d5f2015-12-10 13:09:24 -080022 return this->codec()->getValidSubset(desiredSubset);
msarett3d9d7a72015-10-21 10:27:10 -070023}
24
25SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info, void* pixels,
scroggoe95a0682015-11-04 04:31:12 -080026 size_t rowBytes, const AndroidOptions& options) {
msarett3d9d7a72015-10-21 10:27:10 -070027 // 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;
msarett90c4d5f2015-12-10 13:09:24 -080043 return this->codec()->getPixels(info, pixels, rowBytes, &codecOptions, options.fColorPtr,
msarett3d9d7a72015-10-21 10:27:10 -070044 options.fColorCount);
45}