• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 enum ExifColorSpace : uint16_t {
47   COLOR_SPACE_SRGB = 0x1,
48   COLOR_SPACE_ADOBE_RGB = 0x2,
49   COLOR_SPACE_WIDE_GAMUT_RGB = 0xFFFD,
50   COLOR_SPACE_ICC_PROFILE = 0xFFFE,
51   COLOR_SPACE_UNCALIBRATED = 0xFFFF
52 };
53 
54 // This is based on the camera HIDL shim implementation, which was in turned
55 // based on original ChromeOS ARC implementation of a V4L2 HAL
56 class ExifUtils {
57  public:
58   virtual ~ExifUtils();
59 
60   static ExifUtils* Create(SensorCharacteristics sensor_chars);
61 
62   // Initialize() can be called multiple times. The setting of Exif tags will be
63   // cleared.
64   virtual bool Initialize() = 0;
65 
66   // Set all known fields from a metadata structure
67   virtual bool SetFromMetadata(const HalCameraMetadata& metadata,
68                                size_t image_width, size_t image_height) = 0;
69 
70   // Sets the len aperture.
71   // Returns false if memory allocation fails.
72   virtual bool SetAperture(float aperture) = 0;
73 
74   // sets the color space.
75   // Returns false if memory allocation fails.
76   virtual bool SetColorSpace(uint16_t color_space) = 0;
77 
78   // Sets the date and time of image last modified. It takes local time. The
79   // name of the tag is DateTime in IFD0.
80   // Returns false if memory allocation fails.
81   virtual bool SetDateTime(const struct tm& t) = 0;
82 
83   // Sets make & model
84   virtual bool SetMake(const std::string& make) = 0;
85   virtual bool SetModel(const std::string& model) = 0;
86 
87   // Sets the digital zoom ratio. If the numerator is 0, it means digital zoom
88   // was not used.
89   // Returns false if memory allocation fails.
90   virtual bool SetDigitalZoomRatio(uint32_t crop_width, uint32_t crop_height,
91                                    uint32_t sensor_width,
92                                    uint32_t sensor_height) = 0;
93 
94   // Sets the exposure bias.
95   // Returns false if memory allocation fails.
96   virtual bool SetExposureBias(int32_t ev, uint32_t ev_step_numerator,
97                                uint32_t ev_step_denominator) = 0;
98 
99   // Sets the exposure mode set when the image was shot.
100   // Returns false if memory allocation fails.
101   virtual bool SetExposureMode(uint8_t exposure_mode) = 0;
102 
103   // Sets the exposure time, given in seconds.
104   // Returns false if memory allocation fails.
105   virtual bool SetExposureTime(float exposure_time) = 0;
106 
107   // Sets the status of flash.
108   // Returns false if memory allocation fails.
109   virtual bool SetFlash(uint8_t flash_available, uint8_t flash_state,
110                         uint8_t ae_mode) = 0;
111 
112   // Sets the F number.
113   // Returns false if memory allocation fails.
114   virtual bool SetFNumber(float f_number) = 0;
115 
116   // Sets the focal length of lens used to take the image in millimeters.
117   // Returns false if memory allocation fails.
118   virtual bool SetFocalLength(float focal_length) = 0;
119 
120   // Sets the focal length of lens for 35mm film used to take the image in
121   // millimeters. Returns false if memory allocation fails.
122   virtual bool SetFocalLengthIn35mmFilm(float focal_length, float sensor_size_x,
123                                         float sensor_size_y) = 0;
124 
125   // Sets the altitude in meters.
126   // Returns false if memory allocation fails.
127   virtual bool SetGpsAltitude(double altitude) = 0;
128 
129   // Sets the latitude with degrees minutes seconds format.
130   // Returns false if memory allocation fails.
131   virtual bool SetGpsLatitude(double latitude) = 0;
132 
133   // Sets the longitude with degrees minutes seconds format.
134   // Returns false if memory allocation fails.
135   virtual bool SetGpsLongitude(double longitude) = 0;
136 
137   // Sets GPS processing method.
138   // Returns false if memory allocation fails.
139   virtual bool SetGpsProcessingMethod(const std::string& method) = 0;
140 
141   // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time.
142   // Returns false if memory allocation fails.
143   virtual bool SetGpsTimestamp(const struct tm& t) = 0;
144 
145   // Sets the height (number of rows) of main image.
146   // Returns false if memory allocation fails.
147   virtual bool SetImageHeight(uint32_t length) = 0;
148 
149   // Sets the width (number of columns) of main image.
150   // Returns false if memory allocation fails.
151   virtual bool SetImageWidth(uint32_t width) = 0;
152 
153   // Sets the ISO speed.
154   // Returns false if memory allocation fails.
155   virtual bool SetIsoSpeedRating(uint16_t iso_speed_ratings) = 0;
156 
157   // Sets the smallest F number of the lens.
158   // Returns false if memory allocation fails.
159   virtual bool SetMaxAperture(float aperture) = 0;
160 
161   // Sets image orientation.
162   // Returns false if memory allocation fails.
163   virtual bool SetOrientation(uint16_t degrees) = 0;
164 
165   // Sets image orientation.
166   // Returns false if memory allocation fails.
167   virtual bool SetOrientationValue(ExifOrientation orientation_value) = 0;
168 
169   // Sets the shutter speed.
170   // Returns false if memory allocation fails.
171   virtual bool SetShutterSpeed(float exposure_time) = 0;
172 
173   // Sets the distance to the subject, given in meters.
174   // Returns false if memory allocation fails.
175   virtual bool SetSubjectDistance(float diopters) = 0;
176 
177   // Sets the fractions of seconds for the <DateTime> tag.
178   // Returns false if memory allocation fails.
179   virtual bool SetSubsecTime(const std::string& subsec_time) = 0;
180 
181   // Sets the white balance mode set when the image was shot.
182   // Returns false if memory allocation fails.
183   virtual bool SetWhiteBalance(uint8_t white_blanace) = 0;
184 
185   // Generates APP1 segment.
186   // Returns false if generating APP1 segment fails.
187   virtual bool GenerateApp1(unsigned char* thumbnail_buffer, uint32_t size) = 0;
188 
189   // Gets buffer of APP1 segment. This method must be called only after calling
190   // GenerateAPP1().
191   virtual const uint8_t* GetApp1Buffer() = 0;
192 
193   // Gets length of APP1 segment. This method must be called only after calling
194   // GenerateAPP1().
195   virtual unsigned int GetApp1Length() = 0;
196 };
197 
198 }  // namespace android
199 
200 #endif  // ANDROID_EMULATOR_CAMERA_EXIF_UTILS_H
201