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; 49 #ifdef IMAGE_COLORSPACE_FLAG IsSupportICCProfile()50 bool IsSupportICCProfile() override 51 { 52 return false; 53 } 54 #endif 55 56 private: 57 DISALLOW_COPY_AND_MOVE(BmpDecoder); 58 bool DecodeHeader(); 59 AlphaType ConvertToAlphaType(SkAlphaType alphaType); 60 SkColorType ConvertToColorType(PixelFormat format, PixelFormat &outputFormat); 61 uint32_t SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &context, SkImageInfo &dstInfo); 62 uint32_t SetShareMemBuffer(uint64_t byteCount, DecodeContext &context); 63 InputDataStream *stream_ = nullptr; 64 std::unique_ptr<SkCodec> codec_ = nullptr; 65 SkImageInfo info_; 66 SkColorType desireColor_ = kUnknown_SkColorType; 67 BmpDecodingState state_ = BmpDecodingState::UNDECIDED; 68 }; 69 } // namespace ImagePlugin 70 } // namespace OHOS 71 72 #endif // BMP_DECODER_H 73