blob: c78bab99618e030623a17fcbc5014425830c032a [file] [log] [blame]
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001/*
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_SERVERS_CAMERA_EXIF_UTILS_H
18#define ANDROID_SERVERS_CAMERA_EXIF_UTILS_H
19
20#include "CameraMetadata.h"
21
22namespace android {
23namespace camera3 {
24
25// This is based on the camera HIDL shim implementation, which was in turned
26// based on original ChromeOS ARC implementation of a V4L2 HAL
27
28// ExifUtils can override APP1 segment with tags which caller set. ExifUtils can
29// also add a thumbnail in the APP1 segment if thumbnail size is specified.
30// ExifUtils can be reused with different images by calling initialize().
31//
32// Example of using this class :
33// std::unique_ptr<ExifUtils> utils(ExifUtils::Create());
34// utils->initialize(const unsigned char* app1Segment, size_t app1SegmentSize);
35// ...
36// // Call ExifUtils functions to set Exif tags.
37// ...
38// utils->GenerateApp1();
39// unsigned int app1Length = utils->GetApp1Length();
40// uint8_t* app1Buffer = new uint8_t[app1Length];
41// memcpy(app1Buffer, utils->GetApp1Buffer(), app1Length);
42class ExifUtils {
43
44public:
45 virtual ~ExifUtils();
46
47 static ExifUtils* create();
48
49 // Initialize() can be called multiple times. The setting of Exif tags will be
50 // cleared.
51 virtual bool initialize(const unsigned char *app1Segment, size_t app1SegmentSize) = 0;
52
53 // Set all known fields from a metadata structure
54 virtual bool setFromMetadata(const CameraMetadata& metadata,
Shuzhen Wange7f4b462019-02-12 08:43:07 -080055 const CameraMetadata& staticInfo,
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080056 const size_t imageWidth, const size_t imageHeight) = 0;
57
58 // Sets the len aperture.
59 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080060 virtual bool setAperture(float aperture) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080061
Shuzhen Wange7f4b462019-02-12 08:43:07 -080062 // sets the color space.
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080063 // Returns false if memory allocation fails.
64 virtual bool setColorSpace(uint16_t color_space) = 0;
65
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080066 // Sets the date and time of image last modified. It takes local time. The
67 // name of the tag is DateTime in IFD0.
68 // Returns false if memory allocation fails.
69 virtual bool setDateTime(const struct tm& t) = 0;
70
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080071 // Sets the digital zoom ratio. If the numerator is 0, it means digital zoom
72 // was not used.
73 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080074 virtual bool setDigitalZoomRatio(uint32_t crop_width, uint32_t crop_height,
75 uint32_t sensor_width, uint32_t sensor_height) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080076
77 // Sets the exposure bias.
78 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080079 virtual bool setExposureBias(int32_t ev,
80 uint32_t ev_step_numerator, uint32_t ev_step_denominator) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080081
82 // Sets the exposure mode set when the image was shot.
83 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080084 virtual bool setExposureMode(uint8_t exposure_mode) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080085
86 // Sets the exposure time, given in seconds.
87 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080088 virtual bool setExposureTime(float exposure_time) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080089
90 // Sets the status of flash.
91 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080092 virtual bool setFlash(uint8_t flash_available, uint8_t flash_state, uint8_t ae_mode) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080093
94 // Sets the F number.
95 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -080096 virtual bool setFNumber(float f_number) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080097
98 // Sets the focal length of lens used to take the image in millimeters.
99 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800100 virtual bool setFocalLength(float focal_length) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800101
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800102 // Sets the focal length of lens for 35mm film used to take the image in millimeters.
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800103 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800104 virtual bool setFocalLengthIn35mmFilm(float focal_length,
105 float sensor_size_x, float sensor_size_y) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800106
107 // Sets the altitude in meters.
108 // Returns false if memory allocation fails.
109 virtual bool setGpsAltitude(double altitude) = 0;
110
111 // Sets the latitude with degrees minutes seconds format.
112 // Returns false if memory allocation fails.
113 virtual bool setGpsLatitude(double latitude) = 0;
114
115 // Sets the longitude with degrees minutes seconds format.
116 // Returns false if memory allocation fails.
117 virtual bool setGpsLongitude(double longitude) = 0;
118
119 // Sets GPS processing method.
120 // Returns false if memory allocation fails.
121 virtual bool setGpsProcessingMethod(const std::string& method) = 0;
122
123 // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time.
124 // Returns false if memory allocation fails.
125 virtual bool setGpsTimestamp(const struct tm& t) = 0;
126
127 // Sets the height (number of rows) of main image.
128 // Returns false if memory allocation fails.
129 virtual bool setImageHeight(uint32_t length) = 0;
130
131 // Sets the width (number of columns) of main image.
132 // Returns false if memory allocation fails.
133 virtual bool setImageWidth(uint32_t width) = 0;
134
135 // Sets the ISO speed.
136 // Returns false if memory allocation fails.
137 virtual bool setIsoSpeedRating(uint16_t iso_speed_ratings) = 0;
138
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800139 // Sets the smallest F number of the lens.
140 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800141 virtual bool setMaxAperture(float aperture) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800142
143 // Sets image orientation.
144 // Returns false if memory allocation fails.
145 virtual bool setOrientation(uint16_t orientation) = 0;
146
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800147 // Sets the shutter speed.
148 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800149 virtual bool setShutterSpeed(float exposure_time) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800150
151 // Sets the distance to the subject, given in meters.
152 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800153 virtual bool setSubjectDistance(float diopters) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800154
155 // Sets the fractions of seconds for the <DateTime> tag.
156 // Returns false if memory allocation fails.
157 virtual bool setSubsecTime(const std::string& subsec_time) = 0;
158
159 // Sets the white balance mode set when the image was shot.
160 // Returns false if memory allocation fails.
Shuzhen Wange7f4b462019-02-12 08:43:07 -0800161 virtual bool setWhiteBalance(uint8_t white_blanace) = 0;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800162
163 // Generates APP1 segment.
164 // Returns false if generating APP1 segment fails.
165 virtual bool generateApp1() = 0;
166
167 // Gets buffer of APP1 segment. This method must be called only after calling
168 // GenerateAPP1().
169 virtual const uint8_t* getApp1Buffer() = 0;
170
171 // Gets length of APP1 segment. This method must be called only after calling
172 // GenerateAPP1().
173 virtual unsigned int getApp1Length() = 0;
174};
175
176} // namespace camera3
177} // namespace android
178
179#endif // ANDROID_SERVERS_CAMERA_EXIF_UTILS_H