aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/images/SkBitmapRegionDecoder.h
blob: 56332343ccf329881b275931de67958abd581f61 (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
/*
 * Copyright 2011 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef SkBitmapRegionDecoder_DEFINED
#define SkBitmapRegionDecoder_DEFINED

#include "SkBitmap.h"
#include "SkImageDecoder.h"
#include "SkStream.h"

struct SkIRect;

/**
 * SkBitmapRegionDecoder can be used to decode a specified rect from an image.
 * This is particularly useful when the original image is large and you only
 * need parts of the image.
 *
 * However, not all image codecs on all platforms support this feature so be
 * prepared to fallback to standard decoding if decodeRegion(...) returns false.
 */
class SkBitmapRegionDecoder {
public:
    SkBitmapRegionDecoder(SkImageDecoder* decoder, SkStream* stream,
                          int width, int height) {
        fDecoder = decoder;
        fStream = stream;
        fWidth = width;
        fHeight = height;
    }
    ~SkBitmapRegionDecoder() {
        SkDELETE(fDecoder);
        SkSafeUnref(fStream);
    }

    bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect,
                      SkBitmap::Config pref, int sampleSize);

    SkImageDecoder* getDecoder() const { return fDecoder; }
    int getWidth() const { return fWidth; }
    int getHeight() const { return fHeight; }

private:
    SkImageDecoder* fDecoder;
    SkStream* fStream;
    int fWidth;
    int fHeight;
};

#endif