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