msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 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 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 8 | #ifndef BitmapRegionDecoder_DEFINED |
| 9 | #define BitmapRegionDecoder_DEFINED |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 10 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 11 | #include "client_utils/android/BRDAllocator.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/codec/SkAndroidCodec.h" |
| 13 | #include "include/core/SkBitmap.h" |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 14 | #include "include/core/SkData.h" |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 15 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 16 | namespace android { |
| 17 | namespace skia { |
| 18 | |
Leon Scroggins III | 43182bc | 2020-05-21 11:14:31 -0400 | [diff] [blame] | 19 | class BitmapRegionDecoder final { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 20 | public: |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 21 | static std::unique_ptr<BitmapRegionDecoder> Make(sk_sp<SkData> data); |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 22 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 23 | bool decodeRegion(SkBitmap* bitmap, BRDAllocator* allocator, |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 24 | const SkIRect& desiredSubset, int sampleSize, |
Matt Sarett | 68feef4 | 2017-04-11 09:51:32 -0400 | [diff] [blame] | 25 | SkColorType colorType, bool requireUnpremul, |
Leon Scroggins III | 43182bc | 2020-05-21 11:14:31 -0400 | [diff] [blame] | 26 | sk_sp<SkColorSpace> prefColorSpace); |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 27 | |
Leon Scroggins III | 43182bc | 2020-05-21 11:14:31 -0400 | [diff] [blame] | 28 | SkEncodedImageFormat getEncodedFormat() { return fCodec->getEncodedFormat(); } |
msarett | 3f65e93 | 2015-10-27 13:12:59 -0700 | [diff] [blame] | 29 | |
Leon Scroggins III | 43182bc | 2020-05-21 11:14:31 -0400 | [diff] [blame] | 30 | SkColorType computeOutputColorType(SkColorType requestedColorType) { |
Matt Sarett | 479366c | 2017-04-14 09:23:45 -0400 | [diff] [blame] | 31 | return fCodec->computeOutputColorType(requestedColorType); |
| 32 | } |
| 33 | |
| 34 | sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType, |
Leon Scroggins III | 43182bc | 2020-05-21 11:14:31 -0400 | [diff] [blame] | 35 | sk_sp<SkColorSpace> prefColorSpace = nullptr) { |
Matt Sarett | 479366c | 2017-04-14 09:23:45 -0400 | [diff] [blame] | 36 | return fCodec->computeOutputColorSpace(outputColorType, prefColorSpace); |
| 37 | } |
| 38 | |
Leon Scroggins III | 43182bc | 2020-05-21 11:14:31 -0400 | [diff] [blame] | 39 | int width() const; |
| 40 | int height() const; |
| 41 | |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 42 | private: |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 43 | BitmapRegionDecoder(std::unique_ptr<SkAndroidCodec> codec); |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 44 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 45 | std::unique_ptr<SkAndroidCodec> fCodec; |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 46 | }; |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 47 | |
| 48 | } // namespace skia |
| 49 | } // namespace android |
| 50 | #endif // BitmapRegionDecoder_DEFINED |