blob: 2996df3aee6bad5098594a8f771b17320ea993b8 [file] [log] [blame]
msarett26ad17b2015-10-22 07:29:19 -07001/*
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 III87caae62020-05-04 10:02:45 -04008#ifndef BitmapRegionDecoder_DEFINED
9#define BitmapRegionDecoder_DEFINED
Hal Canary03a7f5f2017-02-10 09:06:38 -050010
Leon Scroggins III87caae62020-05-04 10:02:45 -040011#include "client_utils/android/BRDAllocator.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/codec/SkAndroidCodec.h"
13#include "include/core/SkBitmap.h"
Leon Scroggins III87caae62020-05-04 10:02:45 -040014#include "include/core/SkData.h"
msarett26ad17b2015-10-22 07:29:19 -070015
Leon Scroggins III87caae62020-05-04 10:02:45 -040016namespace android {
17namespace skia {
18
Leon Scroggins III43182bc2020-05-21 11:14:31 -040019class BitmapRegionDecoder final {
msarett26ad17b2015-10-22 07:29:19 -070020public:
Leon Scroggins III87caae62020-05-04 10:02:45 -040021 static std::unique_ptr<BitmapRegionDecoder> Make(sk_sp<SkData> data);
msarett26ad17b2015-10-22 07:29:19 -070022
Leon Scroggins III87caae62020-05-04 10:02:45 -040023 bool decodeRegion(SkBitmap* bitmap, BRDAllocator* allocator,
msarett35e5d1b2015-10-27 12:50:25 -070024 const SkIRect& desiredSubset, int sampleSize,
Matt Sarett68feef42017-04-11 09:51:32 -040025 SkColorType colorType, bool requireUnpremul,
Leon Scroggins III43182bc2020-05-21 11:14:31 -040026 sk_sp<SkColorSpace> prefColorSpace);
msarett26ad17b2015-10-22 07:29:19 -070027
Leon Scroggins III43182bc2020-05-21 11:14:31 -040028 SkEncodedImageFormat getEncodedFormat() { return fCodec->getEncodedFormat(); }
msarett3f65e932015-10-27 13:12:59 -070029
Leon Scroggins III43182bc2020-05-21 11:14:31 -040030 SkColorType computeOutputColorType(SkColorType requestedColorType) {
Matt Sarett479366c2017-04-14 09:23:45 -040031 return fCodec->computeOutputColorType(requestedColorType);
32 }
33
34 sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
Leon Scroggins III43182bc2020-05-21 11:14:31 -040035 sk_sp<SkColorSpace> prefColorSpace = nullptr) {
Matt Sarett479366c2017-04-14 09:23:45 -040036 return fCodec->computeOutputColorSpace(outputColorType, prefColorSpace);
37 }
38
Leon Scroggins III43182bc2020-05-21 11:14:31 -040039 int width() const;
40 int height() const;
41
msarett26ad17b2015-10-22 07:29:19 -070042private:
Leon Scroggins III87caae62020-05-04 10:02:45 -040043 BitmapRegionDecoder(std::unique_ptr<SkAndroidCodec> codec);
msarett26ad17b2015-10-22 07:29:19 -070044
Ben Wagner145dbcd2016-11-03 14:40:50 -040045 std::unique_ptr<SkAndroidCodec> fCodec;
msarett26ad17b2015-10-22 07:29:19 -070046};
Leon Scroggins III87caae62020-05-04 10:02:45 -040047
48} // namespace skia
49} // namespace android
50#endif // BitmapRegionDecoder_DEFINED