aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/codec/SkScaledCodec.h
blob: 028706bc9400bfb7028ba75699029d2454277484 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef SkScaledCodec_DEFINED
#define SkScaledCodec_DEFINED

#include "SkCodec.h"

class SkStream;

/**
 * This class implements scaling, by sampling scanlines in the y direction.
 * x-wise sampling is implemented in the swizzler, when getScanlines() is called.
 */
class SkScaledCodec : public SkCodec {
public:
    static SkCodec* NewFromStream(SkStream*);
    static SkCodec* NewFromData(SkData*);

    virtual ~SkScaledCodec();

    static void ComputeSampleSize(const SkISize& dstDim, const SkISize& srcDim,
                                  int* sampleSizeX, int* sampleSizeY);

protected:
    bool onRewind() override;

    /**
     * Recommend a set of destination dimensions given a requested scale
     */
    SkISize onGetScaledDimensions(float desiredScale) const override;
    bool onDimensionsSupported(const SkISize&) override;

    Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*, int*)
            override;
    SkEncodedFormat onGetEncodedFormat() const override {
        return fCodec->getEncodedFormat();
    }

    bool onReallyHasAlpha() const override {
        return fCodec->reallyHasAlpha();
    }

    uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const override;

    SkScanlineOrder onGetScanlineOrder() const override;

private:

    SkAutoTDelete<SkCodec> fCodec;

    explicit SkScaledCodec(SkCodec*);

    typedef SkCodec INHERITED;
};
#endif // SkScaledCodec_DEFINED