Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include <SkCodec.h> |
| 19 | #include <SkImageInfo.h> |
| 20 | #include <SkPngChunkReader.h> |
| 21 | #include <SkRect.h> |
| 22 | #include <SkSize.h> |
| 23 | #include <cutils/compiler.h> |
| 24 | |
| 25 | #include <optional> |
| 26 | |
| 27 | class SkAndroidCodec; |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | class ANDROID_API ImageDecoder { |
| 32 | public: |
| 33 | std::unique_ptr<SkAndroidCodec> mCodec; |
| 34 | sk_sp<SkPngChunkReader> mPeeker; |
| 35 | |
| 36 | ImageDecoder(std::unique_ptr<SkAndroidCodec> codec, |
| 37 | sk_sp<SkPngChunkReader> peeker = nullptr); |
| 38 | |
| 39 | bool setTargetSize(int width, int height); |
| 40 | bool setCropRect(const SkIRect*); |
| 41 | |
| 42 | bool setOutColorType(SkColorType outColorType); |
| 43 | |
Leon Scroggins III | 1ade46d | 2020-01-15 05:41:06 -0500 | [diff] [blame] | 44 | bool setUnpremultipliedRequired(bool unpremultipliedRequired); |
Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 45 | |
Leon Scroggins III | 6eeca5c | 2020-01-30 13:59:50 -0500 | [diff] [blame] | 46 | sk_sp<SkColorSpace> getDefaultColorSpace() const; |
Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 47 | void setOutColorSpace(sk_sp<SkColorSpace> cs); |
| 48 | |
| 49 | // The size is the final size after scaling and cropping. |
| 50 | SkImageInfo getOutputInfo() const; |
Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 51 | |
| 52 | bool opaque() const; |
| 53 | bool gray() const; |
| 54 | |
| 55 | SkCodec::Result decode(void* pixels, size_t rowBytes); |
| 56 | |
| 57 | private: |
| 58 | SkISize mTargetSize; |
| 59 | SkISize mDecodeSize; |
| 60 | SkColorType mOutColorType; |
Leon Scroggins III | 1ade46d | 2020-01-15 05:41:06 -0500 | [diff] [blame] | 61 | bool mUnpremultipliedRequired; |
Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 62 | sk_sp<SkColorSpace> mOutColorSpace; |
| 63 | int mSampleSize; |
| 64 | std::optional<SkIRect> mCropRect; |
| 65 | |
| 66 | ImageDecoder(const ImageDecoder&) = delete; |
| 67 | ImageDecoder& operator=(const ImageDecoder&) = delete; |
Leon Scroggins III | 1ade46d | 2020-01-15 05:41:06 -0500 | [diff] [blame] | 68 | |
| 69 | SkAlphaType getOutAlphaType() const; |
Leon Scroggins III | e5ace3f | 2020-01-15 15:31:40 -0500 | [diff] [blame] | 70 | sk_sp<SkColorSpace> getOutputColorSpace() const; |
Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace android |