blob: 56332343ccf329881b275931de67958abd581f61 [file] [log] [blame]
commit-bot@chromium.orga936e372013-03-14 14:42:18 +00001/*
2 * Copyright 2011 The Android Open Source Project
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
9#ifndef SkBitmapRegionDecoder_DEFINED
10#define SkBitmapRegionDecoder_DEFINED
11
12#include "SkBitmap.h"
13#include "SkImageDecoder.h"
14#include "SkStream.h"
15
commit-bot@chromium.orgbff83f62013-03-14 15:18:08 +000016struct SkIRect;
commit-bot@chromium.orga936e372013-03-14 14:42:18 +000017
18/**
19 * SkBitmapRegionDecoder can be used to decode a specified rect from an image.
20 * This is particularly useful when the original image is large and you only
21 * need parts of the image.
22 *
23 * However, not all image codecs on all platforms support this feature so be
24 * prepared to fallback to standard decoding if decodeRegion(...) returns false.
25 */
26class SkBitmapRegionDecoder {
27public:
28 SkBitmapRegionDecoder(SkImageDecoder* decoder, SkStream* stream,
29 int width, int height) {
30 fDecoder = decoder;
31 fStream = stream;
32 fWidth = width;
33 fHeight = height;
34 }
35 ~SkBitmapRegionDecoder() {
36 SkDELETE(fDecoder);
37 SkSafeUnref(fStream);
38 }
39
40 bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect,
41 SkBitmap::Config pref, int sampleSize);
42
43 SkImageDecoder* getDecoder() const { return fDecoder; }
44 int getWidth() const { return fWidth; }
45 int getHeight() const { return fHeight; }
46
47private:
48 SkImageDecoder* fDecoder;
49 SkStream* fStream;
50 int fWidth;
51 int fHeight;
52};
53
54#endif