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 BitmapRegionDecoder_DEFINED 9 #define BitmapRegionDecoder_DEFINED 10 11 #include "client_utils/android/BRDAllocator.h" 12 #include "include/codec/SkAndroidCodec.h" 13 #include "include/core/SkBitmap.h" 14 #include "include/core/SkData.h" 15 16 namespace android { 17 namespace skia { 18 19 class BitmapRegionDecoder final { 20 public: 21 static std::unique_ptr<BitmapRegionDecoder> Make(sk_sp<SkData> data); 22 23 bool decodeRegion(SkBitmap* bitmap, 24 BRDAllocator* allocator, 25 const SkIRect& desiredSubset, 26 int sampleSize, 27 SkColorType colorType, 28 bool requireUnpremul, 29 sk_sp<SkColorSpace> prefColorSpace); 30 getEncodedFormat()31 SkEncodedImageFormat getEncodedFormat() { return fCodec->getEncodedFormat(); } 32 computeOutputColorType(SkColorType requestedColorType)33 SkColorType computeOutputColorType(SkColorType requestedColorType) { 34 return fCodec->computeOutputColorType(requestedColorType); 35 } 36 37 sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType, 38 sk_sp<SkColorSpace> prefColorSpace = nullptr) { 39 return fCodec->computeOutputColorSpace(outputColorType, std::move(prefColorSpace)); 40 } 41 42 int width() const; 43 int height() const; 44 getAndroidGainmap(SkGainmapInfo * outInfo,std::unique_ptr<SkStream> * outGainmapImageStream)45 bool getAndroidGainmap(SkGainmapInfo* outInfo, 46 std::unique_ptr<SkStream>* outGainmapImageStream) { 47 return fCodec->getAndroidGainmap(outInfo, outGainmapImageStream); 48 } 49 getGainmapBitmapRegionDecoder(SkGainmapInfo * outInfo,std::unique_ptr<BitmapRegionDecoder> * outDecoder)50 bool getGainmapBitmapRegionDecoder(SkGainmapInfo* outInfo, 51 std::unique_ptr<BitmapRegionDecoder>* outDecoder) { 52 std::unique_ptr<SkAndroidCodec> codec; 53 if (!fCodec->getGainmapAndroidCodec(outInfo, &codec)) { 54 return false; 55 } 56 57 *outDecoder = std::unique_ptr<BitmapRegionDecoder>( 58 new BitmapRegionDecoder(std::move(codec))); 59 return true; 60 } 61 62 private: 63 BitmapRegionDecoder(std::unique_ptr<SkAndroidCodec> codec); 64 65 std::unique_ptr<SkAndroidCodec> fCodec; 66 }; 67 68 } // namespace skia 69 } // namespace android 70 #endif // BitmapRegionDecoder_DEFINED 71