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 /* 26 * Orientation value: 27 * 1 2 3 4 5 6 7 8 28 * 29 * 888888 888888 88 88 8888888888 88 88 8888888888 30 * 88 88 88 88 88 88 88 88 88 88 88 88 31 * 8888 8888 8888 8888 88 8888888888 8888888888 88 32 * 88 88 88 88 33 * 88 88 888888 888888 34 */ 35 enum ExifOrientation : uint16_t { 36 ORIENTATION_UNDEFINED = 0x0, 37 ORIENTATION_0_DEGREES = 0x1, 38 ORIENTATION_90_DEGREES = 0x6, 39 ORIENTATION_180_DEGREES = 0x3, 40 ORIENTATION_270_DEGREES = 0x8, 41 }; 42 43 // This is based on the camera HIDL shim implementation, which was in turned 44 // based on original ChromeOS ARC implementation of a V4L2 HAL 45 46 // ExifUtils can override APP1 segment with tags which caller set. ExifUtils can 47 // also add a thumbnail in the APP1 segment if thumbnail size is specified. 48 // ExifUtils can be reused with different images by calling initialize(). 49 // 50 // Example of using this class : 51 // std::unique_ptr<ExifUtils> utils(ExifUtils::Create()); 52 // utils->initialize(const unsigned char* app1Segment, size_t app1SegmentSize); 53 // ... 54 // // Call ExifUtils functions to set Exif tags. 55 // ... 56 // utils->GenerateApp1(); 57 // unsigned int app1Length = utils->GetApp1Length(); 58 // uint8_t* app1Buffer = new uint8_t[app1Length]; 59 // memcpy(app1Buffer, utils->GetApp1Buffer(), app1Length); 60 class ExifUtils { 61 62 public: 63 virtual ~ExifUtils(); 64 65 static ExifUtils* create(); 66 67 // Initialize() can be called multiple times. The setting of Exif tags will be 68 // cleared. 69 virtual bool initialize(const unsigned char *app1Segment, size_t app1SegmentSize) = 0; 70 virtual bool initializeEmpty() = 0; 71 72 // Set all known fields from a metadata structure 73 virtual bool setFromMetadata(const CameraMetadata& metadata, 74 const CameraMetadata& staticInfo, 75 const size_t imageWidth, const size_t imageHeight) = 0; 76 77 // Sets the len aperture. 78 // Returns false if memory allocation fails. 79 virtual bool setAperture(float aperture) = 0; 80 81 // sets the color space. 82 // Returns false if memory allocation fails. 83 virtual bool setColorSpace(uint16_t color_space) = 0; 84 85 // Sets the date and time of image last modified. It takes local time. The 86 // name of the tag is DateTime in IFD0. 87 // Returns false if memory allocation fails. 88 virtual bool setDateTime(const struct tm& t) = 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 crop_width, uint32_t crop_height, 94 uint32_t sensor_width, uint32_t sensor_height) = 0; 95 96 // Sets the exposure bias. 97 // Returns false if memory allocation fails. 98 virtual bool setExposureBias(int32_t ev, 99 uint32_t ev_step_numerator, uint32_t ev_step_denominator) = 0; 100 101 // Sets the exposure mode set when the image was shot. 102 // Returns false if memory allocation fails. 103 virtual bool setExposureMode(uint8_t exposure_mode) = 0; 104 105 // Sets the exposure time, given in seconds. 106 // Returns false if memory allocation fails. 107 virtual bool setExposureTime(float exposure_time) = 0; 108 109 // Sets the status of flash. 110 // Returns false if memory allocation fails. 111 virtual bool setFlash(uint8_t flash_available, uint8_t flash_state, uint8_t ae_mode) = 0; 112 113 // Sets the F number. 114 // Returns false if memory allocation fails. 115 virtual bool setFNumber(float f_number) = 0; 116 117 // Sets the focal length of lens used to take the image in millimeters. 118 // Returns false if memory allocation fails. 119 virtual bool setFocalLength(float focal_length) = 0; 120 121 // Sets the focal length of lens for 35mm film used to take the image in millimeters. 122 // Returns false if memory allocation fails. 123 virtual bool setFocalLengthIn35mmFilm(float focal_length, 124 float sensor_size_x, float sensor_size_y) = 0; 125 126 // Sets the altitude in meters. 127 // Returns false if memory allocation fails. 128 virtual bool setGpsAltitude(double altitude) = 0; 129 130 // Sets the latitude with degrees minutes seconds format. 131 // Returns false if memory allocation fails. 132 virtual bool setGpsLatitude(double latitude) = 0; 133 134 // Sets the longitude with degrees minutes seconds format. 135 // Returns false if memory allocation fails. 136 virtual bool setGpsLongitude(double longitude) = 0; 137 138 // Sets GPS processing method. 139 // Returns false if memory allocation fails. 140 virtual bool setGpsProcessingMethod(const std::string& method) = 0; 141 142 // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time. 143 // Returns false if memory allocation fails. 144 virtual bool setGpsTimestamp(const struct tm& t) = 0; 145 146 // Sets the height (number of rows) of main image. 147 // Returns false if memory allocation fails. 148 virtual bool setImageHeight(uint32_t length) = 0; 149 150 // Sets the width (number of columns) of main image. 151 // Returns false if memory allocation fails. 152 virtual bool setImageWidth(uint32_t width) = 0; 153 154 // Sets the ISO speed. 155 // Returns false if memory allocation fails. 156 virtual bool setIsoSpeedRating(uint16_t iso_speed_ratings) = 0; 157 158 // Sets the smallest F number of the lens. 159 // Returns false if memory allocation fails. 160 virtual bool setMaxAperture(float aperture) = 0; 161 162 // Sets image orientation. 163 // Returns false if memory allocation fails. 164 virtual bool setOrientation(uint16_t degrees) = 0; 165 166 // Sets image orientation. 167 // Returns false if memory allocation fails. 168 virtual bool setOrientationValue(ExifOrientation orientationValue) = 0; 169 170 // Sets the shutter speed. 171 // Returns false if memory allocation fails. 172 virtual bool setShutterSpeed(float exposure_time) = 0; 173 174 // Sets the distance to the subject, given in meters. 175 // Returns false if memory allocation fails. 176 virtual bool setSubjectDistance(float diopters) = 0; 177 178 // Sets the fractions of seconds for the <DateTime> tag. 179 // Returns false if memory allocation fails. 180 virtual bool setSubsecTime(const std::string& subsec_time) = 0; 181 182 // Sets the white balance mode set when the image was shot. 183 // Returns false if memory allocation fails. 184 virtual bool setWhiteBalance(uint8_t white_blanace) = 0; 185 186 // Generates APP1 segment. 187 // Returns false if generating APP1 segment fails. 188 virtual bool generateApp1() = 0; 189 190 // Gets buffer of APP1 segment. This method must be called only after calling 191 // GenerateAPP1(). 192 virtual const uint8_t* getApp1Buffer() = 0; 193 194 // Gets length of APP1 segment. This method must be called only after calling 195 // GenerateAPP1(). 196 virtual unsigned int getApp1Length() = 0; 197 }; 198 199 } // namespace camera3 200 } // namespace android 201 202 #endif // ANDROID_SERVERS_CAMERA_EXIF_UTILS_H 203