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 
8 #ifndef SkBitmapRegionCodec_DEFINED
9 #define SkBitmapRegionCodec_DEFINED
10 
11 #include "include/android/SkBitmapRegionDecoder.h"
12 #include "include/codec/SkAndroidCodec.h"
13 #include "include/core/SkBitmap.h"
14 
15 /*
16  * This class implements SkBitmapRegionDecoder using an SkAndroidCodec.
17  */
18 class SkBitmapRegionCodec : public SkBitmapRegionDecoder {
19 public:
20 
21     /*
22      * Takes ownership of pointer to codec
23      */
24     SkBitmapRegionCodec(SkAndroidCodec* codec);
25 
26     bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
27                       const SkIRect& desiredSubset, int sampleSize,
28                       SkColorType colorType, bool requireUnpremul,
29                       sk_sp<SkColorSpace> prefColorSpace) override;
30 
getEncodedFormat()31     SkEncodedImageFormat getEncodedFormat() override { return fCodec->getEncodedFormat(); }
32 
computeOutputColorType(SkColorType requestedColorType)33     SkColorType computeOutputColorType(SkColorType requestedColorType) override {
34         return fCodec->computeOutputColorType(requestedColorType);
35     }
36 
37     sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
38             sk_sp<SkColorSpace> prefColorSpace = nullptr) override {
39         return fCodec->computeOutputColorSpace(outputColorType, prefColorSpace);
40     }
41 
42 private:
43 
44     std::unique_ptr<SkAndroidCodec> fCodec;
45 
46     typedef SkBitmapRegionDecoder INHERITED;
47 
48 };
49 #endif  // SkBitmapRegionCodec_DEFINED
50