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 using namespace Media; 22 23 class RawStream; 24 class RawDecoder : public AbsImageDecoder, public OHOS::MultimediaPlugin::PluginClassBase { 25 public: 26 RawDecoder(); 27 ~RawDecoder() override; 28 29 public: 30 void SetSource(InputDataStream &sourceStream) override; 31 void Reset() override; 32 bool HasProperty(std::string key) override; 33 uint32_t SetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info) override; 34 uint32_t Decode(uint32_t index, DecodeContext &context) override; 35 uint32_t PromoteIncrementalDecode(uint32_t index, ProgDecodeContext &progContext) override; 36 uint32_t GetTopLevelImageNum(uint32_t &num) override; 37 uint32_t GetImageSize(uint32_t index, Size &size) override; GetPluginType()38 std::string GetPluginType() override 39 { 40 return "raw"; 41 } 42 #ifdef IMAGE_COLORSPACE_FLAG IsSupportICCProfile()43 bool IsSupportICCProfile() override 44 { 45 return false; 46 } 47 #endif 48 49 private: 50 uint32_t DoDecodeHeader(); 51 uint32_t DoDecodeHeaderByPiex(); 52 53 uint32_t DoSetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info); 54 uint32_t DoGetImageSize(uint32_t index, Size &size); 55 56 uint32_t DoDecode(uint32_t index, DecodeContext &context); 57 58 private: 59 enum class RawDecodingState : int32_t { 60 UNDECIDED = 0, 61 SOURCE_INITED = 1, 62 BASE_INFO_PARSING = 2, 63 BASE_INFO_PARSED = 3, 64 IMAGE_DECODING = 4, 65 IMAGE_ERROR = 5, 66 IMAGE_PARTIAL = 6, 67 IMAGE_DECODED = 7 68 }; 69 70 InputDataStream *inputStream_ {nullptr}; 71 RawDecodingState state_ {RawDecodingState::UNDECIDED}; 72 PixelDecodeOptions opts_; 73 PlImageInfo info_; 74 75 std::unique_ptr<RawStream> rawStream_; 76 77 // PIEX used. 78 std::unique_ptr<InputDataStream> jpegStream_; 79 std::unique_ptr<AbsImageDecoder> jpegDecoder_; 80 }; 81 } // namespace ImagePlugin 82 } // namespace OHOS 83 #endif // RAW_DECODER_H 84