blob: a1b51573db3f5fdb334005adaeb6b2fe99f06300 [file] [log] [blame]
Leon Scroggins III753a56f2019-12-11 11:02:15 -05001/*
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
27class SkAndroidCodec;
28
29namespace android {
30
31class ANDROID_API ImageDecoder {
32public:
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 III1ade46d2020-01-15 05:41:06 -050044 bool setUnpremultipliedRequired(bool unpremultipliedRequired);
Leon Scroggins III753a56f2019-12-11 11:02:15 -050045
Leon Scroggins III6eeca5c2020-01-30 13:59:50 -050046 sk_sp<SkColorSpace> getDefaultColorSpace() const;
Leon Scroggins III753a56f2019-12-11 11:02:15 -050047 void setOutColorSpace(sk_sp<SkColorSpace> cs);
48
49 // The size is the final size after scaling and cropping.
50 SkImageInfo getOutputInfo() const;
Leon Scroggins III753a56f2019-12-11 11:02:15 -050051
52 bool opaque() const;
53 bool gray() const;
54
55 SkCodec::Result decode(void* pixels, size_t rowBytes);
56
57private:
58 SkISize mTargetSize;
59 SkISize mDecodeSize;
60 SkColorType mOutColorType;
Leon Scroggins III1ade46d2020-01-15 05:41:06 -050061 bool mUnpremultipliedRequired;
Leon Scroggins III753a56f2019-12-11 11:02:15 -050062 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 III1ade46d2020-01-15 05:41:06 -050068
69 SkAlphaType getOutAlphaType() const;
Leon Scroggins IIIe5ace3f2020-01-15 15:31:40 -050070 sk_sp<SkColorSpace> getOutputColorSpace() const;
Leon Scroggins III753a56f2019-12-11 11:02:15 -050071};
72
73} // namespace android