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 #ifdef IMAGE_COLORSPACE_FLAG IsSupportICCProfile()37 bool IsSupportICCProfile() override 38 { 39 return false; 40 } 41 #endif 42 43 private: 44 uint32_t DoDecodeHeader(); 45 uint32_t DoDecodeHeaderByPiex(); 46 47 uint32_t DoSetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info); 48 uint32_t DoGetImageSize(uint32_t index, PlSize &size); 49 50 uint32_t DoDecode(uint32_t index, DecodeContext &context); 51 52 private: 53 enum class RawDecodingState : int32_t { 54 UNDECIDED = 0, 55 SOURCE_INITED = 1, 56 BASE_INFO_PARSING = 2, 57 BASE_INFO_PARSED = 3, 58 IMAGE_DECODING = 4, 59 IMAGE_ERROR = 5, 60 IMAGE_PARTIAL = 6, 61 IMAGE_DECODED = 7 62 }; 63 64 InputDataStream *inputStream_ {nullptr}; 65 RawDecodingState state_ {RawDecodingState::UNDECIDED}; 66 PixelDecodeOptions opts_; 67 PlImageInfo info_; 68 69 std::unique_ptr<RawStream> rawStream_; 70 71 // PIEX used. 72 std::unique_ptr<InputDataStream> jpegStream_; 73 std::unique_ptr<AbsImageDecoder> jpegDecoder_; 74 }; 75 } // namespace ImagePlugin 76 } // namespace OHOS 77 #endif // RAW_DECODER_H 78