aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkWebpAdapterCodec.cpp
blob: 5aefe5d805ec6c93d967c90941b93927e5bd8461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * 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)
{}

SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const {
    float scale = get_scale_from_sample_size(sampleSize);
    return this->codec()->getScaledDimensions(scale);
}

bool SkWebpAdapterCodec::onGetSupportedSubset(SkIRect* desiredSubset) const {
    return this->codec()->getValidSubset(desiredSubset);
}

SkCodec::Result SkWebpAdapterCodec::onGetAndroidPixels(const SkImageInfo& info, void* pixels,
        size_t rowBytes, const AndroidOptions& options) {
    // SkWebpCodec will support pretty much any dimensions that we provide, but we want
    // to be stricter about the type of scaling that we allow, so we will add an extra
    // check here.
    SkISize supportedSize;
    if (!options.fSubset) {
        supportedSize = this->onGetSampledDimensions(options.fSampleSize);
    } else {
        supportedSize = this->getSampledSubsetDimensions(options.fSampleSize, *options.fSubset);
    }
    if (supportedSize != info.dimensions()) {
        return SkCodec::kInvalidParameters;
    }

    SkCodec::Options codecOptions;
    codecOptions.fZeroInitialized = options.fZeroInitialized;
    codecOptions.fSubset = options.fSubset;
    return this->codec()->getPixels(info, pixels, rowBytes, &codecOptions, options.fColorPtr,
            options.fColorCount);
}