1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_EMULATOR_CAMERA_EXIF_UTILS_H
18 #define ANDROID_EMULATOR_CAMERA_EXIF_UTILS_H
19 
20 #include "hwl_types.h"
21 
22 namespace android {
23 
24 struct SensorCharacteristics;
25 
26 using google_camera_hal::HalCameraMetadata;
27 
28 /*
29  * Orientation value:
30  *  1      2      3      4      5          6          7          8
31  *
32  *  888888 888888     88 88     8888888888 88                 88 8888888888
33  *  88         88     88 88     88  88     88  88         88  88     88  88
34  *  8888     8888   8888 8888   88         8888888888 8888888888         88
35  *  88         88     88 88
36  *  88         88 888888 888888
37  */
38 enum ExifOrientation : uint16_t {
39   ORIENTATION_UNDEFINED = 0x0,
40   ORIENTATION_0_DEGREES = 0x1,
41   ORIENTATION_90_DEGREES = 0x6,
42   ORIENTATION_180_DEGREES = 0x3,
43   ORIENTATION_270_DEGREES = 0x8,
44 };
45 
46 // This is based on the camera HIDL shim implementation, which was in turned
47 // based on original ChromeOS ARC implementation of a V4L2 HAL
48 class ExifUtils {
49  public:
50   virtual ~ExifUtils();
51 
52   static ExifUtils* Create(SensorCharacteristics sensor_chars);
53 
54   // Initialize() can be called multiple times. The setting of Exif tags will be
55   // cleared.
56   virtual bool Initialize() = 0;
57 
58   // Set all known fields from a metadata structure
59   virtual bool SetFromMetadata(const HalCameraMetadata& metadata,
60                                size_t image_width, size_t image_height) = 0;
61 
62   // Sets the len aperture.
63   // Returns false if memory allocation fails.
64   virtual bool SetAperture(float aperture) = 0;
65 
66   // sets the color space.
67   // Returns false if memory allocation fails.
68   virtual bool SetColorSpace(uint16_t color_space) = 0;
69 
70   // Sets the date and time of image last modified. It takes local time. The
71   // name of the tag is DateTime in IFD0.
72   // Returns false if memory allocation fails.
73   virtual bool SetDateTime(const struct tm& t) = 0;
74 
75   // Sets make & model
76   virtual bool SetMake(const std::string& make) = 0;
77   virtual bool SetModel(const std::string& model) = 0;
78 
79   // Sets the digital zoom ratio. If the numerator is 0, it means digital zoom
80   // was not used.
81   // Returns false if memory allocation fails.
82   virtual bool SetDigitalZoomRatio(uint32_t crop_width, uint32_t crop_height,
83                                    uint32_t sensor_width,
84                                    uint32_t sensor_height) = 0;
85 
86   // Sets the exposure bias.
87   // Returns false if memory allocation fails.
88   virtual bool SetExposureBias(int32_t ev, uint32_t ev_step_numerator,
89                                uint32_t ev_step_denominator) = 0;
90 
91   // Sets the exposure mode set when the image was shot.
92   // Returns false if memory allocation fails.
93   virtual bool SetExposureMode(uint8_t exposure_mode) = 0;
94 
95   // Sets the exposure time, given in seconds.
96   // Returns false if memory allocation fails.
97   virtual bool SetExposureTime(float exposure_time) = 0;
98 
99   // Sets the status of flash.
100   // Returns false if memory allocation fails.
101   virtual bool SetFlash(uint8_t flash_available, uint8_t flash_state,
102                         uint8_t ae_mode) = 0;
103 
104   // Sets the F number.
105   // Returns false if memory allocation fails.
106   virtual bool SetFNumber(float f_number) = 0;
107 
108   // Sets the focal length of lens used to take the image in millimeters.
109   // Returns false if memory allocation fails.
110   virtual bool SetFocalLength(float focal_length) = 0;
111 
112   // Sets the focal length of lens for 35mm film used to take the image in
113   // millimeters. Returns false if memory allocation fails.
114   virtual bool SetFocalLengthIn35mmFilm(float focal_length, float sensor_size_x,
115                                         float sensor_size_y) = 0;
116 
117   // Sets the altitude in meters.
118   // Returns false if memory allocation fails.
119   virtual bool SetGpsAltitude(double altitude) = 0;
120 
121   // Sets the latitude with degrees minutes seconds format.
122   // Returns false if memory allocation fails.
123   virtual bool SetGpsLatitude(double latitude) = 0;
124 
125   // Sets the longitude with degrees minutes seconds format.
126   // Returns false if memory allocation fails.
127   virtual bool SetGpsLongitude(double longitude) = 0;
128 
129   // Sets GPS processing method.
130   // Returns false if memory allocation fails.
131   virtual bool SetGpsProcessingMethod(const std::string& method) = 0;
132 
133   // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time.
134   // Returns false if memory allocation fails.
135   virtual bool SetGpsTimestamp(const struct tm& t) = 0;
136 
137   // Sets the height (number of rows) of main image.
138   // Returns false if memory allocation fails.
139   virtual bool SetImageHeight(uint32_t length) = 0;
140 
141   // Sets the width (number of columns) of main image.
142   // Returns false if memory allocation fails.
143   virtual bool SetImageWidth(uint32_t width) = 0;
144 
145   // Sets the ISO speed.
146   // Returns false if memory allocation fails.
147   virtual bool SetIsoSpeedRating(uint16_t iso_speed_ratings) = 0;
148 
149   // Sets the smallest F number of the lens.
150   // Returns false if memory allocation fails.
151   virtual bool SetMaxAperture(float aperture) = 0;
152 
153   // Sets image orientation.
154   // Returns false if memory allocation fails.
155   virtual bool SetOrientation(uint16_t degrees) = 0;
156 
157   // Sets image orientation.
158   // Returns false if memory allocation fails.
159   virtual bool SetOrientationValue(ExifOrientation orientation_value) = 0;
160 
161   // Sets the shutter speed.
162   // Returns false if memory allocation fails.
163   virtual bool SetShutterSpeed(float exposure_time) = 0;
164 
165   // Sets the distance to the subject, given in meters.
166   // Returns false if memory allocation fails.
167   virtual bool SetSubjectDistance(float diopters) = 0;
168 
169   // Sets the fractions of seconds for the <DateTime> tag.
170   // Returns false if memory allocation fails.
171   virtual bool SetSubsecTime(const std::string& subsec_time) = 0;
172 
173   // Sets the white balance mode set when the image was shot.
174   // Returns false if memory allocation fails.
175   virtual bool SetWhiteBalance(uint8_t white_blanace) = 0;
176 
177   // Generates APP1 segment.
178   // Returns false if generating APP1 segment fails.
179   virtual bool GenerateApp1(unsigned char* thumbnail_buffer, uint32_t size) = 0;
180 
181   // Gets buffer of APP1 segment. This method must be called only after calling
182   // GenerateAPP1().
183   virtual const uint8_t* GetApp1Buffer() = 0;
184 
185   // Gets length of APP1 segment. This method must be called only after calling
186   // GenerateAPP1().
187   virtual unsigned int GetApp1Length() = 0;
188 };
189 
190 }  // namespace android
191 
192 #endif  // ANDROID_EMULATOR_CAMERA_EXIF_UTILS_H
193