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 INCREMENTAL_PIXEL_MAP_H 17 #define INCREMENTAL_PIXEL_MAP_H 18 19 #include "nocopyable.h" 20 #include "image_type.h" 21 #include "pixel_map.h" 22 #include "peer_listener.h" 23 24 namespace OHOS { 25 namespace Media { 26 class ImageSource; 27 28 enum class IncrementalDecodingState : int32_t { 29 UNRESOLVED = 0, 30 BASE_INFO_ERROR = 1, 31 BASE_INFO_PARSED = 2, 32 IMAGE_DECODING = 3, 33 IMAGE_ERROR = 4, 34 PARTIAL_IMAGE = 5, 35 IMAGE_DECODED = 6 36 }; 37 38 struct IncrementalDecodingStatus { 39 static constexpr uint8_t FULL_PROGRESS = 100; 40 IncrementalDecodingState state = IncrementalDecodingState::UNRESOLVED; 41 uint32_t errorDetail = 0; 42 uint8_t decodingProgress = 0; 43 }; 44 45 class IncrementalPixelMap : public PixelMap, public PeerListener { 46 public: 47 IncrementalPixelMap() = delete; 48 ~IncrementalPixelMap() override; 49 uint32_t PromoteDecoding(uint8_t &decodeProgress); 50 void DetachFromDecoding(); 51 const IncrementalDecodingStatus &GetDecodingStatus(); 52 53 private: 54 // declare friend class, only ImageSource can create IncrementalPixelMap object. 55 friend class ImageSource; 56 DISALLOW_COPY_AND_MOVE(IncrementalPixelMap); 57 IncrementalPixelMap(uint32_t index, const DecodeOptions opts, ImageSource *imageSource); 58 void OnPeerDestory() override; 59 void DetachSource(); 60 IncrementalDecodingStatus decodingStatus_; 61 uint32_t index_ = 0; 62 DecodeOptions opts_; 63 ImageSource *imageSource_ = nullptr; 64 }; 65 } // namespace Media 66 } // namespace OHOS 67 68 #endif // INCREMENTAL_PIXEL_MAP_H 69