Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame^] | 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_SERVERS_CAMERA_EXIF_UTILS_H |
| 18 | #define ANDROID_SERVERS_CAMERA_EXIF_UTILS_H |
| 19 | |
| 20 | #include "CameraMetadata.h" |
| 21 | |
| 22 | namespace android { |
| 23 | namespace 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); |
| 42 | class ExifUtils { |
| 43 | |
| 44 | public: |
| 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, |
| 55 | const size_t imageWidth, const size_t imageHeight) = 0; |
| 56 | |
| 57 | // Sets the len aperture. |
| 58 | // Returns false if memory allocation fails. |
| 59 | virtual bool setAperture(uint32_t numerator, uint32_t denominator) = 0; |
| 60 | |
| 61 | // Sets the value of brightness. |
| 62 | // Returns false if memory allocation fails. |
| 63 | virtual bool setBrightness(int32_t numerator, int32_t denominator) = 0; |
| 64 | |
| 65 | // Sets the color space. |
| 66 | // Returns false if memory allocation fails. |
| 67 | virtual bool setColorSpace(uint16_t color_space) = 0; |
| 68 | |
| 69 | // Sets the information to compressed data. |
| 70 | // Returns false if memory allocation fails. |
| 71 | virtual bool setComponentsConfiguration(const std::string& components_configuration) = 0; |
| 72 | |
| 73 | // Sets the compression scheme used for the image data. |
| 74 | // Returns false if memory allocation fails. |
| 75 | virtual bool setCompression(uint16_t compression) = 0; |
| 76 | |
| 77 | // Sets image contrast. |
| 78 | // Returns false if memory allocation fails. |
| 79 | virtual bool setContrast(uint16_t contrast) = 0; |
| 80 | |
| 81 | // Sets the date and time of image last modified. It takes local time. The |
| 82 | // name of the tag is DateTime in IFD0. |
| 83 | // Returns false if memory allocation fails. |
| 84 | virtual bool setDateTime(const struct tm& t) = 0; |
| 85 | |
| 86 | // Sets the image description. |
| 87 | // Returns false if memory allocation fails. |
| 88 | virtual bool setDescription(const std::string& description) = 0; |
| 89 | |
| 90 | // Sets the digital zoom ratio. If the numerator is 0, it means digital zoom |
| 91 | // was not used. |
| 92 | // Returns false if memory allocation fails. |
| 93 | virtual bool setDigitalZoomRatio(uint32_t numerator, uint32_t denominator) = 0; |
| 94 | |
| 95 | // Sets the exposure bias. |
| 96 | // Returns false if memory allocation fails. |
| 97 | virtual bool setExposureBias(int32_t numerator, int32_t 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(uint16_t exposure_mode) = 0; |
| 102 | |
| 103 | // Sets the program used by the camera to set exposure when the picture is |
| 104 | // taken. |
| 105 | // Returns false if memory allocation fails. |
| 106 | virtual bool setExposureProgram(uint16_t exposure_program) = 0; |
| 107 | |
| 108 | // Sets the exposure time, given in seconds. |
| 109 | // Returns false if memory allocation fails. |
| 110 | virtual bool setExposureTime(uint32_t numerator, uint32_t denominator) = 0; |
| 111 | |
| 112 | // Sets the status of flash. |
| 113 | // Returns false if memory allocation fails. |
| 114 | virtual bool setFlash(uint16_t flash) = 0; |
| 115 | |
| 116 | // Sets the F number. |
| 117 | // Returns false if memory allocation fails. |
| 118 | virtual bool setFNumber(uint32_t numerator, uint32_t denominator) = 0; |
| 119 | |
| 120 | // Sets the focal length of lens used to take the image in millimeters. |
| 121 | // Returns false if memory allocation fails. |
| 122 | virtual bool setFocalLength(uint32_t numerator, uint32_t denominator) = 0; |
| 123 | |
| 124 | // Sets the degree of overall image gain adjustment. |
| 125 | // Returns false if memory allocation fails. |
| 126 | virtual bool setGainControl(uint16_t gain_control) = 0; |
| 127 | |
| 128 | // Sets the altitude in meters. |
| 129 | // Returns false if memory allocation fails. |
| 130 | virtual bool setGpsAltitude(double altitude) = 0; |
| 131 | |
| 132 | // Sets the latitude with degrees minutes seconds format. |
| 133 | // Returns false if memory allocation fails. |
| 134 | virtual bool setGpsLatitude(double latitude) = 0; |
| 135 | |
| 136 | // Sets the longitude with degrees minutes seconds format. |
| 137 | // Returns false if memory allocation fails. |
| 138 | virtual bool setGpsLongitude(double longitude) = 0; |
| 139 | |
| 140 | // Sets GPS processing method. |
| 141 | // Returns false if memory allocation fails. |
| 142 | virtual bool setGpsProcessingMethod(const std::string& method) = 0; |
| 143 | |
| 144 | // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time. |
| 145 | // Returns false if memory allocation fails. |
| 146 | virtual bool setGpsTimestamp(const struct tm& t) = 0; |
| 147 | |
| 148 | // Sets the height (number of rows) of main image. |
| 149 | // Returns false if memory allocation fails. |
| 150 | virtual bool setImageHeight(uint32_t length) = 0; |
| 151 | |
| 152 | // Sets the width (number of columns) of main image. |
| 153 | // Returns false if memory allocation fails. |
| 154 | virtual bool setImageWidth(uint32_t width) = 0; |
| 155 | |
| 156 | // Sets the ISO speed. |
| 157 | // Returns false if memory allocation fails. |
| 158 | virtual bool setIsoSpeedRating(uint16_t iso_speed_ratings) = 0; |
| 159 | |
| 160 | // Sets the kind of light source. |
| 161 | // Returns false if memory allocation fails. |
| 162 | virtual bool setLightSource(uint16_t light_source) = 0; |
| 163 | |
| 164 | // Sets the smallest F number of the lens. |
| 165 | // Returns false if memory allocation fails. |
| 166 | virtual bool setMaxAperture(uint32_t numerator, uint32_t denominator) = 0; |
| 167 | |
| 168 | // Sets the metering mode. |
| 169 | // Returns false if memory allocation fails. |
| 170 | virtual bool setMeteringMode(uint16_t metering_mode) = 0; |
| 171 | |
| 172 | // Sets image orientation. |
| 173 | // Returns false if memory allocation fails. |
| 174 | virtual bool setOrientation(uint16_t orientation) = 0; |
| 175 | |
| 176 | // Sets the unit for measuring XResolution and YResolution. |
| 177 | // Returns false if memory allocation fails. |
| 178 | virtual bool setResolutionUnit(uint16_t resolution_unit) = 0; |
| 179 | |
| 180 | // Sets image saturation. |
| 181 | // Returns false if memory allocation fails. |
| 182 | virtual bool setSaturation(uint16_t saturation) = 0; |
| 183 | |
| 184 | // Sets the type of scene that was shot. |
| 185 | // Returns false if memory allocation fails. |
| 186 | virtual bool setSceneCaptureType(uint16_t type) = 0; |
| 187 | |
| 188 | // Sets image sharpness. |
| 189 | // Returns false if memory allocation fails. |
| 190 | virtual bool setSharpness(uint16_t sharpness) = 0; |
| 191 | |
| 192 | // Sets the shutter speed. |
| 193 | // Returns false if memory allocation fails. |
| 194 | virtual bool setShutterSpeed(int32_t numerator, int32_t denominator) = 0; |
| 195 | |
| 196 | // Sets the distance to the subject, given in meters. |
| 197 | // Returns false if memory allocation fails. |
| 198 | virtual bool setSubjectDistance(uint32_t numerator, uint32_t denominator) = 0; |
| 199 | |
| 200 | // Sets the fractions of seconds for the <DateTime> tag. |
| 201 | // Returns false if memory allocation fails. |
| 202 | virtual bool setSubsecTime(const std::string& subsec_time) = 0; |
| 203 | |
| 204 | // Sets the white balance mode set when the image was shot. |
| 205 | // Returns false if memory allocation fails. |
| 206 | virtual bool setWhiteBalance(uint16_t white_balance) = 0; |
| 207 | |
| 208 | // Sets the number of pixels per resolution unit in the image width. |
| 209 | // Returns false if memory allocation fails. |
| 210 | virtual bool setXResolution(uint32_t numerator, uint32_t denominator) = 0; |
| 211 | |
| 212 | // Sets the position of chrominance components in relation to the luminance |
| 213 | // component. |
| 214 | // Returns false if memory allocation fails. |
| 215 | virtual bool setYCbCrPositioning(uint16_t ycbcr_positioning) = 0; |
| 216 | |
| 217 | // Sets the number of pixels per resolution unit in the image length. |
| 218 | // Returns false if memory allocation fails. |
| 219 | virtual bool setYResolution(uint32_t numerator, uint32_t denominator) = 0; |
| 220 | |
| 221 | // Sets the manufacturer of camera. |
| 222 | // Returns false if memory allocation fails. |
| 223 | virtual bool setMake(const std::string& make) = 0; |
| 224 | |
| 225 | // Sets the model number of camera. |
| 226 | // Returns false if memory allocation fails. |
| 227 | virtual bool setModel(const std::string& model) = 0; |
| 228 | |
| 229 | // Generates APP1 segment. |
| 230 | // Returns false if generating APP1 segment fails. |
| 231 | virtual bool generateApp1() = 0; |
| 232 | |
| 233 | // Gets buffer of APP1 segment. This method must be called only after calling |
| 234 | // GenerateAPP1(). |
| 235 | virtual const uint8_t* getApp1Buffer() = 0; |
| 236 | |
| 237 | // Gets length of APP1 segment. This method must be called only after calling |
| 238 | // GenerateAPP1(). |
| 239 | virtual unsigned int getApp1Length() = 0; |
| 240 | }; |
| 241 | |
| 242 | } // namespace camera3 |
| 243 | } // namespace android |
| 244 | |
| 245 | #endif // ANDROID_SERVERS_CAMERA_EXIF_UTILS_H |