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 FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_PARSER_H 17 #define FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_PARSER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 enum RawHeaderType { 25 RAW_HEADER_TYPE_NONE, 26 RAW_HEADER_TYPE_RAW, 27 RAW_HEADER_TYPE_COMPRESSED, 28 }; 29 30 struct RawFrameInfoPtr { 31 enum RawHeaderType type; 32 uint32_t offset; 33 uint32_t length; 34 uint32_t clen; 35 uint8_t *mem; 36 }; 37 38 struct RawHeaderInfo { 39 char magic[8]; 40 uint32_t width; 41 uint32_t height; 42 }; 43 44 struct RawFrameInfo { 45 enum RawHeaderType type; 46 uint32_t offset; 47 uint32_t length; 48 uint32_t clen; 49 uint8_t mem[0]; 50 }; 51 52 class RawParser { 53 public: 54 // 0 for success 55 int32_t Parse(const std::string &file); 56 GetWidth()57 uint32_t GetWidth() const 58 { 59 return width; 60 } 61 GetHeight()62 uint32_t GetHeight() const 63 { 64 return height; 65 } 66 GetSize()67 uint32_t GetSize() const 68 { 69 return width * height * 0x4; 70 } 71 GetCount()72 int32_t GetCount() const 73 { 74 return infos.size(); 75 } 76 77 // 0 for success 78 int32_t GetNextData(uint32_t *addr); 79 int32_t GetNowData(uint32_t *addr); 80 81 private: 82 int32_t ReadFile(const std::string &file, std::unique_ptr<uint8_t[]> &ptr); 83 84 // 0 for success 85 int32_t Uncompress(std::unique_ptr<uint8_t[]> &dst, uint32_t dstlen, uint8_t *cmem, uint32_t clen); 86 87 std::unique_ptr<uint8_t[]> compressed = nullptr; 88 uint32_t clength = 0; 89 90 std::vector<struct RawFrameInfoPtr> infos; 91 std::unique_ptr<uint8_t[]> uncompressed = nullptr; 92 93 int32_t lastID = -1; 94 std::unique_ptr<uint8_t[]> lastData = nullptr; 95 96 uint32_t width = 0; 97 uint32_t height = 0; 98 99 static constexpr int32_t magicHeaderLength = 16; 100 }; 101 } // namespace OHOS 102 103 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_PARSER_H 104