1 /* 2 * Copyright (C) 2024 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_INNERKITSIMPL_HDR_INCLUDE_JPEG_MPF_PARSER_H 17 #define FRAMEWORKS_INNERKITSIMPL_HDR_INCLUDE_JPEG_MPF_PARSER_H 18 19 #include <vector> 20 #include "image_type.h" 21 22 namespace OHOS { 23 namespace Media { 24 25 constexpr uint32_t JPEG_MPF_IDENTIFIER_SIZE = 4; 26 27 struct SingleJpegImage { 28 uint32_t offset; 29 uint32_t size; 30 AuxiliaryPictureType auxType; 31 std::string auxTagName; 32 }; 33 34 class JpegMpfParser { 35 public: 36 bool CheckMpfOffset(uint8_t* data, uint32_t size, uint32_t& offset); 37 bool Parsing(uint8_t* data, uint32_t size); 38 bool ParsingAuxiliaryPictures(uint8_t* data, uint32_t dataSize, bool isBigEndian = true); 39 std::vector<SingleJpegImage> images_; 40 static bool ParsingFragmentMetadata(uint8_t* data, uint32_t size, Rect& fragmentRect, bool isBigEndian = true); 41 42 private: 43 bool ParsingMpIndexIFD(uint8_t* data, uint32_t size, uint32_t dataOffset, bool isBigEndian); 44 bool ParsingMpEntry(uint8_t* data, uint32_t size, bool isBigEndian, uint32_t imageNums); 45 uint32_t imageNums_ = 0; 46 }; 47 48 class JpegMpfPacker { 49 public: 50 static std::vector<uint8_t> PackHdrJpegMpfMarker(SingleJpegImage base, SingleJpegImage gainmap); 51 static std::vector<uint8_t> PackFragmentMetadata(Media::Rect& fragmentRect, bool isBigEndian = true); 52 static std::vector<uint8_t> PackDataSize(uint32_t size, bool isBigEndian = true); 53 static std::vector<uint8_t> PackAuxiliaryTagName(std::string& tagName); 54 }; 55 } // namespace Media 56 } // namespace OHOS 57 58 #endif // FRAMEWORKS_INNERKITSIMPL_HDR_INCLUDE_JPEG_MPF_PARSER_H