• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #ifndef RAW_DECODER_H
16 #define RAW_DECODER_H
17 #include "plugin_class_base.h"
18 #include "abs_image_decoder.h"
19 namespace OHOS {
20 namespace ImagePlugin {
21 class RawStream;
22 class RawDecoder : public AbsImageDecoder, public OHOS::MultimediaPlugin::PluginClassBase {
23 public:
24     RawDecoder();
25     ~RawDecoder() override;
26 
27 public:
28     void SetSource(InputDataStream &sourceStream) override;
29     void Reset() override;
30     bool HasProperty(std::string key) override;
31     uint32_t SetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info) override;
32     uint32_t Decode(uint32_t index, DecodeContext &context) override;
33     uint32_t PromoteIncrementalDecode(uint32_t index, ProgDecodeContext &progContext) override;
34     uint32_t GetTopLevelImageNum(uint32_t &num) override;
35     uint32_t GetImageSize(uint32_t index, PlSize &size) override;
36 
37 private:
38     uint32_t DoDecodeHeader();
39     uint32_t DoDecodeHeaderByPiex();
40 
41     uint32_t DoSetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info);
42     uint32_t DoGetImageSize(uint32_t index, PlSize &size);
43 
44     uint32_t DoDecode(uint32_t index, DecodeContext &context);
45 
46 private:
47     enum class RawDecodingState : int32_t {
48         UNDECIDED = 0,
49         SOURCE_INITED = 1,
50         BASE_INFO_PARSING = 2,
51         BASE_INFO_PARSED = 3,
52         IMAGE_DECODING = 4,
53         IMAGE_ERROR = 5,
54         IMAGE_PARTIAL = 6,
55         IMAGE_DECODED = 7
56     };
57 
58     InputDataStream *inputStream_ {nullptr};
59     RawDecodingState state_ {RawDecodingState::UNDECIDED};
60     PixelDecodeOptions opts_;
61     PlImageInfo info_;
62 
63     std::unique_ptr<RawStream> rawStream_;
64 
65     // PIEX used.
66     std::unique_ptr<InputDataStream> jpegStream_;
67     std::unique_ptr<AbsImageDecoder> jpegDecoder_;
68 };
69 } // namespace ImagePlugin
70 } // namespace OHOS
71 #endif // RAW_DECODER_H
72