1 /* 2 * Copyright (C) 2023 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 #ifndef EXIF_MAKER_NOTE_H 16 #define EXIF_MAKER_NOTE_H 17 #include <string> 18 #include <vector> 19 #include <libexif/exif-data.h> 20 namespace OHOS { 21 namespace ImagePlugin { 22 class ExifMakerNote { 23 public: 24 ExifMakerNote(); 25 ~ExifMakerNote(); 26 27 std::string hwCaptureMode; 28 std::string hwPhysicalAperture; 29 30 static const uint16_t HW_MNOTE_TAG_SCENE_INFO_OFFSET = 0x0000; 31 static const uint16_t HW_MNOTE_TAG_FACE_INFO_OFFSET = 0x0100; 32 static const uint16_t HW_MNOTE_TAG_CAPTURE_MODE = 0x0200; 33 static const uint16_t HW_MNOTE_TAG_BURST_CAPTURE_NUMBER = 0x0201; 34 static const uint16_t HW_MNOTE_TAG_FRONT_CAMERA = 0x0202; 35 static const uint16_t HW_MNOTE_TAG_PHYSICAL_APERTURE = 0x0205; 36 static const uint16_t HW_MNOTE_IFD_SCENE_INFO_OFFSET = HW_MNOTE_TAG_SCENE_INFO_OFFSET; 37 static const uint16_t HW_MNOTE_IFD_FACE_INFO_OFFSET = HW_MNOTE_TAG_FACE_INFO_OFFSET; 38 static const uint16_t HW_MNOTE_IFD_DEFAULT = 0xffff; 39 40 uint32_t Parser(ExifData *exif, const unsigned char *data, uint32_t size); 41 [[nodiscard]] bool IsParsed() const; 42 43 private: 44 static bool FindExifLocation(const unsigned char *data, uint32_t size, const unsigned char *&newData, 45 uint32_t &newSize); 46 static bool FindJpegAPP1(const unsigned char *data, uint32_t size, const unsigned char *&newData, 47 uint32_t &newSize); 48 uint32_t ParserMakerNote(ExifData* exif, bool &moreCheck); 49 uint32_t ParserMakerNote(const unsigned char *data, uint32_t size); 50 51 private: 52 struct ExifItem { 53 uint16_t ifd {0}; 54 uint16_t tag {0}; 55 uint16_t format {0}; 56 uint32_t count {0}; 57 std::vector<unsigned char> data; 58 59 public: 60 ExifItem(); 61 explicit ExifItem(const ExifItem& item); 62 ~ExifItem(); 63 ExifItem& operator=(const ExifItem& item); 64 65 bool GetValue(std::string &value, const ExifByteOrder &order, bool mock = false); 66 bool GetValue(std::string &value, ExifData *exifData, bool mock = false); 67 void Dump(const std::string &info, const ExifByteOrder &order); 68 69 static bool GetValue(std::string &value, const ExifByteOrder &order, ExifItem &item, bool mock = false); 70 static bool GetValue(std::string &value, ExifData *exifData, ExifItem &item, bool mock = false); 71 static void Dump(const std::string &info, const ExifItem &item, const ExifByteOrder &order); 72 73 private: 74 void CopyItem(const ExifItem& item); 75 76 static bool GetValue(std::string &value, ExifContent *exifContent, ExifItem &item, bool &mock); 77 static bool GetValue(std::string &value, ExifEntry *exifEntry, ExifItem &item, bool &mock); 78 }; 79 80 bool IsHwMakerNote(const unsigned char *data, uint32_t size); 81 bool ParserHwMakerNote(); 82 bool ParserIFD(uint32_t offset, uint32_t ifd, uint32_t deep = 0); 83 bool ParserItem(uint32_t offset, uint32_t ifd, uint32_t deep = 0); 84 bool SetValue(const ExifItem &entry, const std::string &value); 85 86 private: 87 bool GetUInt16AndMove(uint32_t &offset, uint16_t &value); 88 bool GetUInt32AndMove(uint32_t &offset, uint32_t &value); 89 bool GetDataAndMove(size_t &offset, size_t count, std::vector<unsigned char> &value); 90 bool GetUInt16(uint32_t offset, uint16_t &value); 91 bool GetUInt32(uint32_t offset, uint32_t &value); 92 bool GetData(size_t offset, size_t count, std::vector<unsigned char> &value); 93 94 static bool GetUInt16(const std::vector<unsigned char> &buffer, ExifByteOrder order, 95 size_t offset, uint16_t &value); 96 static bool GetUInt32(const std::vector<unsigned char> &buffer, ExifByteOrder order, 97 size_t offset, uint32_t &value); 98 static bool GetData(const std::vector<unsigned char> &buffer, size_t offset, size_t count, 99 std::vector<unsigned char> &value); 100 101 static std::string Dump(const std::vector<unsigned char> &data, uint32_t offset = 0, uint32_t sum = UINT32_MAX); 102 103 std::vector<unsigned char> makerNote_; 104 ExifByteOrder order_ {ExifByteOrder::EXIF_BYTE_ORDER_INTEL}; 105 uint32_t tiff_offset_ {0}; 106 uint32_t ifd0_offset_ {0}; 107 108 std::vector<ExifItem> items_; 109 }; 110 } // namespace ImagePlugin 111 } // namespace OHOS 112 #endif // EXIF_MAKER_NOTE_H