• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_EXT_DECODER_H_
17 #define PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_EXT_DECODER_H_
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "SkCodec.h"
23 #include "abs_image_decoder.h"
24 #include "ext_stream.h"
25 #include "exif_info.h"
26 #include "nocopyable.h"
27 #include "plugin_class_base.h"
28 
29 namespace OHOS {
30 namespace ImagePlugin {
31 class ExtDecoder : public AbsImageDecoder, public OHOS::MultimediaPlugin::PluginClassBase, NoCopyable {
32 public:
33     ExtDecoder();
34     ~ExtDecoder() override;
35     bool HasProperty(std::string key) override;
36     uint32_t Decode(uint32_t index, DecodeContext &context) override;
37     uint32_t GifDecode(uint32_t index, DecodeContext &context, const uint64_t rowStride);
38     uint32_t GetImageSize(uint32_t index, PlSize &size) override;
39     uint32_t GetTopLevelImageNum(uint32_t &num) override;
40     uint32_t PromoteIncrementalDecode(uint32_t index, ProgDecodeContext &context) override;
41     uint32_t SetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info) override;
42     void Reset() override;
43     void SetSource(InputDataStream &sourceStream) override;
44 
45     uint32_t GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value) override;
46     uint32_t GetImagePropertyString(uint32_t index, const std::string &key, std::string &value) override;
47     uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value,
48         const std::string &path) override;
49     uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value,
50         const int fd) override;
51     uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value,
52         uint8_t *data, uint32_t size) override;
53     uint32_t GetFilterArea(const int &privacyType, std::vector<std::pair<uint32_t, uint32_t>> &ranges) override;
54 
55 #ifdef IMAGE_COLORSPACE_FLAG
56     OHOS::ColorManager::ColorSpace getGrColorSpace() override;
57     bool IsSupportICCProfile() override;
58 #endif
59 
60 private:
61     bool CheckCodec();
62     bool CheckIndexValied(uint32_t index);
63     bool DecodeHeader();
64     bool IsSupportScaleOnDecode();
65     bool GetScaledSize(int &dWidth, int &dHeight, float &scale);
66     bool IsSupportCropOnDecode();
67     bool IsSupportCropOnDecode(SkIRect &target);
68     bool ConvertInfoToAlphaType(SkAlphaType &alphaType, PlAlphaType &outputType);
69     bool ConvertInfoToColorType(SkColorType &format, PlPixelFormat &outputFormat);
70     bool GetPropertyCheck(uint32_t index, const std::string &key, uint32_t &res);
71     SkAlphaType ConvertToAlphaType(PlAlphaType desiredType, PlAlphaType &outputType);
72     uint32_t PreDecodeCheck(uint32_t index);
73     bool ResetCodec();
74     SkColorType ConvertToColorType(PlPixelFormat format, PlPixelFormat &outputFormat);
75     uint32_t SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &context);
76     ImagePlugin::InputDataStream *stream_ = nullptr;
77     uint32_t streamOff_ = 0;
78     std::unique_ptr<SkCodec> codec_;
79     SkImageInfo info_;
80     SkImageInfo dstInfo_;
81     SkCodec::Options dstOptions_;
82     SkIRect dstSubset_;
83     int32_t frameCount_ = 0;
84     EXIFInfo exifInfo_;
85     uint8_t *gifCache_ = nullptr;
86     uint32_t gifCacheIndex_ = 0;
87 };
88 } // namespace ImagePlugin
89 } // namespace OHOS
90 
91 #endif // PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_EXT_DECODER_H_
92