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_ACCESSOR_INCLUDE_WEBP_EXIF_METADATA_ACCESSOR_H 17 #define FRAMEWORKS_INNERKITSIMPL_ACCESSOR_INCLUDE_WEBP_EXIF_METADATA_ACCESSOR_H 18 19 20 #include <tuple> 21 22 #include "abstract_exif_metadata_accessor.h" 23 #include "buffer_metadata_stream.h" 24 #include "data_buf.h" 25 #include "metadata_stream.h" 26 #include "securec.h" 27 28 namespace OHOS { 29 namespace Media { 30 enum class Vp8xAndExifInfo : int32_t { 31 UNKNOWN = 0, 32 VP8X_NOT_EXIST = 1, 33 EXIF_NOT_EXIST = 2, 34 EXIF_EXIST = 3 35 }; 36 37 class WebpExifMetadataAccessor : public AbstractExifMetadataAccessor { 38 public: 39 WebpExifMetadataAccessor(std::shared_ptr<MetadataStream> &stream); 40 ~WebpExifMetadataAccessor(); 41 42 virtual uint32_t Read() override; 43 bool ReadBlob(DataBuf &blob) override; 44 virtual uint32_t Write() override; 45 uint32_t WriteBlob(DataBuf &blob) override; 46 47 private: 48 bool CheckChunkVp8x(Vp8xAndExifInfo &exifFlag) const; 49 bool GetExifBlob(const DataBuf &blob, uint8_t **dataBlob, uint32_t &size); 50 uint32_t UpdateData(uint8_t *dataBlob, uint32_t size); 51 bool UpdateExifMetadata(BufferMetadataStream &tempStream, uint8_t *dataBlob, uint32_t size); 52 bool GetExifEncodeBlob(uint8_t **dataBlob, uint32_t &size); 53 bool WriteHeader(BufferMetadataStream &bufStream, uint32_t size, Vp8xAndExifInfo &exifFlag); 54 bool WirteChunkVp8x(BufferMetadataStream &bufStream, const Vp8xAndExifInfo &exifFlag); 55 bool CopyRestData(BufferMetadataStream &bufStream); 56 bool InsertExifMetadata(BufferMetadataStream &bufStream, uint8_t *dataBlob, uint32_t size); 57 std::tuple<uint32_t, uint32_t> GetImageWidthAndHeight(); 58 std::tuple<uint32_t, uint32_t> GetWidthAndHeightFormChunk(const std::string &strChunkId, const DataBuf &chunkData); 59 }; 60 } // namespace Media 61 } // namespace OHOS 62 63 #endif 64