commit-bot@chromium.org | a936e37 | 2013-03-14 14:42:18 +0000 | [diff] [blame] | 1 | /* |
| 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.org | bff83f6 | 2013-03-14 15:18:08 +0000 | [diff] [blame] | 16 | struct SkIRect; |
commit-bot@chromium.org | a936e37 | 2013-03-14 14:42:18 +0000 | [diff] [blame] | 17 | |
| 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 | */ |
| 26 | class SkBitmapRegionDecoder { |
| 27 | public: |
| 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 | |
| 47 | private: |
| 48 | SkImageDecoder* fDecoder; |
| 49 | SkStream* fStream; |
| 50 | int fWidth; |
| 51 | int fHeight; |
| 52 | }; |
| 53 | |
| 54 | #endif |