1 /* 2 * Copyright (C) 2021 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 BMP_DECODER_H 17 #define BMP_DECODER_H 18 19 #include <cstdint> 20 #include <string> 21 #include "include/codec/SkCodec.h" 22 #include "abs_image_decoder.h" 23 #include "bmp_stream.h" 24 #include "plugin_class_base.h" 25 26 namespace OHOS { 27 namespace ImagePlugin { 28 using namespace Media; 29 30 enum class BmpDecodingState : int32_t { 31 UNDECIDED = 0, 32 SOURCE_INITED = 1, 33 BASE_INFO_PARSED = 2, 34 IMAGE_DECODING = 3, 35 IMAGE_ERROR = 4, 36 IMAGE_DECODED = 5 37 }; 38 39 class BmpDecoder : public AbsImageDecoder, public OHOS::MultimediaPlugin::PluginClassBase { 40 public: 41 BmpDecoder() = default; ~BmpDecoder()42 virtual ~BmpDecoder() override {}; 43 void SetSource(InputDataStream &sourceStream) override; 44 void Reset() override; 45 uint32_t SetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info) override; 46 uint32_t Decode(uint32_t index, DecodeContext &context) override; 47 uint32_t GetImageSize(uint32_t index, Size &size) override; 48 uint32_t PromoteIncrementalDecode(uint32_t index, ProgDecodeContext &context) override; GetPluginType()49 std::string GetPluginType() override 50 { 51 return "bmp"; 52 } 53 #ifdef IMAGE_COLORSPACE_FLAG IsSupportICCProfile()54 bool IsSupportICCProfile() override 55 { 56 return false; 57 } 58 #endif 59 60 private: 61 DISALLOW_COPY_AND_MOVE(BmpDecoder); 62 bool DecodeHeader(); 63 AlphaType ConvertToAlphaType(SkAlphaType alphaType); 64 SkColorType ConvertToColorType(PixelFormat format, PixelFormat &outputFormat); 65 uint32_t SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &context, SkImageInfo &dstInfo); 66 uint32_t SetShareMemBuffer(uint64_t byteCount, DecodeContext &context); 67 InputDataStream *stream_ = nullptr; 68 std::unique_ptr<SkCodec> codec_ = nullptr; 69 SkImageInfo info_; 70 SkColorType desireColor_ = kUnknown_SkColorType; 71 BmpDecodingState state_ = BmpDecodingState::UNDECIDED; 72 }; 73 } // namespace ImagePlugin 74 } // namespace OHOS 75 76 #endif // BMP_DECODER_H 77