1 /*
2  * Copyright (c) 2022 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 HOS_CAMERA_EXIF_UTILS_H
17 #define HOS_CAMERA_EXIF_UTILS_H
18 
19 #include "libexif/exif-data.h"
20 
21 using int32_t = signed int;
22 using uint32_t = unsigned int;
23 
24 using exif_data = struct {
25     double latitude;
26     double longitude;
27     double altitude;
28     int32_t frame_size;
29 };
30 
31 using data_info = struct {
32     unsigned char *dataBuffer;
33     int32_t dataBufferSize;
34 };
35 
36 enum RetCode : int32_t {
37     RC_OK = 0,
38     RC_ERROR,
39 };
40 
41 enum LatOrLong : int32_t {
42     LATITUDE_TYPE = 0,
43     LONGITUDE_TYPE,
44 };
45 
46 using exif_rational = struct {
47     int32_t numerator;
48     int32_t denominator;
49 };
50 
51 namespace OHOS::Camera {
52 class ExifUtils {
53 public:
54     static uint32_t AddCustomExifInfo(exif_data info, void *address, int32_t &outPutSize);
55 
56 private:
57     static void ConvertGpsDataToDms(double number, int32_t *degrees, int32_t *minutes, int32_t *seconds);
58     static void ConvertAltitudeToRational(double altitude, exif_rational &outPutAltitude);
59     static uint32_t AddLatOrLongInfo(ExifData *exif, double number, LatOrLong latOrLongType);
60     static uint32_t AddAltitudeInfo(ExifData *exif, double altitude);
61     static uint32_t IsJpegPicture(unsigned char *dataBuffer, int32_t dataBufferSize, void *address);
62     static uint32_t PackageJpeg(unsigned char *tempBuffer, int32_t totalTempBufferSize, unsigned char *exifData,
63         unsigned int exifDataLength, data_info sourceData);
64     static uint32_t GetGpsRef(LatOrLong latOrLongType, double number, char *gpsRef, int length);
65     static uint32_t SetExifData(exif_data info, ExifData *exif,
66         unsigned char **exifData, unsigned int *exifDataLength);
67     static void FreeResource(unsigned char *dataBuffer, unsigned char *tempBuffer,
68         ExifData *exif, unsigned char *exifData);
69 };
70 }  // namespace OHOS::Camera
71 #endif
72